/* Generated by Cython 0.26.1 */

/* BEGIN: Cython Metadata
{
    "distutils": {
        "include_dirs": [
            "/usr/lib/python2.7/dist-packages/numpy/core/include"
        ], 
        "name": "lpu.smt.trans_models.triangulate", 
        "sources": [
            "lpu/smt/trans_models/triangulate.pyx"
        ]
    }, 
    "module_name": "lpu.smt.trans_models.triangulate"
}
END: Cython Metadata */

#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 < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03020000)
    #error Cython requires Python 2.6+ or Python 3.2+.
#else
#define CYTHON_ABI "0_26_1"
#include <stddef.h>
#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
#define __PYX_COMMA ,
#ifndef HAVE_LONG_LONG
  #if PY_VERSION_HEX >= 0x03030000 || (PY_MAJOR_VERSION == 2 && PY_VERSION_HEX >= 0x02070000)
    #define HAVE_LONG_LONG
  #endif
#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_PYSTON 0
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #undef CYTHON_USE_TYPE_SLOTS
  #define CYTHON_USE_TYPE_SLOTS 0
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #undef CYTHON_USE_ASYNC_SLOTS
  #define CYTHON_USE_ASYNC_SLOTS 0
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #undef CYTHON_USE_UNICODE_INTERNALS
  #define CYTHON_USE_UNICODE_INTERNALS 0
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #undef CYTHON_AVOID_BORROWED_REFS
  #define CYTHON_AVOID_BORROWED_REFS 1
  #undef CYTHON_ASSUME_SAFE_MACROS
  #define CYTHON_ASSUME_SAFE_MACROS 0
  #undef CYTHON_UNPACK_METHODS
  #define CYTHON_UNPACK_METHODS 0
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
#elif defined(PYSTON_VERSION)
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_PYSTON 1
  #define CYTHON_COMPILING_IN_CPYTHON 0
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #undef CYTHON_USE_PYTYPE_LOOKUP
  #define CYTHON_USE_PYTYPE_LOOKUP 0
  #undef CYTHON_USE_ASYNC_SLOTS
  #define CYTHON_USE_ASYNC_SLOTS 0
  #undef CYTHON_USE_PYLIST_INTERNALS
  #define CYTHON_USE_PYLIST_INTERNALS 0
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #undef CYTHON_USE_UNICODE_WRITER
  #define CYTHON_USE_UNICODE_WRITER 0
  #undef CYTHON_USE_PYLONG_INTERNALS
  #define CYTHON_USE_PYLONG_INTERNALS 0
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #undef CYTHON_FAST_THREAD_STATE
  #define CYTHON_FAST_THREAD_STATE 0
  #undef CYTHON_FAST_PYCALL
  #define CYTHON_FAST_PYCALL 0
#else
  #define CYTHON_COMPILING_IN_PYPY 0
  #define CYTHON_COMPILING_IN_PYSTON 0
  #define CYTHON_COMPILING_IN_CPYTHON 1
  #ifndef CYTHON_USE_TYPE_SLOTS
    #define CYTHON_USE_TYPE_SLOTS 1
  #endif
  #if PY_VERSION_HEX < 0x02070000
    #undef CYTHON_USE_PYTYPE_LOOKUP
    #define CYTHON_USE_PYTYPE_LOOKUP 0
  #elif !defined(CYTHON_USE_PYTYPE_LOOKUP)
    #define CYTHON_USE_PYTYPE_LOOKUP 1
  #endif
  #if PY_MAJOR_VERSION < 3
    #undef CYTHON_USE_ASYNC_SLOTS
    #define CYTHON_USE_ASYNC_SLOTS 0
  #elif !defined(CYTHON_USE_ASYNC_SLOTS)
    #define CYTHON_USE_ASYNC_SLOTS 1
  #endif
  #if PY_VERSION_HEX < 0x02070000
    #undef CYTHON_USE_PYLONG_INTERNALS
    #define CYTHON_USE_PYLONG_INTERNALS 0
  #elif !defined(CYTHON_USE_PYLONG_INTERNALS)
    #define CYTHON_USE_PYLONG_INTERNALS 1
  #endif
  #ifndef CYTHON_USE_PYLIST_INTERNALS
    #define CYTHON_USE_PYLIST_INTERNALS 1
  #endif
  #ifndef CYTHON_USE_UNICODE_INTERNALS
    #define CYTHON_USE_UNICODE_INTERNALS 1
  #endif
  #if PY_VERSION_HEX < 0x030300F0
    #undef CYTHON_USE_UNICODE_WRITER
    #define CYTHON_USE_UNICODE_WRITER 0
  #elif !defined(CYTHON_USE_UNICODE_WRITER)
    #define CYTHON_USE_UNICODE_WRITER 1
  #endif
  #ifndef CYTHON_AVOID_BORROWED_REFS
    #define CYTHON_AVOID_BORROWED_REFS 0
  #endif
  #ifndef CYTHON_ASSUME_SAFE_MACROS
    #define CYTHON_ASSUME_SAFE_MACROS 1
  #endif
  #ifndef CYTHON_UNPACK_METHODS
    #define CYTHON_UNPACK_METHODS 1
  #endif
  #ifndef CYTHON_FAST_THREAD_STATE
    #define CYTHON_FAST_THREAD_STATE 1
  #endif
  #ifndef CYTHON_FAST_PYCALL
    #define CYTHON_FAST_PYCALL 1
  #endif
#endif
#if !defined(CYTHON_FAST_PYCCALL)
#define CYTHON_FAST_PYCCALL  (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1)
#endif
#if CYTHON_USE_PYLONG_INTERNALS
  #include "longintrepr.h"
  #undef SHIFT
  #undef BASE
  #undef MASK
#endif
#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x02070600 && !defined(Py_OptimizeFlag)
  #define Py_OptimizeFlag 0
#endif
#define __PYX_BUILD_PY_SSIZE_T "n"
#define CYTHON_FORMAT_SSIZE_T "z"
#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+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)
  #define __Pyx_DefaultClassType PyClass_Type
#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)
  #define __Pyx_DefaultClassType PyType_Type
#endif
#ifndef Py_TPFLAGS_CHECKTYPES
  #define Py_TPFLAGS_CHECKTYPES 0
#endif
#ifndef Py_TPFLAGS_HAVE_INDEX
  #define Py_TPFLAGS_HAVE_INDEX 0
#endif
#ifndef Py_TPFLAGS_HAVE_NEWBUFFER
  #define Py_TPFLAGS_HAVE_NEWBUFFER 0
#endif
#ifndef Py_TPFLAGS_HAVE_FINALIZE
  #define Py_TPFLAGS_HAVE_FINALIZE 0
#endif
#if PY_VERSION_HEX < 0x030700A0 || !defined(METH_FASTCALL)
  #ifndef METH_FASTCALL
     #define METH_FASTCALL 0x80
  #endif
  typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject **args, Py_ssize_t nargs);
  typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject **args,
                                                          Py_ssize_t nargs, PyObject *kwnames);
#else
  #define __Pyx_PyCFunctionFast _PyCFunctionFast
  #define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords
#endif
#if CYTHON_FAST_PYCCALL
#define __Pyx_PyFastCFunction_Check(func)\
    ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS)))))
#else
#define __Pyx_PyFastCFunction_Check(func) 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_MAX_CHAR_VALUE(u)   PyUnicode_MAX_CHAR_VALUE(u)
  #define __Pyx_PyUnicode_KIND(u)         PyUnicode_KIND(u)
  #define __Pyx_PyUnicode_DATA(u)         PyUnicode_DATA(u)
  #define __Pyx_PyUnicode_READ(k, d, i)   PyUnicode_READ(k, d, i)
  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  PyUnicode_WRITE(k, d, i, ch)
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u)))
#else
  #define CYTHON_PEP393_ENABLED 0
  #define PyUnicode_1BYTE_KIND  1
  #define PyUnicode_2BYTE_KIND  2
  #define PyUnicode_4BYTE_KIND  4
  #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_MAX_CHAR_VALUE(u)   ((sizeof(Py_UNICODE) == 2) ? 65535 : 1114111)
  #define __Pyx_PyUnicode_KIND(u)         (sizeof(Py_UNICODE))
  #define __Pyx_PyUnicode_DATA(u)         ((void*)PyUnicode_AS_UNICODE(u))
  #define __Pyx_PyUnicode_READ(k, d, i)   ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i]))
  #define __Pyx_PyUnicode_WRITE(k, d, i, ch)  (((void)(k)), ((Py_UNICODE*)d)[i] = ch)
  #define __Pyx_PyUnicode_IS_TRUE(u)      (0 != PyUnicode_GET_SIZE(u))
#endif
#if CYTHON_COMPILING_IN_PYPY
  #define __Pyx_PyUnicode_Concat(a, b)      PyNumber_Add(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  PyNumber_Add(a, b)
#else
  #define __Pyx_PyUnicode_Concat(a, b)      PyUnicode_Concat(a, b)
  #define __Pyx_PyUnicode_ConcatSafe(a, b)  ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\
      PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b))
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyUnicode_Contains)
  #define PyUnicode_Contains(u, s)  PySequence_Contains(u, s)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyByteArray_Check)
  #define PyByteArray_Check(obj)  PyObject_TypeCheck(obj, &PyByteArray_Type)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format)
  #define PyObject_Format(obj, fmt)  PyObject_CallMethod(obj, "__format__", "O", fmt)
#endif
#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc)
  #define PyObject_Malloc(s)   PyMem_Malloc(s)
  #define PyObject_Free(p)     PyMem_Free(p)
  #define PyObject_Realloc(p)  PyMem_Realloc(p)
#endif
#if CYTHON_COMPILING_IN_PYSTON
  #define __Pyx_PyCode_HasFreeVars(co)  PyCode_HasFreeVars(co)
  #define __Pyx_PyFrame_SetLineNumber(frame, lineno) PyFrame_SetLineNumber(frame, lineno)
#else
  #define __Pyx_PyCode_HasFreeVars(co)  (PyCode_GetNumFree(co) > 0)
  #define __Pyx_PyFrame_SetLineNumber(frame, lineno)  (frame)->f_lineno = (lineno)
#endif
#define __Pyx_PyString_FormatSafe(a, b)   ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b))
#define __Pyx_PyUnicode_FormatSafe(a, b)  ((unlikely((a) == Py_None)) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b))
#if PY_MAJOR_VERSION >= 3
  #define __Pyx_PyString_Format(a, b)  PyUnicode_Format(a, b)
#else
  #define __Pyx_PyString_Format(a, b)  PyString_Format(a, b)
#endif
#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII)
  #define PyObject_ASCII(o)            PyObject_Repr(o)
#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_MAJOR_VERSION >= 3
  #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj)
  #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj)
#else
  #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
  #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj))
#endif
#ifndef PySet_CheckExact
  #define PySet_CheckExact(obj)        (Py_TYPE(obj) == &PySet_Type)
#endif
#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type)
#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception)
#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
  #define PyNumber_Int                 PyNumber_Long
#endif
#if PY_MAJOR_VERSION >= 3
  #define PyBoolObject                 PyLongObject
#endif
#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY
  #ifndef PyUnicode_InternFromString
    #define PyUnicode_InternFromString(s) PyUnicode_FromString(s)
  #endif
#endif
#if PY_VERSION_HEX < 0x030200A4
  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
  #define __Pyx_PyMethod_New(func, self, klass) ((self) ? PyMethod_New(func, self) : PyInstanceMethod_New(func))
#else
  #define __Pyx_PyMethod_New(func, self, klass) PyMethod_New(func, self, klass)
#endif
#ifndef __has_attribute
  #define __has_attribute(x) 0
#endif
#ifndef __has_cpp_attribute
  #define __has_cpp_attribute(x) 0
#endif
#if CYTHON_USE_ASYNC_SLOTS
  #if PY_VERSION_HEX >= 0x030500B1
    #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods
    #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async)
  #else
    typedef struct {
        unaryfunc am_await;
        unaryfunc am_aiter;
        unaryfunc am_anext;
    } __Pyx_PyAsyncMethodsStruct;
    #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved))
  #endif
#else
  #define __Pyx_PyType_AsAsync(obj) NULL
#endif
#ifndef CYTHON_RESTRICT
  #if defined(__GNUC__)
    #define CYTHON_RESTRICT __restrict__
  #elif defined(_MSC_VER) && _MSC_VER >= 1400
    #define CYTHON_RESTRICT __restrict
  #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define CYTHON_RESTRICT restrict
  #else
    #define CYTHON_RESTRICT
  #endif
#endif
#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
#ifndef CYTHON_MAYBE_UNUSED_VAR
#  if defined(__cplusplus)
     template<class T> void CYTHON_MAYBE_UNUSED_VAR( const T& ) { }
#  else
#    define CYTHON_MAYBE_UNUSED_VAR(x) (void)(x)
#  endif
#endif
#ifndef CYTHON_NCP_UNUSED
# if CYTHON_COMPILING_IN_CPYTHON
#  define CYTHON_NCP_UNUSED
# else
#  define CYTHON_NCP_UNUSED CYTHON_UNUSED
# endif
#endif
#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None)
#ifdef _MSC_VER
    #ifndef _MSC_STDINT_H_
        #if _MSC_VER < 1300
           typedef unsigned char     uint8_t;
           typedef unsigned int      uint32_t;
        #else
           typedef unsigned __int8   uint8_t;
           typedef unsigned __int32  uint32_t;
        #endif
    #endif
#else
   #include <stdint.h>
#endif
#ifndef CYTHON_FALLTHROUGH
  #ifdef __cplusplus
    #if __has_cpp_attribute(fallthrough)
      #define CYTHON_FALLTHROUGH [[fallthrough]]
    #elif __has_cpp_attribute(clang::fallthrough)
      #define CYTHON_FALLTHROUGH [[clang::fallthrough]]
    #endif
  #endif
  #ifndef CYTHON_FALLTHROUGH
    #if __has_attribute(fallthrough) || (defined(__GNUC__) && defined(__attribute__))
      #define CYTHON_FALLTHROUGH __attribute__((fallthrough))
    #else
      #define CYTHON_FALLTHROUGH
    #endif
  #endif
#endif

#ifndef CYTHON_INLINE
  #if defined(__clang__)
    #define CYTHON_INLINE __inline__ __attribute__ ((__unused__))
  #elif 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

#if defined(WIN32) || defined(MS_WINDOWS)
  #define _USE_MATH_DEFINES
#endif
#include <math.h>
#ifdef NAN
#define __PYX_NAN() ((float) NAN)
#else
static CYTHON_INLINE float __PYX_NAN() {
  float value;
  memset(&value, 0xFF, sizeof(value));
  return value;
}
#endif
#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL)
#define __Pyx_truncl trunc
#else
#define __Pyx_truncl truncl
#endif


#define __PYX_ERR(f_index, lineno, Ln_error) \
{ \
  __pyx_filename = __pyx_f[f_index]; __pyx_lineno = lineno; __pyx_clineno = __LINE__; goto Ln_error; \
}

#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

#define __PYX_HAVE__lpu__smt__trans_models__triangulate
#define __PYX_HAVE_API__lpu__smt__trans_models__triangulate
#ifdef _OPENMP
#include <omp.h>
#endif /* _OPENMP */

#ifdef PYREX_WITHOUT_ASSERTIONS
#define CYTHON_WITHOUT_ASSERTIONS
#endif

typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding;
                const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry;

#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0
#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0
#define __PYX_DEFAULT_STRING_ENCODING ""
#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString
#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#define __Pyx_uchar_cast(c) ((unsigned char)c)
#define __Pyx_long_cast(x) ((long)x)
#define __Pyx_fits_Py_ssize_t(v, type, is_signed)  (\
    (sizeof(type) < sizeof(Py_ssize_t))  ||\
    (sizeof(type) > sizeof(Py_ssize_t) &&\
          likely(v < (type)PY_SSIZE_T_MAX ||\
                 v == (type)PY_SSIZE_T_MAX)  &&\
          (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\
                                v == (type)PY_SSIZE_T_MIN)))  ||\
    (sizeof(type) == sizeof(Py_ssize_t) &&\
          (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\
                               v == (type)PY_SSIZE_T_MAX)))  )
#if defined (__cplusplus) && __cplusplus >= 201103L
    #include <cstdlib>
    #define __Pyx_sst_abs(value) std::abs(value)
#elif SIZEOF_INT >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) abs(value)
#elif SIZEOF_LONG >= SIZEOF_SIZE_T
    #define __Pyx_sst_abs(value) labs(value)
#elif defined (_MSC_VER) && defined (_M_X64)
    #define __Pyx_sst_abs(value) _abs64(value)
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
    #define __Pyx_sst_abs(value) llabs(value)
#elif defined (__GNUC__)
    #define __Pyx_sst_abs(value) __builtin_llabs(value)
#else
    #define __Pyx_sst_abs(value) ((value<0) ? -value : value)
#endif
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length);
#define __Pyx_PyByteArray_FromString(s) PyByteArray_FromStringAndSize((const char*)s, strlen((const char*)s))
#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l)
#define __Pyx_PyBytes_FromString        PyBytes_FromString
#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize
static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*);
#if PY_MAJOR_VERSION < 3
    #define __Pyx_PyStr_FromString        __Pyx_PyBytes_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize
#else
    #define __Pyx_PyStr_FromString        __Pyx_PyUnicode_FromString
    #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize
#endif
#define __Pyx_PyObject_AsWritableString(s)    ((char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableSString(s)    ((signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsWritableUString(s)    ((unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsSString(s)    ((const signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsUString(s)    ((const unsigned char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_FromCString(s)  __Pyx_PyObject_FromString((const char*)s)
#define __Pyx_PyBytes_FromCString(s)   __Pyx_PyBytes_FromString((const char*)s)
#define __Pyx_PyByteArray_FromCString(s)   __Pyx_PyByteArray_FromString((const char*)s)
#define __Pyx_PyStr_FromCString(s)     __Pyx_PyStr_FromString((const char*)s)
#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s)
#if PY_MAJOR_VERSION < 3
static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u)
{
    const Py_UNICODE *u_end = u;
    while (*u_end++) ;
    return (size_t)(u_end - u - 1);
}
#else
#define __Pyx_Py_UNICODE_strlen Py_UNICODE_strlen
#endif
#define __Pyx_PyUnicode_FromUnicode(u)       PyUnicode_FromUnicode(u, __Pyx_Py_UNICODE_strlen(u))
#define __Pyx_PyUnicode_FromUnicodeAndLength PyUnicode_FromUnicode
#define __Pyx_PyUnicode_AsUnicode            PyUnicode_AsUnicode
#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj)
#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None)
#define __Pyx_PyBool_FromLong(b) ((b) ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False))
static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*);
static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x);
static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*);
static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t);
#if CYTHON_ASSUME_SAFE_MACROS
#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))
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x))
#else
#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x))
#endif
#define __Pyx_PyNumber_Float(x) (PyFloat_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Float(x))
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
static int __Pyx_sys_getdefaultencoding_not_ascii;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    PyObject* ascii_chars_u = NULL;
    PyObject* ascii_chars_b = NULL;
    const char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    if (strcmp(default_encoding_c, "ascii") == 0) {
        __Pyx_sys_getdefaultencoding_not_ascii = 0;
    } else {
        char ascii_chars[128];
        int c;
        for (c = 0; c < 128; c++) {
            ascii_chars[c] = c;
        }
        __Pyx_sys_getdefaultencoding_not_ascii = 1;
        ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL);
        if (!ascii_chars_u) goto bad;
        ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL);
        if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) {
            PyErr_Format(
                PyExc_ValueError,
                "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.",
                default_encoding_c);
            goto bad;
        }
        Py_DECREF(ascii_chars_u);
        Py_DECREF(ascii_chars_b);
    }
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    Py_XDECREF(ascii_chars_u);
    Py_XDECREF(ascii_chars_b);
    return -1;
}
#endif
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL)
#else
#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL)
#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT
static char* __PYX_DEFAULT_STRING_ENCODING;
static int __Pyx_init_sys_getdefaultencoding_params(void) {
    PyObject* sys;
    PyObject* default_encoding = NULL;
    char* default_encoding_c;
    sys = PyImport_ImportModule("sys");
    if (!sys) goto bad;
    default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL);
    Py_DECREF(sys);
    if (!default_encoding) goto bad;
    default_encoding_c = PyBytes_AsString(default_encoding);
    if (!default_encoding_c) goto bad;
    __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c));
    if (!__PYX_DEFAULT_STRING_ENCODING) goto bad;
    strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c);
    Py_DECREF(default_encoding);
    return 0;
bad:
    Py_XDECREF(default_encoding);
    return -1;
}
#endif
#endif


/* Test for GCC > 2.95 */
#if defined(__GNUC__)     && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95)))
  #define likely(x)   __builtin_expect(!!(x), 1)
  #define unlikely(x) __builtin_expect(!!(x), 0)
#else /* !__GNUC__ or GCC < 2.95 */
  #define likely(x)   (x)
  #define unlikely(x) (x)
#endif /* __GNUC__ */
static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; }

static PyObject *__pyx_m;
static PyObject *__pyx_d;
static PyObject *__pyx_b;
static PyObject *__pyx_cython_runtime;
static PyObject *__pyx_empty_tuple;
static PyObject *__pyx_empty_bytes;
static PyObject *__pyx_empty_unicode;
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[] = {
  "lpu/smt/trans_models/triangulate.pyx",
};

/*--- Type declarations ---*/

/* --- Runtime support code (head) --- */
/* Refnanny.proto */
#ifndef CYTHON_REFNANNY
  #define CYTHON_REFNANNY 0
#endif
#if CYTHON_REFNANNY
  typedef struct {
    void (*INCREF)(void*, PyObject*, int);
    void (*DECREF)(void*, PyObject*, int);
    void (*GOTREF)(void*, PyObject*, int);
    void (*GIVEREF)(void*, PyObject*, int);
    void* (*SetupContext)(const char*, int, const char*);
    void (*FinishContext)(void**);
  } __Pyx_RefNannyAPIStruct;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL;
  static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname);
  #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL;
#ifdef WITH_THREAD
  #define __Pyx_RefNannySetupContext(name, acquire_gil)\
          if (acquire_gil) {\
              PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\
              __pyx_refnanny = __Pyx_RefNanny->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
#define __Pyx_XDECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_XDECREF(tmp);\
    } while (0)
#define __Pyx_DECREF_SET(r, v) do {\
        PyObject *tmp = (PyObject *) r;\
        r = v; __Pyx_DECREF(tmp);\
    } while (0)
#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)

/* PyObjectGetAttrStr.proto */
#if CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_getattro))
        return tp->tp_getattro(obj, attr_name);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_getattr))
        return tp->tp_getattr(obj, PyString_AS_STRING(attr_name));
#endif
    return PyObject_GetAttr(obj, attr_name);
}
#else
#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n)
#endif

/* GetBuiltinName.proto */
static PyObject *__Pyx_GetBuiltinName(PyObject *name);

/* RaiseArgTupleInvalid.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);

/* RaiseDoubleKeywords.proto */
static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name);

/* ParseKeywords.proto */
static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject **argnames[],\
    PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args,\
    const char* function_name);

/* dict_getitem_default.proto */
static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value);

/* PyObjectSetAttrStr.proto */
#if CYTHON_USE_TYPE_SLOTS
#define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o,n,NULL)
static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) {
    PyTypeObject* tp = Py_TYPE(obj);
    if (likely(tp->tp_setattro))
        return tp->tp_setattro(obj, attr_name, value);
#if PY_MAJOR_VERSION < 3
    if (likely(tp->tp_setattr))
        return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value);
#endif
    return PyObject_SetAttr(obj, attr_name, value);
}
#else
#define __Pyx_PyObject_DelAttrStr(o,n)   PyObject_DelAttr(o,n)
#define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v)
#endif

/* GetModuleGlobalName.proto */
static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name);

/* PyFunctionFastCall.proto */
#if CYTHON_FAST_PYCALL
#define __Pyx_PyFunction_FastCall(func, args, nargs)\
    __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL)
#if 1 || PY_VERSION_HEX < 0x030600B1
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs);
#else
#define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs)
#endif
#endif

/* PyCFunctionFastCall.proto */
#if CYTHON_FAST_PYCCALL
static CYTHON_INLINE PyObject *__Pyx_PyCFunction_FastCall(PyObject *func, PyObject **args, Py_ssize_t nargs);
#else
#define __Pyx_PyCFunction_FastCall(func, args, nargs)  (assert(0), NULL)
#endif

/* PyObjectCall.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw);
#else
#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw)
#endif

/* PyObjectCallMethO.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg);
#endif

/* PyObjectCallOneArg.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg);

/* PyObjectCallNoArg.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func);
#else
#define __Pyx_PyObject_CallNoArg(func) __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL)
#endif

/* GetItemInt.proto */
#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\
    (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\
               __Pyx_GetItemInt_Generic(o, to_py_func(i))))
#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\
    (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL))
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              int wraparound, int boundscheck);
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j);
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i,
                                                     int is_list, int wraparound, int boundscheck);

/* IncludeStringH.proto */
#include <string.h>

/* BytesEquals.proto */
static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals);

/* UnicodeEquals.proto */
static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals);

/* StrEquals.proto */
#if PY_MAJOR_VERSION >= 3
#define __Pyx_PyString_Equals __Pyx_PyUnicode_Equals
#else
#define __Pyx_PyString_Equals __Pyx_PyBytes_Equals
#endif

/* SliceObject.proto */
static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(
        PyObject* obj, Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** py_start, PyObject** py_stop, PyObject** py_slice,
        int has_cstart, int has_cstop, int wraparound);

/* StringJoin.proto */
#if PY_MAJOR_VERSION < 3
#define __Pyx_PyString_Join __Pyx_PyBytes_Join
#define __Pyx_PyBaseString_Join(s, v) (PyUnicode_CheckExact(s) ? PyUnicode_Join(s, v) : __Pyx_PyBytes_Join(s, v))
#else
#define __Pyx_PyString_Join PyUnicode_Join
#define __Pyx_PyBaseString_Join PyUnicode_Join
#endif
#if CYTHON_COMPILING_IN_CPYTHON
    #if PY_MAJOR_VERSION < 3
    #define __Pyx_PyBytes_Join _PyString_Join
    #else
    #define __Pyx_PyBytes_Join _PyBytes_Join
    #endif
#else
static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values);
#endif

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddCObj(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_AddCObj(op1, op2, intval, inplace)\
    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
#endif

/* PySequenceContains.proto */
static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) {
    int result = PySequence_Contains(seq, item);
    return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
}

/* RaiseTooManyValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected);

/* RaiseNeedMoreValuesToUnpack.proto */
static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index);

/* IterFinish.proto */
static CYTHON_INLINE int __Pyx_IterFinish(void);

/* UnpackItemEndCheck.proto */
static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected);

/* ListAppend.proto */
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
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) & likely(len > (L->allocated >> 1))) {
        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

/* PyObjectCallMethod1.proto */
static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg);

/* append.proto */
static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x);

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_EqObjC(op1, op2, intval, inplace)\
    PyObject_RichCompare(op1, op2, Py_EQ)
    #endif

/* PyDictContains.proto */
static CYTHON_INLINE int __Pyx_PyDict_ContainsTF(PyObject* item, PyObject* dict, int eq) {
    int result = PyDict_Contains(dict, item);
    return unlikely(result < 0) ? result : (result == (eq == Py_EQ));
}

/* DictGetItem.proto */
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) {
    PyObject *value;
    value = PyDict_GetItemWithError(d, key);
    if (unlikely(!value)) {
        if (!PyErr_Occurred()) {
            PyObject* args = PyTuple_Pack(1, key);
            if (likely(args))
                PyErr_SetObject(PyExc_KeyError, args);
            Py_XDECREF(args);
        }
        return NULL;
    }
    Py_INCREF(value);
    return value;
}
#else
    #define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key)
#endif

/* None.proto */
static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname);

/* py_dict_items.proto */
static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d);

/* UnpackUnboundCMethod.proto */
typedef struct {
    PyObject *type;
    PyObject **method_name;
    PyCFunction func;
    PyObject *method;
    int flag;
} __Pyx_CachedCFunction;

/* CallUnboundCMethod0.proto */
static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self);
#if CYTHON_COMPILING_IN_CPYTHON
#define __Pyx_CallUnboundCMethod0(cfunc, self)\
    ((likely((cfunc)->func)) ?\
        (likely((cfunc)->flag == METH_NOARGS) ?  (*((cfunc)->func))(self, NULL) :\
         (likely((cfunc)->flag == (METH_VARARGS | METH_KEYWORDS)) ?  ((*(PyCFunctionWithKeywords)(cfunc)->func)(self, __pyx_empty_tuple, NULL)) :\
             ((cfunc)->flag == METH_VARARGS ?  (*((cfunc)->func))(self, __pyx_empty_tuple) :\
              (PY_VERSION_HEX >= 0x030600B1 && (cfunc)->flag == METH_FASTCALL ?\
                (PY_VERSION_HEX >= 0x030700A0 ?\
                    (*(__Pyx_PyCFunctionFast)(cfunc)->func)(self, &PyTuple_GET_ITEM(__pyx_empty_tuple, 0), 0) :\
                    (*(__Pyx_PyCFunctionFastWithKeywords)(cfunc)->func)(self, &PyTuple_GET_ITEM(__pyx_empty_tuple, 0), 0, NULL)) :\
              (PY_VERSION_HEX >= 0x030700A0 && (cfunc)->flag == (METH_FASTCALL | METH_KEYWORDS) ?\
                    (*(__Pyx_PyCFunctionFastWithKeywords)(cfunc)->func)(self, &PyTuple_GET_ITEM(__pyx_empty_tuple, 0), 0, NULL) :\
                    __Pyx__CallUnboundCMethod0(cfunc, self)))))) :\
        __Pyx__CallUnboundCMethod0(cfunc, self))
#else
#define __Pyx_CallUnboundCMethod0(cfunc, self)  __Pyx__CallUnboundCMethod0(cfunc, self)
#endif

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_SubtractCObj(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_SubtractCObj(op1, op2, intval, inplace)\
    (inplace ? PyNumber_InPlaceSubtract(op1, op2) : PyNumber_Subtract(op1, op2))
#endif

/* SliceTupleAndList.proto */
#if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop);
static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice(PyObject* src, Py_ssize_t start, Py_ssize_t stop);
#else
#define __Pyx_PyList_GetSlice(seq, start, stop)   PySequence_GetSlice(seq, start, stop)
#define __Pyx_PyTuple_GetSlice(seq, start, stop)  PySequence_GetSlice(seq, start, stop)
#endif

/* py_dict_values.proto */
static CYTHON_INLINE PyObject* __Pyx_PyDict_Values(PyObject* d);

/* PyObjectCallMethod2.proto */
static PyObject* __Pyx_PyObject_CallMethod2(PyObject* obj, PyObject* method_name, PyObject* arg1, PyObject* arg2);

/* dict_setdefault.proto */
static CYTHON_INLINE PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *default_value, int is_safe_type);

/* py_dict_keys.proto */
static CYTHON_INLINE PyObject* __Pyx_PyDict_Keys(PyObject* d);

/* PyIntBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace);
#else
#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace)\
    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
#endif

/* pyobject_as_double.proto */
static double __Pyx__PyObject_AsDouble(PyObject* obj);
#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

/* PyObjectLookupSpecial.proto */
#if CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS
static CYTHON_INLINE PyObject* __Pyx_PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name) {
    PyObject *res;
    PyTypeObject *tp = Py_TYPE(obj);
#if PY_MAJOR_VERSION < 3
    if (unlikely(PyInstance_Check(obj)))
        return __Pyx_PyObject_GetAttrStr(obj, attr_name);
#endif
    res = _PyType_Lookup(tp, attr_name);
    if (likely(res)) {
        descrgetfunc f = Py_TYPE(res)->tp_descr_get;
        if (!f) {
            Py_INCREF(res);
        } else {
            res = f(res, obj, (PyObject *)tp);
        }
    } else {
        PyErr_SetObject(PyExc_AttributeError, attr_name);
    }
    return res;
}
#else
#define __Pyx_PyObject_LookupSpecial(o,n) __Pyx_PyObject_GetAttrStr(o,n)
#endif

/* PyThreadStateGet.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyThreadState_declare  PyThreadState *__pyx_tstate;
#define __Pyx_PyThreadState_assign  __pyx_tstate = PyThreadState_GET();
#else
#define __Pyx_PyThreadState_declare
#define __Pyx_PyThreadState_assign
#endif

/* SaveResetException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_ExceptionSave(type, value, tb)  __Pyx__ExceptionSave(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#define __Pyx_ExceptionReset(type, value, tb)  __Pyx__ExceptionReset(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
#else
#define __Pyx_ExceptionSave(type, value, tb)   PyErr_GetExcInfo(type, value, tb)
#define __Pyx_ExceptionReset(type, value, tb)  PyErr_SetExcInfo(type, value, tb)
#endif

/* GetException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_GetException(type, value, tb)  __Pyx__GetException(__pyx_tstate, type, value, tb)
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb);
#endif

/* PyErrFetchRestore.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_ErrRestoreWithState(type, value, tb)  __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)    __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)    __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb);
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
#define __Pyx_ErrRestoreWithState(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetchWithState(type, value, tb)  PyErr_Fetch(type, value, tb)
#define __Pyx_ErrRestore(type, value, tb)  PyErr_Restore(type, value, tb)
#define __Pyx_ErrFetch(type, value, tb)  PyErr_Fetch(type, value, tb)
#endif

/* PyErrExceptionMatches.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err)
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err);
#else
#define __Pyx_PyErr_ExceptionMatches(err)  PyErr_ExceptionMatches(err)
#endif

/* Import.proto */
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level);

/* ImportFrom.proto */
static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name);

/* FetchCommonType.proto */
static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type);

/* CythonFunction.proto */
#define __Pyx_CyFunction_USED 1
#include <structmember.h>
#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;
#if PY_VERSION_HEX < 0x030500A0
    PyObject *func_weakreflist;
#endif
    PyObject *func_dict;
    PyObject *func_name;
    PyObject *func_qualname;
    PyObject *func_doc;
    PyObject *func_globals;
    PyObject *func_code;
    PyObject *func_closure;
    PyObject *func_classobj;
    void *defaults;
    int defaults_pyobjects;
    int flags;
    PyObject *defaults_tuple;
    PyObject *defaults_kwdict;
    PyObject *(*defaults_getter)(PyObject *);
    PyObject *func_annotations;
} __pyx_CyFunctionObject;
static PyTypeObject *__pyx_CyFunctionType = 0;
#define __Pyx_CyFunction_NewEx(ml, flags, qualname, self, module, globals, code)\
    __Pyx_CyFunction_New(__pyx_CyFunctionType, ml, flags, qualname, self, module, globals, code)
static PyObject *__Pyx_CyFunction_New(PyTypeObject *, PyMethodDef *ml,
                                      int flags, PyObject* qualname,
                                      PyObject *self,
                                      PyObject *module, PyObject *globals,
                                      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 CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m,
                                                             PyObject *dict);
static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m,
                                                              PyObject *dict);
static int __pyx_CyFunction_init(void);

/* CalculateMetaclass.proto */
static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases);

/* Py3ClassCreate.proto */
static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, PyObject *qualname,
                                           PyObject *mkw, PyObject *modname, PyObject *doc);
static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, PyObject *dict,
                                      PyObject *mkw, int calculate_metaclass, int allow_py2_metaclass);

/* CLineInTraceback.proto */
static int __Pyx_CLineForTraceback(int c_line);

/* CodeObjectCache.proto */
typedef struct {
    PyCodeObject* code_object;
    int code_line;
} __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);

/* AddTraceback.proto */
static void __Pyx_AddTraceback(const char *funcname, int c_line,
                               int py_line, const char *filename);

/* None.proto */
static CYTHON_INLINE long __Pyx_pow_long(long, long);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value);

/* Print.proto */
static int __Pyx_Print(PyObject*, PyObject *, int);
#if CYTHON_COMPILING_IN_PYPY || PY_MAJOR_VERSION >= 3
static PyObject* __pyx_print = 0;
static PyObject* __pyx_print_kwargs = 0;
#endif

/* PrintOne.proto */
static int __Pyx_PrintOne(PyObject* stream, PyObject *o);

/* CIntFromPy.proto */
static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *);

/* CIntFromPy.proto */
static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *);

/* CheckBinaryVersion.proto */
static int __Pyx_check_binary_version(void);

/* InitStrings.proto */
static int __Pyx_InitStrings(__Pyx_StringTabEntry *t);


/* Module declarations from 'lpu.smt.trans_models.triangulate' */
#define __Pyx_MODULE_NAME "lpu.smt.trans_models.triangulate"
int __pyx_module_is_main_lpu__smt__trans_models__triangulate = 0;

/* Implementation of 'lpu.smt.trans_models.triangulate' */
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_open;
static PyObject *__pyx_builtin_KeyboardInterrupt;
static PyObject *__pyx_builtin_vars;
static const char __pyx_k_0[] = "0";
static const char __pyx_k_1[] = "1";
static const char __pyx_k_c[] = "c";
static const char __pyx_k_p[] = "p";
static const char __pyx_k_r[] = "r";
static const char __pyx_k_s[] = "\t* \"%s\"\n";
static const char __pyx_k_w[] = "w";
static const char __pyx_k_0w[] = "0w";
static const char __pyx_k_1w[] = "1w";
static const char __pyx_k__3[] = " ";
static const char __pyx_k__8[] = "(";
static const char __pyx_k__9[] = ")";
static const char __pyx_k_co[] = "co";
static const char __pyx_k_wt[] = "wt";
static const char __pyx_k_COL[] = " |COL| ";
static const char __pyx_k__16[] = "";
static const char __pyx_k__17[] = " |||";
static const char __pyx_k__20[] = "\n";
static const char __pyx_k__25[] = ".";
static const char __pyx_k__28[] = "--\n";
static const char __pyx_k__75[] = "_";
static const char __pyx_k_add[] = "add";
static const char __pyx_k_co1[] = "co1";
static const char __pyx_k_co2[] = "co2";
static const char __pyx_k_d_d[] = "%d-%d";
static const char __pyx_k_del[] = "__del__";
static const char __pyx_k_div[] = "div";
static const char __pyx_k_doc[] = "__doc__";
static const char __pyx_k_end[] = "end";
static const char __pyx_k_exp[] = "exp";
static const char __pyx_k_get[] = "get";
static const char __pyx_k_key[] = "key";
static const char __pyx_k_log[] = "log";
static const char __pyx_k_p_2[] = "-p";
static const char __pyx_k_rec[] = "rec";
static const char __pyx_k_s_s[] = "%s ||| %s |||";
static const char __pyx_k_src[] = "src";
static const char __pyx_k_sys[] = "sys";
static const char __pyx_k_trg[] = "trg";
static const char __pyx_k_NULL[] = "NULL";
static const char __pyx_k_args[] = "args";
static const char __pyx_k_cooc[] = "cooc";
static const char __pyx_k_dist[] = "dist";
static const char __pyx_k_egfl[] = "egfl";
static const char __pyx_k_egfp[] = "egfp";
static const char __pyx_k_exit[] = "__exit__";
static const char __pyx_k_fgel[] = "fgel";
static const char __pyx_k_fgep[] = "fgep";
static const char __pyx_k_file[] = "file";
static const char __pyx_k_find[] = "find";
static const char __pyx_k_fobj[] = "fobj";
static const char __pyx_k_help[] = "help";
static const char __pyx_k_init[] = "__init__";
static const char __pyx_k_join[] = "join";
static const char __pyx_k_keys[] = "keys";
static const char __pyx_k_line[] = "line";
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_math[] = "math";
static const char __pyx_k_name[] = "__name__";
static const char __pyx_k_open[] = "open";
static const char __pyx_k_rate[] = "rate";
static const char __pyx_k_rows[] = "rows";
static const char __pyx_k_rule[] = "rule";
static const char __pyx_k_self[] = "self";
static const char __pyx_k_sort[] = "sort";
static const char __pyx_k_sqrt[] = "sqrt";
static const char __pyx_k_term[] = "term";
static const char __pyx_k_test[] = "__test__";
static const char __pyx_k_type[] = "type";
static const char __pyx_k_vars[] = "vars";
static const char __pyx_k_view[] = "view";
static const char __pyx_k_word[] = "word";
static const char __pyx_k_0egfl[] = "0egfl";
static const char __pyx_k_0egfp[] = "0egfp";
static const char __pyx_k_0fgel[] = "0fgel";
static const char __pyx_k_0fgep[] = "0fgep";
static const char __pyx_k_1fgep[] = "1fgep";
static const char __pyx_k_COL_2[] = " |COL|";
static const char __pyx_k_COL_3[] = "|COL|";
static const char __pyx_k_NBEST[] = "NBEST";
static const char __pyx_k_NULLS[] = "NULLS";
static const char __pyx_k_Table[] = "Table";
static const char __pyx_k_align[] = "align";
static const char __pyx_k_close[] = "close";
static const char __pyx_k_coMax[] = "coMax";
static const char __pyx_k_cooc1[] = "cooc1";
static const char __pyx_k_cooc2[] = "cooc2";
static const char __pyx_k_debug[] = "debug";
static const char __pyx_k_enter[] = "__enter__";
static const char __pyx_k_files[] = "files";
static const char __pyx_k_flush[] = "flush";
static const char __pyx_k_hiero[] = "hiero";
static const char __pyx_k_items[] = "items";
static const char __pyx_k_log_2[] = "--log";
static const char __pyx_k_multi[] = "multi";
static const char __pyx_k_nbest[] = "nbest";
static const char __pyx_k_nulls[] = "nulls";
static const char __pyx_k_pivot[] = "pivot";
static const char __pyx_k_print[] = "print";
static const char __pyx_k_range[] = "range";
static const char __pyx_k_s_s_2[] = "%s = %s\n";
static const char __pyx_k_split[] = "split";
static const char __pyx_k_table[] = "table";
static const char __pyx_k_total[] = "total";
static const char __pyx_k_tree1[] = "tree1";
static const char __pyx_k_tree2[] = "tree2";
static const char __pyx_k_trees[] = "trees";
static const char __pyx_k_write[] = "write";
static const char __pyx_k_METHOD[] = "METHOD";
static const char __pyx_k_Record[] = "Record";
static const char __pyx_k_action[] = "action";
static const char __pyx_k_aligns[] = "aligns";
static const char __pyx_k_append[] = "append";
static const char __pyx_k_compat[] = "compat";
static const char __pyx_k_counts[] = "counts";
static const char __pyx_k_elems1[] = "elems1";
static const char __pyx_k_elems2[] = "elems2";
static const char __pyx_k_exit_2[] = "exit";
static const char __pyx_k_import[] = "__import__";
static const char __pyx_k_main_2[] = "main";
static const char __pyx_k_method[] = "method";
static const char __pyx_k_module[] = "__module__";
static const char __pyx_k_parser[] = "parser";
static const char __pyx_k_phrase[] = "phrase";
static const char __pyx_k_prefix[] = "prefix";
static const char __pyx_k_scores[] = "scores";
static const char __pyx_k_table1[] = "table1";
static const char __pyx_k_table2[] = "table2";
static const char __pyx_k_to_str[] = "to_str";
static const char __pyx_k_trgKey[] = "trgKey";
static const char __pyx_k_values[] = "values";
static const char __pyx_k_MINPROB[] = "MINPROB";
static const char __pyx_k_WorkSet[] = "WorkSet";
static const char __pyx_k_addPair[] = "addPair";
static const char __pyx_k_choices[] = "choices";
static const char __pyx_k_counts1[] = "counts1";
static const char __pyx_k_counts2[] = "counts2";
static const char __pyx_k_default[] = "default";
static const char __pyx_k_fileObj[] = "fileObj";
static const char __pyx_k_lastSrc[] = "lastSrc";
static const char __pyx_k_lexProb[] = "lexProb";
static const char __pyx_k_logFile[] = "logFile";
static const char __pyx_k_logging[] = "logging";
static const char __pyx_k_minProb[] = "minProb";
static const char __pyx_k_nbest_2[] = "--nbest";
static const char __pyx_k_nulls_2[] = "--nulls";
static const char __pyx_k_options[] = "options";
static const char __pyx_k_prepare[] = "__prepare__";
static const char __pyx_k_recPair[] = "recPair";
static const char __pyx_k_records[] = "records";
static const char __pyx_k_reverse[] = "reverse";
static const char __pyx_k_srcTerm[] = "srcTerm";
static const char __pyx_k_srcWord[] = "srcWord";
static const char __pyx_k_symbols[] = "symbols";
static const char __pyx_k_trgPair[] = "trgPair";
static const char __pyx_k_trgProb[] = "trgProb";
static const char __pyx_k_trgTerm[] = "trgTerm";
static const char __pyx_k_workdir[] = "workdir";
static const char __pyx_k_workset[] = "workset";
static const char __pyx_k_alignMap[] = "alignMap";
static const char __pyx_k_alignlex[] = "alignlex";
static const char __pyx_k_argparse[] = "argparse";
static const char __pyx_k_bidiravr[] = "bidiravr";
static const char __pyx_k_bidirmax[] = "bidirmax";
static const char __pyx_k_bidirmin[] = "bidirmin";
static const char __pyx_k_countmin[] = "countmin";
static const char __pyx_k_features[] = "features";
static const char __pyx_k_find_src[] = "find_src";
static const char __pyx_k_ignoring[] = "ignoring";
static const char __pyx_k_key_type[] = "key_type";
static const char __pyx_k_method_2[] = "--method";
static const char __pyx_k_multiKey[] = "multiKey";
static const char __pyx_k_multiRec[] = "multiRec";
static const char __pyx_k_numElems[] = "numElems";
static const char __pyx_k_numNulls[] = "numNulls";
static const char __pyx_k_numTerms[] = "numTerms";
static const char __pyx_k_prodprob[] = "prodprob";
static const char __pyx_k_progress[] = "progress";
static const char __pyx_k_pvtIndex[] = "pvtIndex";
static const char __pyx_k_qualname[] = "__qualname__";
static const char __pyx_k_recMulti[] = "recMulti";
static const char __pyx_k_recPivot[] = "recPivot";
static const char __pyx_k_saveFile[] = "saveFile";
static const char __pyx_k_savePath[] = "savePath";
static const char __pyx_k_savefile[] = "savefile";
static const char __pyx_k_srcCount[] = "srcCount";
static const char __pyx_k_srcIndex[] = "srcIndex";
static const char __pyx_k_srcTerms[] = "srcTerms";
static const char __pyx_k_treecomp[] = "treecomp";
static const char __pyx_k_treedist[] = "treedist";
static const char __pyx_k_trgIndex[] = "trgIndex";
static const char __pyx_k_trgTerms[] = "trgTerms";
static const char __pyx_k_THRESHOLD[] = "THRESHOLD";
static const char __pyx_k_foutPivot[] = "foutPivot";
static const char __pyx_k_lexCounts[] = "lexCounts";
static const char __pyx_k_lexMethod[] = "lexMethod";
static const char __pyx_k_lexWeight[] = "lexWeight";
static const char __pyx_k_lexmethod[] = "lexmethod";
static const char __pyx_k_loading_s[] = "loading: %s";
static const char __pyx_k_max_count[] = "max_count";
static const char __pyx_k_metaclass[] = "__metaclass__";
static const char __pyx_k_multiList[] = "multiList";
static const char __pyx_k_recPvtTrg[] = "recPvtTrg";
static const char __pyx_k_recSrcPvt[] = "recSrcPvt";
static const char __pyx_k_srcCounts[] = "srcCounts";
static const char __pyx_k_src_hiero[] = "src_hiero";
static const char __pyx_k_threshold[] = "threshold";
static const char __pyx_k_trgCounts[] = "trgCounts";
static const char __pyx_k_workdir_2[] = "--workdir";
static const char __pyx_k_LEX_METHOD[] = "LEX_METHOD";
static const char __pyx_k_Lost_Words[] = "Lost Words:\n";
static const char __pyx_k_alignlex_2[] = "--alignlex";
static const char __pyx_k_bidirgmean[] = "bidirgmean";
static const char __pyx_k_featureKey[] = "featureKey";
static const char __pyx_k_lpu_common[] = "lpu.common";
static const char __pyx_k_memoryless[] = "memoryless";
static const char __pyx_k_newRecords[] = "newRecords";
static const char __pyx_k_parse_args[] = "parse_args";
static const char __pyx_k_processing[] = "processing";
static const char __pyx_k_prodweight[] = "prodweight";
static const char __pyx_k_progress_2[] = "--progress";
static const char __pyx_k_pvtIndices[] = "pvtIndices";
static const char __pyx_k_recordList[] = "recordList";
static const char __pyx_k_setdefault[] = "setdefault";
static const char __pyx_k_srcIndices[] = "srcIndices";
static const char __pyx_k_store_true[] = "store_true";
static const char __pyx_k_table_file[] = "table_file";
static const char __pyx_k_table_path[] = "table_path";
static const char __pyx_k_trgSumProb[] = "trgSumProb";
static const char __pyx_k_trgSymbols[] = "trgSymbols";
static const char __pyx_k_MosesRecord[] = "MosesRecord";
static const char __pyx_k_NOPREFILTER[] = "NOPREFILTER";
static const char __pyx_k_RecordClass[] = "RecordClass";
static const char __pyx_k_alignMapRev[] = "alignMapRev";
static const char __pyx_k_bestRecords[] = "bestRecords";
static const char __pyx_k_calcLexProb[] = "calcLexProb";
static const char __pyx_k_description[] = "description";
static const char __pyx_k_independent[] = "independent";
static const char __pyx_k_jointMethod[] = "jointMethod";
static const char __pyx_k_jointmethod[] = "jointmethod";
static const char __pyx_k_lexmethod_2[] = "--lexmethod";
static const char __pyx_k_matchMethod[] = "matchMethod";
static const char __pyx_k_matchmethod[] = "matchmethod";
static const char __pyx_k_mergeAligns[] = "mergeAligns";
static const char __pyx_k_method_list[] = "method_list";
static const char __pyx_k_multitarget[] = "multitarget";
static const char __pyx_k_noprefilter[] = "--noprefilter";
static const char __pyx_k_srcFeatures[] = "srcFeatures";
static const char __pyx_k_src_symbols[] = "src_symbols";
static const char __pyx_k_strMultiTrg[] = "strMultiTrg";
static const char __pyx_k_tablePvtTrg[] = "tablePvtTrg";
static const char __pyx_k_tableSrcPvt[] = "tableSrcPvt";
static const char __pyx_k_threshold_2[] = "--threshold";
static const char __pyx_k_treedistexp[] = "treedistexp";
static const char __pyx_k_trgFeatures[] = "trgFeatures";
static const char __pyx_k_workOptions[] = "workOptions";
static const char __pyx_k_writeRecord[] = "writeRecord";
static const char __pyx_k_JOINT_METHOD[] = "JOINT_METHOD";
static const char __pyx_k_MATCH_METHOD[] = "MATCH_METHOD";
static const char __pyx_k_add_argument[] = "add_argument";
static const char __pyx_k_alignLexPath[] = "alignLexPath";
static const char __pyx_k_bestMultiRec[] = "bestMultiRec";
static const char __pyx_k_calcSrcCount[] = "calcSrcCount";
static const char __pyx_k_multiRecords[] = "multiRecords";
static const char __pyx_k_multi_target[] = "multi_target";
static const char __pyx_k_numRecPvtTrg[] = "numRecPvtTrg";
static const char __pyx_k_numRecSrcPvt[] = "numRecSrcPvt";
static const char __pyx_k_numRecSrcTrg[] = "numRecSrcTrg";
static const char __pyx_k_rule_table_1[] = "rule table 1";
static const char __pyx_k_rule_table_2[] = "rule table 2";
static const char __pyx_k_showProgress[] = "showProgress";
static const char __pyx_k_updateCounts[] = "updateCounts";
static const char __pyx_k_writeRecords[] = "writeRecords";
static const char __pyx_k_WorkSet___del[] = "WorkSet.__del__";
static const char __pyx_k_WorkSet_close[] = "WorkSet.close";
static const char __pyx_k_calcLexWeight[] = "calcLexWeight";
static const char __pyx_k_countElements[] = "countElements";
static const char __pyx_k_jointmethod_2[] = "--jointmethod";
static const char __pyx_k_matchmethod_2[] = "--matchmethod";
static const char __pyx_k_multitarget_2[] = "--multitarget";
static const char __pyx_k_pivotRecPairs[] = "pivotRecPairs";
static const char __pyx_k_show_progress[] = "show progress";
static const char __pyx_k_ArgumentParser[] = "ArgumentParser";
static const char __pyx_k_TravatarRecord[] = "TravatarRecord";
static const char __pyx_k_WorkSet___init[] = "WorkSet.__init__";
static const char __pyx_k_alignMapPvtTrg[] = "alignMapPvtTrg";
static const char __pyx_k_alignMapSrcPvt[] = "alignMapSrcPvt";
static const char __pyx_k_bestTrgRecords[] = "bestTrgRecords";
static const char __pyx_k_bidirmin_table[] = "bidirmin+table";
static const char __pyx_k_calcLexProbRev[] = "calcLexProbRev";
static const char __pyx_k_calcLexWeights[] = "calcLexWeights";
static const char __pyx_k_countmin_table[] = "countmin+table";
static const char __pyx_k_flattenRecords[] = "flattenRecords";
static const char __pyx_k_prodprob_table[] = "prodprob+table";
static const char __pyx_k_setWordsPvtTrg[] = "setWordsPvtTrg";
static const char __pyx_k_setWordsSrcPvt[] = "setWordsSrcPvt";
static const char __pyx_k_setWordsSrcTrg[] = "setWordsSrcTrg";
static const char __pyx_k_updateFeatures[] = "updateFeatures";
static const char __pyx_k_Invalid_records[] = "Invalid records";
static const char __pyx_k_beginning_pivot[] = "beginning pivot\n";
static const char __pyx_k_lex_method_list[] = "lex_method_list";
static const char __pyx_k_matching_method[] = "matching method";
static const char __pyx_k_phrase_table_gz[] = "phrase-table.gz";
static const char __pyx_k_uniqWordsPvtTrg[] = "uniqWordsPvtTrg";
static const char __pyx_k_uniqWordsSrcPvt[] = "uniqWordsSrcPvt";
static const char __pyx_k_uniqWordsSrcTrg[] = "uniqWordsSrcTrg";
static const char __pyx_k_Invalid_method_s[] = "Invalid method: %s";
static const char __pyx_k_No_pre_filtering[] = "No pre-filtering";
static const char __pyx_k_bestMultiRecords[] = "bestMultiRecords";
static const char __pyx_k_bidirgmean_table[] = "bidirgmean+table";
static const char __pyx_k_filterNBestBySrc[] = "filterNBestBySrc";
static const char __pyx_k_lpu_data_structs[] = "lpu.data_structs";
static const char __pyx_k_parseSExpression[] = "parseSExpression";
static const char __pyx_k_setPhrasesPvtTrg[] = "setPhrasesPvtTrg";
static const char __pyx_k_setPhrasesSrcPvt[] = "setPhrasesSrcPvt";
static const char __pyx_k_setPhrasesSrcTrg[] = "setPhrasesSrcTrg";
static const char __pyx_k_KeyboardInterrupt[] = "KeyboardInterrupt";
static const char __pyx_k_joint_method_list[] = "joint_method_list";
static const char __pyx_k_log_file_optional[] = "log file (optional)";
static const char __pyx_k_match_method_list[] = "match_method_list";
static const char __pyx_k_uniqPhrasesPvtTrg[] = "uniqPhrasesPvtTrg";
static const char __pyx_k_uniqPhrasesSrcPvt[] = "uniqPhrasesSrcPvt";
static const char __pyx_k_uniqPhrasesSrcTrg[] = "uniqPhrasesSrcTrg";
static const char __pyx_k_working_directory[] = "working directory";
static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
static const char __pyx_k_Invalid_Match_Method[] = "Invalid Match Method";
static const char __pyx_k_calcTreeEditDistance[] = "calcTreeEditDistance";
static const char __pyx_k_triangulation_method[] = "triangulation method";
static const char __pyx_k_updateWordPairCounts[] = "updateWordPairCounts";
static const char __pyx_k_word_pair_counts_file[] = "word pair counts file";
static const char __pyx_k_filterByCountRatioToMax[] = "filterByCountRatioToMax";
static const char __pyx_k_bestForwardJointTransProb[] = "bestForwardJointTransProb";
static const char __pyx_k_calcPhraseTransProbsOnTable[] = "calcPhraseTransProbsOnTable";
static const char __pyx_k_enabling_multi_target_model[] = "enabling multi target model";
static const char __pyx_k_lpu_smt_trans_models_tables[] = "lpu.smt.trans_models.tables";
static const char __pyx_k_aligned_lexfile_is_not_given[] = "aligned lexfile is not given";
static const char __pyx_k_calcPhraseTransProbsByCounts[] = "calcPhraseTransProbsByCounts";
static const char __pyx_k_lexical_triangulation_method[] = "lexical triangulation method";
static const char __pyx_k_lpu_smt_trans_models_records[] = "lpu.smt.trans_models.records";
static const char __pyx_k_data_set_for_multi_processing[] = "data set for multi-processing";
static const char __pyx_k_number_of_NULLs_lines_for_table[] = "number of NULLs (lines) for table lex";
static const char __pyx_k_Caught_KeyboardInterrupt_termina[] = "Caught KeyboardInterrupt, terminating all the worker processes";
static const char __pyx_k_best_n_scores_for_rule_pair_filt[] = "best n scores for rule pair filtering (default = 20)";
static const char __pyx_k_functions_to_triangulate_2_phras[] = "functions to triangulate 2 phrase tables into 1 table\nby combining source-pivot and pivot-target for common pivot phrase";
static const char __pyx_k_load_2_rule_tables_and_pivot_int[] = "load 2 rule tables and pivot into one travatar rule table";
static const char __pyx_k_lpu_smt_trans_models_triangulate[] = "lpu.smt.trans_models.triangulate";
static const char __pyx_k_method_to_estimate_joint_trans_p[] = "method to estimate joint trans probs";
static const char __pyx_k_path_for_saving_travatar_rule_ta[] = "path for saving travatar rule table file";
static const char __pyx_k_threshold_for_ignoring_the_phras[] = "threshold for ignoring the phrase translation probability (real number)";
static const char __pyx_k_lpu_smt_trans_models_triangulate_2[] = "lpu/smt/trans_models/triangulate.pyx";
static PyObject *__pyx_kp_s_0;
static PyObject *__pyx_kp_s_0egfl;
static PyObject *__pyx_kp_s_0egfp;
static PyObject *__pyx_kp_s_0fgel;
static PyObject *__pyx_kp_s_0fgep;
static PyObject *__pyx_kp_s_0w;
static PyObject *__pyx_kp_s_1;
static PyObject *__pyx_kp_s_1fgep;
static PyObject *__pyx_kp_s_1w;
static PyObject *__pyx_n_s_ArgumentParser;
static PyObject *__pyx_kp_s_COL;
static PyObject *__pyx_kp_s_COL_2;
static PyObject *__pyx_kp_s_COL_3;
static PyObject *__pyx_kp_s_Caught_KeyboardInterrupt_termina;
static PyObject *__pyx_kp_s_Invalid_Match_Method;
static PyObject *__pyx_kp_s_Invalid_method_s;
static PyObject *__pyx_kp_s_Invalid_records;
static PyObject *__pyx_n_s_JOINT_METHOD;
static PyObject *__pyx_n_s_KeyboardInterrupt;
static PyObject *__pyx_n_s_LEX_METHOD;
static PyObject *__pyx_kp_s_Lost_Words;
static PyObject *__pyx_n_s_MATCH_METHOD;
static PyObject *__pyx_n_s_METHOD;
static PyObject *__pyx_n_s_MINPROB;
static PyObject *__pyx_n_s_MosesRecord;
static PyObject *__pyx_n_s_NBEST;
static PyObject *__pyx_n_s_NOPREFILTER;
static PyObject *__pyx_n_s_NULL;
static PyObject *__pyx_n_s_NULLS;
static PyObject *__pyx_kp_s_No_pre_filtering;
static PyObject *__pyx_n_s_Record;
static PyObject *__pyx_n_s_RecordClass;
static PyObject *__pyx_n_s_THRESHOLD;
static PyObject *__pyx_n_s_Table;
static PyObject *__pyx_n_s_TravatarRecord;
static PyObject *__pyx_n_s_WorkSet;
static PyObject *__pyx_n_s_WorkSet___del;
static PyObject *__pyx_n_s_WorkSet___init;
static PyObject *__pyx_n_s_WorkSet_close;
static PyObject *__pyx_kp_s__16;
static PyObject *__pyx_kp_s__17;
static PyObject *__pyx_kp_s__20;
static PyObject *__pyx_kp_s__25;
static PyObject *__pyx_kp_s__28;
static PyObject *__pyx_kp_s__3;
static PyObject *__pyx_n_s__75;
static PyObject *__pyx_kp_s__8;
static PyObject *__pyx_kp_s__9;
static PyObject *__pyx_n_s_action;
static PyObject *__pyx_n_s_add;
static PyObject *__pyx_n_s_addPair;
static PyObject *__pyx_n_s_add_argument;
static PyObject *__pyx_n_s_align;
static PyObject *__pyx_n_s_alignLexPath;
static PyObject *__pyx_n_s_alignMap;
static PyObject *__pyx_n_s_alignMapPvtTrg;
static PyObject *__pyx_n_s_alignMapRev;
static PyObject *__pyx_n_s_alignMapSrcPvt;
static PyObject *__pyx_kp_s_aligned_lexfile_is_not_given;
static PyObject *__pyx_n_s_alignlex;
static PyObject *__pyx_kp_s_alignlex_2;
static PyObject *__pyx_n_s_aligns;
static PyObject *__pyx_n_s_append;
static PyObject *__pyx_n_s_argparse;
static PyObject *__pyx_n_s_args;
static PyObject *__pyx_kp_s_beginning_pivot;
static PyObject *__pyx_n_s_bestForwardJointTransProb;
static PyObject *__pyx_n_s_bestMultiRec;
static PyObject *__pyx_n_s_bestMultiRecords;
static PyObject *__pyx_n_s_bestRecords;
static PyObject *__pyx_n_s_bestTrgRecords;
static PyObject *__pyx_kp_s_best_n_scores_for_rule_pair_filt;
static PyObject *__pyx_n_s_bidiravr;
static PyObject *__pyx_n_s_bidirgmean;
static PyObject *__pyx_kp_s_bidirgmean_table;
static PyObject *__pyx_n_s_bidirmax;
static PyObject *__pyx_n_s_bidirmin;
static PyObject *__pyx_kp_s_bidirmin_table;
static PyObject *__pyx_n_s_c;
static PyObject *__pyx_n_s_calcLexProb;
static PyObject *__pyx_n_s_calcLexProbRev;
static PyObject *__pyx_n_s_calcLexWeight;
static PyObject *__pyx_n_s_calcLexWeights;
static PyObject *__pyx_n_s_calcPhraseTransProbsByCounts;
static PyObject *__pyx_n_s_calcPhraseTransProbsOnTable;
static PyObject *__pyx_n_s_calcSrcCount;
static PyObject *__pyx_n_s_calcTreeEditDistance;
static PyObject *__pyx_n_s_choices;
static PyObject *__pyx_n_s_cline_in_traceback;
static PyObject *__pyx_n_s_close;
static PyObject *__pyx_n_s_co;
static PyObject *__pyx_n_s_co1;
static PyObject *__pyx_n_s_co2;
static PyObject *__pyx_n_s_coMax;
static PyObject *__pyx_n_s_compat;
static PyObject *__pyx_n_s_cooc;
static PyObject *__pyx_n_s_cooc1;
static PyObject *__pyx_n_s_cooc2;
static PyObject *__pyx_n_s_countElements;
static PyObject *__pyx_n_s_countmin;
static PyObject *__pyx_kp_s_countmin_table;
static PyObject *__pyx_n_s_counts;
static PyObject *__pyx_n_s_counts1;
static PyObject *__pyx_n_s_counts2;
static PyObject *__pyx_kp_s_d_d;
static PyObject *__pyx_kp_s_data_set_for_multi_processing;
static PyObject *__pyx_n_s_debug;
static PyObject *__pyx_n_s_default;
static PyObject *__pyx_n_s_del;
static PyObject *__pyx_n_s_description;
static PyObject *__pyx_n_s_dist;
static PyObject *__pyx_n_s_div;
static PyObject *__pyx_n_s_doc;
static PyObject *__pyx_n_s_egfl;
static PyObject *__pyx_n_s_egfp;
static PyObject *__pyx_n_s_elems1;
static PyObject *__pyx_n_s_elems2;
static PyObject *__pyx_kp_s_enabling_multi_target_model;
static PyObject *__pyx_n_s_end;
static PyObject *__pyx_n_s_enter;
static PyObject *__pyx_n_s_exit;
static PyObject *__pyx_n_s_exit_2;
static PyObject *__pyx_n_s_exp;
static PyObject *__pyx_n_s_featureKey;
static PyObject *__pyx_n_s_features;
static PyObject *__pyx_n_s_fgel;
static PyObject *__pyx_n_s_fgep;
static PyObject *__pyx_n_s_file;
static PyObject *__pyx_n_s_fileObj;
static PyObject *__pyx_n_s_files;
static PyObject *__pyx_n_s_filterByCountRatioToMax;
static PyObject *__pyx_n_s_filterNBestBySrc;
static PyObject *__pyx_n_s_find;
static PyObject *__pyx_n_s_find_src;
static PyObject *__pyx_n_s_flattenRecords;
static PyObject *__pyx_n_s_flush;
static PyObject *__pyx_n_s_fobj;
static PyObject *__pyx_n_s_foutPivot;
static PyObject *__pyx_n_s_get;
static PyObject *__pyx_n_s_help;
static PyObject *__pyx_n_s_hiero;
static PyObject *__pyx_n_s_ignoring;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_n_s_independent;
static PyObject *__pyx_n_s_init;
static PyObject *__pyx_n_s_items;
static PyObject *__pyx_n_s_join;
static PyObject *__pyx_n_s_jointMethod;
static PyObject *__pyx_n_s_joint_method_list;
static PyObject *__pyx_n_s_jointmethod;
static PyObject *__pyx_kp_s_jointmethod_2;
static PyObject *__pyx_n_s_key;
static PyObject *__pyx_n_s_key_type;
static PyObject *__pyx_n_s_keys;
static PyObject *__pyx_n_s_lastSrc;
static PyObject *__pyx_n_s_lexCounts;
static PyObject *__pyx_n_s_lexMethod;
static PyObject *__pyx_n_s_lexProb;
static PyObject *__pyx_n_s_lexWeight;
static PyObject *__pyx_n_s_lex_method_list;
static PyObject *__pyx_kp_s_lexical_triangulation_method;
static PyObject *__pyx_n_s_lexmethod;
static PyObject *__pyx_kp_s_lexmethod_2;
static PyObject *__pyx_n_s_line;
static PyObject *__pyx_kp_s_load_2_rule_tables_and_pivot_int;
static PyObject *__pyx_kp_s_loading_s;
static PyObject *__pyx_n_s_log;
static PyObject *__pyx_n_s_logFile;
static PyObject *__pyx_kp_s_log_2;
static PyObject *__pyx_kp_s_log_file_optional;
static PyObject *__pyx_n_s_logging;
static PyObject *__pyx_n_s_lpu_common;
static PyObject *__pyx_n_s_lpu_data_structs;
static PyObject *__pyx_n_s_lpu_smt_trans_models_records;
static PyObject *__pyx_n_s_lpu_smt_trans_models_tables;
static PyObject *__pyx_n_s_lpu_smt_trans_models_triangulate;
static PyObject *__pyx_kp_s_lpu_smt_trans_models_triangulate_2;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_n_s_main_2;
static PyObject *__pyx_n_s_matchMethod;
static PyObject *__pyx_n_s_match_method_list;
static PyObject *__pyx_kp_s_matching_method;
static PyObject *__pyx_n_s_matchmethod;
static PyObject *__pyx_kp_s_matchmethod_2;
static PyObject *__pyx_n_s_math;
static PyObject *__pyx_n_s_max_count;
static PyObject *__pyx_n_s_memoryless;
static PyObject *__pyx_n_s_mergeAligns;
static PyObject *__pyx_n_s_metaclass;
static PyObject *__pyx_n_s_method;
static PyObject *__pyx_kp_s_method_2;
static PyObject *__pyx_n_s_method_list;
static PyObject *__pyx_kp_s_method_to_estimate_joint_trans_p;
static PyObject *__pyx_n_s_minProb;
static PyObject *__pyx_n_s_module;
static PyObject *__pyx_n_s_multi;
static PyObject *__pyx_n_s_multiKey;
static PyObject *__pyx_n_s_multiList;
static PyObject *__pyx_n_s_multiRec;
static PyObject *__pyx_n_s_multiRecords;
static PyObject *__pyx_n_s_multi_target;
static PyObject *__pyx_n_s_multitarget;
static PyObject *__pyx_kp_s_multitarget_2;
static PyObject *__pyx_n_s_name;
static PyObject *__pyx_n_s_nbest;
static PyObject *__pyx_kp_s_nbest_2;
static PyObject *__pyx_n_s_newRecords;
static PyObject *__pyx_kp_s_noprefilter;
static PyObject *__pyx_n_s_nulls;
static PyObject *__pyx_kp_s_nulls_2;
static PyObject *__pyx_n_s_numElems;
static PyObject *__pyx_n_s_numNulls;
static PyObject *__pyx_n_s_numRecPvtTrg;
static PyObject *__pyx_n_s_numRecSrcPvt;
static PyObject *__pyx_n_s_numRecSrcTrg;
static PyObject *__pyx_n_s_numTerms;
static PyObject *__pyx_kp_s_number_of_NULLs_lines_for_table;
static PyObject *__pyx_n_s_open;
static PyObject *__pyx_n_s_options;
static PyObject *__pyx_n_s_p;
static PyObject *__pyx_kp_s_p_2;
static PyObject *__pyx_n_s_parseSExpression;
static PyObject *__pyx_n_s_parse_args;
static PyObject *__pyx_n_s_parser;
static PyObject *__pyx_kp_s_path_for_saving_travatar_rule_ta;
static PyObject *__pyx_n_s_phrase;
static PyObject *__pyx_kp_s_phrase_table_gz;
static PyObject *__pyx_n_s_pivot;
static PyObject *__pyx_n_s_pivotRecPairs;
static PyObject *__pyx_n_s_prefix;
static PyObject *__pyx_n_s_prepare;
static PyObject *__pyx_n_s_print;
static PyObject *__pyx_n_s_processing;
static PyObject *__pyx_n_s_prodprob;
static PyObject *__pyx_kp_s_prodprob_table;
static PyObject *__pyx_n_s_prodweight;
static PyObject *__pyx_n_s_progress;
static PyObject *__pyx_kp_s_progress_2;
static PyObject *__pyx_n_s_pvtIndex;
static PyObject *__pyx_n_s_pvtIndices;
static PyObject *__pyx_n_s_qualname;
static PyObject *__pyx_n_s_r;
static PyObject *__pyx_n_s_range;
static PyObject *__pyx_n_s_rate;
static PyObject *__pyx_n_s_rec;
static PyObject *__pyx_n_s_recMulti;
static PyObject *__pyx_n_s_recPair;
static PyObject *__pyx_n_s_recPivot;
static PyObject *__pyx_n_s_recPvtTrg;
static PyObject *__pyx_n_s_recSrcPvt;
static PyObject *__pyx_n_s_recordList;
static PyObject *__pyx_n_s_records;
static PyObject *__pyx_n_s_reverse;
static PyObject *__pyx_n_s_rows;
static PyObject *__pyx_n_s_rule;
static PyObject *__pyx_kp_s_rule_table_1;
static PyObject *__pyx_kp_s_rule_table_2;
static PyObject *__pyx_kp_s_s;
static PyObject *__pyx_kp_s_s_s;
static PyObject *__pyx_kp_s_s_s_2;
static PyObject *__pyx_n_s_saveFile;
static PyObject *__pyx_n_s_savePath;
static PyObject *__pyx_n_s_savefile;
static PyObject *__pyx_n_s_scores;
static PyObject *__pyx_n_s_self;
static PyObject *__pyx_n_s_setPhrasesPvtTrg;
static PyObject *__pyx_n_s_setPhrasesSrcPvt;
static PyObject *__pyx_n_s_setPhrasesSrcTrg;
static PyObject *__pyx_n_s_setWordsPvtTrg;
static PyObject *__pyx_n_s_setWordsSrcPvt;
static PyObject *__pyx_n_s_setWordsSrcTrg;
static PyObject *__pyx_n_s_setdefault;
static PyObject *__pyx_n_s_showProgress;
static PyObject *__pyx_kp_s_show_progress;
static PyObject *__pyx_n_s_sort;
static PyObject *__pyx_n_s_split;
static PyObject *__pyx_n_s_sqrt;
static PyObject *__pyx_n_s_src;
static PyObject *__pyx_n_s_srcCount;
static PyObject *__pyx_n_s_srcCounts;
static PyObject *__pyx_n_s_srcFeatures;
static PyObject *__pyx_n_s_srcIndex;
static PyObject *__pyx_n_s_srcIndices;
static PyObject *__pyx_n_s_srcTerm;
static PyObject *__pyx_n_s_srcTerms;
static PyObject *__pyx_n_s_srcWord;
static PyObject *__pyx_n_s_src_hiero;
static PyObject *__pyx_n_s_src_symbols;
static PyObject *__pyx_n_s_store_true;
static PyObject *__pyx_n_s_strMultiTrg;
static PyObject *__pyx_n_s_symbols;
static PyObject *__pyx_n_s_sys;
static PyObject *__pyx_n_s_table;
static PyObject *__pyx_n_s_table1;
static PyObject *__pyx_n_s_table2;
static PyObject *__pyx_n_s_tablePvtTrg;
static PyObject *__pyx_n_s_tableSrcPvt;
static PyObject *__pyx_n_s_table_file;
static PyObject *__pyx_n_s_table_path;
static PyObject *__pyx_n_s_term;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_threshold;
static PyObject *__pyx_kp_s_threshold_2;
static PyObject *__pyx_kp_s_threshold_for_ignoring_the_phras;
static PyObject *__pyx_n_s_to_str;
static PyObject *__pyx_n_s_total;
static PyObject *__pyx_n_s_tree1;
static PyObject *__pyx_n_s_tree2;
static PyObject *__pyx_n_s_treecomp;
static PyObject *__pyx_n_s_treedist;
static PyObject *__pyx_n_s_treedistexp;
static PyObject *__pyx_n_s_trees;
static PyObject *__pyx_n_s_trg;
static PyObject *__pyx_n_s_trgCounts;
static PyObject *__pyx_n_s_trgFeatures;
static PyObject *__pyx_n_s_trgIndex;
static PyObject *__pyx_n_s_trgKey;
static PyObject *__pyx_n_s_trgPair;
static PyObject *__pyx_n_s_trgProb;
static PyObject *__pyx_n_s_trgSumProb;
static PyObject *__pyx_n_s_trgSymbols;
static PyObject *__pyx_n_s_trgTerm;
static PyObject *__pyx_n_s_trgTerms;
static PyObject *__pyx_kp_s_triangulation_method;
static PyObject *__pyx_n_s_type;
static PyObject *__pyx_n_s_uniqPhrasesPvtTrg;
static PyObject *__pyx_n_s_uniqPhrasesSrcPvt;
static PyObject *__pyx_n_s_uniqPhrasesSrcTrg;
static PyObject *__pyx_n_s_uniqWordsPvtTrg;
static PyObject *__pyx_n_s_uniqWordsSrcPvt;
static PyObject *__pyx_n_s_uniqWordsSrcTrg;
static PyObject *__pyx_n_s_updateCounts;
static PyObject *__pyx_n_s_updateFeatures;
static PyObject *__pyx_n_s_updateWordPairCounts;
static PyObject *__pyx_n_s_values;
static PyObject *__pyx_n_s_vars;
static PyObject *__pyx_n_s_view;
static PyObject *__pyx_n_s_w;
static PyObject *__pyx_n_s_word;
static PyObject *__pyx_kp_s_word_pair_counts_file;
static PyObject *__pyx_n_s_workOptions;
static PyObject *__pyx_n_s_workdir;
static PyObject *__pyx_kp_s_workdir_2;
static PyObject *__pyx_kp_s_working_directory;
static PyObject *__pyx_n_s_workset;
static PyObject *__pyx_n_s_write;
static PyObject *__pyx_n_s_writeRecord;
static PyObject *__pyx_n_s_writeRecords;
static PyObject *__pyx_n_s_wt;
static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_7WorkSet___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_savefile, PyObject *__pyx_v_workdir, PyObject *__pyx_v_method, PyObject *__pyx_v_options); /* proto */
static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_7WorkSet_2__del__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_7WorkSet_4close(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */
static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_updateFeatures(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_recPivot, PyObject *__pyx_v_recPair, PyObject *__pyx_v_workset, PyObject *__pyx_v_multi_target); /* proto */
static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_2updateCounts(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_recPivot, PyObject *__pyx_v_recPair, PyObject *__pyx_v_method); /* proto */
static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_4mergeAligns(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_recPivot, PyObject *__pyx_v_recPair); /* proto */
static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_6filterByCountRatioToMax(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_records, PyObject *__pyx_v_div); /* proto */
static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_8calcPhraseTransProbsByCounts(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_records); /* proto */
static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_10calcPhraseTransProbsOnTable(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table_path, PyObject *__pyx_v_savePath, PyObject *__pyx_v_options); /* proto */
static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_12calcSrcCount(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_records); /* proto */
static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_14updateWordPairCounts(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_lexCounts, PyObject *__pyx_v_records); /* proto */
static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_16flattenRecords(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_records, PyObject *__pyx_v_sort); /* proto */
static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_18pivotRecPairs(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_rows, PyObject *__pyx_v_workset); /* proto */
static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_20writeRecords(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_fileObj, PyObject *__pyx_v_records); /* proto */
static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_22writeRecord(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_rec, PyObject *__pyx_v_workset); /* proto */
static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_24calcLexWeight(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_rec, PyObject *__pyx_v_lexCounts, PyObject *__pyx_v_reverse); /* proto */
static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_26calcLexWeights(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table_path, PyObject *__pyx_v_lexCounts, PyObject *__pyx_v_savePath, PyObject *__pyx_v_RecordClass); /* proto */
static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_28pivot(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table1, PyObject *__pyx_v_table2, PyObject *__pyx_v_savefile, PyObject *__pyx_v_workdir, PyObject *__pyx_v_options); /* proto */
static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_30main(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_items = {0, &__pyx_n_s_items, 0, 0, 0};
static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_keys = {0, &__pyx_n_s_keys, 0, 0, 0};
static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_values = {0, &__pyx_n_s_values, 0, 0, 0};
static PyObject *__pyx_float_0_5;
static PyObject *__pyx_float_1_0;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_20;
static PyObject *__pyx_int_100;
static PyObject *__pyx_int_10000;
static PyObject *__pyx_int_neg_1;
static PyObject *__pyx_k__23;
static PyObject *__pyx_tuple_;
static PyObject *__pyx_slice__5;
static PyObject *__pyx_slice__7;
static PyObject *__pyx_tuple__2;
static PyObject *__pyx_tuple__4;
static PyObject *__pyx_tuple__6;
static PyObject *__pyx_slice__11;
static PyObject *__pyx_slice__13;
static PyObject *__pyx_tuple__10;
static PyObject *__pyx_tuple__12;
static PyObject *__pyx_tuple__14;
static PyObject *__pyx_tuple__15;
static PyObject *__pyx_tuple__18;
static PyObject *__pyx_tuple__19;
static PyObject *__pyx_tuple__21;
static PyObject *__pyx_tuple__22;
static PyObject *__pyx_tuple__24;
static PyObject *__pyx_tuple__26;
static PyObject *__pyx_tuple__27;
static PyObject *__pyx_tuple__29;
static PyObject *__pyx_tuple__30;
static PyObject *__pyx_tuple__31;
static PyObject *__pyx_tuple__32;
static PyObject *__pyx_tuple__33;
static PyObject *__pyx_tuple__34;
static PyObject *__pyx_tuple__35;
static PyObject *__pyx_tuple__36;
static PyObject *__pyx_tuple__37;
static PyObject *__pyx_tuple__38;
static PyObject *__pyx_tuple__39;
static PyObject *__pyx_tuple__40;
static PyObject *__pyx_tuple__41;
static PyObject *__pyx_tuple__42;
static PyObject *__pyx_tuple__43;
static PyObject *__pyx_tuple__44;
static PyObject *__pyx_tuple__45;
static PyObject *__pyx_tuple__46;
static PyObject *__pyx_tuple__47;
static PyObject *__pyx_tuple__48;
static PyObject *__pyx_tuple__49;
static PyObject *__pyx_tuple__50;
static PyObject *__pyx_tuple__51;
static PyObject *__pyx_tuple__53;
static PyObject *__pyx_tuple__55;
static PyObject *__pyx_tuple__57;
static PyObject *__pyx_tuple__59;
static PyObject *__pyx_tuple__61;
static PyObject *__pyx_tuple__63;
static PyObject *__pyx_tuple__65;
static PyObject *__pyx_tuple__67;
static PyObject *__pyx_tuple__69;
static PyObject *__pyx_tuple__71;
static PyObject *__pyx_tuple__73;
static PyObject *__pyx_tuple__76;
static PyObject *__pyx_tuple__78;
static PyObject *__pyx_tuple__80;
static PyObject *__pyx_tuple__82;
static PyObject *__pyx_tuple__84;
static PyObject *__pyx_tuple__86;
static PyObject *__pyx_tuple__88;
static PyObject *__pyx_codeobj__52;
static PyObject *__pyx_codeobj__54;
static PyObject *__pyx_codeobj__56;
static PyObject *__pyx_codeobj__58;
static PyObject *__pyx_codeobj__60;
static PyObject *__pyx_codeobj__62;
static PyObject *__pyx_codeobj__64;
static PyObject *__pyx_codeobj__66;
static PyObject *__pyx_codeobj__68;
static PyObject *__pyx_codeobj__70;
static PyObject *__pyx_codeobj__72;
static PyObject *__pyx_codeobj__74;
static PyObject *__pyx_codeobj__77;
static PyObject *__pyx_codeobj__79;
static PyObject *__pyx_codeobj__81;
static PyObject *__pyx_codeobj__83;
static PyObject *__pyx_codeobj__85;
static PyObject *__pyx_codeobj__87;
static PyObject *__pyx_codeobj__89;

/* "lpu/smt/trans_models/triangulate.pyx":57
 * class WorkSet:
 *     '''data set for multi-processing'''
 *     def __init__(self, savefile, workdir, method, **options):             # <<<<<<<<<<<<<<
 *         prefix = options.get('prefix', 'phrase')
 *         self.multi_target = options.get('multi_target', False)
 */

/* Python wrapper */
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_7WorkSet_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_3lpu_3smt_12trans_models_11triangulate_7WorkSet_1__init__ = {"__init__", (PyCFunction)__pyx_pw_3lpu_3smt_12trans_models_11triangulate_7WorkSet_1__init__, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_7WorkSet_1__init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_self = 0;
  PyObject *__pyx_v_savefile = 0;
  PyObject *__pyx_v_workdir = 0;
  PyObject *__pyx_v_method = 0;
  PyObject *__pyx_v_options = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__init__ (wrapper)", 0);
  __pyx_v_options = PyDict_New(); if (unlikely(!__pyx_v_options)) return NULL;
  __Pyx_GOTREF(__pyx_v_options);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_savefile,&__pyx_n_s_workdir,&__pyx_n_s_method,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);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        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_self)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_savefile)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 1, 4, 4, 1); __PYX_ERR(0, 57, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_workdir)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 1, 4, 4, 2); __PYX_ERR(0, 57, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_method)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("__init__", 1, 4, 4, 3); __PYX_ERR(0, 57, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_options, values, pos_args, "__init__") < 0)) __PYX_ERR(0, 57, __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_self = values[0];
    __pyx_v_savefile = values[1];
    __pyx_v_workdir = values[2];
    __pyx_v_method = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("__init__", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 57, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_options); __pyx_v_options = 0;
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.WorkSet.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_3lpu_3smt_12trans_models_11triangulate_7WorkSet___init__(__pyx_self, __pyx_v_self, __pyx_v_savefile, __pyx_v_workdir, __pyx_v_method, __pyx_v_options);

  /* function exit code */
  __Pyx_XDECREF(__pyx_v_options);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_7WorkSet___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_savefile, PyObject *__pyx_v_workdir, PyObject *__pyx_v_method, PyObject *__pyx_v_options) {
  CYTHON_UNUSED PyObject *__pyx_v_prefix = NULL;
  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;
  PyObject *__pyx_t_5 = NULL;
  __Pyx_RefNannySetupContext("__init__", 0);

  /* "lpu/smt/trans_models/triangulate.pyx":58
 *     '''data set for multi-processing'''
 *     def __init__(self, savefile, workdir, method, **options):
 *         prefix = options.get('prefix', 'phrase')             # <<<<<<<<<<<<<<
 *         self.multi_target = options.get('multi_target', False)
 *         self.Record = options.get('RecordClass', MosesRecord)
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_options, __pyx_n_s_prefix, __pyx_n_s_phrase); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 58, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_prefix = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":59
 *     def __init__(self, savefile, workdir, method, **options):
 *         prefix = options.get('prefix', 'phrase')
 *         self.multi_target = options.get('multi_target', False)             # <<<<<<<<<<<<<<
 *         self.Record = options.get('RecordClass', MosesRecord)
 *         self.method = method
 */
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_options, __pyx_n_s_multi_target, Py_False); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 59, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_multi_target, __pyx_t_1) < 0) __PYX_ERR(0, 59, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":60
 *         prefix = options.get('prefix', 'phrase')
 *         self.multi_target = options.get('multi_target', False)
 *         self.Record = options.get('RecordClass', MosesRecord)             # <<<<<<<<<<<<<<
 *         self.method = method
 *         self.matchMethod = options.get('matchMethod', MATCH_METHOD)
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_MosesRecord); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 60, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyDict_GetItemDefault(__pyx_v_options, __pyx_n_s_RecordClass, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 60, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_Record, __pyx_t_2) < 0) __PYX_ERR(0, 60, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":61
 *         self.multi_target = options.get('multi_target', False)
 *         self.Record = options.get('RecordClass', MosesRecord)
 *         self.method = method             # <<<<<<<<<<<<<<
 *         self.matchMethod = options.get('matchMethod', MATCH_METHOD)
 *         self.jointMethod = options.get('jointMethod', JOINT_METHOD)
 */
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_method, __pyx_v_method) < 0) __PYX_ERR(0, 61, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":62
 *         self.Record = options.get('RecordClass', MosesRecord)
 *         self.method = method
 *         self.matchMethod = options.get('matchMethod', MATCH_METHOD)             # <<<<<<<<<<<<<<
 *         self.jointMethod = options.get('jointMethod', JOINT_METHOD)
 * #        if method.find('multi') >= 0:
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_MATCH_METHOD); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 62, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_options, __pyx_n_s_matchMethod, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 62, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_matchMethod, __pyx_t_1) < 0) __PYX_ERR(0, 62, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":63
 *         self.method = method
 *         self.matchMethod = options.get('matchMethod', MATCH_METHOD)
 *         self.jointMethod = options.get('jointMethod', JOINT_METHOD)             # <<<<<<<<<<<<<<
 * #        if method.find('multi') >= 0:
 * #            self.multi_target = True
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_JOINT_METHOD); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 63, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyDict_GetItemDefault(__pyx_v_options, __pyx_n_s_jointMethod, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 63, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_jointMethod, __pyx_t_2) < 0) __PYX_ERR(0, 63, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":67
 * #            self.multi_target = True
 * #            self.method = method.replace('multi','').replace('+','')
 *         self.nbest = NBEST             # <<<<<<<<<<<<<<
 *         self.savePath = savefile
 *         self.threshold = THRESHOLD
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_NBEST); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 67, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_nbest, __pyx_t_2) < 0) __PYX_ERR(0, 67, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":68
 * #            self.method = method.replace('multi','').replace('+','')
 *         self.nbest = NBEST
 *         self.savePath = savefile             # <<<<<<<<<<<<<<
 *         self.threshold = THRESHOLD
 *         self.workdir = workdir
 */
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_savePath, __pyx_v_savefile) < 0) __PYX_ERR(0, 68, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":69
 *         self.nbest = NBEST
 *         self.savePath = savefile
 *         self.threshold = THRESHOLD             # <<<<<<<<<<<<<<
 *         self.workdir = workdir
 *         self.foutPivot = files.open(savefile, 'wt')
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_THRESHOLD); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 69, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_threshold, __pyx_t_2) < 0) __PYX_ERR(0, 69, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":70
 *         self.savePath = savefile
 *         self.threshold = THRESHOLD
 *         self.workdir = workdir             # <<<<<<<<<<<<<<
 *         self.foutPivot = files.open(savefile, 'wt')
 *         #self.pivotProc = multiprocessing.Process( target = pivotRecPairs, args = (self,) )
 */
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_workdir, __pyx_v_workdir) < 0) __PYX_ERR(0, 70, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":71
 *         self.threshold = THRESHOLD
 *         self.workdir = workdir
 *         self.foutPivot = files.open(savefile, 'wt')             # <<<<<<<<<<<<<<
 *         #self.pivotProc = multiprocessing.Process( target = pivotRecPairs, args = (self,) )
 *         #self.recordProc = multiprocessing.Process( target = writeRecordQueue, args = (self,) )
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_files); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 71, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_open); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 71, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  __pyx_t_4 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_savefile, __pyx_n_s_wt};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 71, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_2);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_savefile, __pyx_n_s_wt};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 71, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_2);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 71, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (__pyx_t_1) {
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); __pyx_t_1 = NULL;
    }
    __Pyx_INCREF(__pyx_v_savefile);
    __Pyx_GIVEREF(__pyx_v_savefile);
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_savefile);
    __Pyx_INCREF(__pyx_n_s_wt);
    __Pyx_GIVEREF(__pyx_n_s_wt);
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_n_s_wt);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 71, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_foutPivot, __pyx_t_2) < 0) __PYX_ERR(0, 71, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":74
 *         #self.pivotProc = multiprocessing.Process( target = pivotRecPairs, args = (self,) )
 *         #self.recordProc = multiprocessing.Process( target = writeRecordQueue, args = (self,) )
 *         self.numRecSrcPvt = 0             # <<<<<<<<<<<<<<
 *         self.setPhrasesSrcPvt = set()
 *         self.setWordsSrcPvt = set()
 */
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_numRecSrcPvt, __pyx_int_0) < 0) __PYX_ERR(0, 74, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":75
 *         #self.recordProc = multiprocessing.Process( target = writeRecordQueue, args = (self,) )
 *         self.numRecSrcPvt = 0
 *         self.setPhrasesSrcPvt = set()             # <<<<<<<<<<<<<<
 *         self.setWordsSrcPvt = set()
 *         self.numRecPvtTrg = 0
 */
  __pyx_t_2 = PySet_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 75, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_setPhrasesSrcPvt, __pyx_t_2) < 0) __PYX_ERR(0, 75, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":76
 *         self.numRecSrcPvt = 0
 *         self.setPhrasesSrcPvt = set()
 *         self.setWordsSrcPvt = set()             # <<<<<<<<<<<<<<
 *         self.numRecPvtTrg = 0
 *         self.setPhrasesPvtTrg = set()
 */
  __pyx_t_2 = PySet_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 76, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_setWordsSrcPvt, __pyx_t_2) < 0) __PYX_ERR(0, 76, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":77
 *         self.setPhrasesSrcPvt = set()
 *         self.setWordsSrcPvt = set()
 *         self.numRecPvtTrg = 0             # <<<<<<<<<<<<<<
 *         self.setPhrasesPvtTrg = set()
 *         self.setWordsPvtTrg = set()
 */
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_numRecPvtTrg, __pyx_int_0) < 0) __PYX_ERR(0, 77, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":78
 *         self.setWordsSrcPvt = set()
 *         self.numRecPvtTrg = 0
 *         self.setPhrasesPvtTrg = set()             # <<<<<<<<<<<<<<
 *         self.setWordsPvtTrg = set()
 *         self.numRecSrcTrg = 0
 */
  __pyx_t_2 = PySet_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 78, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_setPhrasesPvtTrg, __pyx_t_2) < 0) __PYX_ERR(0, 78, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":79
 *         self.numRecPvtTrg = 0
 *         self.setPhrasesPvtTrg = set()
 *         self.setWordsPvtTrg = set()             # <<<<<<<<<<<<<<
 *         self.numRecSrcTrg = 0
 *         self.setPhrasesSrcTrg = set()
 */
  __pyx_t_2 = PySet_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 79, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_setWordsPvtTrg, __pyx_t_2) < 0) __PYX_ERR(0, 79, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":80
 *         self.setPhrasesPvtTrg = set()
 *         self.setWordsPvtTrg = set()
 *         self.numRecSrcTrg = 0             # <<<<<<<<<<<<<<
 *         self.setPhrasesSrcTrg = set()
 *         self.setWordsSrcTrg = set()
 */
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_numRecSrcTrg, __pyx_int_0) < 0) __PYX_ERR(0, 80, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":81
 *         self.setWordsPvtTrg = set()
 *         self.numRecSrcTrg = 0
 *         self.setPhrasesSrcTrg = set()             # <<<<<<<<<<<<<<
 *         self.setWordsSrcTrg = set()
 * 
 */
  __pyx_t_2 = PySet_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 81, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_setPhrasesSrcTrg, __pyx_t_2) < 0) __PYX_ERR(0, 81, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":82
 *         self.numRecSrcTrg = 0
 *         self.setPhrasesSrcTrg = set()
 *         self.setWordsSrcTrg = set()             # <<<<<<<<<<<<<<
 * 
 *     def __del__(self):
 */
  __pyx_t_2 = PySet_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 82, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_setWordsSrcTrg, __pyx_t_2) < 0) __PYX_ERR(0, 82, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":57
 * class WorkSet:
 *     '''data set for multi-processing'''
 *     def __init__(self, savefile, workdir, method, **options):             # <<<<<<<<<<<<<<
 *         prefix = options.get('prefix', 'phrase')
 *         self.multi_target = options.get('multi_target', False)
 */

  /* function exit code */
  __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_5);
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.WorkSet.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_prefix);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "lpu/smt/trans_models/triangulate.pyx":84
 *         self.setWordsSrcTrg = set()
 * 
 *     def __del__(self):             # <<<<<<<<<<<<<<
 *         self.close()
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_7WorkSet_3__del__(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static PyMethodDef __pyx_mdef_3lpu_3smt_12trans_models_11triangulate_7WorkSet_3__del__ = {"__del__", (PyCFunction)__pyx_pw_3lpu_3smt_12trans_models_11triangulate_7WorkSet_3__del__, METH_O, 0};
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_7WorkSet_3__del__(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__del__ (wrapper)", 0);
  __pyx_r = __pyx_pf_3lpu_3smt_12trans_models_11triangulate_7WorkSet_2__del__(__pyx_self, ((PyObject *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_7WorkSet_2__del__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("__del__", 0);

  /* "lpu/smt/trans_models/triangulate.pyx":85
 * 
 *     def __del__(self):
 *         self.close()             # <<<<<<<<<<<<<<
 * 
 *     def close(self):
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 85, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 85, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 85, __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;

  /* "lpu/smt/trans_models/triangulate.pyx":84
 *         self.setWordsSrcTrg = set()
 * 
 *     def __del__(self):             # <<<<<<<<<<<<<<
 *         self.close()
 * 
 */

  /* function exit code */
  __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("lpu.smt.trans_models.triangulate.WorkSet.__del__", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "lpu/smt/trans_models/triangulate.pyx":87
 *         self.close()
 * 
 *     def close(self):             # <<<<<<<<<<<<<<
 *         if self.foutPivot:
 *             self.foutPivot.close()
 */

/* Python wrapper */
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_7WorkSet_5close(PyObject *__pyx_self, PyObject *__pyx_v_self); /*proto*/
static PyMethodDef __pyx_mdef_3lpu_3smt_12trans_models_11triangulate_7WorkSet_5close = {"close", (PyCFunction)__pyx_pw_3lpu_3smt_12trans_models_11triangulate_7WorkSet_5close, METH_O, 0};
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_7WorkSet_5close(PyObject *__pyx_self, PyObject *__pyx_v_self) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("close (wrapper)", 0);
  __pyx_r = __pyx_pf_3lpu_3smt_12trans_models_11triangulate_7WorkSet_4close(__pyx_self, ((PyObject *)__pyx_v_self));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_7WorkSet_4close(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) {
  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;
  __Pyx_RefNannySetupContext("close", 0);

  /* "lpu/smt/trans_models/triangulate.pyx":88
 * 
 *     def close(self):
 *         if self.foutPivot:             # <<<<<<<<<<<<<<
 *             self.foutPivot.close()
 *             self.foutPivot = None
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_foutPivot); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 88, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 88, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "lpu/smt/trans_models/triangulate.pyx":89
 *     def close(self):
 *         if self.foutPivot:
 *             self.foutPivot.close()             # <<<<<<<<<<<<<<
 *             self.foutPivot = None
 * #        if self.pivotProc.pid:
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_self, __pyx_n_s_foutPivot); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 89, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_close); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 89, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (__pyx_t_3) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 89, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else {
      __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 89, __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;

    /* "lpu/smt/trans_models/triangulate.pyx":90
 *         if self.foutPivot:
 *             self.foutPivot.close()
 *             self.foutPivot = None             # <<<<<<<<<<<<<<
 * #        if self.pivotProc.pid:
 * #            if self.pivotProc.exitcode == None:
 */
    if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_foutPivot, Py_None) < 0) __PYX_ERR(0, 90, __pyx_L1_error)

    /* "lpu/smt/trans_models/triangulate.pyx":88
 * 
 *     def close(self):
 *         if self.foutPivot:             # <<<<<<<<<<<<<<
 *             self.foutPivot.close()
 *             self.foutPivot = None
 */
  }

  /* "lpu/smt/trans_models/triangulate.pyx":87
 *         self.close()
 * 
 *     def close(self):             # <<<<<<<<<<<<<<
 *         if self.foutPivot:
 *             self.foutPivot.close()
 */

  /* function exit code */
  __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("lpu.smt.trans_models.triangulate.WorkSet.close", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "lpu/smt/trans_models/triangulate.pyx":116
 * 
 * #def updateFeatures(recPivot, recPair, method, multi_target = False, jointMethod = 'memoryless'):
 * def updateFeatures(recPivot, recPair, workset, multi_target = False):             # <<<<<<<<<<<<<<
 *     '''update features'''
 *     features = recPivot.features
 */

/* Python wrapper */
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_1updateFeatures(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_3lpu_3smt_12trans_models_11triangulate_updateFeatures[] = "update features";
static PyMethodDef __pyx_mdef_3lpu_3smt_12trans_models_11triangulate_1updateFeatures = {"updateFeatures", (PyCFunction)__pyx_pw_3lpu_3smt_12trans_models_11triangulate_1updateFeatures, METH_VARARGS|METH_KEYWORDS, __pyx_doc_3lpu_3smt_12trans_models_11triangulate_updateFeatures};
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_1updateFeatures(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_recPivot = 0;
  PyObject *__pyx_v_recPair = 0;
  PyObject *__pyx_v_workset = 0;
  PyObject *__pyx_v_multi_target = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("updateFeatures (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_recPivot,&__pyx_n_s_recPair,&__pyx_n_s_workset,&__pyx_n_s_multi_target,0};
    PyObject* values[4] = {0,0,0,0};
    values[3] = ((PyObject *)Py_False);
    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);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        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_recPivot)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_recPair)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("updateFeatures", 0, 3, 4, 1); __PYX_ERR(0, 116, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_workset)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("updateFeatures", 0, 3, 4, 2); __PYX_ERR(0, 116, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_multi_target);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "updateFeatures") < 0)) __PYX_ERR(0, 116, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        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_recPivot = values[0];
    __pyx_v_recPair = values[1];
    __pyx_v_workset = values[2];
    __pyx_v_multi_target = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("updateFeatures", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 116, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.updateFeatures", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_3lpu_3smt_12trans_models_11triangulate_updateFeatures(__pyx_self, __pyx_v_recPivot, __pyx_v_recPair, __pyx_v_workset, __pyx_v_multi_target);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_updateFeatures(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_recPivot, PyObject *__pyx_v_recPair, PyObject *__pyx_v_workset, PyObject *__pyx_v_multi_target) {
  PyObject *__pyx_v_features = NULL;
  PyObject *__pyx_v_srcFeatures = NULL;
  PyObject *__pyx_v_trgFeatures = NULL;
  PyObject *__pyx_v_key = NULL;
  PyObject *__pyx_v_elems1 = NULL;
  PyObject *__pyx_v_elems2 = NULL;
  PyObject *__pyx_v_tree1 = NULL;
  PyObject *__pyx_v_tree2 = NULL;
  PyObject *__pyx_v_dist = NULL;
  PyObject *__pyx_v_numTerms = NULL;
  PyObject *__pyx_v_numElems = NULL;
  PyObject *__pyx_v_rate = 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;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  Py_ssize_t __pyx_t_11;
  long __pyx_t_12;
  __Pyx_RefNannySetupContext("updateFeatures", 0);

  /* "lpu/smt/trans_models/triangulate.pyx":118
 * def updateFeatures(recPivot, recPair, workset, multi_target = False):
 *     '''update features'''
 *     features = recPivot.features             # <<<<<<<<<<<<<<
 *     srcFeatures = recPair[0].features
 *     trgFeatures = recPair[1].features
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_recPivot, __pyx_n_s_features); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 118, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_features = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":119
 *     '''update features'''
 *     features = recPivot.features
 *     srcFeatures = recPair[0].features             # <<<<<<<<<<<<<<
 *     trgFeatures = recPair[1].features
 *     #logging.debug(method)
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_recPair, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 119, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_features); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 119, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_srcFeatures = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":120
 *     features = recPivot.features
 *     srcFeatures = recPair[0].features
 *     trgFeatures = recPair[1].features             # <<<<<<<<<<<<<<
 *     #logging.debug(method)
 *     #logging.debug(srcFeatures)
 */
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_recPair, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 120, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_features); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 120, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_trgFeatures = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":125
 *     #logging.debug(trgFeatures)
 *     #if method.find('prodprob') >= 0:
 *     if workset.method.find('prodprob') >= 0:             # <<<<<<<<<<<<<<
 *         # multiplying scores and marginalizing
 *         if not multi_target:
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_method); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 125, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_find); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 125, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 125, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_RichCompare(__pyx_t_1, __pyx_int_0, Py_GE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 125, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 125, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "lpu/smt/trans_models/triangulate.pyx":127
 *     if workset.method.find('prodprob') >= 0:
 *         # multiplying scores and marginalizing
 *         if not multi_target:             # <<<<<<<<<<<<<<
 *             for key in ['egfl', 'egfp', 'fgel', 'fgep']:
 *                 features.setdefault(key, 0)
 */
    __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_multi_target); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 127, __pyx_L1_error)
    __pyx_t_4 = ((!__pyx_t_3) != 0);
    if (__pyx_t_4) {

      /* "lpu/smt/trans_models/triangulate.pyx":128
 *         # multiplying scores and marginalizing
 *         if not multi_target:
 *             for key in ['egfl', 'egfp', 'fgel', 'fgep']:             # <<<<<<<<<<<<<<
 *                 features.setdefault(key, 0)
 *                 if workset.matchMethod == 'hiero':
 */
      __pyx_t_2 = __pyx_tuple__2; __Pyx_INCREF(__pyx_t_2); __pyx_t_5 = 0;
      for (;;) {
        if (__pyx_t_5 >= 4) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 128, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 128, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
        __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_1);
        __pyx_t_1 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":129
 *         if not multi_target:
 *             for key in ['egfl', 'egfp', 'fgel', 'fgep']:
 *                 features.setdefault(key, 0)             # <<<<<<<<<<<<<<
 *                 if workset.matchMethod == 'hiero':
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])
 */
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_features, __pyx_n_s_setdefault); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 129, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = NULL;
        __pyx_t_8 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
          __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6);
          if (likely(__pyx_t_7)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_7);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_6, function);
            __pyx_t_8 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_6)) {
          PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_key, __pyx_int_0};
          __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_GOTREF(__pyx_t_1);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
          PyObject *__pyx_temp[3] = {__pyx_t_7, __pyx_v_key, __pyx_int_0};
          __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_GOTREF(__pyx_t_1);
        } else
        #endif
        {
          __pyx_t_9 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 129, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          if (__pyx_t_7) {
            __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_7); __pyx_t_7 = NULL;
          }
          __Pyx_INCREF(__pyx_v_key);
          __Pyx_GIVEREF(__pyx_v_key);
          PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, __pyx_v_key);
          __Pyx_INCREF(__pyx_int_0);
          __Pyx_GIVEREF(__pyx_int_0);
          PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_int_0);
          __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        }
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":130
 *             for key in ['egfl', 'egfp', 'fgel', 'fgep']:
 *                 features.setdefault(key, 0)
 *                 if workset.matchMethod == 'hiero':             # <<<<<<<<<<<<<<
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])
 *                 elif workset.matchMethod == 'symbols':
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_matchMethod); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 130, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_n_s_hiero, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 130, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (__pyx_t_4) {

          /* "lpu/smt/trans_models/triangulate.pyx":131
 *                 features.setdefault(key, 0)
 *                 if workset.matchMethod == 'hiero':
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])             # <<<<<<<<<<<<<<
 *                 elif workset.matchMethod == 'symbols':
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])
 */
          __Pyx_INCREF(__pyx_v_key);
          __pyx_t_1 = __pyx_v_key;
          __pyx_t_6 = PyObject_GetItem(__pyx_v_features, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 131, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_9 = PyObject_GetItem(__pyx_v_srcFeatures, __pyx_v_key); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 131, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_7 = PyObject_GetItem(__pyx_v_trgFeatures, __pyx_v_key); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 131, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_10 = PyNumber_Multiply(__pyx_t_9, __pyx_t_7); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 131, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = PyNumber_InPlaceAdd(__pyx_t_6, __pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 131, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          if (unlikely(PyObject_SetItem(__pyx_v_features, __pyx_t_1, __pyx_t_7) < 0)) __PYX_ERR(0, 131, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":130
 *             for key in ['egfl', 'egfp', 'fgel', 'fgep']:
 *                 features.setdefault(key, 0)
 *                 if workset.matchMethod == 'hiero':             # <<<<<<<<<<<<<<
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])
 *                 elif workset.matchMethod == 'symbols':
 */
          goto __pyx_L7;
        }

        /* "lpu/smt/trans_models/triangulate.pyx":132
 *                 if workset.matchMethod == 'hiero':
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])
 *                 elif workset.matchMethod == 'symbols':             # <<<<<<<<<<<<<<
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])
 *                 elif workset.matchMethod == 'treecomp':
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_matchMethod); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 132, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_n_s_symbols, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 132, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (__pyx_t_4) {

          /* "lpu/smt/trans_models/triangulate.pyx":133
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])
 *                 elif workset.matchMethod == 'symbols':
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])             # <<<<<<<<<<<<<<
 *                 elif workset.matchMethod == 'treecomp':
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])
 */
          __Pyx_INCREF(__pyx_v_key);
          __pyx_t_1 = __pyx_v_key;
          __pyx_t_7 = PyObject_GetItem(__pyx_v_features, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 133, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_10 = PyObject_GetItem(__pyx_v_srcFeatures, __pyx_v_key); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 133, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_6 = PyObject_GetItem(__pyx_v_trgFeatures, __pyx_v_key); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 133, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_9 = PyNumber_Multiply(__pyx_t_10, __pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 133, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = PyNumber_InPlaceAdd(__pyx_t_7, __pyx_t_9); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 133, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          if (unlikely(PyObject_SetItem(__pyx_v_features, __pyx_t_1, __pyx_t_6) < 0)) __PYX_ERR(0, 133, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":132
 *                 if workset.matchMethod == 'hiero':
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])
 *                 elif workset.matchMethod == 'symbols':             # <<<<<<<<<<<<<<
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])
 *                 elif workset.matchMethod == 'treecomp':
 */
          goto __pyx_L7;
        }

        /* "lpu/smt/trans_models/triangulate.pyx":134
 *                 elif workset.matchMethod == 'symbols':
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])
 *                 elif workset.matchMethod == 'treecomp':             # <<<<<<<<<<<<<<
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])
 *                 elif workset.matchMethod == 'treedist':
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_matchMethod); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 134, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_n_s_treecomp, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 134, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (__pyx_t_4) {

          /* "lpu/smt/trans_models/triangulate.pyx":135
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])
 *                 elif workset.matchMethod == 'treecomp':
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])             # <<<<<<<<<<<<<<
 *                 elif workset.matchMethod == 'treedist':
 *                     elems1 = recPair[0].trg.split(' ')[0:-1]
 */
          __Pyx_INCREF(__pyx_v_key);
          __pyx_t_1 = __pyx_v_key;
          __pyx_t_6 = PyObject_GetItem(__pyx_v_features, __pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 135, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_9 = PyObject_GetItem(__pyx_v_srcFeatures, __pyx_v_key); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 135, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_7 = PyObject_GetItem(__pyx_v_trgFeatures, __pyx_v_key); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 135, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_10 = PyNumber_Multiply(__pyx_t_9, __pyx_t_7); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 135, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = PyNumber_InPlaceAdd(__pyx_t_6, __pyx_t_10); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 135, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          if (unlikely(PyObject_SetItem(__pyx_v_features, __pyx_t_1, __pyx_t_7) < 0)) __PYX_ERR(0, 135, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":134
 *                 elif workset.matchMethod == 'symbols':
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])
 *                 elif workset.matchMethod == 'treecomp':             # <<<<<<<<<<<<<<
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])
 *                 elif workset.matchMethod == 'treedist':
 */
          goto __pyx_L7;
        }

        /* "lpu/smt/trans_models/triangulate.pyx":136
 *                 elif workset.matchMethod == 'treecomp':
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])
 *                 elif workset.matchMethod == 'treedist':             # <<<<<<<<<<<<<<
 *                     elems1 = recPair[0].trg.split(' ')[0:-1]
 *                     elems2 = recPair[1].src.split(' ')[0:-1]
 */
        __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_matchMethod); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 136, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_n_s_treedist, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 136, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        if (__pyx_t_4) {

          /* "lpu/smt/trans_models/triangulate.pyx":137
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])
 *                 elif workset.matchMethod == 'treedist':
 *                     elems1 = recPair[0].trg.split(' ')[0:-1]             # <<<<<<<<<<<<<<
 *                     elems2 = recPair[1].src.split(' ')[0:-1]
 *                     tree1 = trees.parseSExpression('(' + str.join(' ', elems1) + ')')[0]
 */
          __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_recPair, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 137, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_trg); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 137, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_split); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 137, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 137, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_t_7, 0, -1L, NULL, NULL, &__pyx_slice__5, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 137, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_XDECREF_SET(__pyx_v_elems1, __pyx_t_1);
          __pyx_t_1 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":138
 *                 elif workset.matchMethod == 'treedist':
 *                     elems1 = recPair[0].trg.split(' ')[0:-1]
 *                     elems2 = recPair[1].src.split(' ')[0:-1]             # <<<<<<<<<<<<<<
 *                     tree1 = trees.parseSExpression('(' + str.join(' ', elems1) + ')')[0]
 *                     tree2 = trees.parseSExpression('(' + str.join(' ', elems2) + ')')[0]
 */
          __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_recPair, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 138, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_src); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 138, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_split); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 138, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 138, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_t_7, 0, -1L, NULL, NULL, &__pyx_slice__7, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 138, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_XDECREF_SET(__pyx_v_elems2, __pyx_t_1);
          __pyx_t_1 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":139
 *                     elems1 = recPair[0].trg.split(' ')[0:-1]
 *                     elems2 = recPair[1].src.split(' ')[0:-1]
 *                     tree1 = trees.parseSExpression('(' + str.join(' ', elems1) + ')')[0]             # <<<<<<<<<<<<<<
 *                     tree2 = trees.parseSExpression('(' + str.join(' ', elems2) + ')')[0]
 *                     dist = trees.calcTreeEditDistance(tree1, tree2)
 */
          __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_trees); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 139, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_parseSExpression); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 139, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = __Pyx_PyString_Join(__pyx_kp_s__3, __pyx_v_elems1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 139, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_6 = PyNumber_Add(__pyx_kp_s__8, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 139, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = PyNumber_Add(__pyx_t_6, __pyx_kp_s__9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 139, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) {
            __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_10);
            if (likely(__pyx_t_6)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
              __Pyx_INCREF(__pyx_t_6);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_10, function);
            }
          }
          if (!__pyx_t_6) {
            __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 139, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            __Pyx_GOTREF(__pyx_t_1);
          } else {
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_10)) {
              PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_7};
              __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 139, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) {
              PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_7};
              __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 139, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            } else
            #endif
            {
              __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 139, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_9);
              __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_6); __pyx_t_6 = NULL;
              __Pyx_GIVEREF(__pyx_t_7);
              PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_7);
              __pyx_t_7 = 0;
              __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_9, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 139, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            }
          }
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __pyx_t_10 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 139, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_XDECREF_SET(__pyx_v_tree1, __pyx_t_10);
          __pyx_t_10 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":140
 *                     elems2 = recPair[1].src.split(' ')[0:-1]
 *                     tree1 = trees.parseSExpression('(' + str.join(' ', elems1) + ')')[0]
 *                     tree2 = trees.parseSExpression('(' + str.join(' ', elems2) + ')')[0]             # <<<<<<<<<<<<<<
 *                     dist = trees.calcTreeEditDistance(tree1, tree2)
 *                     numTerms = len(recPair[0].trgTerms)
 */
          __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_trees); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 140, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_parseSExpression); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 140, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_1 = __Pyx_PyString_Join(__pyx_kp_s__3, __pyx_v_elems2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 140, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_7 = PyNumber_Add(__pyx_kp_s__8, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 140, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_1 = PyNumber_Add(__pyx_t_7, __pyx_kp_s__9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 140, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
            __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_9);
            if (likely(__pyx_t_7)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
              __Pyx_INCREF(__pyx_t_7);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_9, function);
            }
          }
          if (!__pyx_t_7) {
            __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 140, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_GOTREF(__pyx_t_10);
          } else {
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_9)) {
              PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_1};
              __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 140, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
              __Pyx_GOTREF(__pyx_t_10);
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
              PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_1};
              __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 140, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
              __Pyx_GOTREF(__pyx_t_10);
              __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
            } else
            #endif
            {
              __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 140, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_7); __pyx_t_7 = NULL;
              __Pyx_GIVEREF(__pyx_t_1);
              PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_1);
              __pyx_t_1 = 0;
              __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_6, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 140, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_10);
              __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            }
          }
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_9 = __Pyx_GetItemInt(__pyx_t_10, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 140, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_XDECREF_SET(__pyx_v_tree2, __pyx_t_9);
          __pyx_t_9 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":141
 *                     tree1 = trees.parseSExpression('(' + str.join(' ', elems1) + ')')[0]
 *                     tree2 = trees.parseSExpression('(' + str.join(' ', elems2) + ')')[0]
 *                     dist = trees.calcTreeEditDistance(tree1, tree2)             # <<<<<<<<<<<<<<
 *                     numTerms = len(recPair[0].trgTerms)
 *                     numElems = max(trees.countElements(tree1), trees.countElements(tree2))
 */
          __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_trees); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 141, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_calcTreeEditDistance); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 141, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __pyx_t_10 = NULL;
          __pyx_t_8 = 0;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
            __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_6);
            if (likely(__pyx_t_10)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
              __Pyx_INCREF(__pyx_t_10);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_6, function);
              __pyx_t_8 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_6)) {
            PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_tree1, __pyx_v_tree2};
            __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 141, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
            __Pyx_GOTREF(__pyx_t_9);
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
            PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_tree1, __pyx_v_tree2};
            __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 141, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
            __Pyx_GOTREF(__pyx_t_9);
          } else
          #endif
          {
            __pyx_t_1 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 141, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
            if (__pyx_t_10) {
              __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_10); __pyx_t_10 = NULL;
            }
            __Pyx_INCREF(__pyx_v_tree1);
            __Pyx_GIVEREF(__pyx_v_tree1);
            PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_8, __pyx_v_tree1);
            __Pyx_INCREF(__pyx_v_tree2);
            __Pyx_GIVEREF(__pyx_v_tree2);
            PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_8, __pyx_v_tree2);
            __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_1, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 141, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_9);
            __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          }
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_XDECREF_SET(__pyx_v_dist, __pyx_t_9);
          __pyx_t_9 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":142
 *                     tree2 = trees.parseSExpression('(' + str.join(' ', elems2) + ')')[0]
 *                     dist = trees.calcTreeEditDistance(tree1, tree2)
 *                     numTerms = len(recPair[0].trgTerms)             # <<<<<<<<<<<<<<
 *                     numElems = max(trees.countElements(tree1), trees.countElements(tree2))
 *                     rate = max(1, 1 + numElems - numTerms - dist) / float(max(1, 1 + numElems - numTerms))
 */
          __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_recPair, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 142, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_trgTerms); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 142, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_11 = PyObject_Length(__pyx_t_6); if (unlikely(__pyx_t_11 == -1)) __PYX_ERR(0, 142, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = PyInt_FromSsize_t(__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 142, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_XDECREF_SET(__pyx_v_numTerms, __pyx_t_6);
          __pyx_t_6 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":143
 *                     dist = trees.calcTreeEditDistance(tree1, tree2)
 *                     numTerms = len(recPair[0].trgTerms)
 *                     numElems = max(trees.countElements(tree1), trees.countElements(tree2))             # <<<<<<<<<<<<<<
 *                     rate = max(1, 1 + numElems - numTerms - dist) / float(max(1, 1 + numElems - numTerms))
 *                     features[key] += (rate * srcFeatures[key] * trgFeatures[key])
 */
          __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_trees); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 143, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_countElements); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 143, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_9 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
            __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_1);
            if (likely(__pyx_t_9)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
              __Pyx_INCREF(__pyx_t_9);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_1, function);
            }
          }
          if (!__pyx_t_9) {
            __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_tree2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 143, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
          } else {
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_1)) {
              PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_v_tree2};
              __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 143, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
              __Pyx_GOTREF(__pyx_t_6);
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
              PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_v_tree2};
              __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 143, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
              __Pyx_GOTREF(__pyx_t_6);
            } else
            #endif
            {
              __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 143, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_10);
              __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9); __pyx_t_9 = NULL;
              __Pyx_INCREF(__pyx_v_tree2);
              __Pyx_GIVEREF(__pyx_v_tree2);
              PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_v_tree2);
              __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_10, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 143, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
            }
          }
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_trees); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 143, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_countElements); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 143, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __pyx_t_10 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
            __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9);
            if (likely(__pyx_t_10)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
              __Pyx_INCREF(__pyx_t_10);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_9, function);
            }
          }
          if (!__pyx_t_10) {
            __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_tree1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 143, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_1);
          } else {
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_9)) {
              PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_tree1};
              __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 143, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
              __Pyx_GOTREF(__pyx_t_1);
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
              PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_tree1};
              __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 143, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
              __Pyx_GOTREF(__pyx_t_1);
            } else
            #endif
            {
              __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 143, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_7);
              __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_10); __pyx_t_10 = NULL;
              __Pyx_INCREF(__pyx_v_tree1);
              __Pyx_GIVEREF(__pyx_v_tree1);
              PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_tree1);
              __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 143, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            }
          }
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_7 = PyObject_RichCompare(__pyx_t_6, __pyx_t_1, Py_GT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 143, __pyx_L1_error)
          __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 143, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (__pyx_t_4) {
            __Pyx_INCREF(__pyx_t_6);
            __pyx_t_9 = __pyx_t_6;
          } else {
            __Pyx_INCREF(__pyx_t_1);
            __pyx_t_9 = __pyx_t_1;
          }
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = __pyx_t_9;
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_XDECREF_SET(__pyx_v_numElems, __pyx_t_6);
          __pyx_t_6 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":144
 *                     numTerms = len(recPair[0].trgTerms)
 *                     numElems = max(trees.countElements(tree1), trees.countElements(tree2))
 *                     rate = max(1, 1 + numElems - numTerms - dist) / float(max(1, 1 + numElems - numTerms))             # <<<<<<<<<<<<<<
 *                     features[key] += (rate * srcFeatures[key] * trgFeatures[key])
 *                 elif workset.matchMethod == 'treedistexp':
 */
          __pyx_t_6 = __Pyx_PyInt_AddCObj(__pyx_int_1, __pyx_v_numElems, 1, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 144, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_9 = PyNumber_Subtract(__pyx_t_6, __pyx_v_numTerms); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 144, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = PyNumber_Subtract(__pyx_t_9, __pyx_v_dist); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 144, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_12 = 1;
          __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_t_12); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 144, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_7 = PyObject_RichCompare(__pyx_t_6, __pyx_t_1, Py_GT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 144, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 144, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          if (__pyx_t_4) {
            __Pyx_INCREF(__pyx_t_6);
            __pyx_t_9 = __pyx_t_6;
          } else {
            __pyx_t_7 = __Pyx_PyInt_From_long(__pyx_t_12); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 144, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_7);
            __pyx_t_9 = __pyx_t_7;
            __pyx_t_7 = 0;
          }
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = __Pyx_PyInt_AddCObj(__pyx_int_1, __pyx_v_numElems, 1, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 144, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_7 = PyNumber_Subtract(__pyx_t_6, __pyx_v_numTerms); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 144, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_12 = 1;
          __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_t_12); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 144, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_10 = PyObject_RichCompare(__pyx_t_7, __pyx_t_1, Py_GT); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 144, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 144, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          if (__pyx_t_4) {
            __Pyx_INCREF(__pyx_t_7);
            __pyx_t_6 = __pyx_t_7;
          } else {
            __pyx_t_10 = __Pyx_PyInt_From_long(__pyx_t_12); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 144, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_10);
            __pyx_t_6 = __pyx_t_10;
            __pyx_t_10 = 0;
          }
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = __Pyx_PyNumber_Float(__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 144, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = __Pyx_PyNumber_Divide(__pyx_t_9, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 144, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_XDECREF_SET(__pyx_v_rate, __pyx_t_6);
          __pyx_t_6 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":145
 *                     numElems = max(trees.countElements(tree1), trees.countElements(tree2))
 *                     rate = max(1, 1 + numElems - numTerms - dist) / float(max(1, 1 + numElems - numTerms))
 *                     features[key] += (rate * srcFeatures[key] * trgFeatures[key])             # <<<<<<<<<<<<<<
 *                 elif workset.matchMethod == 'treedistexp':
 *                     elems1 = recPair[0].trg.split(' ')[0:-1]
 */
          __Pyx_INCREF(__pyx_v_key);
          __pyx_t_6 = __pyx_v_key;
          __pyx_t_7 = PyObject_GetItem(__pyx_v_features, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 145, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_9 = PyObject_GetItem(__pyx_v_srcFeatures, __pyx_v_key); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 145, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_10 = PyNumber_Multiply(__pyx_v_rate, __pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 145, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_9 = PyObject_GetItem(__pyx_v_trgFeatures, __pyx_v_key); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 145, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_1 = PyNumber_Multiply(__pyx_t_10, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 145, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_9 = PyNumber_InPlaceAdd(__pyx_t_7, __pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 145, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          if (unlikely(PyObject_SetItem(__pyx_v_features, __pyx_t_6, __pyx_t_9) < 0)) __PYX_ERR(0, 145, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":136
 *                 elif workset.matchMethod == 'treecomp':
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])
 *                 elif workset.matchMethod == 'treedist':             # <<<<<<<<<<<<<<
 *                     elems1 = recPair[0].trg.split(' ')[0:-1]
 *                     elems2 = recPair[1].src.split(' ')[0:-1]
 */
          goto __pyx_L7;
        }

        /* "lpu/smt/trans_models/triangulate.pyx":146
 *                     rate = max(1, 1 + numElems - numTerms - dist) / float(max(1, 1 + numElems - numTerms))
 *                     features[key] += (rate * srcFeatures[key] * trgFeatures[key])
 *                 elif workset.matchMethod == 'treedistexp':             # <<<<<<<<<<<<<<
 *                     elems1 = recPair[0].trg.split(' ')[0:-1]
 *                     elems2 = recPair[1].src.split(' ')[0:-1]
 */
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_matchMethod); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 146, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_t_6, __pyx_n_s_treedistexp, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 146, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (__pyx_t_4) {

          /* "lpu/smt/trans_models/triangulate.pyx":147
 *                     features[key] += (rate * srcFeatures[key] * trgFeatures[key])
 *                 elif workset.matchMethod == 'treedistexp':
 *                     elems1 = recPair[0].trg.split(' ')[0:-1]             # <<<<<<<<<<<<<<
 *                     elems2 = recPair[1].src.split(' ')[0:-1]
 *                     tree1 = trees.parseSExpression('(' + str.join(' ', elems1) + ')')[0]
 */
          __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_recPair, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 147, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_trg); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 147, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_split); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 147, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 147, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = __Pyx_PyObject_GetSlice(__pyx_t_9, 0, -1L, NULL, NULL, &__pyx_slice__11, 1, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 147, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_XDECREF_SET(__pyx_v_elems1, __pyx_t_6);
          __pyx_t_6 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":148
 *                 elif workset.matchMethod == 'treedistexp':
 *                     elems1 = recPair[0].trg.split(' ')[0:-1]
 *                     elems2 = recPair[1].src.split(' ')[0:-1]             # <<<<<<<<<<<<<<
 *                     tree1 = trees.parseSExpression('(' + str.join(' ', elems1) + ')')[0]
 *                     tree2 = trees.parseSExpression('(' + str.join(' ', elems2) + ')')[0]
 */
          __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_recPair, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 148, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_src); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 148, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_split); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 148, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 148, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = __Pyx_PyObject_GetSlice(__pyx_t_9, 0, -1L, NULL, NULL, &__pyx_slice__13, 1, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 148, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_XDECREF_SET(__pyx_v_elems2, __pyx_t_6);
          __pyx_t_6 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":149
 *                     elems1 = recPair[0].trg.split(' ')[0:-1]
 *                     elems2 = recPair[1].src.split(' ')[0:-1]
 *                     tree1 = trees.parseSExpression('(' + str.join(' ', elems1) + ')')[0]             # <<<<<<<<<<<<<<
 *                     tree2 = trees.parseSExpression('(' + str.join(' ', elems2) + ')')[0]
 *                     dist = trees.calcTreeEditDistance(tree1, tree2)
 */
          __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_trees); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 149, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_parseSExpression); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 149, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_9 = __Pyx_PyString_Join(__pyx_kp_s__3, __pyx_v_elems1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 149, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_7 = PyNumber_Add(__pyx_kp_s__8, __pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 149, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_9 = PyNumber_Add(__pyx_t_7, __pyx_kp_s__9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 149, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
            __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1);
            if (likely(__pyx_t_7)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
              __Pyx_INCREF(__pyx_t_7);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_1, function);
            }
          }
          if (!__pyx_t_7) {
            __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_9); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 149, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            __Pyx_GOTREF(__pyx_t_6);
          } else {
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_1)) {
              PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_9};
              __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 149, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
              PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_9};
              __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 149, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            } else
            #endif
            {
              __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 149, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_10);
              __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_7); __pyx_t_7 = NULL;
              __Pyx_GIVEREF(__pyx_t_9);
              PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_9);
              __pyx_t_9 = 0;
              __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_10, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 149, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
            }
          }
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_6, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 149, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_XDECREF_SET(__pyx_v_tree1, __pyx_t_1);
          __pyx_t_1 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":150
 *                     elems2 = recPair[1].src.split(' ')[0:-1]
 *                     tree1 = trees.parseSExpression('(' + str.join(' ', elems1) + ')')[0]
 *                     tree2 = trees.parseSExpression('(' + str.join(' ', elems2) + ')')[0]             # <<<<<<<<<<<<<<
 *                     dist = trees.calcTreeEditDistance(tree1, tree2)
 *                     rate = math.exp(-dist)
 */
          __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_trees); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 150, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_parseSExpression); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 150, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = __Pyx_PyString_Join(__pyx_kp_s__3, __pyx_v_elems2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 150, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_9 = PyNumber_Add(__pyx_kp_s__8, __pyx_t_6); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 150, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = PyNumber_Add(__pyx_t_9, __pyx_kp_s__9); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 150, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_9 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) {
            __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_10);
            if (likely(__pyx_t_9)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
              __Pyx_INCREF(__pyx_t_9);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_10, function);
            }
          }
          if (!__pyx_t_9) {
            __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 150, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            __Pyx_GOTREF(__pyx_t_1);
          } else {
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_10)) {
              PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_6};
              __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 150, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) {
              PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_6};
              __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 150, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            } else
            #endif
            {
              __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 150, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_7);
              __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_9); __pyx_t_9 = NULL;
              __Pyx_GIVEREF(__pyx_t_6);
              PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_6);
              __pyx_t_6 = 0;
              __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 150, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_1);
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            }
          }
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __pyx_t_10 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 150, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_XDECREF_SET(__pyx_v_tree2, __pyx_t_10);
          __pyx_t_10 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":151
 *                     tree1 = trees.parseSExpression('(' + str.join(' ', elems1) + ')')[0]
 *                     tree2 = trees.parseSExpression('(' + str.join(' ', elems2) + ')')[0]
 *                     dist = trees.calcTreeEditDistance(tree1, tree2)             # <<<<<<<<<<<<<<
 *                     rate = math.exp(-dist)
 *                     features[key] += (rate * srcFeatures[key] * trgFeatures[key])
 */
          __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_trees); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 151, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_calcTreeEditDistance); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 151, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_1 = NULL;
          __pyx_t_8 = 0;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_7))) {
            __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_7);
            if (likely(__pyx_t_1)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
              __Pyx_INCREF(__pyx_t_1);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_7, function);
              __pyx_t_8 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_7)) {
            PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_tree1, __pyx_v_tree2};
            __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 151, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_GOTREF(__pyx_t_10);
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
            PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_tree1, __pyx_v_tree2};
            __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 151, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_GOTREF(__pyx_t_10);
          } else
          #endif
          {
            __pyx_t_6 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 151, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            if (__pyx_t_1) {
              __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); __pyx_t_1 = NULL;
            }
            __Pyx_INCREF(__pyx_v_tree1);
            __Pyx_GIVEREF(__pyx_v_tree1);
            PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_8, __pyx_v_tree1);
            __Pyx_INCREF(__pyx_v_tree2);
            __Pyx_GIVEREF(__pyx_v_tree2);
            PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_8, __pyx_v_tree2);
            __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_6, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 151, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_10);
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          }
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_XDECREF_SET(__pyx_v_dist, __pyx_t_10);
          __pyx_t_10 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":152
 *                     tree2 = trees.parseSExpression('(' + str.join(' ', elems2) + ')')[0]
 *                     dist = trees.calcTreeEditDistance(tree1, tree2)
 *                     rate = math.exp(-dist)             # <<<<<<<<<<<<<<
 *                     features[key] += (rate * srcFeatures[key] * trgFeatures[key])
 *                 else:
 */
          __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_math); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 152, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_exp); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 152, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = PyNumber_Negative(__pyx_v_dist); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 152, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_1 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
            __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_6);
            if (likely(__pyx_t_1)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
              __Pyx_INCREF(__pyx_t_1);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_6, function);
            }
          }
          if (!__pyx_t_1) {
            __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 152, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            __Pyx_GOTREF(__pyx_t_10);
          } else {
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_6)) {
              PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_7};
              __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 152, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
              __Pyx_GOTREF(__pyx_t_10);
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
              PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_7};
              __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 152, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
              __Pyx_GOTREF(__pyx_t_10);
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
            } else
            #endif
            {
              __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 152, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_9);
              __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1); __pyx_t_1 = NULL;
              __Pyx_GIVEREF(__pyx_t_7);
              PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_7);
              __pyx_t_7 = 0;
              __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_9, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 152, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_10);
              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            }
          }
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_XDECREF_SET(__pyx_v_rate, __pyx_t_10);
          __pyx_t_10 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":153
 *                     dist = trees.calcTreeEditDistance(tree1, tree2)
 *                     rate = math.exp(-dist)
 *                     features[key] += (rate * srcFeatures[key] * trgFeatures[key])             # <<<<<<<<<<<<<<
 *                 else:
 *                     assert False, 'Invalid Match Method'
 */
          __Pyx_INCREF(__pyx_v_key);
          __pyx_t_10 = __pyx_v_key;
          __pyx_t_6 = PyObject_GetItem(__pyx_v_features, __pyx_t_10); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 153, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_9 = PyObject_GetItem(__pyx_v_srcFeatures, __pyx_v_key); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 153, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_7 = PyNumber_Multiply(__pyx_v_rate, __pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 153, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_9 = PyObject_GetItem(__pyx_v_trgFeatures, __pyx_v_key); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 153, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_1 = PyNumber_Multiply(__pyx_t_7, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 153, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __pyx_t_9 = PyNumber_InPlaceAdd(__pyx_t_6, __pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 153, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          if (unlikely(PyObject_SetItem(__pyx_v_features, __pyx_t_10, __pyx_t_9) < 0)) __PYX_ERR(0, 153, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":146
 *                     rate = max(1, 1 + numElems - numTerms - dist) / float(max(1, 1 + numElems - numTerms))
 *                     features[key] += (rate * srcFeatures[key] * trgFeatures[key])
 *                 elif workset.matchMethod == 'treedistexp':             # <<<<<<<<<<<<<<
 *                     elems1 = recPair[0].trg.split(' ')[0:-1]
 *                     elems2 = recPair[1].src.split(' ')[0:-1]
 */
          goto __pyx_L7;
        }

        /* "lpu/smt/trans_models/triangulate.pyx":155
 *                     features[key] += (rate * srcFeatures[key] * trgFeatures[key])
 *                 else:
 *                     assert False, 'Invalid Match Method'             # <<<<<<<<<<<<<<
 *         if multi_target:
 *             # p(trg,pvt|src) ~ p(trg|pvt) * p(pvt|src)
 */
        /*else*/ {
          #ifndef CYTHON_WITHOUT_ASSERTIONS
          if (unlikely(!Py_OptimizeFlag)) {
            if (unlikely(!0)) {
              PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_Invalid_Match_Method);
              __PYX_ERR(0, 155, __pyx_L1_error)
            }
          }
          #endif
        }
        __pyx_L7:;

        /* "lpu/smt/trans_models/triangulate.pyx":128
 *         # multiplying scores and marginalizing
 *         if not multi_target:
 *             for key in ['egfl', 'egfp', 'fgel', 'fgep']:             # <<<<<<<<<<<<<<
 *                 features.setdefault(key, 0)
 *                 if workset.matchMethod == 'hiero':
 */
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":127
 *     if workset.method.find('prodprob') >= 0:
 *         # multiplying scores and marginalizing
 *         if not multi_target:             # <<<<<<<<<<<<<<
 *             for key in ['egfl', 'egfp', 'fgel', 'fgep']:
 *                 features.setdefault(key, 0)
 */
    }

    /* "lpu/smt/trans_models/triangulate.pyx":156
 *                 else:
 *                     assert False, 'Invalid Match Method'
 *         if multi_target:             # <<<<<<<<<<<<<<
 *             # p(trg,pvt|src) ~ p(trg|pvt) * p(pvt|src)
 *             features['egfp'] =  srcFeatures['egfp'] * trgFeatures['egfp']
 */
    __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_v_multi_target); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 156, __pyx_L1_error)
    if (__pyx_t_4) {

      /* "lpu/smt/trans_models/triangulate.pyx":158
 *         if multi_target:
 *             # p(trg,pvt|src) ~ p(trg|pvt) * p(pvt|src)
 *             features['egfp'] =  srcFeatures['egfp'] * trgFeatures['egfp']             # <<<<<<<<<<<<<<
 *             if workset.jointMethod == 'memoryless':
 *                 # p(src|pvt,trg) ~ f(src|pvt)
 */
      __pyx_t_2 = PyObject_GetItem(__pyx_v_srcFeatures, __pyx_n_s_egfp); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 158, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_10 = PyObject_GetItem(__pyx_v_trgFeatures, __pyx_n_s_egfp); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 158, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_9 = PyNumber_Multiply(__pyx_t_2, __pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 158, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      if (unlikely(PyObject_SetItem(__pyx_v_features, __pyx_n_s_egfp, __pyx_t_9) < 0)) __PYX_ERR(0, 158, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":159
 *             # p(trg,pvt|src) ~ p(trg|pvt) * p(pvt|src)
 *             features['egfp'] =  srcFeatures['egfp'] * trgFeatures['egfp']
 *             if workset.jointMethod == 'memoryless':             # <<<<<<<<<<<<<<
 *                 # p(src|pvt,trg) ~ f(src|pvt)
 *                 features['fgep'] = srcFeatures['fgep']
 */
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_jointMethod); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 159, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_t_9, __pyx_n_s_memoryless, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 159, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      if (__pyx_t_4) {

        /* "lpu/smt/trans_models/triangulate.pyx":161
 *             if workset.jointMethod == 'memoryless':
 *                 # p(src|pvt,trg) ~ f(src|pvt)
 *                 features['fgep'] = srcFeatures['fgep']             # <<<<<<<<<<<<<<
 *             else:
 *                 features['fgep'] = 1.0
 */
        __pyx_t_9 = PyObject_GetItem(__pyx_v_srcFeatures, __pyx_n_s_fgep); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 161, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_9);
        if (unlikely(PyObject_SetItem(__pyx_v_features, __pyx_n_s_fgep, __pyx_t_9) < 0)) __PYX_ERR(0, 161, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":159
 *             # p(trg,pvt|src) ~ p(trg|pvt) * p(pvt|src)
 *             features['egfp'] =  srcFeatures['egfp'] * trgFeatures['egfp']
 *             if workset.jointMethod == 'memoryless':             # <<<<<<<<<<<<<<
 *                 # p(src|pvt,trg) ~ f(src|pvt)
 *                 features['fgep'] = srcFeatures['fgep']
 */
        goto __pyx_L9;
      }

      /* "lpu/smt/trans_models/triangulate.pyx":163
 *                 features['fgep'] = srcFeatures['fgep']
 *             else:
 *                 features['fgep'] = 1.0             # <<<<<<<<<<<<<<
 * #            for key in ['egfp', 'fgep']:
 * #                features.setdefault(key, 0)
 */
      /*else*/ {
        if (unlikely(PyObject_SetItem(__pyx_v_features, __pyx_n_s_fgep, __pyx_float_1_0) < 0)) __PYX_ERR(0, 163, __pyx_L1_error)
      }
      __pyx_L9:;

      /* "lpu/smt/trans_models/triangulate.pyx":171
 * #            # P(src|pvt,trg) ~ P(src|pvt)
 * #            features['fgep'] = srcFeatures['fgep']
 *             for key in ['egfl', 'egfp', 'fgel', 'fgep']:             # <<<<<<<<<<<<<<
 *                 features['1'+key] = srcFeatures[key]
 *     else:
 */
      __pyx_t_9 = __pyx_tuple__14; __Pyx_INCREF(__pyx_t_9); __pyx_t_5 = 0;
      for (;;) {
        if (__pyx_t_5 >= 4) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_10 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_5); __Pyx_INCREF(__pyx_t_10); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 171, __pyx_L1_error)
        #else
        __pyx_t_10 = PySequence_ITEM(__pyx_t_9, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 171, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        #endif
        __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_10);
        __pyx_t_10 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":172
 * #            features['fgep'] = srcFeatures['fgep']
 *             for key in ['egfl', 'egfp', 'fgel', 'fgep']:
 *                 features['1'+key] = srcFeatures[key]             # <<<<<<<<<<<<<<
 *     else:
 *         # multiplying only lexical weights and marginalizing
 */
        __pyx_t_10 = PyObject_GetItem(__pyx_v_srcFeatures, __pyx_v_key); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 172, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_2 = PyNumber_Add(__pyx_kp_s_1, __pyx_v_key); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 172, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        if (unlikely(PyObject_SetItem(__pyx_v_features, __pyx_t_2, __pyx_t_10) < 0)) __PYX_ERR(0, 172, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":171
 * #            # P(src|pvt,trg) ~ P(src|pvt)
 * #            features['fgep'] = srcFeatures['fgep']
 *             for key in ['egfl', 'egfp', 'fgel', 'fgep']:             # <<<<<<<<<<<<<<
 *                 features['1'+key] = srcFeatures[key]
 *     else:
 */
      }
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":156
 *                 else:
 *                     assert False, 'Invalid Match Method'
 *         if multi_target:             # <<<<<<<<<<<<<<
 *             # p(trg,pvt|src) ~ p(trg|pvt) * p(pvt|src)
 *             features['egfp'] =  srcFeatures['egfp'] * trgFeatures['egfp']
 */
    }

    /* "lpu/smt/trans_models/triangulate.pyx":125
 *     #logging.debug(trgFeatures)
 *     #if method.find('prodprob') >= 0:
 *     if workset.method.find('prodprob') >= 0:             # <<<<<<<<<<<<<<
 *         # multiplying scores and marginalizing
 *         if not multi_target:
 */
    goto __pyx_L3;
  }

  /* "lpu/smt/trans_models/triangulate.pyx":175
 *     else:
 *         # multiplying only lexical weights and marginalizing
 *         for key in ['egfl', 'fgel']:             # <<<<<<<<<<<<<<
 *             features.setdefault(key, 0)
 *             features[key] += (srcFeatures[key] * trgFeatures[key])
 */
  /*else*/ {
    __pyx_t_9 = __pyx_tuple__15; __Pyx_INCREF(__pyx_t_9); __pyx_t_5 = 0;
    for (;;) {
      if (__pyx_t_5 >= 2) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_10 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_5); __Pyx_INCREF(__pyx_t_10); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 175, __pyx_L1_error)
      #else
      __pyx_t_10 = PySequence_ITEM(__pyx_t_9, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 175, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      #endif
      __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_10);
      __pyx_t_10 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":176
 *         # multiplying only lexical weights and marginalizing
 *         for key in ['egfl', 'fgel']:
 *             features.setdefault(key, 0)             # <<<<<<<<<<<<<<
 *             features[key] += (srcFeatures[key] * trgFeatures[key])
 *     # using 'p' and 'w' of target
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_features, __pyx_n_s_setdefault); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 176, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = NULL;
      __pyx_t_8 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
          __pyx_t_8 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_key, __pyx_int_0};
        __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 176, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_10);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[3] = {__pyx_t_1, __pyx_v_key, __pyx_int_0};
        __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_8, 2+__pyx_t_8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 176, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_10);
      } else
      #endif
      {
        __pyx_t_6 = PyTuple_New(2+__pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 176, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        if (__pyx_t_1) {
          __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); __pyx_t_1 = NULL;
        }
        __Pyx_INCREF(__pyx_v_key);
        __Pyx_GIVEREF(__pyx_v_key);
        PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_8, __pyx_v_key);
        __Pyx_INCREF(__pyx_int_0);
        __Pyx_GIVEREF(__pyx_int_0);
        PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_8, __pyx_int_0);
        __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 176, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":177
 *         for key in ['egfl', 'fgel']:
 *             features.setdefault(key, 0)
 *             features[key] += (srcFeatures[key] * trgFeatures[key])             # <<<<<<<<<<<<<<
 *     # using 'p' and 'w' of target
 *     if 'p' in trgFeatures:
 */
      __Pyx_INCREF(__pyx_v_key);
      __pyx_t_10 = __pyx_v_key;
      __pyx_t_2 = PyObject_GetItem(__pyx_v_features, __pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 177, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = PyObject_GetItem(__pyx_v_srcFeatures, __pyx_v_key); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 177, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_1 = PyObject_GetItem(__pyx_v_trgFeatures, __pyx_v_key); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 177, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_7 = PyNumber_Multiply(__pyx_t_6, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 177, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_t_2, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 177, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (unlikely(PyObject_SetItem(__pyx_v_features, __pyx_t_10, __pyx_t_1) < 0)) __PYX_ERR(0, 177, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":175
 *     else:
 *         # multiplying only lexical weights and marginalizing
 *         for key in ['egfl', 'fgel']:             # <<<<<<<<<<<<<<
 *             features.setdefault(key, 0)
 *             features[key] += (srcFeatures[key] * trgFeatures[key])
 */
    }
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  }
  __pyx_L3:;

  /* "lpu/smt/trans_models/triangulate.pyx":179
 *             features[key] += (srcFeatures[key] * trgFeatures[key])
 *     # using 'p' and 'w' of target
 *     if 'p' in trgFeatures:             # <<<<<<<<<<<<<<
 *         features['p'] = trgFeatures['p']
 *     if multi_target:
 */
  __pyx_t_4 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_p, __pyx_v_trgFeatures, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 179, __pyx_L1_error)
  __pyx_t_3 = (__pyx_t_4 != 0);
  if (__pyx_t_3) {

    /* "lpu/smt/trans_models/triangulate.pyx":180
 *     # using 'p' and 'w' of target
 *     if 'p' in trgFeatures:
 *         features['p'] = trgFeatures['p']             # <<<<<<<<<<<<<<
 *     if multi_target:
 *         if 'w' in trgFeatures:
 */
    __pyx_t_9 = PyObject_GetItem(__pyx_v_trgFeatures, __pyx_n_s_p); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 180, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    if (unlikely(PyObject_SetItem(__pyx_v_features, __pyx_n_s_p, __pyx_t_9) < 0)) __PYX_ERR(0, 180, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":179
 *             features[key] += (srcFeatures[key] * trgFeatures[key])
 *     # using 'p' and 'w' of target
 *     if 'p' in trgFeatures:             # <<<<<<<<<<<<<<
 *         features['p'] = trgFeatures['p']
 *     if multi_target:
 */
  }

  /* "lpu/smt/trans_models/triangulate.pyx":181
 *     if 'p' in trgFeatures:
 *         features['p'] = trgFeatures['p']
 *     if multi_target:             # <<<<<<<<<<<<<<
 *         if 'w' in trgFeatures:
 *             features['0w'] = trgFeatures['w']
 */
  __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_multi_target); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 181, __pyx_L1_error)
  if (__pyx_t_3) {

    /* "lpu/smt/trans_models/triangulate.pyx":182
 *         features['p'] = trgFeatures['p']
 *     if multi_target:
 *         if 'w' in trgFeatures:             # <<<<<<<<<<<<<<
 *             features['0w'] = trgFeatures['w']
 *         if 'w' in srcFeatures:
 */
    __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_w, __pyx_v_trgFeatures, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 182, __pyx_L1_error)
    __pyx_t_4 = (__pyx_t_3 != 0);
    if (__pyx_t_4) {

      /* "lpu/smt/trans_models/triangulate.pyx":183
 *     if multi_target:
 *         if 'w' in trgFeatures:
 *             features['0w'] = trgFeatures['w']             # <<<<<<<<<<<<<<
 *         if 'w' in srcFeatures:
 *             features['1w'] = srcFeatures['w']
 */
      __pyx_t_9 = PyObject_GetItem(__pyx_v_trgFeatures, __pyx_n_s_w); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 183, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      if (unlikely(PyObject_SetItem(__pyx_v_features, __pyx_kp_s_0w, __pyx_t_9) < 0)) __PYX_ERR(0, 183, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":182
 *         features['p'] = trgFeatures['p']
 *     if multi_target:
 *         if 'w' in trgFeatures:             # <<<<<<<<<<<<<<
 *             features['0w'] = trgFeatures['w']
 *         if 'w' in srcFeatures:
 */
    }

    /* "lpu/smt/trans_models/triangulate.pyx":184
 *         if 'w' in trgFeatures:
 *             features['0w'] = trgFeatures['w']
 *         if 'w' in srcFeatures:             # <<<<<<<<<<<<<<
 *             features['1w'] = srcFeatures['w']
 *     else:
 */
    __pyx_t_4 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_w, __pyx_v_srcFeatures, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 184, __pyx_L1_error)
    __pyx_t_3 = (__pyx_t_4 != 0);
    if (__pyx_t_3) {

      /* "lpu/smt/trans_models/triangulate.pyx":185
 *             features['0w'] = trgFeatures['w']
 *         if 'w' in srcFeatures:
 *             features['1w'] = srcFeatures['w']             # <<<<<<<<<<<<<<
 *     else:
 *         if 'w' in trgFeatures:
 */
      __pyx_t_9 = PyObject_GetItem(__pyx_v_srcFeatures, __pyx_n_s_w); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 185, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      if (unlikely(PyObject_SetItem(__pyx_v_features, __pyx_kp_s_1w, __pyx_t_9) < 0)) __PYX_ERR(0, 185, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":184
 *         if 'w' in trgFeatures:
 *             features['0w'] = trgFeatures['w']
 *         if 'w' in srcFeatures:             # <<<<<<<<<<<<<<
 *             features['1w'] = srcFeatures['w']
 *     else:
 */
    }

    /* "lpu/smt/trans_models/triangulate.pyx":181
 *     if 'p' in trgFeatures:
 *         features['p'] = trgFeatures['p']
 *     if multi_target:             # <<<<<<<<<<<<<<
 *         if 'w' in trgFeatures:
 *             features['0w'] = trgFeatures['w']
 */
    goto __pyx_L15;
  }

  /* "lpu/smt/trans_models/triangulate.pyx":187
 *             features['1w'] = srcFeatures['w']
 *     else:
 *         if 'w' in trgFeatures:             # <<<<<<<<<<<<<<
 *             features['w'] = trgFeatures['w']
 * 
 */
  /*else*/ {
    __pyx_t_3 = (__Pyx_PySequence_ContainsTF(__pyx_n_s_w, __pyx_v_trgFeatures, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 187, __pyx_L1_error)
    __pyx_t_4 = (__pyx_t_3 != 0);
    if (__pyx_t_4) {

      /* "lpu/smt/trans_models/triangulate.pyx":188
 *     else:
 *         if 'w' in trgFeatures:
 *             features['w'] = trgFeatures['w']             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __pyx_t_9 = PyObject_GetItem(__pyx_v_trgFeatures, __pyx_n_s_w); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 188, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      if (unlikely(PyObject_SetItem(__pyx_v_features, __pyx_n_s_w, __pyx_t_9) < 0)) __PYX_ERR(0, 188, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":187
 *             features['1w'] = srcFeatures['w']
 *     else:
 *         if 'w' in trgFeatures:             # <<<<<<<<<<<<<<
 *             features['w'] = trgFeatures['w']
 * 
 */
    }
  }
  __pyx_L15:;

  /* "lpu/smt/trans_models/triangulate.pyx":116
 * 
 * #def updateFeatures(recPivot, recPair, method, multi_target = False, jointMethod = 'memoryless'):
 * def updateFeatures(recPivot, recPair, workset, multi_target = False):             # <<<<<<<<<<<<<<
 *     '''update features'''
 *     features = recPivot.features
 */

  /* function exit code */
  __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_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.updateFeatures", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_features);
  __Pyx_XDECREF(__pyx_v_srcFeatures);
  __Pyx_XDECREF(__pyx_v_trgFeatures);
  __Pyx_XDECREF(__pyx_v_key);
  __Pyx_XDECREF(__pyx_v_elems1);
  __Pyx_XDECREF(__pyx_v_elems2);
  __Pyx_XDECREF(__pyx_v_tree1);
  __Pyx_XDECREF(__pyx_v_tree2);
  __Pyx_XDECREF(__pyx_v_dist);
  __Pyx_XDECREF(__pyx_v_numTerms);
  __Pyx_XDECREF(__pyx_v_numElems);
  __Pyx_XDECREF(__pyx_v_rate);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "lpu/smt/trans_models/triangulate.pyx":191
 * 
 * 
 * def updateCounts(recPivot, recPair, method):             # <<<<<<<<<<<<<<
 *     '''update occurrence counts of phrase'''
 *     counts = recPivot.counts
 */

/* Python wrapper */
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_3updateCounts(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_3lpu_3smt_12trans_models_11triangulate_2updateCounts[] = "update occurrence counts of phrase";
static PyMethodDef __pyx_mdef_3lpu_3smt_12trans_models_11triangulate_3updateCounts = {"updateCounts", (PyCFunction)__pyx_pw_3lpu_3smt_12trans_models_11triangulate_3updateCounts, METH_VARARGS|METH_KEYWORDS, __pyx_doc_3lpu_3smt_12trans_models_11triangulate_2updateCounts};
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_3updateCounts(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_recPivot = 0;
  PyObject *__pyx_v_recPair = 0;
  PyObject *__pyx_v_method = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("updateCounts (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_recPivot,&__pyx_n_s_recPair,&__pyx_n_s_method,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);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        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_recPivot)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_recPair)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("updateCounts", 1, 3, 3, 1); __PYX_ERR(0, 191, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_method)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("updateCounts", 1, 3, 3, 2); __PYX_ERR(0, 191, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "updateCounts") < 0)) __PYX_ERR(0, 191, __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_recPivot = values[0];
    __pyx_v_recPair = values[1];
    __pyx_v_method = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("updateCounts", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 191, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.updateCounts", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_3lpu_3smt_12trans_models_11triangulate_2updateCounts(__pyx_self, __pyx_v_recPivot, __pyx_v_recPair, __pyx_v_method);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_2updateCounts(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_recPivot, PyObject *__pyx_v_recPair, PyObject *__pyx_v_method) {
  PyObject *__pyx_v_counts = NULL;
  PyObject *__pyx_v_features = NULL;
  PyObject *__pyx_v_c = NULL;
  PyObject *__pyx_v_counts1 = NULL;
  PyObject *__pyx_v_counts2 = NULL;
  PyObject *__pyx_v_cooc1 = NULL;
  PyObject *__pyx_v_cooc2 = NULL;
  PyObject *__pyx_v_co1 = NULL;
  PyObject *__pyx_v_co2 = 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;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  __Pyx_RefNannySetupContext("updateCounts", 0);

  /* "lpu/smt/trans_models/triangulate.pyx":193
 * def updateCounts(recPivot, recPair, method):
 *     '''update occurrence counts of phrase'''
 *     counts = recPivot.counts             # <<<<<<<<<<<<<<
 *     features = recPivot.features
 *     if method == 'countmin':
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_recPivot, __pyx_n_s_counts); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 193, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_counts = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":194
 *     '''update occurrence counts of phrase'''
 *     counts = recPivot.counts
 *     features = recPivot.features             # <<<<<<<<<<<<<<
 *     if method == 'countmin':
 *         #counts.co = max(counts.co, min(recPair[0].counts.co, recPair[1].counts.co))
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_recPivot, __pyx_n_s_features); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 194, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_features = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":195
 *     counts = recPivot.counts
 *     features = recPivot.features
 *     if method == 'countmin':             # <<<<<<<<<<<<<<
 *         #counts.co = max(counts.co, min(recPair[0].counts.co, recPair[1].counts.co))
 *         #c = recPair[0].counts.co * recPair[1].counts.co
 */
  __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_v_method, __pyx_n_s_countmin, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 195, __pyx_L1_error)
  if (__pyx_t_2) {

    /* "lpu/smt/trans_models/triangulate.pyx":198
 *         #counts.co = max(counts.co, min(recPair[0].counts.co, recPair[1].counts.co))
 *         #c = recPair[0].counts.co * recPair[1].counts.co
 *         c = min(recPair[0].counts.cooc, recPair[1].counts.cooc)             # <<<<<<<<<<<<<<
 *         counts.cooc += c
 *         #counts.co = counts.co + c + 2 * math.sqrt(counts.co * c)
 */
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_recPair, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 198, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_counts); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 198, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_cooc); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 198, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_recPair, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 198, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_counts); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 198, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_cooc); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 198, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = PyObject_RichCompare(__pyx_t_1, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 198, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 198, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__pyx_t_2) {
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_4 = __pyx_t_1;
    } else {
      __Pyx_INCREF(__pyx_t_3);
      __pyx_t_4 = __pyx_t_3;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __pyx_t_4;
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_c = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":199
 *         #c = recPair[0].counts.co * recPair[1].counts.co
 *         c = min(recPair[0].counts.cooc, recPair[1].counts.cooc)
 *         counts.cooc += c             # <<<<<<<<<<<<<<
 *         #counts.co = counts.co + c + 2 * math.sqrt(counts.co * c)
 *     elif method == 'bidirmin':
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts, __pyx_n_s_cooc); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 199, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_t_1, __pyx_v_c); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 199, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__Pyx_PyObject_SetAttrStr(__pyx_v_counts, __pyx_n_s_cooc, __pyx_t_4) < 0) __PYX_ERR(0, 199, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":195
 *     counts = recPivot.counts
 *     features = recPivot.features
 *     if method == 'countmin':             # <<<<<<<<<<<<<<
 *         #counts.co = max(counts.co, min(recPair[0].counts.co, recPair[1].counts.co))
 *         #c = recPair[0].counts.co * recPair[1].counts.co
 */
    goto __pyx_L3;
  }

  /* "lpu/smt/trans_models/triangulate.pyx":201
 *         counts.cooc += c
 *         #counts.co = counts.co + c + 2 * math.sqrt(counts.co * c)
 *     elif method == 'bidirmin':             # <<<<<<<<<<<<<<
 *         counts1 = recPair[0].counts
 *         counts2 = recPair[1].counts
 */
  __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_v_method, __pyx_n_s_bidirmin, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 201, __pyx_L1_error)
  if (__pyx_t_2) {

    /* "lpu/smt/trans_models/triangulate.pyx":202
 *         #counts.co = counts.co + c + 2 * math.sqrt(counts.co * c)
 *     elif method == 'bidirmin':
 *         counts1 = recPair[0].counts             # <<<<<<<<<<<<<<
 *         counts2 = recPair[1].counts
 *         cooc1 = counts1.cooc * counts2.cooc / float(counts2.src)
 */
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_v_recPair, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 202, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_counts); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 202, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_counts1 = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":203
 *     elif method == 'bidirmin':
 *         counts1 = recPair[0].counts
 *         counts2 = recPair[1].counts             # <<<<<<<<<<<<<<
 *         cooc1 = counts1.cooc * counts2.cooc / float(counts2.src)
 *         cooc2 = counts2.cooc * counts1.cooc / float(counts1.trg)
 */
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_recPair, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 203, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_counts); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 203, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_counts2 = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":204
 *         counts1 = recPair[0].counts
 *         counts2 = recPair[1].counts
 *         cooc1 = counts1.cooc * counts2.cooc / float(counts2.src)             # <<<<<<<<<<<<<<
 *         cooc2 = counts2.cooc * counts1.cooc / float(counts1.trg)
 *         counts.cooc += min(cooc1, cooc2)
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts1, __pyx_n_s_cooc); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 204, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts2, __pyx_n_s_cooc); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 204, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_3 = PyNumber_Multiply(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 204, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts2, __pyx_n_s_src); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 204, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyNumber_Float(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 204, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 204, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_cooc1 = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":205
 *         counts2 = recPair[1].counts
 *         cooc1 = counts1.cooc * counts2.cooc / float(counts2.src)
 *         cooc2 = counts2.cooc * counts1.cooc / float(counts1.trg)             # <<<<<<<<<<<<<<
 *         counts.cooc += min(cooc1, cooc2)
 * #        if True:
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts2, __pyx_n_s_cooc); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 205, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts1, __pyx_n_s_cooc); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 205, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyNumber_Multiply(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 205, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts1, __pyx_n_s_trg); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 205, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = __Pyx_PyNumber_Float(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 205, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyNumber_Divide(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 205, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_cooc2 = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":206
 *         cooc1 = counts1.cooc * counts2.cooc / float(counts2.src)
 *         cooc2 = counts2.cooc * counts1.cooc / float(counts1.trg)
 *         counts.cooc += min(cooc1, cooc2)             # <<<<<<<<<<<<<<
 * #        if True:
 * #        if recPair[0].src.find('Dieu') >= 0:
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts, __pyx_n_s_cooc); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 206, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_v_cooc2);
    __pyx_t_1 = __pyx_v_cooc2;
    __Pyx_INCREF(__pyx_v_cooc1);
    __pyx_t_3 = __pyx_v_cooc1;
    __pyx_t_6 = PyObject_RichCompare(__pyx_t_1, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 206, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 206, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (__pyx_t_2) {
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_5 = __pyx_t_1;
    } else {
      __Pyx_INCREF(__pyx_t_3);
      __pyx_t_5 = __pyx_t_3;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 206, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__Pyx_PyObject_SetAttrStr(__pyx_v_counts, __pyx_n_s_cooc, __pyx_t_1) < 0) __PYX_ERR(0, 206, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":201
 *         counts.cooc += c
 *         #counts.co = counts.co + c + 2 * math.sqrt(counts.co * c)
 *     elif method == 'bidirmin':             # <<<<<<<<<<<<<<
 *         counts1 = recPair[0].counts
 *         counts2 = recPair[1].counts
 */
    goto __pyx_L3;
  }

  /* "lpu/smt/trans_models/triangulate.pyx":210
 * #        if recPair[0].src.find('Dieu') >= 0:
 * #            progress.log("%s ||| %s ||| %s ||| (%s %s %s) * (%s %s %s) -> %s %s -> %s\n" % (recPair[0].src, recPair[0].trg, recPair[1].trg, counts1.co, counts1.src, counts1.trg, counts2.co, counts2.src, counts2.trg, co1, co2, min(co1,co2)))
 *     elif method == 'bidirgmean':             # <<<<<<<<<<<<<<
 *         counts1 = recPair[0].counts
 *         counts2 = recPair[1].counts
 */
  __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_v_method, __pyx_n_s_bidirgmean, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 210, __pyx_L1_error)
  if (__pyx_t_2) {

    /* "lpu/smt/trans_models/triangulate.pyx":211
 * #            progress.log("%s ||| %s ||| %s ||| (%s %s %s) * (%s %s %s) -> %s %s -> %s\n" % (recPair[0].src, recPair[0].trg, recPair[1].trg, counts1.co, counts1.src, counts1.trg, counts2.co, counts2.src, counts2.trg, co1, co2, min(co1,co2)))
 *     elif method == 'bidirgmean':
 *         counts1 = recPair[0].counts             # <<<<<<<<<<<<<<
 *         counts2 = recPair[1].counts
 *         co1 = counts1.co * counts2.co / float(counts2.src)
 */
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_recPair, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 211, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_counts); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 211, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_counts1 = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":212
 *     elif method == 'bidirgmean':
 *         counts1 = recPair[0].counts
 *         counts2 = recPair[1].counts             # <<<<<<<<<<<<<<
 *         co1 = counts1.co * counts2.co / float(counts2.src)
 *         co2 = counts2.co * counts1.co / float(counts1.trg)
 */
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_recPair, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 212, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_counts); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 212, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_counts2 = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":213
 *         counts1 = recPair[0].counts
 *         counts2 = recPair[1].counts
 *         co1 = counts1.co * counts2.co / float(counts2.src)             # <<<<<<<<<<<<<<
 *         co2 = counts2.co * counts1.co / float(counts1.trg)
 *         counts.co += math.sqrt(co1*co2)
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts1, __pyx_n_s_co); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 213, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts2, __pyx_n_s_co); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 213, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = PyNumber_Multiply(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 213, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts2, __pyx_n_s_src); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 213, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_PyNumber_Float(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 213, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyNumber_Divide(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 213, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_v_co1 = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":214
 *         counts2 = recPair[1].counts
 *         co1 = counts1.co * counts2.co / float(counts2.src)
 *         co2 = counts2.co * counts1.co / float(counts1.trg)             # <<<<<<<<<<<<<<
 *         counts.co += math.sqrt(co1*co2)
 * #        progress.log("%s ||| %s ||| %s ||| (%s %s %s) * (%s %s %s) -> %s %s -> %s\n" % (recPair[0].src, recPair[0].trg, recPair[1].trg, counts1.co, counts1.src, counts1.trg, counts2.co, counts2.src, counts2.trg, co1, co2, math.sqrt(co1*co2)))
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts2, __pyx_n_s_co); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 214, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts1, __pyx_n_s_co); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 214, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = PyNumber_Multiply(__pyx_t_5, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 214, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts1, __pyx_n_s_trg); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 214, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_5 = __Pyx_PyNumber_Float(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 214, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 214, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_co2 = __pyx_t_1;
    __pyx_t_1 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":215
 *         co1 = counts1.co * counts2.co / float(counts2.src)
 *         co2 = counts2.co * counts1.co / float(counts1.trg)
 *         counts.co += math.sqrt(co1*co2)             # <<<<<<<<<<<<<<
 * #        progress.log("%s ||| %s ||| %s ||| (%s %s %s) * (%s %s %s) -> %s %s -> %s\n" % (recPair[0].src, recPair[0].trg, recPair[1].trg, counts1.co, counts1.src, counts1.trg, counts2.co, counts2.src, counts2.trg, co1, co2, math.sqrt(co1*co2)))
 *     elif method == 'bidirmax':
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts, __pyx_n_s_co); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 215, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_math); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 215, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_sqrt); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 215, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_Multiply(__pyx_v_co1, __pyx_v_co2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 215, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_6 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_6)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
      }
    }
    if (!__pyx_t_6) {
      __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 215, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_5);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_3)) {
        PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_4};
        __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 215, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
        PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_4};
        __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 215, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      } else
      #endif
      {
        __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 215, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL;
        __Pyx_GIVEREF(__pyx_t_4);
        PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_4);
        __pyx_t_4 = 0;
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 215, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 215, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (__Pyx_PyObject_SetAttrStr(__pyx_v_counts, __pyx_n_s_co, __pyx_t_3) < 0) __PYX_ERR(0, 215, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":210
 * #        if recPair[0].src.find('Dieu') >= 0:
 * #            progress.log("%s ||| %s ||| %s ||| (%s %s %s) * (%s %s %s) -> %s %s -> %s\n" % (recPair[0].src, recPair[0].trg, recPair[1].trg, counts1.co, counts1.src, counts1.trg, counts2.co, counts2.src, counts2.trg, co1, co2, min(co1,co2)))
 *     elif method == 'bidirgmean':             # <<<<<<<<<<<<<<
 *         counts1 = recPair[0].counts
 *         counts2 = recPair[1].counts
 */
    goto __pyx_L3;
  }

  /* "lpu/smt/trans_models/triangulate.pyx":217
 *         counts.co += math.sqrt(co1*co2)
 * #        progress.log("%s ||| %s ||| %s ||| (%s %s %s) * (%s %s %s) -> %s %s -> %s\n" % (recPair[0].src, recPair[0].trg, recPair[1].trg, counts1.co, counts1.src, counts1.trg, counts2.co, counts2.src, counts2.trg, co1, co2, math.sqrt(co1*co2)))
 *     elif method == 'bidirmax':             # <<<<<<<<<<<<<<
 *         counts1 = recPair[0].counts
 *         counts2 = recPair[1].counts
 */
  __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_v_method, __pyx_n_s_bidirmax, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 217, __pyx_L1_error)
  if (__pyx_t_2) {

    /* "lpu/smt/trans_models/triangulate.pyx":218
 * #        progress.log("%s ||| %s ||| %s ||| (%s %s %s) * (%s %s %s) -> %s %s -> %s\n" % (recPair[0].src, recPair[0].trg, recPair[1].trg, counts1.co, counts1.src, counts1.trg, counts2.co, counts2.src, counts2.trg, co1, co2, math.sqrt(co1*co2)))
 *     elif method == 'bidirmax':
 *         counts1 = recPair[0].counts             # <<<<<<<<<<<<<<
 *         counts2 = recPair[1].counts
 *         co1 = counts1.co * counts2.co / float(counts2.src)
 */
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_recPair, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 218, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_counts); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 218, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_counts1 = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":219
 *     elif method == 'bidirmax':
 *         counts1 = recPair[0].counts
 *         counts2 = recPair[1].counts             # <<<<<<<<<<<<<<
 *         co1 = counts1.co * counts2.co / float(counts2.src)
 *         co2 = counts2.co * counts1.co / float(counts1.trg)
 */
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_recPair, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 219, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_counts); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 219, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_counts2 = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":220
 *         counts1 = recPair[0].counts
 *         counts2 = recPair[1].counts
 *         co1 = counts1.co * counts2.co / float(counts2.src)             # <<<<<<<<<<<<<<
 *         co2 = counts2.co * counts1.co / float(counts1.trg)
 *         counts.co += max(co1, co2)
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts1, __pyx_n_s_co); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 220, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts2, __pyx_n_s_co); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 220, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_1 = PyNumber_Multiply(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 220, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts2, __pyx_n_s_src); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 220, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = __Pyx_PyNumber_Float(__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 220, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyNumber_Divide(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 220, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_v_co1 = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":221
 *         counts2 = recPair[1].counts
 *         co1 = counts1.co * counts2.co / float(counts2.src)
 *         co2 = counts2.co * counts1.co / float(counts1.trg)             # <<<<<<<<<<<<<<
 *         counts.co += max(co1, co2)
 *     elif method == 'bidiravr':
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts2, __pyx_n_s_co); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 221, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts1, __pyx_n_s_co); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 221, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_1 = PyNumber_Multiply(__pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 221, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts1, __pyx_n_s_trg); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 221, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyNumber_Float(__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 221, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyNumber_Divide(__pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 221, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_co2 = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":222
 *         co1 = counts1.co * counts2.co / float(counts2.src)
 *         co2 = counts2.co * counts1.co / float(counts1.trg)
 *         counts.co += max(co1, co2)             # <<<<<<<<<<<<<<
 *     elif method == 'bidiravr':
 *         counts1 = recPair[0].counts
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts, __pyx_n_s_co); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 222, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_co2);
    __pyx_t_5 = __pyx_v_co2;
    __Pyx_INCREF(__pyx_v_co1);
    __pyx_t_1 = __pyx_v_co1;
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_5, __pyx_t_1, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 222, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 222, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_2) {
      __Pyx_INCREF(__pyx_t_5);
      __pyx_t_7 = __pyx_t_5;
    } else {
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_7 = __pyx_t_1;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_t_3, __pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 222, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (__Pyx_PyObject_SetAttrStr(__pyx_v_counts, __pyx_n_s_co, __pyx_t_5) < 0) __PYX_ERR(0, 222, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":217
 *         counts.co += math.sqrt(co1*co2)
 * #        progress.log("%s ||| %s ||| %s ||| (%s %s %s) * (%s %s %s) -> %s %s -> %s\n" % (recPair[0].src, recPair[0].trg, recPair[1].trg, counts1.co, counts1.src, counts1.trg, counts2.co, counts2.src, counts2.trg, co1, co2, math.sqrt(co1*co2)))
 *     elif method == 'bidirmax':             # <<<<<<<<<<<<<<
 *         counts1 = recPair[0].counts
 *         counts2 = recPair[1].counts
 */
    goto __pyx_L3;
  }

  /* "lpu/smt/trans_models/triangulate.pyx":223
 *         co2 = counts2.co * counts1.co / float(counts1.trg)
 *         counts.co += max(co1, co2)
 *     elif method == 'bidiravr':             # <<<<<<<<<<<<<<
 *         counts1 = recPair[0].counts
 *         counts2 = recPair[1].counts
 */
  __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_v_method, __pyx_n_s_bidiravr, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 223, __pyx_L1_error)
  if (__pyx_t_2) {

    /* "lpu/smt/trans_models/triangulate.pyx":224
 *         counts.co += max(co1, co2)
 *     elif method == 'bidiravr':
 *         counts1 = recPair[0].counts             # <<<<<<<<<<<<<<
 *         counts2 = recPair[1].counts
 *         co1 = counts1.cooc * counts2.co / float(counts2.src)
 */
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_recPair, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 224, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_counts); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 224, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_counts1 = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":225
 *     elif method == 'bidiravr':
 *         counts1 = recPair[0].counts
 *         counts2 = recPair[1].counts             # <<<<<<<<<<<<<<
 *         co1 = counts1.cooc * counts2.co / float(counts2.src)
 *         co2 = counts2.cooc * counts1.co / float(counts1.trg)
 */
    __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_recPair, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 225, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_counts); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 225, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_v_counts2 = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":226
 *         counts1 = recPair[0].counts
 *         counts2 = recPair[1].counts
 *         co1 = counts1.cooc * counts2.co / float(counts2.src)             # <<<<<<<<<<<<<<
 *         co2 = counts2.cooc * counts1.co / float(counts1.trg)
 *         counts.co += (co1 + co2) * 0.5
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts1, __pyx_n_s_cooc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 226, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts2, __pyx_n_s_co); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 226, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_3 = PyNumber_Multiply(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 226, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts2, __pyx_n_s_src); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 226, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_5 = __Pyx_PyNumber_Float(__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 226, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyNumber_Divide(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 226, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_co1 = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":227
 *         counts2 = recPair[1].counts
 *         co1 = counts1.cooc * counts2.co / float(counts2.src)
 *         co2 = counts2.cooc * counts1.co / float(counts1.trg)             # <<<<<<<<<<<<<<
 *         counts.co += (co1 + co2) * 0.5
 *     elif method == 'prodprob':
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts2, __pyx_n_s_cooc); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 227, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts1, __pyx_n_s_co); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 227, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyNumber_Multiply(__pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 227, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts1, __pyx_n_s_trg); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 227, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = __Pyx_PyNumber_Float(__pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 227, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyNumber_Divide(__pyx_t_3, __pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 227, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_v_co2 = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":228
 *         co1 = counts1.cooc * counts2.co / float(counts2.src)
 *         co2 = counts2.cooc * counts1.co / float(counts1.trg)
 *         counts.co += (co1 + co2) * 0.5             # <<<<<<<<<<<<<<
 *     elif method == 'prodprob':
 *         counts.src  = recPair[0].counts.src
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts, __pyx_n_s_co); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 228, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_7 = PyNumber_Add(__pyx_v_co1, __pyx_v_co2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 228, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_3 = PyNumber_Multiply(__pyx_t_7, __pyx_float_0_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 228, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = PyNumber_InPlaceAdd(__pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 228, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__Pyx_PyObject_SetAttrStr(__pyx_v_counts, __pyx_n_s_co, __pyx_t_7) < 0) __PYX_ERR(0, 228, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":223
 *         co2 = counts2.co * counts1.co / float(counts1.trg)
 *         counts.co += max(co1, co2)
 *     elif method == 'bidiravr':             # <<<<<<<<<<<<<<
 *         counts1 = recPair[0].counts
 *         counts2 = recPair[1].counts
 */
    goto __pyx_L3;
  }

  /* "lpu/smt/trans_models/triangulate.pyx":229
 *         co2 = counts2.cooc * counts1.co / float(counts1.trg)
 *         counts.co += (co1 + co2) * 0.5
 *     elif method == 'prodprob':             # <<<<<<<<<<<<<<
 *         counts.src  = recPair[0].counts.src
 *         counts.cooc = counts.src * features['egfp']
 */
  __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_v_method, __pyx_n_s_prodprob, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 229, __pyx_L1_error)
  if (__pyx_t_2) {

    /* "lpu/smt/trans_models/triangulate.pyx":230
 *         counts.co += (co1 + co2) * 0.5
 *     elif method == 'prodprob':
 *         counts.src  = recPair[0].counts.src             # <<<<<<<<<<<<<<
 *         counts.cooc = counts.src * features['egfp']
 *         counts.trg  = counts.cooc / features['fgep']
 */
    __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_recPair, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 230, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_counts); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 230, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_src); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 230, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__Pyx_PyObject_SetAttrStr(__pyx_v_counts, __pyx_n_s_src, __pyx_t_7) < 0) __PYX_ERR(0, 230, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":231
 *     elif method == 'prodprob':
 *         counts.src  = recPair[0].counts.src
 *         counts.cooc = counts.src * features['egfp']             # <<<<<<<<<<<<<<
 *         counts.trg  = counts.cooc / features['fgep']
 *     elif method == 'multi':
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts, __pyx_n_s_src); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 231, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_3 = PyObject_GetItem(__pyx_v_features, __pyx_n_s_egfp); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 231, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = PyNumber_Multiply(__pyx_t_7, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 231, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__Pyx_PyObject_SetAttrStr(__pyx_v_counts, __pyx_n_s_cooc, __pyx_t_5) < 0) __PYX_ERR(0, 231, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":232
 *         counts.src  = recPair[0].counts.src
 *         counts.cooc = counts.src * features['egfp']
 *         counts.trg  = counts.cooc / features['fgep']             # <<<<<<<<<<<<<<
 *     elif method == 'multi':
 *         c = min(recPair[0].counts.co, recPair[1].counts.co)
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts, __pyx_n_s_cooc); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 232, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_3 = PyObject_GetItem(__pyx_v_features, __pyx_n_s_fgep); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 232, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_7 = __Pyx_PyNumber_Divide(__pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 232, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__Pyx_PyObject_SetAttrStr(__pyx_v_counts, __pyx_n_s_trg, __pyx_t_7) < 0) __PYX_ERR(0, 232, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":229
 *         co2 = counts2.cooc * counts1.co / float(counts1.trg)
 *         counts.co += (co1 + co2) * 0.5
 *     elif method == 'prodprob':             # <<<<<<<<<<<<<<
 *         counts.src  = recPair[0].counts.src
 *         counts.cooc = counts.src * features['egfp']
 */
    goto __pyx_L3;
  }

  /* "lpu/smt/trans_models/triangulate.pyx":233
 *         counts.cooc = counts.src * features['egfp']
 *         counts.trg  = counts.cooc / features['fgep']
 *     elif method == 'multi':             # <<<<<<<<<<<<<<
 *         c = min(recPair[0].counts.co, recPair[1].counts.co)
 *         counts.co += c
 */
  __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_v_method, __pyx_n_s_multi, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 233, __pyx_L1_error)
  if (__pyx_t_2) {

    /* "lpu/smt/trans_models/triangulate.pyx":234
 *         counts.trg  = counts.cooc / features['fgep']
 *     elif method == 'multi':
 *         c = min(recPair[0].counts.co, recPair[1].counts.co)             # <<<<<<<<<<<<<<
 *         counts.co += c
 *     else:
 */
    __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_recPair, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 234, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_counts); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 234, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_co); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 234, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_recPair, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 234, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_counts); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 234, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_co); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 234, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_1 = PyObject_RichCompare(__pyx_t_7, __pyx_t_3, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 234, __pyx_L1_error)
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 234, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_2) {
      __Pyx_INCREF(__pyx_t_7);
      __pyx_t_5 = __pyx_t_7;
    } else {
      __Pyx_INCREF(__pyx_t_3);
      __pyx_t_5 = __pyx_t_3;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __pyx_t_5;
    __Pyx_INCREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_v_c = __pyx_t_7;
    __pyx_t_7 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":235
 *     elif method == 'multi':
 *         c = min(recPair[0].counts.co, recPair[1].counts.co)
 *         counts.co += c             # <<<<<<<<<<<<<<
 *     else:
 *         assert False, "Invalid method: %s" % method
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts, __pyx_n_s_co); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 235, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_t_7, __pyx_v_c); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 235, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (__Pyx_PyObject_SetAttrStr(__pyx_v_counts, __pyx_n_s_co, __pyx_t_5) < 0) __PYX_ERR(0, 235, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":233
 *         counts.cooc = counts.src * features['egfp']
 *         counts.trg  = counts.cooc / features['fgep']
 *     elif method == 'multi':             # <<<<<<<<<<<<<<
 *         c = min(recPair[0].counts.co, recPair[1].counts.co)
 *         counts.co += c
 */
    goto __pyx_L3;
  }

  /* "lpu/smt/trans_models/triangulate.pyx":237
 *         counts.co += c
 *     else:
 *         assert False, "Invalid method: %s" % method             # <<<<<<<<<<<<<<
 * 
 * 
 */
  /*else*/ {
    #ifndef CYTHON_WITHOUT_ASSERTIONS
    if (unlikely(!Py_OptimizeFlag)) {
      if (unlikely(!0)) {
        __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_Invalid_method_s, __pyx_v_method); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 237, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        PyErr_SetObject(PyExc_AssertionError, __pyx_t_5);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __PYX_ERR(0, 237, __pyx_L1_error)
      }
    }
    #endif
  }
  __pyx_L3:;

  /* "lpu/smt/trans_models/triangulate.pyx":191
 * 
 * 
 * def updateCounts(recPivot, recPair, method):             # <<<<<<<<<<<<<<
 *     '''update occurrence counts of phrase'''
 *     counts = recPivot.counts
 */

  /* function exit code */
  __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_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.updateCounts", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_counts);
  __Pyx_XDECREF(__pyx_v_features);
  __Pyx_XDECREF(__pyx_v_c);
  __Pyx_XDECREF(__pyx_v_counts1);
  __Pyx_XDECREF(__pyx_v_counts2);
  __Pyx_XDECREF(__pyx_v_cooc1);
  __Pyx_XDECREF(__pyx_v_cooc2);
  __Pyx_XDECREF(__pyx_v_co1);
  __Pyx_XDECREF(__pyx_v_co2);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "lpu/smt/trans_models/triangulate.pyx":240
 * 
 * 
 * def mergeAligns(recPivot, recPair):             # <<<<<<<<<<<<<<
 *     '''merge word alignments'''
 * #    if recPivot.aligns:
 */

/* Python wrapper */
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_5mergeAligns(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_3lpu_3smt_12trans_models_11triangulate_4mergeAligns[] = "merge word alignments";
static PyMethodDef __pyx_mdef_3lpu_3smt_12trans_models_11triangulate_5mergeAligns = {"mergeAligns", (PyCFunction)__pyx_pw_3lpu_3smt_12trans_models_11triangulate_5mergeAligns, METH_VARARGS|METH_KEYWORDS, __pyx_doc_3lpu_3smt_12trans_models_11triangulate_4mergeAligns};
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_5mergeAligns(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_recPivot = 0;
  PyObject *__pyx_v_recPair = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("mergeAligns (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_recPivot,&__pyx_n_s_recPair,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);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        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_recPivot)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_recPair)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("mergeAligns", 1, 2, 2, 1); __PYX_ERR(0, 240, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "mergeAligns") < 0)) __PYX_ERR(0, 240, __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_recPivot = values[0];
    __pyx_v_recPair = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("mergeAligns", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 240, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.mergeAligns", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_3lpu_3smt_12trans_models_11triangulate_4mergeAligns(__pyx_self, __pyx_v_recPivot, __pyx_v_recPair);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_4mergeAligns(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_recPivot, PyObject *__pyx_v_recPair) {
  PyObject *__pyx_v_alignMapSrcPvt = NULL;
  PyObject *__pyx_v_alignMapPvtTrg = NULL;
  PyObject *__pyx_v_srcIndex = NULL;
  PyObject *__pyx_v_pvtIndices = NULL;
  PyObject *__pyx_v_pvtIndex = NULL;
  PyObject *__pyx_v_trgIndex = NULL;
  PyObject *__pyx_v_align = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  Py_ssize_t __pyx_t_4;
  PyObject *(*__pyx_t_5)(PyObject *);
  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 *);
  PyObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  Py_ssize_t __pyx_t_14;
  PyObject *(*__pyx_t_15)(PyObject *);
  __Pyx_RefNannySetupContext("mergeAligns", 0);

  /* "lpu/smt/trans_models/triangulate.pyx":245
 * #      return
 * #    alignSet = set()
 *     alignMapSrcPvt = recPair[0].alignMap             # <<<<<<<<<<<<<<
 *     alignMapPvtTrg = recPair[1].alignMap
 *     for srcIndex, pvtIndices in alignMapSrcPvt.items():
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_recPair, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 245, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_alignMap); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 245, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_alignMapSrcPvt = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":246
 * #    alignSet = set()
 *     alignMapSrcPvt = recPair[0].alignMap
 *     alignMapPvtTrg = recPair[1].alignMap             # <<<<<<<<<<<<<<
 *     for srcIndex, pvtIndices in alignMapSrcPvt.items():
 *         for pvtIndex in pvtIndices:
 */
  __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_recPair, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 246, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_alignMap); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 246, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_alignMapPvtTrg = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":247
 *     alignMapSrcPvt = recPair[0].alignMap
 *     alignMapPvtTrg = recPair[1].alignMap
 *     for srcIndex, pvtIndices in alignMapSrcPvt.items():             # <<<<<<<<<<<<<<
 *         for pvtIndex in pvtIndices:
 *             for trgIndex in alignMapPvtTrg.get(pvtIndex, []):
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_alignMapSrcPvt, __pyx_n_s_items); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 247, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 247, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 247, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_2 = __pyx_t_1; __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_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 247, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_5 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 247, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_5)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 247, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 247, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_1); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 247, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 247, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_5(__pyx_t_2);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 247, __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_PYPY
      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_ERR(0, 247, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_6 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_6);
      #else
      __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 247, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 247, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_7 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 247, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext;
      index = 0; __pyx_t_3 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_3)) goto __pyx_L5_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_3);
      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_ERR(0, 247, __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_ERR(0, 247, __pyx_L1_error)
      __pyx_L6_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_srcIndex, __pyx_t_3);
    __pyx_t_3 = 0;
    __Pyx_XDECREF_SET(__pyx_v_pvtIndices, __pyx_t_6);
    __pyx_t_6 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":248
 *     alignMapPvtTrg = recPair[1].alignMap
 *     for srcIndex, pvtIndices in alignMapSrcPvt.items():
 *         for pvtIndex in pvtIndices:             # <<<<<<<<<<<<<<
 *             for trgIndex in alignMapPvtTrg.get(pvtIndex, []):
 *               align = '%d-%d' % (srcIndex, trgIndex)
 */
    if (likely(PyList_CheckExact(__pyx_v_pvtIndices)) || PyTuple_CheckExact(__pyx_v_pvtIndices)) {
      __pyx_t_1 = __pyx_v_pvtIndices; __Pyx_INCREF(__pyx_t_1); __pyx_t_9 = 0;
      __pyx_t_10 = NULL;
    } else {
      __pyx_t_9 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_pvtIndices); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 248, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_10 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 248, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_10)) {
        if (likely(PyList_CheckExact(__pyx_t_1))) {
          if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_6 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_9); __Pyx_INCREF(__pyx_t_6); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 248, __pyx_L1_error)
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_1, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 248, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        } else {
          if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_9); __Pyx_INCREF(__pyx_t_6); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 248, __pyx_L1_error)
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_1, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 248, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
        }
      } else {
        __pyx_t_6 = __pyx_t_10(__pyx_t_1);
        if (unlikely(!__pyx_t_6)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 248, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_6);
      }
      __Pyx_XDECREF_SET(__pyx_v_pvtIndex, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":249
 *     for srcIndex, pvtIndices in alignMapSrcPvt.items():
 *         for pvtIndex in pvtIndices:
 *             for trgIndex in alignMapPvtTrg.get(pvtIndex, []):             # <<<<<<<<<<<<<<
 *               align = '%d-%d' % (srcIndex, trgIndex)
 * #              alignSet.add(align)
 */
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_alignMapPvtTrg, __pyx_n_s_get); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 249, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 249, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_11 = NULL;
      __pyx_t_12 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_11)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_11);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
          __pyx_t_12 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_3)) {
        PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_pvtIndex, __pyx_t_7};
        __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 249, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
        PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_pvtIndex, __pyx_t_7};
        __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 249, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      } else
      #endif
      {
        __pyx_t_13 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 249, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        if (__pyx_t_11) {
          __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_11); __pyx_t_11 = NULL;
        }
        __Pyx_INCREF(__pyx_v_pvtIndex);
        __Pyx_GIVEREF(__pyx_v_pvtIndex);
        PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_12, __pyx_v_pvtIndex);
        __Pyx_GIVEREF(__pyx_t_7);
        PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_12, __pyx_t_7);
        __pyx_t_7 = 0;
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_13, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 249, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (likely(PyList_CheckExact(__pyx_t_6)) || PyTuple_CheckExact(__pyx_t_6)) {
        __pyx_t_3 = __pyx_t_6; __Pyx_INCREF(__pyx_t_3); __pyx_t_14 = 0;
        __pyx_t_15 = NULL;
      } else {
        __pyx_t_14 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 249, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_15 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 249, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      for (;;) {
        if (likely(!__pyx_t_15)) {
          if (likely(PyList_CheckExact(__pyx_t_3))) {
            if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_3)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_6 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_14); __Pyx_INCREF(__pyx_t_6); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 249, __pyx_L1_error)
            #else
            __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 249, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            #endif
          } else {
            if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_14); __Pyx_INCREF(__pyx_t_6); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 249, __pyx_L1_error)
            #else
            __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 249, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            #endif
          }
        } else {
          __pyx_t_6 = __pyx_t_15(__pyx_t_3);
          if (unlikely(!__pyx_t_6)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 249, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_6);
        }
        __Pyx_XDECREF_SET(__pyx_v_trgIndex, __pyx_t_6);
        __pyx_t_6 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":250
 *         for pvtIndex in pvtIndices:
 *             for trgIndex in alignMapPvtTrg.get(pvtIndex, []):
 *               align = '%d-%d' % (srcIndex, trgIndex)             # <<<<<<<<<<<<<<
 * #              alignSet.add(align)
 *               recPivot.aligns.add(align)
 */
        __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 250, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_INCREF(__pyx_v_srcIndex);
        __Pyx_GIVEREF(__pyx_v_srcIndex);
        PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_srcIndex);
        __Pyx_INCREF(__pyx_v_trgIndex);
        __Pyx_GIVEREF(__pyx_v_trgIndex);
        PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_trgIndex);
        __pyx_t_13 = __Pyx_PyString_Format(__pyx_kp_s_d_d, __pyx_t_6); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 250, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_13);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF_SET(__pyx_v_align, ((PyObject*)__pyx_t_13));
        __pyx_t_13 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":252
 *               align = '%d-%d' % (srcIndex, trgIndex)
 * #              alignSet.add(align)
 *               recPivot.aligns.add(align)             # <<<<<<<<<<<<<<
 * #    recPivot.aligns = sorted(alignSet)
 * 
 */
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_recPivot, __pyx_n_s_aligns); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 252, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_add); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 252, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_6 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
          __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_7);
          if (likely(__pyx_t_6)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
            __Pyx_INCREF(__pyx_t_6);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_7, function);
          }
        }
        if (!__pyx_t_6) {
          __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_align); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 252, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_13);
        } else {
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_7)) {
            PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_align};
            __pyx_t_13 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 252, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
            __Pyx_GOTREF(__pyx_t_13);
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
            PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_align};
            __pyx_t_13 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 252, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
            __Pyx_GOTREF(__pyx_t_13);
          } else
          #endif
          {
            __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 252, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_11);
            __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_6); __pyx_t_6 = NULL;
            __Pyx_INCREF(__pyx_v_align);
            __Pyx_GIVEREF(__pyx_v_align);
            PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_align);
            __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_11, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 252, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_13);
            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          }
        }
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":249
 *     for srcIndex, pvtIndices in alignMapSrcPvt.items():
 *         for pvtIndex in pvtIndices:
 *             for trgIndex in alignMapPvtTrg.get(pvtIndex, []):             # <<<<<<<<<<<<<<
 *               align = '%d-%d' % (srcIndex, trgIndex)
 * #              alignSet.add(align)
 */
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":248
 *     alignMapPvtTrg = recPair[1].alignMap
 *     for srcIndex, pvtIndices in alignMapSrcPvt.items():
 *         for pvtIndex in pvtIndices:             # <<<<<<<<<<<<<<
 *             for trgIndex in alignMapPvtTrg.get(pvtIndex, []):
 *               align = '%d-%d' % (srcIndex, trgIndex)
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":247
 *     alignMapSrcPvt = recPair[0].alignMap
 *     alignMapPvtTrg = recPair[1].alignMap
 *     for srcIndex, pvtIndices in alignMapSrcPvt.items():             # <<<<<<<<<<<<<<
 *         for pvtIndex in pvtIndices:
 *             for trgIndex in alignMapPvtTrg.get(pvtIndex, []):
 */
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":240
 * 
 * 
 * def mergeAligns(recPivot, recPair):             # <<<<<<<<<<<<<<
 *     '''merge word alignments'''
 * #    if recPivot.aligns:
 */

  /* function exit code */
  __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_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.mergeAligns", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_alignMapSrcPvt);
  __Pyx_XDECREF(__pyx_v_alignMapPvtTrg);
  __Pyx_XDECREF(__pyx_v_srcIndex);
  __Pyx_XDECREF(__pyx_v_pvtIndices);
  __Pyx_XDECREF(__pyx_v_pvtIndex);
  __Pyx_XDECREF(__pyx_v_trgIndex);
  __Pyx_XDECREF(__pyx_v_align);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "lpu/smt/trans_models/triangulate.pyx":256
 * 
 * 
 * def filterByCountRatioToMax(records, div = 100):             # <<<<<<<<<<<<<<
 *     coMax = 0
 *     for rec in flattenRecords(records):
 */

/* Python wrapper */
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_7filterByCountRatioToMax(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_3lpu_3smt_12trans_models_11triangulate_7filterByCountRatioToMax = {"filterByCountRatioToMax", (PyCFunction)__pyx_pw_3lpu_3smt_12trans_models_11triangulate_7filterByCountRatioToMax, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_7filterByCountRatioToMax(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_records = 0;
  PyObject *__pyx_v_div = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("filterByCountRatioToMax (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_records,&__pyx_n_s_div,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)__pyx_int_100);
    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);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        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_records)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_div);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "filterByCountRatioToMax") < 0)) __PYX_ERR(0, 256, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_records = values[0];
    __pyx_v_div = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("filterByCountRatioToMax", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 256, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.filterByCountRatioToMax", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_3lpu_3smt_12trans_models_11triangulate_6filterByCountRatioToMax(__pyx_self, __pyx_v_records, __pyx_v_div);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_6filterByCountRatioToMax(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_records, PyObject *__pyx_v_div) {
  PyObject *__pyx_v_coMax = NULL;
  PyObject *__pyx_v_rec = NULL;
  PyObject *__pyx_v_newRecords = NULL;
  PyObject *__pyx_v_key = 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;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  PyObject *__pyx_t_7 = NULL;
  int __pyx_t_8;
  int __pyx_t_9;
  int __pyx_t_10;
  PyObject *(*__pyx_t_11)(PyObject *);
  __Pyx_RefNannySetupContext("filterByCountRatioToMax", 0);
  __Pyx_INCREF(__pyx_v_records);

  /* "lpu/smt/trans_models/triangulate.pyx":257
 * 
 * def filterByCountRatioToMax(records, div = 100):
 *     coMax = 0             # <<<<<<<<<<<<<<
 *     for rec in flattenRecords(records):
 *         coMax = max(coMax, rec.counts.co)
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_v_coMax = __pyx_int_0;

  /* "lpu/smt/trans_models/triangulate.pyx":258
 * def filterByCountRatioToMax(records, div = 100):
 *     coMax = 0
 *     for rec in flattenRecords(records):             # <<<<<<<<<<<<<<
 *         coMax = max(coMax, rec.counts.co)
 *     if isinstance(records, list):
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_flattenRecords); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 258, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_records); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 258, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_records};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 258, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_records};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 258, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 258, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_INCREF(__pyx_v_records);
      __Pyx_GIVEREF(__pyx_v_records);
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_records);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 258, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 258, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 258, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 258, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 258, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 258, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 258, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_6(__pyx_t_2);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 258, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XDECREF_SET(__pyx_v_rec, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":259
 *     coMax = 0
 *     for rec in flattenRecords(records):
 *         coMax = max(coMax, rec.counts.co)             # <<<<<<<<<<<<<<
 *     if isinstance(records, list):
 *         newRecords = []
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_counts); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 259, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_co); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 259, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_INCREF(__pyx_v_coMax);
    __pyx_t_1 = __pyx_v_coMax;
    __pyx_t_7 = PyObject_RichCompare(__pyx_t_4, __pyx_t_1, Py_GT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 259, __pyx_L1_error)
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 259, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (__pyx_t_8) {
      __Pyx_INCREF(__pyx_t_4);
      __pyx_t_3 = __pyx_t_4;
    } else {
      __Pyx_INCREF(__pyx_t_1);
      __pyx_t_3 = __pyx_t_1;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __pyx_t_3;
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_coMax, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":258
 * def filterByCountRatioToMax(records, div = 100):
 *     coMax = 0
 *     for rec in flattenRecords(records):             # <<<<<<<<<<<<<<
 *         coMax = max(coMax, rec.counts.co)
 *     if isinstance(records, list):
 */
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":260
 *     for rec in flattenRecords(records):
 *         coMax = max(coMax, rec.counts.co)
 *     if isinstance(records, list):             # <<<<<<<<<<<<<<
 *         newRecords = []
 *         for rec in records:
 */
  __pyx_t_8 = PyList_Check(__pyx_v_records); 
  __pyx_t_9 = (__pyx_t_8 != 0);
  if (__pyx_t_9) {

    /* "lpu/smt/trans_models/triangulate.pyx":261
 *         coMax = max(coMax, rec.counts.co)
 *     if isinstance(records, list):
 *         newRecords = []             # <<<<<<<<<<<<<<
 *         for rec in records:
 *             if rec.counts.co >= coMax / float(div):
 */
    __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 261, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_v_newRecords = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":262
 *     if isinstance(records, list):
 *         newRecords = []
 *         for rec in records:             # <<<<<<<<<<<<<<
 *             if rec.counts.co >= coMax / float(div):
 *                 newRecords.append( rec )
 */
    if (likely(PyList_CheckExact(__pyx_v_records)) || PyTuple_CheckExact(__pyx_v_records)) {
      __pyx_t_2 = __pyx_v_records; __Pyx_INCREF(__pyx_t_2); __pyx_t_5 = 0;
      __pyx_t_6 = NULL;
    } else {
      __pyx_t_5 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_records); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 262, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 262, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_6)) {
        if (likely(PyList_CheckExact(__pyx_t_2))) {
          if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_4 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 262, __pyx_L1_error)
          #else
          __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 262, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          #endif
        } else {
          if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 262, __pyx_L1_error)
          #else
          __pyx_t_4 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 262, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          #endif
        }
      } else {
        __pyx_t_4 = __pyx_t_6(__pyx_t_2);
        if (unlikely(!__pyx_t_4)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 262, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_4);
      }
      __Pyx_XDECREF_SET(__pyx_v_rec, __pyx_t_4);
      __pyx_t_4 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":263
 *         newRecords = []
 *         for rec in records:
 *             if rec.counts.co >= coMax / float(div):             # <<<<<<<<<<<<<<
 *                 newRecords.append( rec )
 *         records = newRecords
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_counts); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 263, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_co); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 263, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyNumber_Float(__pyx_v_div); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 263, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_v_coMax, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 263, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_t_1, Py_GE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 263, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 263, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_9) {

        /* "lpu/smt/trans_models/triangulate.pyx":264
 *         for rec in records:
 *             if rec.counts.co >= coMax / float(div):
 *                 newRecords.append( rec )             # <<<<<<<<<<<<<<
 *         records = newRecords
 *     elif isinstance(records, dict):
 */
        __pyx_t_10 = __Pyx_PyObject_Append(__pyx_v_newRecords, __pyx_v_rec); if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 264, __pyx_L1_error)

        /* "lpu/smt/trans_models/triangulate.pyx":263
 *         newRecords = []
 *         for rec in records:
 *             if rec.counts.co >= coMax / float(div):             # <<<<<<<<<<<<<<
 *                 newRecords.append( rec )
 *         records = newRecords
 */
      }

      /* "lpu/smt/trans_models/triangulate.pyx":262
 *     if isinstance(records, list):
 *         newRecords = []
 *         for rec in records:             # <<<<<<<<<<<<<<
 *             if rec.counts.co >= coMax / float(div):
 *                 newRecords.append( rec )
 */
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":265
 *             if rec.counts.co >= coMax / float(div):
 *                 newRecords.append( rec )
 *         records = newRecords             # <<<<<<<<<<<<<<
 *     elif isinstance(records, dict):
 *         newRecords = {}
 */
    __Pyx_INCREF(__pyx_v_newRecords);
    __Pyx_DECREF_SET(__pyx_v_records, __pyx_v_newRecords);

    /* "lpu/smt/trans_models/triangulate.pyx":260
 *     for rec in flattenRecords(records):
 *         coMax = max(coMax, rec.counts.co)
 *     if isinstance(records, list):             # <<<<<<<<<<<<<<
 *         newRecords = []
 *         for rec in records:
 */
    goto __pyx_L5;
  }

  /* "lpu/smt/trans_models/triangulate.pyx":266
 *                 newRecords.append( rec )
 *         records = newRecords
 *     elif isinstance(records, dict):             # <<<<<<<<<<<<<<
 *         newRecords = {}
 *         for key, rec in records.items():
 */
  __pyx_t_9 = PyDict_Check(__pyx_v_records); 
  __pyx_t_8 = (__pyx_t_9 != 0);
  if (__pyx_t_8) {

    /* "lpu/smt/trans_models/triangulate.pyx":267
 *         records = newRecords
 *     elif isinstance(records, dict):
 *         newRecords = {}             # <<<<<<<<<<<<<<
 *         for key, rec in records.items():
 *             if rec.counts.co >= coMax / float(div):
 */
    __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 267, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_v_newRecords = __pyx_t_2;
    __pyx_t_2 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":268
 *     elif isinstance(records, dict):
 *         newRecords = {}
 *         for key, rec in records.items():             # <<<<<<<<<<<<<<
 *             if rec.counts.co >= coMax / float(div):
 *                 newRecords[key] = rec
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_records, __pyx_n_s_items); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 268, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_1)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (__pyx_t_1) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 268, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else {
      __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 268, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
      __pyx_t_4 = __pyx_t_2; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
      __pyx_t_6 = NULL;
    } else {
      __pyx_t_5 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 268, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 268, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    for (;;) {
      if (likely(!__pyx_t_6)) {
        if (likely(PyList_CheckExact(__pyx_t_4))) {
          if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_4)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 268, __pyx_L1_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 268, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        } else {
          if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_5); __Pyx_INCREF(__pyx_t_2); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 268, __pyx_L1_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 268, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        }
      } else {
        __pyx_t_2 = __pyx_t_6(__pyx_t_4);
        if (unlikely(!__pyx_t_2)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 268, __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 !CYTHON_COMPILING_IN_PYPY
        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_ERR(0, 268, __pyx_L1_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_3);
        #else
        __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 268, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 268, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
        __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_ERR(0, 268, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __pyx_t_11 = Py_TYPE(__pyx_t_7)->tp_iternext;
        index = 0; __pyx_t_1 = __pyx_t_11(__pyx_t_7); if (unlikely(!__pyx_t_1)) goto __pyx_L11_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_1);
        index = 1; __pyx_t_3 = __pyx_t_11(__pyx_t_7); if (unlikely(!__pyx_t_3)) goto __pyx_L11_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_3);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_7), 2) < 0) __PYX_ERR(0, 268, __pyx_L1_error)
        __pyx_t_11 = NULL;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        goto __pyx_L12_unpacking_done;
        __pyx_L11_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_11 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 268, __pyx_L1_error)
        __pyx_L12_unpacking_done:;
      }
      __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_1);
      __pyx_t_1 = 0;
      __Pyx_XDECREF_SET(__pyx_v_rec, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":269
 *         newRecords = {}
 *         for key, rec in records.items():
 *             if rec.counts.co >= coMax / float(div):             # <<<<<<<<<<<<<<
 *                 newRecords[key] = rec
 *         records = newRecords
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_counts); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 269, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_co); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 269, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyNumber_Float(__pyx_v_div); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 269, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_v_coMax, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 269, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_t_1, Py_GE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 269, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 269, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (__pyx_t_8) {

        /* "lpu/smt/trans_models/triangulate.pyx":270
 *         for key, rec in records.items():
 *             if rec.counts.co >= coMax / float(div):
 *                 newRecords[key] = rec             # <<<<<<<<<<<<<<
 *         records = newRecords
 *     return records
 */
        if (unlikely(PyObject_SetItem(__pyx_v_newRecords, __pyx_v_key, __pyx_v_rec) < 0)) __PYX_ERR(0, 270, __pyx_L1_error)

        /* "lpu/smt/trans_models/triangulate.pyx":269
 *         newRecords = {}
 *         for key, rec in records.items():
 *             if rec.counts.co >= coMax / float(div):             # <<<<<<<<<<<<<<
 *                 newRecords[key] = rec
 *         records = newRecords
 */
      }

      /* "lpu/smt/trans_models/triangulate.pyx":268
 *     elif isinstance(records, dict):
 *         newRecords = {}
 *         for key, rec in records.items():             # <<<<<<<<<<<<<<
 *             if rec.counts.co >= coMax / float(div):
 *                 newRecords[key] = rec
 */
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":271
 *             if rec.counts.co >= coMax / float(div):
 *                 newRecords[key] = rec
 *         records = newRecords             # <<<<<<<<<<<<<<
 *     return records
 * 
 */
    __Pyx_INCREF(__pyx_v_newRecords);
    __Pyx_DECREF_SET(__pyx_v_records, __pyx_v_newRecords);

    /* "lpu/smt/trans_models/triangulate.pyx":266
 *                 newRecords.append( rec )
 *         records = newRecords
 *     elif isinstance(records, dict):             # <<<<<<<<<<<<<<
 *         newRecords = {}
 *         for key, rec in records.items():
 */
  }
  __pyx_L5:;

  /* "lpu/smt/trans_models/triangulate.pyx":272
 *                 newRecords[key] = rec
 *         records = newRecords
 *     return records             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_records);
  __pyx_r = __pyx_v_records;
  goto __pyx_L0;

  /* "lpu/smt/trans_models/triangulate.pyx":256
 * 
 * 
 * def filterByCountRatioToMax(records, div = 100):             # <<<<<<<<<<<<<<
 *     coMax = 0
 *     for rec in flattenRecords(records):
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.filterByCountRatioToMax", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_coMax);
  __Pyx_XDECREF(__pyx_v_rec);
  __Pyx_XDECREF(__pyx_v_newRecords);
  __Pyx_XDECREF(__pyx_v_key);
  __Pyx_XDECREF(__pyx_v_records);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "lpu/smt/trans_models/triangulate.pyx":275
 * 
 * 
 * def calcPhraseTransProbsByCounts(records):             # <<<<<<<<<<<<<<
 *     '''calculate forward phrase trans probs by occurrence counts of the phrases'''
 *     srcCount = calcSrcCount(records)
 */

/* Python wrapper */
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_9calcPhraseTransProbsByCounts(PyObject *__pyx_self, PyObject *__pyx_v_records); /*proto*/
static char __pyx_doc_3lpu_3smt_12trans_models_11triangulate_8calcPhraseTransProbsByCounts[] = "calculate forward phrase trans probs by occurrence counts of the phrases";
static PyMethodDef __pyx_mdef_3lpu_3smt_12trans_models_11triangulate_9calcPhraseTransProbsByCounts = {"calcPhraseTransProbsByCounts", (PyCFunction)__pyx_pw_3lpu_3smt_12trans_models_11triangulate_9calcPhraseTransProbsByCounts, METH_O, __pyx_doc_3lpu_3smt_12trans_models_11triangulate_8calcPhraseTransProbsByCounts};
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_9calcPhraseTransProbsByCounts(PyObject *__pyx_self, PyObject *__pyx_v_records) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calcPhraseTransProbsByCounts (wrapper)", 0);
  __pyx_r = __pyx_pf_3lpu_3smt_12trans_models_11triangulate_8calcPhraseTransProbsByCounts(__pyx_self, ((PyObject *)__pyx_v_records));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_8calcPhraseTransProbsByCounts(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_records) {
  PyObject *__pyx_v_srcCount = NULL;
  PyObject *__pyx_v_rec = NULL;
  PyObject *__pyx_v_counts = 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;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  int __pyx_t_7;
  __Pyx_RefNannySetupContext("calcPhraseTransProbsByCounts", 0);

  /* "lpu/smt/trans_models/triangulate.pyx":277
 * def calcPhraseTransProbsByCounts(records):
 *     '''calculate forward phrase trans probs by occurrence counts of the phrases'''
 *     srcCount = calcSrcCount(records)             # <<<<<<<<<<<<<<
 *     for rec in records.values():
 *     #for rec in flattenRecords(records):
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_calcSrcCount); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 277, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_records); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 277, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_records};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 277, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_records};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 277, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 277, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_INCREF(__pyx_v_records);
      __Pyx_GIVEREF(__pyx_v_records);
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_records);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 277, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_srcCount = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":278
 *     '''calculate forward phrase trans probs by occurrence counts of the phrases'''
 *     srcCount = calcSrcCount(records)
 *     for rec in records.values():             # <<<<<<<<<<<<<<
 *     #for rec in flattenRecords(records):
 *         counts = rec.counts
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_records, __pyx_n_s_values); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 278, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_4)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_4) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 278, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 278, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 278, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 278, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 278, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 278, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 278, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 278, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_6(__pyx_t_2);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 278, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XDECREF_SET(__pyx_v_rec, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":280
 *     for rec in records.values():
 *     #for rec in flattenRecords(records):
 *         counts = rec.counts             # <<<<<<<<<<<<<<
 *         counts.src = srcCount
 *         if srcCount > 0:
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_counts); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 280, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF_SET(__pyx_v_counts, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":281
 *     #for rec in flattenRecords(records):
 *         counts = rec.counts
 *         counts.src = srcCount             # <<<<<<<<<<<<<<
 *         if srcCount > 0:
 *             rec.features['egfp'] = counts.co / float(srcCount)
 */
    if (__Pyx_PyObject_SetAttrStr(__pyx_v_counts, __pyx_n_s_src, __pyx_v_srcCount) < 0) __PYX_ERR(0, 281, __pyx_L1_error)

    /* "lpu/smt/trans_models/triangulate.pyx":282
 *         counts = rec.counts
 *         counts.src = srcCount
 *         if srcCount > 0:             # <<<<<<<<<<<<<<
 *             rec.features['egfp'] = counts.co / float(srcCount)
 *         else:
 */
    __pyx_t_1 = PyObject_RichCompare(__pyx_v_srcCount, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 282, __pyx_L1_error)
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 282, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (__pyx_t_7) {

      /* "lpu/smt/trans_models/triangulate.pyx":283
 *         counts.src = srcCount
 *         if srcCount > 0:
 *             rec.features['egfp'] = counts.co / float(srcCount)             # <<<<<<<<<<<<<<
 *         else:
 *             rec.features['egfp'] == 0
 */
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_counts, __pyx_n_s_co); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 283, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = __Pyx_PyNumber_Float(__pyx_v_srcCount); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 283, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = __Pyx_PyNumber_Divide(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 283, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_features); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 283, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (unlikely(PyObject_SetItem(__pyx_t_4, __pyx_n_s_egfp, __pyx_t_3) < 0)) __PYX_ERR(0, 283, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":282
 *         counts = rec.counts
 *         counts.src = srcCount
 *         if srcCount > 0:             # <<<<<<<<<<<<<<
 *             rec.features['egfp'] = counts.co / float(srcCount)
 *         else:
 */
      goto __pyx_L5;
    }

    /* "lpu/smt/trans_models/triangulate.pyx":285
 *             rec.features['egfp'] = counts.co / float(srcCount)
 *         else:
 *             rec.features['egfp'] == 0             # <<<<<<<<<<<<<<
 * 
 * 
 */
    /*else*/ {
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_features); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 285, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_GetItem(__pyx_t_3, __pyx_n_s_egfp); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 285, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = __Pyx_PyInt_EqObjC(__pyx_t_4, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 285, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __pyx_L5:;

    /* "lpu/smt/trans_models/triangulate.pyx":278
 *     '''calculate forward phrase trans probs by occurrence counts of the phrases'''
 *     srcCount = calcSrcCount(records)
 *     for rec in records.values():             # <<<<<<<<<<<<<<
 *     #for rec in flattenRecords(records):
 *         counts = rec.counts
 */
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":275
 * 
 * 
 * def calcPhraseTransProbsByCounts(records):             # <<<<<<<<<<<<<<
 *     '''calculate forward phrase trans probs by occurrence counts of the phrases'''
 *     srcCount = calcSrcCount(records)
 */

  /* function exit code */
  __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_AddTraceback("lpu.smt.trans_models.triangulate.calcPhraseTransProbsByCounts", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_srcCount);
  __Pyx_XDECREF(__pyx_v_rec);
  __Pyx_XDECREF(__pyx_v_counts);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "lpu/smt/trans_models/triangulate.pyx":288
 * 
 * 
 * def calcPhraseTransProbsOnTable(table_path, savePath, **options):             # <<<<<<<<<<<<<<
 *     '''calculate phrase trans probs on the table in which co-occurrence counts are estimated'''
 *     method = options.get('method', METHOD)
 */

/* Python wrapper */
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_11calcPhraseTransProbsOnTable(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_3lpu_3smt_12trans_models_11triangulate_10calcPhraseTransProbsOnTable[] = "calculate phrase trans probs on the table in which co-occurrence counts are estimated";
static PyMethodDef __pyx_mdef_3lpu_3smt_12trans_models_11triangulate_11calcPhraseTransProbsOnTable = {"calcPhraseTransProbsOnTable", (PyCFunction)__pyx_pw_3lpu_3smt_12trans_models_11triangulate_11calcPhraseTransProbsOnTable, METH_VARARGS|METH_KEYWORDS, __pyx_doc_3lpu_3smt_12trans_models_11triangulate_10calcPhraseTransProbsOnTable};
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_11calcPhraseTransProbsOnTable(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_table_path = 0;
  PyObject *__pyx_v_savePath = 0;
  PyObject *__pyx_v_options = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calcPhraseTransProbsOnTable (wrapper)", 0);
  __pyx_v_options = PyDict_New(); if (unlikely(!__pyx_v_options)) return NULL;
  __Pyx_GOTREF(__pyx_v_options);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_table_path,&__pyx_n_s_savePath,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);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        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_table_path)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_savePath)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("calcPhraseTransProbsOnTable", 1, 2, 2, 1); __PYX_ERR(0, 288, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_options, values, pos_args, "calcPhraseTransProbsOnTable") < 0)) __PYX_ERR(0, 288, __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_table_path = values[0];
    __pyx_v_savePath = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("calcPhraseTransProbsOnTable", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 288, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_options); __pyx_v_options = 0;
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.calcPhraseTransProbsOnTable", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_3lpu_3smt_12trans_models_11triangulate_10calcPhraseTransProbsOnTable(__pyx_self, __pyx_v_table_path, __pyx_v_savePath, __pyx_v_options);

  /* function exit code */
  __Pyx_XDECREF(__pyx_v_options);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_10calcPhraseTransProbsOnTable(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table_path, PyObject *__pyx_v_savePath, PyObject *__pyx_v_options) {
  CYTHON_UNUSED PyObject *__pyx_v_method = NULL;
  PyObject *__pyx_v_RecordClass = NULL;
  PyObject *__pyx_v_table_file = NULL;
  PyObject *__pyx_v_saveFile = NULL;
  PyObject *__pyx_v_records = NULL;
  PyObject *__pyx_v_lastSrc = NULL;
  PyObject *__pyx_v_line = NULL;
  PyObject *__pyx_v_rec = NULL;
  PyObject *__pyx_v_key = NULL;
  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;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  int __pyx_t_10;
  __Pyx_RefNannySetupContext("calcPhraseTransProbsOnTable", 0);

  /* "lpu/smt/trans_models/triangulate.pyx":290
 * def calcPhraseTransProbsOnTable(table_path, savePath, **options):
 *     '''calculate phrase trans probs on the table in which co-occurrence counts are estimated'''
 *     method = options.get('method', METHOD)             # <<<<<<<<<<<<<<
 *     RecordClass = options.get('RecordClass', MosesRecord)
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_METHOD); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 290, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyDict_GetItemDefault(__pyx_v_options, __pyx_n_s_method, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 290, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_method = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":291
 *     '''calculate phrase trans probs on the table in which co-occurrence counts are estimated'''
 *     method = options.get('method', METHOD)
 *     RecordClass = options.get('RecordClass', MosesRecord)             # <<<<<<<<<<<<<<
 * 
 *     table_file = files.open(table_path, "r")
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_MosesRecord); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 291, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = __Pyx_PyDict_GetItemDefault(__pyx_v_options, __pyx_n_s_RecordClass, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 291, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_RecordClass = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":293
 *     RecordClass = options.get('RecordClass', MosesRecord)
 * 
 *     table_file = files.open(table_path, "r")             # <<<<<<<<<<<<<<
 *     saveFile  = files.open(savePath, "w")
 *     records = {}
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_files); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 293, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_open); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 293, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_4 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_table_path, __pyx_n_s_r};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 293, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_table_path, __pyx_n_s_r};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 293, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 293, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (__pyx_t_2) {
      __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL;
    }
    __Pyx_INCREF(__pyx_v_table_path);
    __Pyx_GIVEREF(__pyx_v_table_path);
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_table_path);
    __Pyx_INCREF(__pyx_n_s_r);
    __Pyx_GIVEREF(__pyx_n_s_r);
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_n_s_r);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 293, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_table_file = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":294
 * 
 *     table_file = files.open(table_path, "r")
 *     saveFile  = files.open(savePath, "w")             # <<<<<<<<<<<<<<
 *     records = {}
 *     lastSrc = ''
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_files); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 294, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_open); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 294, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
      __pyx_t_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_5)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_savePath, __pyx_n_s_w};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 294, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_savePath, __pyx_n_s_w};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 294, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_2 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 294, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (__pyx_t_3) {
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __pyx_t_3 = NULL;
    }
    __Pyx_INCREF(__pyx_v_savePath);
    __Pyx_GIVEREF(__pyx_v_savePath);
    PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_4, __pyx_v_savePath);
    __Pyx_INCREF(__pyx_n_s_w);
    __Pyx_GIVEREF(__pyx_n_s_w);
    PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_4, __pyx_n_s_w);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 294, __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_v_saveFile = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":295
 *     table_file = files.open(table_path, "r")
 *     saveFile  = files.open(savePath, "w")
 *     records = {}             # <<<<<<<<<<<<<<
 *     lastSrc = ''
 *     for line in table_file:
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 295, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_records = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":296
 *     saveFile  = files.open(savePath, "w")
 *     records = {}
 *     lastSrc = ''             # <<<<<<<<<<<<<<
 *     for line in table_file:
 *         rec = RecordClass(line)
 */
  __Pyx_INCREF(__pyx_kp_s__16);
  __pyx_v_lastSrc = __pyx_kp_s__16;

  /* "lpu/smt/trans_models/triangulate.pyx":297
 *     records = {}
 *     lastSrc = ''
 *     for line in table_file:             # <<<<<<<<<<<<<<
 *         rec = RecordClass(line)
 *         key = "%s ||| %s |||" % (rec.src, rec.trg)
 */
  if (likely(PyList_CheckExact(__pyx_v_table_file)) || PyTuple_CheckExact(__pyx_v_table_file)) {
    __pyx_t_1 = __pyx_v_table_file; __Pyx_INCREF(__pyx_t_1); __pyx_t_6 = 0;
    __pyx_t_7 = NULL;
  } else {
    __pyx_t_6 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_table_file); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 297, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 297, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_7)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 297, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 297, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      } else {
        if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 297, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 297, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      }
    } else {
      __pyx_t_5 = __pyx_t_7(__pyx_t_1);
      if (unlikely(!__pyx_t_5)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 297, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_5);
    }
    __Pyx_XDECREF_SET(__pyx_v_line, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":298
 *     lastSrc = ''
 *     for line in table_file:
 *         rec = RecordClass(line)             # <<<<<<<<<<<<<<
 *         key = "%s ||| %s |||" % (rec.src, rec.trg)
 *         if rec.src != lastSrc and records:
 */
    __Pyx_INCREF(__pyx_v_RecordClass);
    __pyx_t_2 = __pyx_v_RecordClass; __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    if (!__pyx_t_3) {
      __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_line); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 298, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_line};
        __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 298, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_line};
        __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 298, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else
      #endif
      {
        __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 298, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3); __pyx_t_3 = NULL;
        __Pyx_INCREF(__pyx_v_line);
        __Pyx_GIVEREF(__pyx_v_line);
        PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_line);
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_8, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 298, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF_SET(__pyx_v_rec, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":299
 *     for line in table_file:
 *         rec = RecordClass(line)
 *         key = "%s ||| %s |||" % (rec.src, rec.trg)             # <<<<<<<<<<<<<<
 *         if rec.src != lastSrc and records:
 *             calcPhraseTransProbsByCounts(records)
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_src); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 299, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_trg); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 299, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 299, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_2);
    __pyx_t_5 = 0;
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 299, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_XDECREF_SET(__pyx_v_key, ((PyObject*)__pyx_t_2));
    __pyx_t_2 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":300
 *         rec = RecordClass(line)
 *         key = "%s ||| %s |||" % (rec.src, rec.trg)
 *         if rec.src != lastSrc and records:             # <<<<<<<<<<<<<<
 *             calcPhraseTransProbsByCounts(records)
 *             writeRecords(saveFile, records)
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_src); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 300, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_8 = PyObject_RichCompare(__pyx_t_2, __pyx_v_lastSrc, Py_NE); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 300, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 300, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (__pyx_t_10) {
    } else {
      __pyx_t_9 = __pyx_t_10;
      goto __pyx_L6_bool_binop_done;
    }
    __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_v_records); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 300, __pyx_L1_error)
    __pyx_t_9 = __pyx_t_10;
    __pyx_L6_bool_binop_done:;
    if (__pyx_t_9) {

      /* "lpu/smt/trans_models/triangulate.pyx":301
 *         key = "%s ||| %s |||" % (rec.src, rec.trg)
 *         if rec.src != lastSrc and records:
 *             calcPhraseTransProbsByCounts(records)             # <<<<<<<<<<<<<<
 *             writeRecords(saveFile, records)
 *             records = {}
 */
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_calcPhraseTransProbsByCounts); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 301, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      if (!__pyx_t_5) {
        __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_records); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 301, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_2)) {
          PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_records};
          __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 301, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_GOTREF(__pyx_t_8);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
          PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_records};
          __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 301, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_GOTREF(__pyx_t_8);
        } else
        #endif
        {
          __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 301, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); __pyx_t_5 = NULL;
          __Pyx_INCREF(__pyx_v_records);
          __Pyx_GIVEREF(__pyx_v_records);
          PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_v_records);
          __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 301, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":302
 *         if rec.src != lastSrc and records:
 *             calcPhraseTransProbsByCounts(records)
 *             writeRecords(saveFile, records)             # <<<<<<<<<<<<<<
 *             records = {}
 *         if rec.counts.co > 0:
 */
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_writeRecords); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 302, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = NULL;
      __pyx_t_4 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
          __pyx_t_4 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_saveFile, __pyx_v_records};
        __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 302, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_8);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_saveFile, __pyx_v_records};
        __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 302, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_8);
      } else
      #endif
      {
        __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 302, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (__pyx_t_3) {
          __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL;
        }
        __Pyx_INCREF(__pyx_v_saveFile);
        __Pyx_GIVEREF(__pyx_v_saveFile);
        PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_saveFile);
        __Pyx_INCREF(__pyx_v_records);
        __Pyx_GIVEREF(__pyx_v_records);
        PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_records);
        __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 302, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":303
 *             calcPhraseTransProbsByCounts(records)
 *             writeRecords(saveFile, records)
 *             records = {}             # <<<<<<<<<<<<<<
 *         if rec.counts.co > 0:
 *             records[key] = rec
 */
      __pyx_t_8 = PyDict_New(); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 303, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF_SET(__pyx_v_records, ((PyObject*)__pyx_t_8));
      __pyx_t_8 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":300
 *         rec = RecordClass(line)
 *         key = "%s ||| %s |||" % (rec.src, rec.trg)
 *         if rec.src != lastSrc and records:             # <<<<<<<<<<<<<<
 *             calcPhraseTransProbsByCounts(records)
 *             writeRecords(saveFile, records)
 */
    }

    /* "lpu/smt/trans_models/triangulate.pyx":304
 *             writeRecords(saveFile, records)
 *             records = {}
 *         if rec.counts.co > 0:             # <<<<<<<<<<<<<<
 *             records[key] = rec
 *         lastSrc = rec.src
 */
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_counts); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 304, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_co); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 304, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_8); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 304, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 304, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (__pyx_t_9) {

      /* "lpu/smt/trans_models/triangulate.pyx":305
 *             records = {}
 *         if rec.counts.co > 0:
 *             records[key] = rec             # <<<<<<<<<<<<<<
 *         lastSrc = rec.src
 *     if records:
 */
      if (unlikely(PyDict_SetItem(__pyx_v_records, __pyx_v_key, __pyx_v_rec) < 0)) __PYX_ERR(0, 305, __pyx_L1_error)

      /* "lpu/smt/trans_models/triangulate.pyx":304
 *             writeRecords(saveFile, records)
 *             records = {}
 *         if rec.counts.co > 0:             # <<<<<<<<<<<<<<
 *             records[key] = rec
 *         lastSrc = rec.src
 */
    }

    /* "lpu/smt/trans_models/triangulate.pyx":306
 *         if rec.counts.co > 0:
 *             records[key] = rec
 *         lastSrc = rec.src             # <<<<<<<<<<<<<<
 *     if records:
 *         calcPhraseTransProbsByCounts(records)
 */
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_src); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 306, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF_SET(__pyx_v_lastSrc, __pyx_t_8);
    __pyx_t_8 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":297
 *     records = {}
 *     lastSrc = ''
 *     for line in table_file:             # <<<<<<<<<<<<<<
 *         rec = RecordClass(line)
 *         key = "%s ||| %s |||" % (rec.src, rec.trg)
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":307
 *             records[key] = rec
 *         lastSrc = rec.src
 *     if records:             # <<<<<<<<<<<<<<
 *         calcPhraseTransProbsByCounts(records)
 *         writeRecords(saveFile, records)
 */
  __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_records); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 307, __pyx_L1_error)
  if (__pyx_t_9) {

    /* "lpu/smt/trans_models/triangulate.pyx":308
 *         lastSrc = rec.src
 *     if records:
 *         calcPhraseTransProbsByCounts(records)             # <<<<<<<<<<<<<<
 *         writeRecords(saveFile, records)
 *     saveFile.close()
 */
    __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_calcPhraseTransProbsByCounts); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 308, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
      }
    }
    if (!__pyx_t_2) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_records); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 308, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_8)) {
        PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_records};
        __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 308, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GOTREF(__pyx_t_1);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
        PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_records};
        __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 308, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GOTREF(__pyx_t_1);
      } else
      #endif
      {
        __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 308, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL;
        __Pyx_INCREF(__pyx_v_records);
        __Pyx_GIVEREF(__pyx_v_records);
        PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_v_records);
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 308, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":309
 *     if records:
 *         calcPhraseTransProbsByCounts(records)
 *         writeRecords(saveFile, records)             # <<<<<<<<<<<<<<
 *     saveFile.close()
 *     table_file.close()
 */
    __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_writeRecords); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 309, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_5 = NULL;
    __pyx_t_4 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
        __pyx_t_4 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_8)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_saveFile, __pyx_v_records};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 309, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_saveFile, __pyx_v_records};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 309, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_2 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 309, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (__pyx_t_5) {
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5); __pyx_t_5 = NULL;
      }
      __Pyx_INCREF(__pyx_v_saveFile);
      __Pyx_GIVEREF(__pyx_v_saveFile);
      PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_4, __pyx_v_saveFile);
      __Pyx_INCREF(__pyx_v_records);
      __Pyx_GIVEREF(__pyx_v_records);
      PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_4, __pyx_v_records);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 309, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":307
 *             records[key] = rec
 *         lastSrc = rec.src
 *     if records:             # <<<<<<<<<<<<<<
 *         calcPhraseTransProbsByCounts(records)
 *         writeRecords(saveFile, records)
 */
  }

  /* "lpu/smt/trans_models/triangulate.pyx":310
 *         calcPhraseTransProbsByCounts(records)
 *         writeRecords(saveFile, records)
 *     saveFile.close()             # <<<<<<<<<<<<<<
 *     table_file.close()
 * 
 */
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_saveFile, __pyx_n_s_close); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 310, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_8);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_8, function);
    }
  }
  if (__pyx_t_2) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 310, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 310, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":311
 *         writeRecords(saveFile, records)
 *     saveFile.close()
 *     table_file.close()             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_table_file, __pyx_n_s_close); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 311, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_8);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_8, function);
    }
  }
  if (__pyx_t_2) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 311, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 311, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":288
 * 
 * 
 * def calcPhraseTransProbsOnTable(table_path, savePath, **options):             # <<<<<<<<<<<<<<
 *     '''calculate phrase trans probs on the table in which co-occurrence counts are estimated'''
 *     method = options.get('method', METHOD)
 */

  /* function exit code */
  __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_5);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.calcPhraseTransProbsOnTable", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_method);
  __Pyx_XDECREF(__pyx_v_RecordClass);
  __Pyx_XDECREF(__pyx_v_table_file);
  __Pyx_XDECREF(__pyx_v_saveFile);
  __Pyx_XDECREF(__pyx_v_records);
  __Pyx_XDECREF(__pyx_v_lastSrc);
  __Pyx_XDECREF(__pyx_v_line);
  __Pyx_XDECREF(__pyx_v_rec);
  __Pyx_XDECREF(__pyx_v_key);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "lpu/smt/trans_models/triangulate.pyx":314
 * 
 * 
 * def calcSrcCount(records):             # <<<<<<<<<<<<<<
 *     '''calculate source phrase occurrence counts by co-occurrence counts'''
 *     total = 0
 */

/* Python wrapper */
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_13calcSrcCount(PyObject *__pyx_self, PyObject *__pyx_v_records); /*proto*/
static char __pyx_doc_3lpu_3smt_12trans_models_11triangulate_12calcSrcCount[] = "calculate source phrase occurrence counts by co-occurrence counts";
static PyMethodDef __pyx_mdef_3lpu_3smt_12trans_models_11triangulate_13calcSrcCount = {"calcSrcCount", (PyCFunction)__pyx_pw_3lpu_3smt_12trans_models_11triangulate_13calcSrcCount, METH_O, __pyx_doc_3lpu_3smt_12trans_models_11triangulate_12calcSrcCount};
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_13calcSrcCount(PyObject *__pyx_self, PyObject *__pyx_v_records) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calcSrcCount (wrapper)", 0);
  __pyx_r = __pyx_pf_3lpu_3smt_12trans_models_11triangulate_12calcSrcCount(__pyx_self, ((PyObject *)__pyx_v_records));

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_12calcSrcCount(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_records) {
  PyObject *__pyx_v_total = NULL;
  PyObject *__pyx_v_rec = 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;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  __Pyx_RefNannySetupContext("calcSrcCount", 0);

  /* "lpu/smt/trans_models/triangulate.pyx":316
 * def calcSrcCount(records):
 *     '''calculate source phrase occurrence counts by co-occurrence counts'''
 *     total = 0             # <<<<<<<<<<<<<<
 *     for rec in flattenRecords(records):
 *         total += rec.counts.co
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_v_total = __pyx_int_0;

  /* "lpu/smt/trans_models/triangulate.pyx":317
 *     '''calculate source phrase occurrence counts by co-occurrence counts'''
 *     total = 0
 *     for rec in flattenRecords(records):             # <<<<<<<<<<<<<<
 *         total += rec.counts.co
 *     return total
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_flattenRecords); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 317, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (!__pyx_t_3) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_records); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 317, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_records};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 317, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
      PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_records};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 317, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 317, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3); __pyx_t_3 = NULL;
      __Pyx_INCREF(__pyx_v_records);
      __Pyx_GIVEREF(__pyx_v_records);
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_records);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 317, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 317, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_6 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 317, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 317, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 317, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 317, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 317, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_6(__pyx_t_2);
      if (unlikely(!__pyx_t_1)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 317, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    __Pyx_XDECREF_SET(__pyx_v_rec, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":318
 *     total = 0
 *     for rec in flattenRecords(records):
 *         total += rec.counts.co             # <<<<<<<<<<<<<<
 *     return total
 * 
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_counts); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 318, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_co); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 318, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_v_total, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 318, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF_SET(__pyx_v_total, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":317
 *     '''calculate source phrase occurrence counts by co-occurrence counts'''
 *     total = 0
 *     for rec in flattenRecords(records):             # <<<<<<<<<<<<<<
 *         total += rec.counts.co
 *     return total
 */
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":319
 *     for rec in flattenRecords(records):
 *         total += rec.counts.co
 *     return total             # <<<<<<<<<<<<<<
 * 
 * def updateWordPairCounts(lexCounts, records):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_total);
  __pyx_r = __pyx_v_total;
  goto __pyx_L0;

  /* "lpu/smt/trans_models/triangulate.pyx":314
 * 
 * 
 * def calcSrcCount(records):             # <<<<<<<<<<<<<<
 *     '''calculate source phrase occurrence counts by co-occurrence counts'''
 *     total = 0
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.calcSrcCount", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_total);
  __Pyx_XDECREF(__pyx_v_rec);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "lpu/smt/trans_models/triangulate.pyx":321
 *     return total
 * 
 * def updateWordPairCounts(lexCounts, records):             # <<<<<<<<<<<<<<
 *     '''find word pairs in phrase pairs, and update the counts of word pairs'''
 *     if len(records) > 0:
 */

/* Python wrapper */
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_15updateWordPairCounts(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_3lpu_3smt_12trans_models_11triangulate_14updateWordPairCounts[] = "find word pairs in phrase pairs, and update the counts of word pairs";
static PyMethodDef __pyx_mdef_3lpu_3smt_12trans_models_11triangulate_15updateWordPairCounts = {"updateWordPairCounts", (PyCFunction)__pyx_pw_3lpu_3smt_12trans_models_11triangulate_15updateWordPairCounts, METH_VARARGS|METH_KEYWORDS, __pyx_doc_3lpu_3smt_12trans_models_11triangulate_14updateWordPairCounts};
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_15updateWordPairCounts(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_lexCounts = 0;
  PyObject *__pyx_v_records = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("updateWordPairCounts (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_lexCounts,&__pyx_n_s_records,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);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        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_lexCounts)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_records)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("updateWordPairCounts", 1, 2, 2, 1); __PYX_ERR(0, 321, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "updateWordPairCounts") < 0)) __PYX_ERR(0, 321, __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_lexCounts = values[0];
    __pyx_v_records = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("updateWordPairCounts", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 321, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.updateWordPairCounts", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_3lpu_3smt_12trans_models_11triangulate_14updateWordPairCounts(__pyx_self, __pyx_v_lexCounts, __pyx_v_records);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_14updateWordPairCounts(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_lexCounts, PyObject *__pyx_v_records) {
  PyObject *__pyx_v_src_symbols = NULL;
  PyObject *__pyx_v_rec = NULL;
  PyObject *__pyx_v_trgSymbols = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *(*__pyx_t_6)(PyObject *);
  Py_ssize_t __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  int __pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  __Pyx_RefNannySetupContext("updateWordPairCounts", 0);

  /* "lpu/smt/trans_models/triangulate.pyx":323
 * def updateWordPairCounts(lexCounts, records):
 *     '''find word pairs in phrase pairs, and update the counts of word pairs'''
 *     if len(records) > 0:             # <<<<<<<<<<<<<<
 *         src_symbols = records.values()[0].src_symbols
 *         if len(src_symbols) == 1:
 */
  __pyx_t_1 = PyObject_Length(__pyx_v_records); if (unlikely(__pyx_t_1 == -1)) __PYX_ERR(0, 323, __pyx_L1_error)
  __pyx_t_2 = ((__pyx_t_1 > 0) != 0);
  if (__pyx_t_2) {

    /* "lpu/smt/trans_models/triangulate.pyx":324
 *     '''find word pairs in phrase pairs, and update the counts of word pairs'''
 *     if len(records) > 0:
 *         src_symbols = records.values()[0].src_symbols             # <<<<<<<<<<<<<<
 *         if len(src_symbols) == 1:
 *            for rec in records.values():
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_records, __pyx_n_s_values); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 324, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_5)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_5);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (__pyx_t_5) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 324, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    } else {
      __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 324, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_3, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 324, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_src_symbols); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 324, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_v_src_symbols = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":325
 *     if len(records) > 0:
 *         src_symbols = records.values()[0].src_symbols
 *         if len(src_symbols) == 1:             # <<<<<<<<<<<<<<
 *            for rec in records.values():
 *                trgSymbols = rec.trgSymbols
 */
    __pyx_t_1 = PyObject_Length(__pyx_v_src_symbols); if (unlikely(__pyx_t_1 == -1)) __PYX_ERR(0, 325, __pyx_L1_error)
    __pyx_t_2 = ((__pyx_t_1 == 1) != 0);
    if (__pyx_t_2) {

      /* "lpu/smt/trans_models/triangulate.pyx":326
 *         src_symbols = records.values()[0].src_symbols
 *         if len(src_symbols) == 1:
 *            for rec in records.values():             # <<<<<<<<<<<<<<
 *                trgSymbols = rec.trgSymbols
 *                if len(trgSymbols) == 1:
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_records, __pyx_n_s_values); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 326, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
        }
      }
      if (__pyx_t_5) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 326, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      } else {
        __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 326, __pyx_L1_error)
      }
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
        __pyx_t_4 = __pyx_t_3; __Pyx_INCREF(__pyx_t_4); __pyx_t_1 = 0;
        __pyx_t_6 = NULL;
      } else {
        __pyx_t_1 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 326, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_6 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 326, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      for (;;) {
        if (likely(!__pyx_t_6)) {
          if (likely(PyList_CheckExact(__pyx_t_4))) {
            if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_4)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_3 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 326, __pyx_L1_error)
            #else
            __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 326, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            #endif
          } else {
            if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 326, __pyx_L1_error)
            #else
            __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 326, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            #endif
          }
        } else {
          __pyx_t_3 = __pyx_t_6(__pyx_t_4);
          if (unlikely(!__pyx_t_3)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 326, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_3);
        }
        __Pyx_XDECREF_SET(__pyx_v_rec, __pyx_t_3);
        __pyx_t_3 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":327
 *         if len(src_symbols) == 1:
 *            for rec in records.values():
 *                trgSymbols = rec.trgSymbols             # <<<<<<<<<<<<<<
 *                if len(trgSymbols) == 1:
 *                    lexCounts.addPair(src_symbols[0], trgSymbols[0], rec.counts.co)
 */
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_trgSymbols); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 327, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_XDECREF_SET(__pyx_v_trgSymbols, __pyx_t_3);
        __pyx_t_3 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":328
 *            for rec in records.values():
 *                trgSymbols = rec.trgSymbols
 *                if len(trgSymbols) == 1:             # <<<<<<<<<<<<<<
 *                    lexCounts.addPair(src_symbols[0], trgSymbols[0], rec.counts.co)
 *         lexCounts.filterNBestBySrc(srcWord = src_symbols[0])
 */
        __pyx_t_7 = PyObject_Length(__pyx_v_trgSymbols); if (unlikely(__pyx_t_7 == -1)) __PYX_ERR(0, 328, __pyx_L1_error)
        __pyx_t_2 = ((__pyx_t_7 == 1) != 0);
        if (__pyx_t_2) {

          /* "lpu/smt/trans_models/triangulate.pyx":329
 *                trgSymbols = rec.trgSymbols
 *                if len(trgSymbols) == 1:
 *                    lexCounts.addPair(src_symbols[0], trgSymbols[0], rec.counts.co)             # <<<<<<<<<<<<<<
 *         lexCounts.filterNBestBySrc(srcWord = src_symbols[0])
 * 
 */
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_lexCounts, __pyx_n_s_addPair); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 329, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_src_symbols, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 329, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_9 = __Pyx_GetItemInt(__pyx_v_trgSymbols, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 329, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_counts); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 329, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_co); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 329, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __pyx_t_10 = NULL;
          __pyx_t_12 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
            __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_5);
            if (likely(__pyx_t_10)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
              __Pyx_INCREF(__pyx_t_10);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_5, function);
              __pyx_t_12 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_5)) {
            PyObject *__pyx_temp[4] = {__pyx_t_10, __pyx_t_8, __pyx_t_9, __pyx_t_11};
            __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_12, 3+__pyx_t_12); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 329, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
            PyObject *__pyx_temp[4] = {__pyx_t_10, __pyx_t_8, __pyx_t_9, __pyx_t_11};
            __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_12, 3+__pyx_t_12); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 329, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          } else
          #endif
          {
            __pyx_t_13 = PyTuple_New(3+__pyx_t_12); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 329, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_13);
            if (__pyx_t_10) {
              __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_10); __pyx_t_10 = NULL;
            }
            __Pyx_GIVEREF(__pyx_t_8);
            PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_12, __pyx_t_8);
            __Pyx_GIVEREF(__pyx_t_9);
            PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_12, __pyx_t_9);
            __Pyx_GIVEREF(__pyx_t_11);
            PyTuple_SET_ITEM(__pyx_t_13, 2+__pyx_t_12, __pyx_t_11);
            __pyx_t_8 = 0;
            __pyx_t_9 = 0;
            __pyx_t_11 = 0;
            __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_13, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 329, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          }
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":328
 *            for rec in records.values():
 *                trgSymbols = rec.trgSymbols
 *                if len(trgSymbols) == 1:             # <<<<<<<<<<<<<<
 *                    lexCounts.addPair(src_symbols[0], trgSymbols[0], rec.counts.co)
 *         lexCounts.filterNBestBySrc(srcWord = src_symbols[0])
 */
        }

        /* "lpu/smt/trans_models/triangulate.pyx":326
 *         src_symbols = records.values()[0].src_symbols
 *         if len(src_symbols) == 1:
 *            for rec in records.values():             # <<<<<<<<<<<<<<
 *                trgSymbols = rec.trgSymbols
 *                if len(trgSymbols) == 1:
 */
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":325
 *     if len(records) > 0:
 *         src_symbols = records.values()[0].src_symbols
 *         if len(src_symbols) == 1:             # <<<<<<<<<<<<<<
 *            for rec in records.values():
 *                trgSymbols = rec.trgSymbols
 */
    }

    /* "lpu/smt/trans_models/triangulate.pyx":330
 *                if len(trgSymbols) == 1:
 *                    lexCounts.addPair(src_symbols[0], trgSymbols[0], rec.counts.co)
 *         lexCounts.filterNBestBySrc(srcWord = src_symbols[0])             # <<<<<<<<<<<<<<
 * 
 * def flattenRecords(records, sort = False):
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_lexCounts, __pyx_n_s_filterNBestBySrc); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 330, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 330, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_src_symbols, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 330, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_srcWord, __pyx_t_5) < 0) __PYX_ERR(0, 330, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 330, __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_5); __pyx_t_5 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":323
 * def updateWordPairCounts(lexCounts, records):
 *     '''find word pairs in phrase pairs, and update the counts of word pairs'''
 *     if len(records) > 0:             # <<<<<<<<<<<<<<
 *         src_symbols = records.values()[0].src_symbols
 *         if len(src_symbols) == 1:
 */
  }

  /* "lpu/smt/trans_models/triangulate.pyx":321
 *     return total
 * 
 * def updateWordPairCounts(lexCounts, records):             # <<<<<<<<<<<<<<
 *     '''find word pairs in phrase pairs, and update the counts of word pairs'''
 *     if len(records) > 0:
 */

  /* function exit code */
  __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_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_XDECREF(__pyx_t_13);
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.updateWordPairCounts", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_src_symbols);
  __Pyx_XDECREF(__pyx_v_rec);
  __Pyx_XDECREF(__pyx_v_trgSymbols);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "lpu/smt/trans_models/triangulate.pyx":332
 *         lexCounts.filterNBestBySrc(srcWord = src_symbols[0])
 * 
 * def flattenRecords(records, sort = False):             # <<<<<<<<<<<<<<
 *     '''if records are type of dict, return them as a list'''
 *     if type(records) == dict:
 */

/* Python wrapper */
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_17flattenRecords(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_3lpu_3smt_12trans_models_11triangulate_16flattenRecords[] = "if records are type of dict, return them as a list";
static PyMethodDef __pyx_mdef_3lpu_3smt_12trans_models_11triangulate_17flattenRecords = {"flattenRecords", (PyCFunction)__pyx_pw_3lpu_3smt_12trans_models_11triangulate_17flattenRecords, METH_VARARGS|METH_KEYWORDS, __pyx_doc_3lpu_3smt_12trans_models_11triangulate_16flattenRecords};
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_17flattenRecords(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_records = 0;
  PyObject *__pyx_v_sort = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("flattenRecords (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_records,&__pyx_n_s_sort,0};
    PyObject* values[2] = {0,0};
    values[1] = ((PyObject *)Py_False);
    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);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        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_records)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sort);
          if (value) { values[1] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "flattenRecords") < 0)) __PYX_ERR(0, 332, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        break;
        default: goto __pyx_L5_argtuple_error;
      }
    }
    __pyx_v_records = values[0];
    __pyx_v_sort = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("flattenRecords", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 332, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.flattenRecords", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_3lpu_3smt_12trans_models_11triangulate_16flattenRecords(__pyx_self, __pyx_v_records, __pyx_v_sort);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_16flattenRecords(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_records, PyObject *__pyx_v_sort) {
  PyObject *__pyx_v_recordList = NULL;
  PyObject *__pyx_v_key = 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;
  PyObject *__pyx_t_5 = NULL;
  int __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  __Pyx_RefNannySetupContext("flattenRecords", 0);

  /* "lpu/smt/trans_models/triangulate.pyx":334
 * def flattenRecords(records, sort = False):
 *     '''if records are type of dict, return them as a list'''
 *     if type(records) == dict:             # <<<<<<<<<<<<<<
 *         if sort:
 *             recordList = []
 */
  __pyx_t_1 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_records)), ((PyObject *)(&PyDict_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 334, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 334, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (__pyx_t_2) {

    /* "lpu/smt/trans_models/triangulate.pyx":335
 *     '''if records are type of dict, return them as a list'''
 *     if type(records) == dict:
 *         if sort:             # <<<<<<<<<<<<<<
 *             recordList = []
 *             for key in sorted(records.keys()):
 */
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_sort); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 335, __pyx_L1_error)
    if (__pyx_t_2) {

      /* "lpu/smt/trans_models/triangulate.pyx":336
 *     if type(records) == dict:
 *         if sort:
 *             recordList = []             # <<<<<<<<<<<<<<
 *             for key in sorted(records.keys()):
 *               recordList.append(records[key])
 */
      __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 336, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_v_recordList = ((PyObject*)__pyx_t_1);
      __pyx_t_1 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":337
 *         if sort:
 *             recordList = []
 *             for key in sorted(records.keys()):             # <<<<<<<<<<<<<<
 *               recordList.append(records[key])
 *             return recordList
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_records, __pyx_n_s_keys); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 337, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
        }
      }
      if (__pyx_t_5) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 337, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      } else {
        __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 337, __pyx_L1_error)
      }
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = PySequence_List(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 337, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_1 = ((PyObject*)__pyx_t_4);
      __pyx_t_4 = 0;
      __pyx_t_6 = PyList_Sort(__pyx_t_1); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 337, __pyx_L1_error)
      if (unlikely(__pyx_t_1 == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
        __PYX_ERR(0, 337, __pyx_L1_error)
      }
      __pyx_t_4 = __pyx_t_1; __Pyx_INCREF(__pyx_t_4); __pyx_t_7 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      for (;;) {
        if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_7); __Pyx_INCREF(__pyx_t_1); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 337, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_4, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 337, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
        __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_1);
        __pyx_t_1 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":338
 *             recordList = []
 *             for key in sorted(records.keys()):
 *               recordList.append(records[key])             # <<<<<<<<<<<<<<
 *             return recordList
 *         else:
 */
        __pyx_t_1 = PyObject_GetItem(__pyx_v_records, __pyx_v_key); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 338, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_6 = __Pyx_PyList_Append(__pyx_v_recordList, __pyx_t_1); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 338, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":337
 *         if sort:
 *             recordList = []
 *             for key in sorted(records.keys()):             # <<<<<<<<<<<<<<
 *               recordList.append(records[key])
 *             return recordList
 */
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":339
 *             for key in sorted(records.keys()):
 *               recordList.append(records[key])
 *             return recordList             # <<<<<<<<<<<<<<
 *         else:
 *             return records.values()
 */
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_v_recordList);
      __pyx_r = __pyx_v_recordList;
      goto __pyx_L0;

      /* "lpu/smt/trans_models/triangulate.pyx":335
 *     '''if records are type of dict, return them as a list'''
 *     if type(records) == dict:
 *         if sort:             # <<<<<<<<<<<<<<
 *             recordList = []
 *             for key in sorted(records.keys()):
 */
    }

    /* "lpu/smt/trans_models/triangulate.pyx":341
 *             return recordList
 *         else:
 *             return records.values()             # <<<<<<<<<<<<<<
 *     elif type(records) == list:
 *         if sort:
 */
    /*else*/ {
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_records, __pyx_n_s_values); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 341, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_1, function);
        }
      }
      if (__pyx_t_3) {
        __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 341, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      } else {
        __pyx_t_4 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 341, __pyx_L1_error)
      }
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_r = __pyx_t_4;
      __pyx_t_4 = 0;
      goto __pyx_L0;
    }

    /* "lpu/smt/trans_models/triangulate.pyx":334
 * def flattenRecords(records, sort = False):
 *     '''if records are type of dict, return them as a list'''
 *     if type(records) == dict:             # <<<<<<<<<<<<<<
 *         if sort:
 *             recordList = []
 */
  }

  /* "lpu/smt/trans_models/triangulate.pyx":342
 *         else:
 *             return records.values()
 *     elif type(records) == list:             # <<<<<<<<<<<<<<
 *         if sort:
 *             return sorted(records)
 */
  __pyx_t_4 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_records)), ((PyObject *)(&PyList_Type)), Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 342, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 342, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  if (__pyx_t_2) {

    /* "lpu/smt/trans_models/triangulate.pyx":343
 *             return records.values()
 *     elif type(records) == list:
 *         if sort:             # <<<<<<<<<<<<<<
 *             return sorted(records)
 *         else:
 */
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_sort); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 343, __pyx_L1_error)
    if (__pyx_t_2) {

      /* "lpu/smt/trans_models/triangulate.pyx":344
 *     elif type(records) == list:
 *         if sort:
 *             return sorted(records)             # <<<<<<<<<<<<<<
 *         else:
 *             return records
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = PySequence_List(__pyx_v_records); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 344, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = ((PyObject*)__pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_6 = PyList_Sort(__pyx_t_4); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 344, __pyx_L1_error)
      __pyx_r = __pyx_t_4;
      __pyx_t_4 = 0;
      goto __pyx_L0;

      /* "lpu/smt/trans_models/triangulate.pyx":343
 *             return records.values()
 *     elif type(records) == list:
 *         if sort:             # <<<<<<<<<<<<<<
 *             return sorted(records)
 *         else:
 */
    }

    /* "lpu/smt/trans_models/triangulate.pyx":346
 *             return sorted(records)
 *         else:
 *             return records             # <<<<<<<<<<<<<<
 *     else:
 *         assert False, "Invalid records"
 */
    /*else*/ {
      __Pyx_XDECREF(__pyx_r);
      __Pyx_INCREF(__pyx_v_records);
      __pyx_r = __pyx_v_records;
      goto __pyx_L0;
    }

    /* "lpu/smt/trans_models/triangulate.pyx":342
 *         else:
 *             return records.values()
 *     elif type(records) == list:             # <<<<<<<<<<<<<<
 *         if sort:
 *             return sorted(records)
 */
  }

  /* "lpu/smt/trans_models/triangulate.pyx":348
 *             return records
 *     else:
 *         assert False, "Invalid records"             # <<<<<<<<<<<<<<
 * 
 * def pivotRecPairs(rows, workset):
 */
  /*else*/ {
    #ifndef CYTHON_WITHOUT_ASSERTIONS
    if (unlikely(!Py_OptimizeFlag)) {
      if (unlikely(!0)) {
        PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_Invalid_records);
        __PYX_ERR(0, 348, __pyx_L1_error)
      }
    }
    #endif
  }

  /* "lpu/smt/trans_models/triangulate.pyx":332
 *         lexCounts.filterNBestBySrc(srcWord = src_symbols[0])
 * 
 * def flattenRecords(records, sort = False):             # <<<<<<<<<<<<<<
 *     '''if records are type of dict, return them as a list'''
 *     if type(records) == dict:
 */

  /* function exit code */
  __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_XDECREF(__pyx_t_5);
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.flattenRecords", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_recordList);
  __Pyx_XDECREF(__pyx_v_key);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "lpu/smt/trans_models/triangulate.pyx":350
 *         assert False, "Invalid records"
 * 
 * def pivotRecPairs(rows, workset):             # <<<<<<<<<<<<<<
 *     '''combine the source-pivot and pivot-target records for common pivot phrases
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_19pivotRecPairs(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_3lpu_3smt_12trans_models_11triangulate_18pivotRecPairs[] = "combine the source-pivot and pivot-target records for common pivot phrases\n\n    get the list of record pairs in pivotQueue and put the processed data in outQueue\n\n    if workset.method == \"prodprob\", estimate trans probs by marginalization\n    otherwise, calculate them by estimating co-occurrence counts\n    ";
static PyMethodDef __pyx_mdef_3lpu_3smt_12trans_models_11triangulate_19pivotRecPairs = {"pivotRecPairs", (PyCFunction)__pyx_pw_3lpu_3smt_12trans_models_11triangulate_19pivotRecPairs, METH_VARARGS|METH_KEYWORDS, __pyx_doc_3lpu_3smt_12trans_models_11triangulate_18pivotRecPairs};
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_19pivotRecPairs(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_rows = 0;
  PyObject *__pyx_v_workset = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("pivotRecPairs (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_rows,&__pyx_n_s_workset,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);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        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_rows)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_workset)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("pivotRecPairs", 1, 2, 2, 1); __PYX_ERR(0, 350, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "pivotRecPairs") < 0)) __PYX_ERR(0, 350, __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_rows = values[0];
    __pyx_v_workset = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("pivotRecPairs", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 350, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.pivotRecPairs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_3lpu_3smt_12trans_models_11triangulate_18pivotRecPairs(__pyx_self, __pyx_v_rows, __pyx_v_workset);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_18pivotRecPairs(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_rows, PyObject *__pyx_v_workset) {
  PyObject *__pyx_v_records = NULL;
  PyObject *__pyx_v_multiRecords = NULL;
  PyObject *__pyx_v_recPair = NULL;
  PyObject *__pyx_v_trgKey = NULL;
  PyObject *__pyx_v_strMultiTrg = NULL;
  PyObject *__pyx_v_multiKey = NULL;
  PyObject *__pyx_v_recPivot = NULL;
  PyObject *__pyx_v_recMulti = NULL;
  PyObject *__pyx_v_trgPair = NULL;
  PyObject *__pyx_v_featureKey = NULL;
  PyObject *__pyx_v_ignoring = NULL;
  PyObject *__pyx_v_key = NULL;
  PyObject *__pyx_v_rec = NULL;
  PyObject *__pyx_v_scores = NULL;
  PyObject *__pyx_v_bestRecords = NULL;
  CYTHON_UNUSED PyObject *__pyx_v__ = NULL;
  PyObject *__pyx_v_bestTrgRecords = NULL;
  PyObject *__pyx_v_bestMultiRecords = NULL;
  PyObject *__pyx_v_multiList = NULL;
  PyObject *__pyx_v_bestMultiRec = NULL;
  PyObject *__pyx_v_bestForwardJointTransProb = NULL;
  PyObject *__pyx_v_multiRec = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  Py_ssize_t __pyx_t_1;
  int __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;
  int __pyx_t_8;
  int __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  PyObject *(*__pyx_t_12)(PyObject *);
  Py_ssize_t __pyx_t_13;
  int __pyx_t_14;
  PyObject *(*__pyx_t_15)(PyObject *);
  PyObject *__pyx_t_16 = NULL;
  __Pyx_RefNannySetupContext("pivotRecPairs", 0);

  /* "lpu/smt/trans_models/triangulate.pyx":360
 *     #lexCounts = lex.PairCounter()
 * 
 *     if len(rows) > 0:             # <<<<<<<<<<<<<<
 *         records = {}
 *         if workset.multi_target:
 */
  __pyx_t_1 = PyObject_Length(__pyx_v_rows); if (unlikely(__pyx_t_1 == -1)) __PYX_ERR(0, 360, __pyx_L1_error)
  __pyx_t_2 = ((__pyx_t_1 > 0) != 0);
  if (__pyx_t_2) {

    /* "lpu/smt/trans_models/triangulate.pyx":361
 * 
 *     if len(rows) > 0:
 *         records = {}             # <<<<<<<<<<<<<<
 *         if workset.multi_target:
 *             multiRecords = {}
 */
    __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 361, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_records = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":362
 *     if len(rows) > 0:
 *         records = {}
 *         if workset.multi_target:             # <<<<<<<<<<<<<<
 *             multiRecords = {}
 *             #jointMethod = workset.jointMethod
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_multi_target); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 362, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 362, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_2) {

      /* "lpu/smt/trans_models/triangulate.pyx":363
 *         records = {}
 *         if workset.multi_target:
 *             multiRecords = {}             # <<<<<<<<<<<<<<
 *             #jointMethod = workset.jointMethod
 *         for recPair in rows:
 */
      __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 363, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_v_multiRecords = ((PyObject*)__pyx_t_3);
      __pyx_t_3 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":362
 *     if len(rows) > 0:
 *         records = {}
 *         if workset.multi_target:             # <<<<<<<<<<<<<<
 *             multiRecords = {}
 *             #jointMethod = workset.jointMethod
 */
    }

    /* "lpu/smt/trans_models/triangulate.pyx":365
 *             multiRecords = {}
 *             #jointMethod = workset.jointMethod
 *         for recPair in rows:             # <<<<<<<<<<<<<<
 *             if workset.matchMethod == 'treecomp':
 *                 # pvt1 and pvt2 must be same
 */
    if (likely(PyList_CheckExact(__pyx_v_rows)) || PyTuple_CheckExact(__pyx_v_rows)) {
      __pyx_t_3 = __pyx_v_rows; __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = 0;
      __pyx_t_4 = NULL;
    } else {
      __pyx_t_1 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_rows); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 365, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 365, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_4)) {
        if (likely(PyList_CheckExact(__pyx_t_3))) {
          if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_3)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_5 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_5); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 365, __pyx_L1_error)
          #else
          __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 365, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          #endif
        } else {
          if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_5); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 365, __pyx_L1_error)
          #else
          __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 365, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          #endif
        }
      } else {
        __pyx_t_5 = __pyx_t_4(__pyx_t_3);
        if (unlikely(!__pyx_t_5)) {
          PyObject* exc_type = PyErr_Occurred();
          if (exc_type) {
            if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
            else __PYX_ERR(0, 365, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_5);
      }
      __Pyx_XDECREF_SET(__pyx_v_recPair, __pyx_t_5);
      __pyx_t_5 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":366
 *             #jointMethod = workset.jointMethod
 *         for recPair in rows:
 *             if workset.matchMethod == 'treecomp':             # <<<<<<<<<<<<<<
 *                 # pvt1 and pvt2 must be same
 *                 if recPair[0].trg != recPair[1].src:
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_matchMethod); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 366, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_t_5, __pyx_n_s_treecomp, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 366, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_2) {

        /* "lpu/smt/trans_models/triangulate.pyx":368
 *             if workset.matchMethod == 'treecomp':
 *                 # pvt1 and pvt2 must be same
 *                 if recPair[0].trg != recPair[1].src:             # <<<<<<<<<<<<<<
 *                     continue
 *             elif workset.matchMethod == 'symbols':
 */
        __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_recPair, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 368, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_trg); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 368, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_recPair, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 368, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_src); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 368, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_5 = PyObject_RichCompare(__pyx_t_6, __pyx_t_7, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 368, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 368, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        if (__pyx_t_2) {

          /* "lpu/smt/trans_models/triangulate.pyx":369
 *                 # pvt1 and pvt2 must be same
 *                 if recPair[0].trg != recPair[1].src:
 *                     continue             # <<<<<<<<<<<<<<
 *             elif workset.matchMethod == 'symbols':
 *                 if recPair[0].trgSymbols != recPair[1].src_symbols:
 */
          goto __pyx_L5_continue;

          /* "lpu/smt/trans_models/triangulate.pyx":368
 *             if workset.matchMethod == 'treecomp':
 *                 # pvt1 and pvt2 must be same
 *                 if recPair[0].trg != recPair[1].src:             # <<<<<<<<<<<<<<
 *                     continue
 *             elif workset.matchMethod == 'symbols':
 */
        }

        /* "lpu/smt/trans_models/triangulate.pyx":366
 *             #jointMethod = workset.jointMethod
 *         for recPair in rows:
 *             if workset.matchMethod == 'treecomp':             # <<<<<<<<<<<<<<
 *                 # pvt1 and pvt2 must be same
 *                 if recPair[0].trg != recPair[1].src:
 */
        goto __pyx_L7;
      }

      /* "lpu/smt/trans_models/triangulate.pyx":370
 *                 if recPair[0].trg != recPair[1].src:
 *                     continue
 *             elif workset.matchMethod == 'symbols':             # <<<<<<<<<<<<<<
 *                 if recPair[0].trgSymbols != recPair[1].src_symbols:
 *                     continue
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_matchMethod); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 370, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_t_5, __pyx_n_s_symbols, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 370, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_2) {

        /* "lpu/smt/trans_models/triangulate.pyx":371
 *                     continue
 *             elif workset.matchMethod == 'symbols':
 *                 if recPair[0].trgSymbols != recPair[1].src_symbols:             # <<<<<<<<<<<<<<
 *                     continue
 *             trgKey = recPair[1].trg + ' |||'
 */
        __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_recPair, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 371, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_trgSymbols); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 371, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_recPair, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 371, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_src_symbols); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 371, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_5 = PyObject_RichCompare(__pyx_t_7, __pyx_t_6, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 371, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 371, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        if (__pyx_t_2) {

          /* "lpu/smt/trans_models/triangulate.pyx":372
 *             elif workset.matchMethod == 'symbols':
 *                 if recPair[0].trgSymbols != recPair[1].src_symbols:
 *                     continue             # <<<<<<<<<<<<<<
 *             trgKey = recPair[1].trg + ' |||'
 *             if workset.multi_target:
 */
          goto __pyx_L5_continue;

          /* "lpu/smt/trans_models/triangulate.pyx":371
 *                     continue
 *             elif workset.matchMethod == 'symbols':
 *                 if recPair[0].trgSymbols != recPair[1].src_symbols:             # <<<<<<<<<<<<<<
 *                     continue
 *             trgKey = recPair[1].trg + ' |||'
 */
        }

        /* "lpu/smt/trans_models/triangulate.pyx":370
 *                 if recPair[0].trg != recPair[1].src:
 *                     continue
 *             elif workset.matchMethod == 'symbols':             # <<<<<<<<<<<<<<
 *                 if recPair[0].trgSymbols != recPair[1].src_symbols:
 *                     continue
 */
      }
      __pyx_L7:;

      /* "lpu/smt/trans_models/triangulate.pyx":373
 *                 if recPair[0].trgSymbols != recPair[1].src_symbols:
 *                     continue
 *             trgKey = recPair[1].trg + ' |||'             # <<<<<<<<<<<<<<
 *             if workset.multi_target:
 *                 #strMultiTrg = intern(recPair[1].trg + ' |COL| ' + recPair[0].trg)
 */
      __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_recPair, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 373, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_trg); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 373, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = PyNumber_Add(__pyx_t_6, __pyx_kp_s__17); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 373, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF_SET(__pyx_v_trgKey, __pyx_t_5);
      __pyx_t_5 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":374
 *                     continue
 *             trgKey = recPair[1].trg + ' |||'
 *             if workset.multi_target:             # <<<<<<<<<<<<<<
 *                 #strMultiTrg = intern(recPair[1].trg + ' |COL| ' + recPair[0].trg)
 *                 strMultiTrg = recPair[1].trg + ' |COL| ' + recPair[0].trg
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_multi_target); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 374, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 374, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_2) {

        /* "lpu/smt/trans_models/triangulate.pyx":376
 *             if workset.multi_target:
 *                 #strMultiTrg = intern(recPair[1].trg + ' |COL| ' + recPair[0].trg)
 *                 strMultiTrg = recPair[1].trg + ' |COL| ' + recPair[0].trg             # <<<<<<<<<<<<<<
 *                 multiKey = strMultiTrg + ' |||'
 *             if not trgKey in records:
 */
        __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_recPair, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 376, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_trg); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 376, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_5 = PyNumber_Add(__pyx_t_6, __pyx_kp_s_COL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 376, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_recPair, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 376, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_trg); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 376, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_6 = PyNumber_Add(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 376, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_XDECREF_SET(__pyx_v_strMultiTrg, __pyx_t_6);
        __pyx_t_6 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":377
 *                 #strMultiTrg = intern(recPair[1].trg + ' |COL| ' + recPair[0].trg)
 *                 strMultiTrg = recPair[1].trg + ' |COL| ' + recPair[0].trg
 *                 multiKey = strMultiTrg + ' |||'             # <<<<<<<<<<<<<<
 *             if not trgKey in records:
 *                 # source-target record not yet exists, so making new record
 */
        __pyx_t_6 = PyNumber_Add(__pyx_v_strMultiTrg, __pyx_kp_s__17); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 377, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_XDECREF_SET(__pyx_v_multiKey, __pyx_t_6);
        __pyx_t_6 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":374
 *                     continue
 *             trgKey = recPair[1].trg + ' |||'
 *             if workset.multi_target:             # <<<<<<<<<<<<<<
 *                 #strMultiTrg = intern(recPair[1].trg + ' |COL| ' + recPair[0].trg)
 *                 strMultiTrg = recPair[1].trg + ' |COL| ' + recPair[0].trg
 */
      }

      /* "lpu/smt/trans_models/triangulate.pyx":378
 *                 strMultiTrg = recPair[1].trg + ' |COL| ' + recPair[0].trg
 *                 multiKey = strMultiTrg + ' |||'
 *             if not trgKey in records:             # <<<<<<<<<<<<<<
 *                 # source-target record not yet exists, so making new record
 *                 recPivot = workset.Record()
 */
      __pyx_t_2 = (__Pyx_PyDict_ContainsTF(__pyx_v_trgKey, __pyx_v_records, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 378, __pyx_L1_error)
      __pyx_t_8 = (__pyx_t_2 != 0);
      if (__pyx_t_8) {

        /* "lpu/smt/trans_models/triangulate.pyx":380
 *             if not trgKey in records:
 *                 # source-target record not yet exists, so making new record
 *                 recPivot = workset.Record()             # <<<<<<<<<<<<<<
 *                 recPivot.src = recPair[0].src
 *                 recPivot.trg = recPair[1].trg
 */
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_Record); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 380, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_5 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
          __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_7);
          if (likely(__pyx_t_5)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
            __Pyx_INCREF(__pyx_t_5);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_7, function);
          }
        }
        if (__pyx_t_5) {
          __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 380, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        } else {
          __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 380, __pyx_L1_error)
        }
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_XDECREF_SET(__pyx_v_recPivot, __pyx_t_6);
        __pyx_t_6 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":381
 *                 # source-target record not yet exists, so making new record
 *                 recPivot = workset.Record()
 *                 recPivot.src = recPair[0].src             # <<<<<<<<<<<<<<
 *                 recPivot.trg = recPair[1].trg
 *                 records[trgKey] = recPivot
 */
        __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_recPair, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 381, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_src); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 381, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (__Pyx_PyObject_SetAttrStr(__pyx_v_recPivot, __pyx_n_s_src, __pyx_t_7) < 0) __PYX_ERR(0, 381, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":382
 *                 recPivot = workset.Record()
 *                 recPivot.src = recPair[0].src
 *                 recPivot.trg = recPair[1].trg             # <<<<<<<<<<<<<<
 *                 records[trgKey] = recPivot
 *             recPivot = records[trgKey]
 */
        __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_recPair, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 382, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_trg); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 382, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        if (__Pyx_PyObject_SetAttrStr(__pyx_v_recPivot, __pyx_n_s_trg, __pyx_t_6) < 0) __PYX_ERR(0, 382, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":383
 *                 recPivot.src = recPair[0].src
 *                 recPivot.trg = recPair[1].trg
 *                 records[trgKey] = recPivot             # <<<<<<<<<<<<<<
 *             recPivot = records[trgKey]
 *             if workset.multi_target:
 */
        if (unlikely(PyDict_SetItem(__pyx_v_records, __pyx_v_trgKey, __pyx_v_recPivot) < 0)) __PYX_ERR(0, 383, __pyx_L1_error)

        /* "lpu/smt/trans_models/triangulate.pyx":378
 *                 strMultiTrg = recPair[1].trg + ' |COL| ' + recPair[0].trg
 *                 multiKey = strMultiTrg + ' |||'
 *             if not trgKey in records:             # <<<<<<<<<<<<<<
 *                 # source-target record not yet exists, so making new record
 *                 recPivot = workset.Record()
 */
      }

      /* "lpu/smt/trans_models/triangulate.pyx":384
 *                 recPivot.trg = recPair[1].trg
 *                 records[trgKey] = recPivot
 *             recPivot = records[trgKey]             # <<<<<<<<<<<<<<
 *             if workset.multi_target:
 *                 recMulti = workset.Record()
 */
      __pyx_t_6 = __Pyx_PyDict_GetItem(__pyx_v_records, __pyx_v_trgKey); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 384, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_XDECREF_SET(__pyx_v_recPivot, __pyx_t_6);
      __pyx_t_6 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":385
 *                 records[trgKey] = recPivot
 *             recPivot = records[trgKey]
 *             if workset.multi_target:             # <<<<<<<<<<<<<<
 *                 recMulti = workset.Record()
 *                 recMulti.src = recPair[0].src
 */
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_multi_target); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 385, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 385, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (__pyx_t_8) {

        /* "lpu/smt/trans_models/triangulate.pyx":386
 *             recPivot = records[trgKey]
 *             if workset.multi_target:
 *                 recMulti = workset.Record()             # <<<<<<<<<<<<<<
 *                 recMulti.src = recPair[0].src
 *                 recMulti.trg = strMultiTrg
 */
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_Record); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 386, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __pyx_t_5 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
          __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_7);
          if (likely(__pyx_t_5)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
            __Pyx_INCREF(__pyx_t_5);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_7, function);
          }
        }
        if (__pyx_t_5) {
          __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 386, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        } else {
          __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 386, __pyx_L1_error)
        }
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_XDECREF_SET(__pyx_v_recMulti, __pyx_t_6);
        __pyx_t_6 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":387
 *             if workset.multi_target:
 *                 recMulti = workset.Record()
 *                 recMulti.src = recPair[0].src             # <<<<<<<<<<<<<<
 *                 recMulti.trg = strMultiTrg
 *                 multiRecords[multiKey] = recMulti
 */
        __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_recPair, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 387, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_src); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 387, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        if (__Pyx_PyObject_SetAttrStr(__pyx_v_recMulti, __pyx_n_s_src, __pyx_t_7) < 0) __PYX_ERR(0, 387, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":388
 *                 recMulti = workset.Record()
 *                 recMulti.src = recPair[0].src
 *                 recMulti.trg = strMultiTrg             # <<<<<<<<<<<<<<
 *                 multiRecords[multiKey] = recMulti
 *             # estimating updated features
 */
        if (unlikely(!__pyx_v_strMultiTrg)) { __Pyx_RaiseUnboundLocalError("strMultiTrg"); __PYX_ERR(0, 388, __pyx_L1_error) }
        if (__Pyx_PyObject_SetAttrStr(__pyx_v_recMulti, __pyx_n_s_trg, __pyx_v_strMultiTrg) < 0) __PYX_ERR(0, 388, __pyx_L1_error)

        /* "lpu/smt/trans_models/triangulate.pyx":389
 *                 recMulti.src = recPair[0].src
 *                 recMulti.trg = strMultiTrg
 *                 multiRecords[multiKey] = recMulti             # <<<<<<<<<<<<<<
 *             # estimating updated features
 *             #updateFeatures(recPivot, recPair, workset.method)
 */
        if (unlikely(!__pyx_v_multiRecords)) { __Pyx_RaiseUnboundLocalError("multiRecords"); __PYX_ERR(0, 389, __pyx_L1_error) }
        if (unlikely(!__pyx_v_multiKey)) { __Pyx_RaiseUnboundLocalError("multiKey"); __PYX_ERR(0, 389, __pyx_L1_error) }
        if (unlikely(PyDict_SetItem(__pyx_v_multiRecords, __pyx_v_multiKey, __pyx_v_recMulti) < 0)) __PYX_ERR(0, 389, __pyx_L1_error)

        /* "lpu/smt/trans_models/triangulate.pyx":385
 *                 records[trgKey] = recPivot
 *             recPivot = records[trgKey]
 *             if workset.multi_target:             # <<<<<<<<<<<<<<
 *                 recMulti = workset.Record()
 *                 recMulti.src = recPair[0].src
 */
      }

      /* "lpu/smt/trans_models/triangulate.pyx":392
 *             # estimating updated features
 *             #updateFeatures(recPivot, recPair, workset.method)
 *             updateFeatures(recPivot, recPair, workset, False)             # <<<<<<<<<<<<<<
 *             # updating the count of phrase pair
 *             updateCounts(recPivot, recPair, workset.method)
 */
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_updateFeatures); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 392, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_5 = NULL;
      __pyx_t_9 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
          __pyx_t_9 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[5] = {__pyx_t_5, __pyx_v_recPivot, __pyx_v_recPair, __pyx_v_workset, Py_False};
        __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 4+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 392, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_7);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[5] = {__pyx_t_5, __pyx_v_recPivot, __pyx_v_recPair, __pyx_v_workset, Py_False};
        __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 4+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 392, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_7);
      } else
      #endif
      {
        __pyx_t_10 = PyTuple_New(4+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 392, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        if (__pyx_t_5) {
          __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_5); __pyx_t_5 = NULL;
        }
        __Pyx_INCREF(__pyx_v_recPivot);
        __Pyx_GIVEREF(__pyx_v_recPivot);
        PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_v_recPivot);
        __Pyx_INCREF(__pyx_v_recPair);
        __Pyx_GIVEREF(__pyx_v_recPair);
        PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_v_recPair);
        __Pyx_INCREF(__pyx_v_workset);
        __Pyx_GIVEREF(__pyx_v_workset);
        PyTuple_SET_ITEM(__pyx_t_10, 2+__pyx_t_9, __pyx_v_workset);
        __Pyx_INCREF(Py_False);
        __Pyx_GIVEREF(Py_False);
        PyTuple_SET_ITEM(__pyx_t_10, 3+__pyx_t_9, Py_False);
        __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_10, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 392, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":394
 *             updateFeatures(recPivot, recPair, workset, False)
 *             # updating the count of phrase pair
 *             updateCounts(recPivot, recPair, workset.method)             # <<<<<<<<<<<<<<
 *             #updateCounts(recPivot, recPair, workset)
 *             # merging the word alignments
 */
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_updateCounts); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 394, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_method); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 394, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_5 = NULL;
      __pyx_t_9 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
          __pyx_t_9 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[4] = {__pyx_t_5, __pyx_v_recPivot, __pyx_v_recPair, __pyx_t_10};
        __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 394, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[4] = {__pyx_t_5, __pyx_v_recPivot, __pyx_v_recPair, __pyx_t_10};
        __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 394, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      } else
      #endif
      {
        __pyx_t_11 = PyTuple_New(3+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 394, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        if (__pyx_t_5) {
          __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_5); __pyx_t_5 = NULL;
        }
        __Pyx_INCREF(__pyx_v_recPivot);
        __Pyx_GIVEREF(__pyx_v_recPivot);
        PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_9, __pyx_v_recPivot);
        __Pyx_INCREF(__pyx_v_recPair);
        __Pyx_GIVEREF(__pyx_v_recPair);
        PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_9, __pyx_v_recPair);
        __Pyx_GIVEREF(__pyx_t_10);
        PyTuple_SET_ITEM(__pyx_t_11, 2+__pyx_t_9, __pyx_t_10);
        __pyx_t_10 = 0;
        __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_11, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 394, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":397
 *             #updateCounts(recPivot, recPair, workset)
 *             # merging the word alignments
 *             mergeAligns(recPivot, recPair)             # <<<<<<<<<<<<<<
 *             if workset.multi_target:
 *                 #updateFeatures(recMulti, recPair, workset.method, multi_target = True, jointMethod = jointMethod)
 */
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_mergeAligns); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 397, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_11 = NULL;
      __pyx_t_9 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_11)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_11);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
          __pyx_t_9 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_recPivot, __pyx_v_recPair};
        __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 397, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_GOTREF(__pyx_t_7);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_recPivot, __pyx_v_recPair};
        __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 397, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_GOTREF(__pyx_t_7);
      } else
      #endif
      {
        __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 397, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        if (__pyx_t_11) {
          __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_11); __pyx_t_11 = NULL;
        }
        __Pyx_INCREF(__pyx_v_recPivot);
        __Pyx_GIVEREF(__pyx_v_recPivot);
        PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_v_recPivot);
        __Pyx_INCREF(__pyx_v_recPair);
        __Pyx_GIVEREF(__pyx_v_recPair);
        PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_v_recPair);
        __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_10, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 397, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":398
 *             # merging the word alignments
 *             mergeAligns(recPivot, recPair)
 *             if workset.multi_target:             # <<<<<<<<<<<<<<
 *                 #updateFeatures(recMulti, recPair, workset.method, multi_target = True, jointMethod = jointMethod)
 *                 updateFeatures(recMulti, recPair, workset, multi_target = True)
 */
      __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_multi_target); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 398, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 398, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      if (__pyx_t_8) {

        /* "lpu/smt/trans_models/triangulate.pyx":400
 *             if workset.multi_target:
 *                 #updateFeatures(recMulti, recPair, workset.method, multi_target = True, jointMethod = jointMethod)
 *                 updateFeatures(recMulti, recPair, workset, multi_target = True)             # <<<<<<<<<<<<<<
 *                 updateCounts(recMulti, recPair, workset.method)
 *                 mergeAligns(recMulti, recPair)
 */
        __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_updateFeatures); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 400, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        if (unlikely(!__pyx_v_recMulti)) { __Pyx_RaiseUnboundLocalError("recMulti"); __PYX_ERR(0, 400, __pyx_L1_error) }
        __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 400, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_INCREF(__pyx_v_recMulti);
        __Pyx_GIVEREF(__pyx_v_recMulti);
        PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_recMulti);
        __Pyx_INCREF(__pyx_v_recPair);
        __Pyx_GIVEREF(__pyx_v_recPair);
        PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_recPair);
        __Pyx_INCREF(__pyx_v_workset);
        __Pyx_GIVEREF(__pyx_v_workset);
        PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_v_workset);
        __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 400, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        if (PyDict_SetItem(__pyx_t_10, __pyx_n_s_multi_target, Py_True) < 0) __PYX_ERR(0, 400, __pyx_L1_error)
        __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_6, __pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 400, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":401
 *                 #updateFeatures(recMulti, recPair, workset.method, multi_target = True, jointMethod = jointMethod)
 *                 updateFeatures(recMulti, recPair, workset, multi_target = True)
 *                 updateCounts(recMulti, recPair, workset.method)             # <<<<<<<<<<<<<<
 *                 mergeAligns(recMulti, recPair)
 *         # at this time, all the source-target records are determined for given source
 */
        __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_updateCounts); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 401, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        if (unlikely(!__pyx_v_recMulti)) { __Pyx_RaiseUnboundLocalError("recMulti"); __PYX_ERR(0, 401, __pyx_L1_error) }
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_method); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 401, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_7 = NULL;
        __pyx_t_9 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) {
          __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_10);
          if (likely(__pyx_t_7)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
            __Pyx_INCREF(__pyx_t_7);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_10, function);
            __pyx_t_9 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_10)) {
          PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_v_recMulti, __pyx_v_recPair, __pyx_t_6};
          __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 401, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) {
          PyObject *__pyx_temp[4] = {__pyx_t_7, __pyx_v_recMulti, __pyx_v_recPair, __pyx_t_6};
          __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 401, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        } else
        #endif
        {
          __pyx_t_5 = PyTuple_New(3+__pyx_t_9); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 401, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          if (__pyx_t_7) {
            __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_7); __pyx_t_7 = NULL;
          }
          __Pyx_INCREF(__pyx_v_recMulti);
          __Pyx_GIVEREF(__pyx_v_recMulti);
          PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_9, __pyx_v_recMulti);
          __Pyx_INCREF(__pyx_v_recPair);
          __Pyx_GIVEREF(__pyx_v_recPair);
          PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_9, __pyx_v_recPair);
          __Pyx_GIVEREF(__pyx_t_6);
          PyTuple_SET_ITEM(__pyx_t_5, 2+__pyx_t_9, __pyx_t_6);
          __pyx_t_6 = 0;
          __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_5, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 401, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        }
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":402
 *                 updateFeatures(recMulti, recPair, workset, multi_target = True)
 *                 updateCounts(recMulti, recPair, workset.method)
 *                 mergeAligns(recMulti, recPair)             # <<<<<<<<<<<<<<
 *         # at this time, all the source-target records are determined for given source
 *         if workset.multi_target:
 */
        __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_mergeAligns); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 402, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        if (unlikely(!__pyx_v_recMulti)) { __Pyx_RaiseUnboundLocalError("recMulti"); __PYX_ERR(0, 402, __pyx_L1_error) }
        __pyx_t_5 = NULL;
        __pyx_t_9 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) {
          __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_10);
          if (likely(__pyx_t_5)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
            __Pyx_INCREF(__pyx_t_5);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_10, function);
            __pyx_t_9 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_10)) {
          PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_recMulti, __pyx_v_recPair};
          __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 402, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_GOTREF(__pyx_t_11);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) {
          PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_recMulti, __pyx_v_recPair};
          __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 402, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_GOTREF(__pyx_t_11);
        } else
        #endif
        {
          __pyx_t_6 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 402, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          if (__pyx_t_5) {
            __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;
          }
          __Pyx_INCREF(__pyx_v_recMulti);
          __Pyx_GIVEREF(__pyx_v_recMulti);
          PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_9, __pyx_v_recMulti);
          __Pyx_INCREF(__pyx_v_recPair);
          __Pyx_GIVEREF(__pyx_v_recPair);
          PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_9, __pyx_v_recPair);
          __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_6, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 402, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        }
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":398
 *             # merging the word alignments
 *             mergeAligns(recPivot, recPair)
 *             if workset.multi_target:             # <<<<<<<<<<<<<<
 *                 #updateFeatures(recMulti, recPair, workset.method, multi_target = True, jointMethod = jointMethod)
 *                 updateFeatures(recMulti, recPair, workset, multi_target = True)
 */
      }

      /* "lpu/smt/trans_models/triangulate.pyx":365
 *             multiRecords = {}
 *             #jointMethod = workset.jointMethod
 *         for recPair in rows:             # <<<<<<<<<<<<<<
 *             if workset.matchMethod == 'treecomp':
 *                 # pvt1 and pvt2 must be same
 */
      __pyx_L5_continue:;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":404
 *                 mergeAligns(recMulti, recPair)
 *         # at this time, all the source-target records are determined for given source
 *         if workset.multi_target:             # <<<<<<<<<<<<<<
 *             # copying the estimated features of source-target records to source-target-pivot records
 *             for multiKey, recMulti in multiRecords.items():
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_multi_target); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 404, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 404, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_8) {

      /* "lpu/smt/trans_models/triangulate.pyx":406
 *         if workset.multi_target:
 *             # copying the estimated features of source-target records to source-target-pivot records
 *             for multiKey, recMulti in multiRecords.items():             # <<<<<<<<<<<<<<
 *                 trgPair = recMulti.trg.split(' |COL| ')
 *                 recPivot = records[trgPair[0]+' |||']
 */
      if (unlikely(!__pyx_v_multiRecords)) { __Pyx_RaiseUnboundLocalError("multiRecords"); __PYX_ERR(0, 406, __pyx_L1_error) }
      __pyx_t_3 = __Pyx_PyDict_Items(__pyx_v_multiRecords); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 406, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
        __pyx_t_11 = __pyx_t_3; __Pyx_INCREF(__pyx_t_11); __pyx_t_1 = 0;
        __pyx_t_4 = NULL;
      } else {
        __pyx_t_1 = -1; __pyx_t_11 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 406, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_4 = Py_TYPE(__pyx_t_11)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 406, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      for (;;) {
        if (likely(!__pyx_t_4)) {
          if (likely(PyList_CheckExact(__pyx_t_11))) {
            if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_11)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_3 = PyList_GET_ITEM(__pyx_t_11, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 406, __pyx_L1_error)
            #else
            __pyx_t_3 = PySequence_ITEM(__pyx_t_11, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 406, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            #endif
          } else {
            if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_11)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_11, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 406, __pyx_L1_error)
            #else
            __pyx_t_3 = PySequence_ITEM(__pyx_t_11, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 406, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            #endif
          }
        } else {
          __pyx_t_3 = __pyx_t_4(__pyx_t_11);
          if (unlikely(!__pyx_t_3)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 406, __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_PYPY
          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_ERR(0, 406, __pyx_L1_error)
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          if (likely(PyTuple_CheckExact(sequence))) {
            __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); 
            __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); 
          } else {
            __pyx_t_10 = PyList_GET_ITEM(sequence, 0); 
            __pyx_t_6 = PyList_GET_ITEM(sequence, 1); 
          }
          __Pyx_INCREF(__pyx_t_10);
          __Pyx_INCREF(__pyx_t_6);
          #else
          __pyx_t_10 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 406, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 406, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
          __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_ERR(0, 406, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_12 = Py_TYPE(__pyx_t_5)->tp_iternext;
          index = 0; __pyx_t_10 = __pyx_t_12(__pyx_t_5); if (unlikely(!__pyx_t_10)) goto __pyx_L17_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_10);
          index = 1; __pyx_t_6 = __pyx_t_12(__pyx_t_5); if (unlikely(!__pyx_t_6)) goto __pyx_L17_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_6);
          if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_5), 2) < 0) __PYX_ERR(0, 406, __pyx_L1_error)
          __pyx_t_12 = NULL;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          goto __pyx_L18_unpacking_done;
          __pyx_L17_unpacking_failed:;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __pyx_t_12 = NULL;
          if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
          __PYX_ERR(0, 406, __pyx_L1_error)
          __pyx_L18_unpacking_done:;
        }
        __Pyx_XDECREF_SET(__pyx_v_multiKey, __pyx_t_10);
        __pyx_t_10 = 0;
        __Pyx_XDECREF_SET(__pyx_v_recMulti, __pyx_t_6);
        __pyx_t_6 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":407
 *             # copying the estimated features of source-target records to source-target-pivot records
 *             for multiKey, recMulti in multiRecords.items():
 *                 trgPair = recMulti.trg.split(' |COL| ')             # <<<<<<<<<<<<<<
 *                 recPivot = records[trgPair[0]+' |||']
 *                 for featureKey in ['egfl', 'egfp', 'fgel', 'fgep']:
 */
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_recMulti, __pyx_n_s_trg); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 407, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_split); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 407, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__18, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 407, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF_SET(__pyx_v_trgPair, __pyx_t_3);
        __pyx_t_3 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":408
 *             for multiKey, recMulti in multiRecords.items():
 *                 trgPair = recMulti.trg.split(' |COL| ')
 *                 recPivot = records[trgPair[0]+' |||']             # <<<<<<<<<<<<<<
 *                 for featureKey in ['egfl', 'egfp', 'fgel', 'fgep']:
 *                     recMulti.features['0'+featureKey] = recPivot.features[featureKey]
 */
        __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_trgPair, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 408, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_6 = PyNumber_Add(__pyx_t_3, __pyx_kp_s__17); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 408, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_records, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 408, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF_SET(__pyx_v_recPivot, __pyx_t_3);
        __pyx_t_3 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":409
 *                 trgPair = recMulti.trg.split(' |COL| ')
 *                 recPivot = records[trgPair[0]+' |||']
 *                 for featureKey in ['egfl', 'egfp', 'fgel', 'fgep']:             # <<<<<<<<<<<<<<
 *                     recMulti.features['0'+featureKey] = recPivot.features[featureKey]
 *                 if workset.jointMethod == 'independent':
 */
        __pyx_t_3 = __pyx_tuple__19; __Pyx_INCREF(__pyx_t_3); __pyx_t_13 = 0;
        for (;;) {
          if (__pyx_t_13 >= 4) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_13); __Pyx_INCREF(__pyx_t_6); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 409, __pyx_L1_error)
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 409, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
          __Pyx_XDECREF_SET(__pyx_v_featureKey, __pyx_t_6);
          __pyx_t_6 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":410
 *                 recPivot = records[trgPair[0]+' |||']
 *                 for featureKey in ['egfl', 'egfp', 'fgel', 'fgep']:
 *                     recMulti.features['0'+featureKey] = recPivot.features[featureKey]             # <<<<<<<<<<<<<<
 *                 if workset.jointMethod == 'independent':
 *                     # p(src|pvt,trg) ~ 1 - (1 - p(src|pvt))(1 - p(src|trg))
 */
          __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_recPivot, __pyx_n_s_features); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 410, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_10 = PyObject_GetItem(__pyx_t_6, __pyx_v_featureKey); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 410, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_recMulti, __pyx_n_s_features); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 410, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_5 = PyNumber_Add(__pyx_kp_s_0, __pyx_v_featureKey); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 410, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          if (unlikely(PyObject_SetItem(__pyx_t_6, __pyx_t_5, __pyx_t_10) < 0)) __PYX_ERR(0, 410, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":409
 *                 trgPair = recMulti.trg.split(' |COL| ')
 *                 recPivot = records[trgPair[0]+' |||']
 *                 for featureKey in ['egfl', 'egfp', 'fgel', 'fgep']:             # <<<<<<<<<<<<<<
 *                     recMulti.features['0'+featureKey] = recPivot.features[featureKey]
 *                 if workset.jointMethod == 'independent':
 */
        }
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":411
 *                 for featureKey in ['egfl', 'egfp', 'fgel', 'fgep']:
 *                     recMulti.features['0'+featureKey] = recPivot.features[featureKey]
 *                 if workset.jointMethod == 'independent':             # <<<<<<<<<<<<<<
 *                     # p(src|pvt,trg) ~ 1 - (1 - p(src|pvt))(1 - p(src|trg))
 *                     recMulti.features['fgep'] = 1 - (1 - recMulti.features['1fgep']) * (1 - recMulti.features['0fgep'])
 */
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_jointMethod); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 411, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_8 = (__Pyx_PyString_Equals(__pyx_t_3, __pyx_n_s_independent, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 411, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (__pyx_t_8) {

          /* "lpu/smt/trans_models/triangulate.pyx":413
 *                 if workset.jointMethod == 'independent':
 *                     # p(src|pvt,trg) ~ 1 - (1 - p(src|pvt))(1 - p(src|trg))
 *                     recMulti.features['fgep'] = 1 - (1 - recMulti.features['1fgep']) * (1 - recMulti.features['0fgep'])             # <<<<<<<<<<<<<<
 * #        if workset.method != 'prodprob':
 * #            # find word pairs in phrase pairs and update the counts of word pairs
 */
          __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_recMulti, __pyx_n_s_features); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 413, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_10 = PyObject_GetItem(__pyx_t_3, __pyx_kp_s_1fgep); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 413, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_3 = __Pyx_PyInt_SubtractCObj(__pyx_int_1, __pyx_t_10, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 413, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_recMulti, __pyx_n_s_features); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 413, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_5 = PyObject_GetItem(__pyx_t_10, __pyx_kp_s_0fgep); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 413, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __pyx_t_10 = __Pyx_PyInt_SubtractCObj(__pyx_int_1, __pyx_t_5, 1, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 413, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __pyx_t_5 = PyNumber_Multiply(__pyx_t_3, __pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 413, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __pyx_t_10 = __Pyx_PyInt_SubtractCObj(__pyx_int_1, __pyx_t_5, 1, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 413, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_recMulti, __pyx_n_s_features); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 413, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          if (unlikely(PyObject_SetItem(__pyx_t_5, __pyx_n_s_fgep, __pyx_t_10) < 0)) __PYX_ERR(0, 413, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":411
 *                 for featureKey in ['egfl', 'egfp', 'fgel', 'fgep']:
 *                     recMulti.features['0'+featureKey] = recPivot.features[featureKey]
 *                 if workset.jointMethod == 'independent':             # <<<<<<<<<<<<<<
 *                     # p(src|pvt,trg) ~ 1 - (1 - p(src|pvt))(1 - p(src|trg))
 *                     recMulti.features['fgep'] = 1 - (1 - recMulti.features['1fgep']) * (1 - recMulti.features['0fgep'])
 */
        }

        /* "lpu/smt/trans_models/triangulate.pyx":406
 *         if workset.multi_target:
 *             # copying the estimated features of source-target records to source-target-pivot records
 *             for multiKey, recMulti in multiRecords.items():             # <<<<<<<<<<<<<<
 *                 trgPair = recMulti.trg.split(' |COL| ')
 *                 recPivot = records[trgPair[0]+' |||']
 */
      }
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":404
 *                 mergeAligns(recMulti, recPair)
 *         # at this time, all the source-target records are determined for given source
 *         if workset.multi_target:             # <<<<<<<<<<<<<<
 *             # copying the estimated features of source-target records to source-target-pivot records
 *             for multiKey, recMulti in multiRecords.items():
 */
    }

    /* "lpu/smt/trans_models/triangulate.pyx":432
 * #            calcPhraseTransProbsByCounts(records)
 *         # if threshold is set (non-zero), aborting the records having trans probs under it
 *         if workset.threshold < 0:             # <<<<<<<<<<<<<<
 *             # aborting records for extremely small trans probs
 *             ignoring = []
 */
    __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_threshold); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 432, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_10 = PyObject_RichCompare(__pyx_t_11, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 432, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 432, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    if (__pyx_t_8) {

      /* "lpu/smt/trans_models/triangulate.pyx":434
 *         if workset.threshold < 0:
 *             # aborting records for extremely small trans probs
 *             ignoring = []             # <<<<<<<<<<<<<<
 *             for key, rec in records.items():
 *                 if rec[0]['fgep'] < workset.threshold and rec[0]['egfp'] < workset.threshold:
 */
      __pyx_t_10 = PyList_New(0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 434, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_v_ignoring = ((PyObject*)__pyx_t_10);
      __pyx_t_10 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":435
 *             # aborting records for extremely small trans probs
 *             ignoring = []
 *             for key, rec in records.items():             # <<<<<<<<<<<<<<
 *                 if rec[0]['fgep'] < workset.threshold and rec[0]['egfp'] < workset.threshold:
 *                     #ignoring.append(pair)
 */
      __pyx_t_10 = __Pyx_PyDict_Items(__pyx_v_records); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 435, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      if (likely(PyList_CheckExact(__pyx_t_10)) || PyTuple_CheckExact(__pyx_t_10)) {
        __pyx_t_11 = __pyx_t_10; __Pyx_INCREF(__pyx_t_11); __pyx_t_1 = 0;
        __pyx_t_4 = NULL;
      } else {
        __pyx_t_1 = -1; __pyx_t_11 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 435, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_4 = Py_TYPE(__pyx_t_11)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 435, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      for (;;) {
        if (likely(!__pyx_t_4)) {
          if (likely(PyList_CheckExact(__pyx_t_11))) {
            if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_11)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_10 = PyList_GET_ITEM(__pyx_t_11, __pyx_t_1); __Pyx_INCREF(__pyx_t_10); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 435, __pyx_L1_error)
            #else
            __pyx_t_10 = PySequence_ITEM(__pyx_t_11, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 435, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_10);
            #endif
          } else {
            if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_11)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_10 = PyTuple_GET_ITEM(__pyx_t_11, __pyx_t_1); __Pyx_INCREF(__pyx_t_10); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 435, __pyx_L1_error)
            #else
            __pyx_t_10 = PySequence_ITEM(__pyx_t_11, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 435, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_10);
            #endif
          }
        } else {
          __pyx_t_10 = __pyx_t_4(__pyx_t_11);
          if (unlikely(!__pyx_t_10)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 435, __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 !CYTHON_COMPILING_IN_PYPY
          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_ERR(0, 435, __pyx_L1_error)
          }
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          if (likely(PyTuple_CheckExact(sequence))) {
            __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); 
            __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
          } else {
            __pyx_t_5 = PyList_GET_ITEM(sequence, 0); 
            __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
          }
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_3);
          #else
          __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 435, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 435, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        } else {
          Py_ssize_t index = -1;
          __pyx_t_6 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 435, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __pyx_t_12 = Py_TYPE(__pyx_t_6)->tp_iternext;
          index = 0; __pyx_t_5 = __pyx_t_12(__pyx_t_6); if (unlikely(!__pyx_t_5)) goto __pyx_L25_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_5);
          index = 1; __pyx_t_3 = __pyx_t_12(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L25_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_3);
          if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_6), 2) < 0) __PYX_ERR(0, 435, __pyx_L1_error)
          __pyx_t_12 = NULL;
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          goto __pyx_L26_unpacking_done;
          __pyx_L25_unpacking_failed:;
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __pyx_t_12 = NULL;
          if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
          __PYX_ERR(0, 435, __pyx_L1_error)
          __pyx_L26_unpacking_done:;
        }
        __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_5);
        __pyx_t_5 = 0;
        __Pyx_XDECREF_SET(__pyx_v_rec, __pyx_t_3);
        __pyx_t_3 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":436
 *             ignoring = []
 *             for key, rec in records.items():
 *                 if rec[0]['fgep'] < workset.threshold and rec[0]['egfp'] < workset.threshold:             # <<<<<<<<<<<<<<
 *                     #ignoring.append(pair)
 *                     ignoring.append(key)
 */
        __pyx_t_10 = __Pyx_GetItemInt(__pyx_v_rec, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 436, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_3 = PyObject_GetItem(__pyx_t_10, __pyx_n_s_fgep); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 436, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_threshold); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 436, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_t_10, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 436, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 436, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        if (__pyx_t_2) {
        } else {
          __pyx_t_8 = __pyx_t_2;
          goto __pyx_L28_bool_binop_done;
        }
        __pyx_t_5 = __Pyx_GetItemInt(__pyx_v_rec, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 436, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_10 = PyObject_GetItem(__pyx_t_5, __pyx_n_s_egfp); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 436, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_threshold); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 436, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_3 = PyObject_RichCompare(__pyx_t_10, __pyx_t_5, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 436, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 436, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_8 = __pyx_t_2;
        __pyx_L28_bool_binop_done:;
        if (__pyx_t_8) {

          /* "lpu/smt/trans_models/triangulate.pyx":438
 *                 if rec[0]['fgep'] < workset.threshold and rec[0]['egfp'] < workset.threshold:
 *                     #ignoring.append(pair)
 *                     ignoring.append(key)             # <<<<<<<<<<<<<<
 *             for key in ignoring:
 *                 del records[key]
 */
          __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_ignoring, __pyx_v_key); if (unlikely(__pyx_t_14 == -1)) __PYX_ERR(0, 438, __pyx_L1_error)

          /* "lpu/smt/trans_models/triangulate.pyx":436
 *             ignoring = []
 *             for key, rec in records.items():
 *                 if rec[0]['fgep'] < workset.threshold and rec[0]['egfp'] < workset.threshold:             # <<<<<<<<<<<<<<
 *                     #ignoring.append(pair)
 *                     ignoring.append(key)
 */
        }

        /* "lpu/smt/trans_models/triangulate.pyx":435
 *             # aborting records for extremely small trans probs
 *             ignoring = []
 *             for key, rec in records.items():             # <<<<<<<<<<<<<<
 *                 if rec[0]['fgep'] < workset.threshold and rec[0]['egfp'] < workset.threshold:
 *                     #ignoring.append(pair)
 */
      }
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":439
 *                     #ignoring.append(pair)
 *                     ignoring.append(key)
 *             for key in ignoring:             # <<<<<<<<<<<<<<
 *                 del records[key]
 *         # if limit number of records is set (non-zero), filter the n-best records by forward trans probs
 */
      __pyx_t_11 = __pyx_v_ignoring; __Pyx_INCREF(__pyx_t_11); __pyx_t_1 = 0;
      for (;;) {
        if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_11)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_11, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 439, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_11, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 439, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
        __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_3);
        __pyx_t_3 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":440
 *                     ignoring.append(key)
 *             for key in ignoring:
 *                 del records[key]             # <<<<<<<<<<<<<<
 *         # if limit number of records is set (non-zero), filter the n-best records by forward trans probs
 *         if workset.nbest > 0:
 */
        if (unlikely(PyDict_DelItem(__pyx_v_records, __pyx_v_key) < 0)) __PYX_ERR(0, 440, __pyx_L1_error)

        /* "lpu/smt/trans_models/triangulate.pyx":439
 *                     #ignoring.append(pair)
 *                     ignoring.append(key)
 *             for key in ignoring:             # <<<<<<<<<<<<<<
 *                 del records[key]
 *         # if limit number of records is set (non-zero), filter the n-best records by forward trans probs
 */
      }
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":432
 * #            calcPhraseTransProbsByCounts(records)
 *         # if threshold is set (non-zero), aborting the records having trans probs under it
 *         if workset.threshold < 0:             # <<<<<<<<<<<<<<
 *             # aborting records for extremely small trans probs
 *             ignoring = []
 */
    }

    /* "lpu/smt/trans_models/triangulate.pyx":442
 *                 del records[key]
 *         # if limit number of records is set (non-zero), filter the n-best records by forward trans probs
 *         if workset.nbest > 0:             # <<<<<<<<<<<<<<
 *             if len(records) > workset.nbest:
 *                 scores = []
 */
    __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_nbest); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 442, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_3 = PyObject_RichCompare(__pyx_t_11, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 442, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 442, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_8) {

      /* "lpu/smt/trans_models/triangulate.pyx":443
 *         # if limit number of records is set (non-zero), filter the n-best records by forward trans probs
 *         if workset.nbest > 0:
 *             if len(records) > workset.nbest:             # <<<<<<<<<<<<<<
 *                 scores = []
 *                 for key, rec in records.items():
 */
      __pyx_t_1 = PyDict_Size(__pyx_v_records); if (unlikely(__pyx_t_1 == -1)) __PYX_ERR(0, 443, __pyx_L1_error)
      __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 443, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_nbest); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 443, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_5 = PyObject_RichCompare(__pyx_t_3, __pyx_t_11, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 443, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 443, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_8) {

        /* "lpu/smt/trans_models/triangulate.pyx":444
 *         if workset.nbest > 0:
 *             if len(records) > workset.nbest:
 *                 scores = []             # <<<<<<<<<<<<<<
 *                 for key, rec in records.items():
 *                     scores.append( (rec.features['egfp'],key) )
 */
        __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 444, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_v_scores = ((PyObject*)__pyx_t_5);
        __pyx_t_5 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":445
 *             if len(records) > workset.nbest:
 *                 scores = []
 *                 for key, rec in records.items():             # <<<<<<<<<<<<<<
 *                     scores.append( (rec.features['egfp'],key) )
 *                     #scores.append( (rec.features['fgep'],key) )
 */
        __pyx_t_5 = __Pyx_PyDict_Items(__pyx_v_records); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 445, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (likely(PyList_CheckExact(__pyx_t_5)) || PyTuple_CheckExact(__pyx_t_5)) {
          __pyx_t_11 = __pyx_t_5; __Pyx_INCREF(__pyx_t_11); __pyx_t_1 = 0;
          __pyx_t_4 = NULL;
        } else {
          __pyx_t_1 = -1; __pyx_t_11 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 445, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          __pyx_t_4 = Py_TYPE(__pyx_t_11)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 445, __pyx_L1_error)
        }
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        for (;;) {
          if (likely(!__pyx_t_4)) {
            if (likely(PyList_CheckExact(__pyx_t_11))) {
              if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_11)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_5 = PyList_GET_ITEM(__pyx_t_11, __pyx_t_1); __Pyx_INCREF(__pyx_t_5); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 445, __pyx_L1_error)
              #else
              __pyx_t_5 = PySequence_ITEM(__pyx_t_11, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 445, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_5);
              #endif
            } else {
              if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_11)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_11, __pyx_t_1); __Pyx_INCREF(__pyx_t_5); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 445, __pyx_L1_error)
              #else
              __pyx_t_5 = PySequence_ITEM(__pyx_t_11, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 445, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_5);
              #endif
            }
          } else {
            __pyx_t_5 = __pyx_t_4(__pyx_t_11);
            if (unlikely(!__pyx_t_5)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else __PYX_ERR(0, 445, __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_PYPY
            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_ERR(0, 445, __pyx_L1_error)
            }
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            if (likely(PyTuple_CheckExact(sequence))) {
              __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
              __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); 
            } else {
              __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
              __pyx_t_10 = PyList_GET_ITEM(sequence, 1); 
            }
            __Pyx_INCREF(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_10);
            #else
            __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 445, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 445, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_10);
            #endif
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          } else {
            Py_ssize_t index = -1;
            __pyx_t_6 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 445, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __pyx_t_12 = Py_TYPE(__pyx_t_6)->tp_iternext;
            index = 0; __pyx_t_3 = __pyx_t_12(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L36_unpacking_failed;
            __Pyx_GOTREF(__pyx_t_3);
            index = 1; __pyx_t_10 = __pyx_t_12(__pyx_t_6); if (unlikely(!__pyx_t_10)) goto __pyx_L36_unpacking_failed;
            __Pyx_GOTREF(__pyx_t_10);
            if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_6), 2) < 0) __PYX_ERR(0, 445, __pyx_L1_error)
            __pyx_t_12 = NULL;
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            goto __pyx_L37_unpacking_done;
            __pyx_L36_unpacking_failed:;
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            __pyx_t_12 = NULL;
            if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
            __PYX_ERR(0, 445, __pyx_L1_error)
            __pyx_L37_unpacking_done:;
          }
          __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_3);
          __pyx_t_3 = 0;
          __Pyx_XDECREF_SET(__pyx_v_rec, __pyx_t_10);
          __pyx_t_10 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":446
 *                 scores = []
 *                 for key, rec in records.items():
 *                     scores.append( (rec.features['egfp'],key) )             # <<<<<<<<<<<<<<
 *                     #scores.append( (rec.features['fgep'],key) )
 *                 scores.sort(reverse = True)
 */
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_features); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 446, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_10 = PyObject_GetItem(__pyx_t_5, __pyx_n_s_egfp); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 446, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 446, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_GIVEREF(__pyx_t_10);
          PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_10);
          __Pyx_INCREF(__pyx_v_key);
          __Pyx_GIVEREF(__pyx_v_key);
          PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_key);
          __pyx_t_10 = 0;
          __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_scores, __pyx_t_5); if (unlikely(__pyx_t_14 == -1)) __PYX_ERR(0, 446, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":445
 *             if len(records) > workset.nbest:
 *                 scores = []
 *                 for key, rec in records.items():             # <<<<<<<<<<<<<<
 *                     scores.append( (rec.features['egfp'],key) )
 *                     #scores.append( (rec.features['fgep'],key) )
 */
        }
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":448
 *                     scores.append( (rec.features['egfp'],key) )
 *                     #scores.append( (rec.features['fgep'],key) )
 *                 scores.sort(reverse = True)             # <<<<<<<<<<<<<<
 *                 bestRecords = {}
 *                 for _, key in scores[:workset.nbest]:
 */
        __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_scores, __pyx_n_s_sort); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 448, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 448, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_reverse, Py_True) < 0) __PYX_ERR(0, 448, __pyx_L1_error)
        __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_empty_tuple, __pyx_t_5); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 448, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":449
 *                     #scores.append( (rec.features['fgep'],key) )
 *                 scores.sort(reverse = True)
 *                 bestRecords = {}             # <<<<<<<<<<<<<<
 *                 for _, key in scores[:workset.nbest]:
 *                     bestRecords[key] = records[key]
 */
        __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 449, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_v_bestRecords = ((PyObject*)__pyx_t_10);
        __pyx_t_10 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":450
 *                 scores.sort(reverse = True)
 *                 bestRecords = {}
 *                 for _, key in scores[:workset.nbest]:             # <<<<<<<<<<<<<<
 *                     bestRecords[key] = records[key]
 *                 records = bestRecords
 */
        __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_nbest); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 450, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_1 = __Pyx_PyIndex_AsSsize_t(__pyx_t_10); if (unlikely((__pyx_t_1 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 450, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_10 = __Pyx_PyList_GetSlice(__pyx_v_scores, 0, __pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 450, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_5 = __pyx_t_10; __Pyx_INCREF(__pyx_t_5); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        for (;;) {
          if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_5)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_10 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_1); __Pyx_INCREF(__pyx_t_10); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 450, __pyx_L1_error)
          #else
          __pyx_t_10 = PySequence_ITEM(__pyx_t_5, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 450, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          #endif
          if ((likely(PyTuple_CheckExact(__pyx_t_10))) || (PyList_CheckExact(__pyx_t_10))) {
            PyObject* sequence = __pyx_t_10;
            #if !CYTHON_COMPILING_IN_PYPY
            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_ERR(0, 450, __pyx_L1_error)
            }
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            if (likely(PyTuple_CheckExact(sequence))) {
              __pyx_t_11 = PyTuple_GET_ITEM(sequence, 0); 
              __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
            } else {
              __pyx_t_11 = PyList_GET_ITEM(sequence, 0); 
              __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
            }
            __Pyx_INCREF(__pyx_t_11);
            __Pyx_INCREF(__pyx_t_3);
            #else
            __pyx_t_11 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 450, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_11);
            __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 450, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            #endif
            __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          } else {
            Py_ssize_t index = -1;
            __pyx_t_6 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 450, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
            __pyx_t_12 = Py_TYPE(__pyx_t_6)->tp_iternext;
            index = 0; __pyx_t_11 = __pyx_t_12(__pyx_t_6); if (unlikely(!__pyx_t_11)) goto __pyx_L40_unpacking_failed;
            __Pyx_GOTREF(__pyx_t_11);
            index = 1; __pyx_t_3 = __pyx_t_12(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L40_unpacking_failed;
            __Pyx_GOTREF(__pyx_t_3);
            if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_6), 2) < 0) __PYX_ERR(0, 450, __pyx_L1_error)
            __pyx_t_12 = NULL;
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            goto __pyx_L41_unpacking_done;
            __pyx_L40_unpacking_failed:;
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            __pyx_t_12 = NULL;
            if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
            __PYX_ERR(0, 450, __pyx_L1_error)
            __pyx_L41_unpacking_done:;
          }
          __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_11);
          __pyx_t_11 = 0;
          __Pyx_XDECREF_SET(__pyx_v_key, __pyx_t_3);
          __pyx_t_3 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":451
 *                 bestRecords = {}
 *                 for _, key in scores[:workset.nbest]:
 *                     bestRecords[key] = records[key]             # <<<<<<<<<<<<<<
 *                 records = bestRecords
 *             if workset.multi_target:
 */
          __pyx_t_10 = __Pyx_PyDict_GetItem(__pyx_v_records, __pyx_v_key); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 451, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          if (unlikely(PyDict_SetItem(__pyx_v_bestRecords, __pyx_v_key, __pyx_t_10) < 0)) __PYX_ERR(0, 451, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":450
 *                 scores.sort(reverse = True)
 *                 bestRecords = {}
 *                 for _, key in scores[:workset.nbest]:             # <<<<<<<<<<<<<<
 *                     bestRecords[key] = records[key]
 *                 records = bestRecords
 */
        }
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":452
 *                 for _, key in scores[:workset.nbest]:
 *                     bestRecords[key] = records[key]
 *                 records = bestRecords             # <<<<<<<<<<<<<<
 *             if workset.multi_target:
 *                 if len(multiRecords) > workset.nbest:
 */
        __Pyx_INCREF(__pyx_v_bestRecords);
        __Pyx_DECREF_SET(__pyx_v_records, __pyx_v_bestRecords);

        /* "lpu/smt/trans_models/triangulate.pyx":443
 *         # if limit number of records is set (non-zero), filter the n-best records by forward trans probs
 *         if workset.nbest > 0:
 *             if len(records) > workset.nbest:             # <<<<<<<<<<<<<<
 *                 scores = []
 *                 for key, rec in records.items():
 */
      }

      /* "lpu/smt/trans_models/triangulate.pyx":453
 *                     bestRecords[key] = records[key]
 *                 records = bestRecords
 *             if workset.multi_target:             # <<<<<<<<<<<<<<
 *                 if len(multiRecords) > workset.nbest:
 *                     # T1-filtering method
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_multi_target); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 453, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 453, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      if (__pyx_t_8) {

        /* "lpu/smt/trans_models/triangulate.pyx":454
 *                 records = bestRecords
 *             if workset.multi_target:
 *                 if len(multiRecords) > workset.nbest:             # <<<<<<<<<<<<<<
 *                     # T1-filtering method
 *                     bestTrgRecords = {}
 */
        if (unlikely(!__pyx_v_multiRecords)) { __Pyx_RaiseUnboundLocalError("multiRecords"); __PYX_ERR(0, 454, __pyx_L1_error) }
        __pyx_t_1 = PyDict_Size(__pyx_v_multiRecords); if (unlikely(__pyx_t_1 == -1)) __PYX_ERR(0, 454, __pyx_L1_error)
        __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 454, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_nbest); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 454, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_3 = PyObject_RichCompare(__pyx_t_5, __pyx_t_10, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 454, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 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_ERR(0, 454, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        if (__pyx_t_8) {

          /* "lpu/smt/trans_models/triangulate.pyx":456
 *                 if len(multiRecords) > workset.nbest:
 *                     # T1-filtering method
 *                     bestTrgRecords = {}             # <<<<<<<<<<<<<<
 *                     # first, filtering src-pvt-trg records including n-best src-trg records
 *                     for multiKey, recMulti in multiRecords.items():
 */
          __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 456, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_v_bestTrgRecords = ((PyObject*)__pyx_t_3);
          __pyx_t_3 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":458
 *                     bestTrgRecords = {}
 *                     # first, filtering src-pvt-trg records including n-best src-trg records
 *                     for multiKey, recMulti in multiRecords.items():             # <<<<<<<<<<<<<<
 *                         for rec in records.values():
 *                             if multiKey.find(rec.trg + ' |COL|') == 0:
 */
          if (unlikely(!__pyx_v_multiRecords)) { __Pyx_RaiseUnboundLocalError("multiRecords"); __PYX_ERR(0, 458, __pyx_L1_error) }
          __pyx_t_3 = __Pyx_PyDict_Items(__pyx_v_multiRecords); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 458, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
            __pyx_t_10 = __pyx_t_3; __Pyx_INCREF(__pyx_t_10); __pyx_t_1 = 0;
            __pyx_t_4 = NULL;
          } else {
            __pyx_t_1 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 458, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_10);
            __pyx_t_4 = Py_TYPE(__pyx_t_10)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 458, __pyx_L1_error)
          }
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          for (;;) {
            if (likely(!__pyx_t_4)) {
              if (likely(PyList_CheckExact(__pyx_t_10))) {
                if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_10)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_3 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 458, __pyx_L1_error)
                #else
                __pyx_t_3 = PySequence_ITEM(__pyx_t_10, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 458, __pyx_L1_error)
                __Pyx_GOTREF(__pyx_t_3);
                #endif
              } else {
                if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_10)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 458, __pyx_L1_error)
                #else
                __pyx_t_3 = PySequence_ITEM(__pyx_t_10, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 458, __pyx_L1_error)
                __Pyx_GOTREF(__pyx_t_3);
                #endif
              }
            } else {
              __pyx_t_3 = __pyx_t_4(__pyx_t_10);
              if (unlikely(!__pyx_t_3)) {
                PyObject* exc_type = PyErr_Occurred();
                if (exc_type) {
                  if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                  else __PYX_ERR(0, 458, __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_PYPY
              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_ERR(0, 458, __pyx_L1_error)
              }
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              if (likely(PyTuple_CheckExact(sequence))) {
                __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); 
                __pyx_t_11 = PyTuple_GET_ITEM(sequence, 1); 
              } else {
                __pyx_t_5 = PyList_GET_ITEM(sequence, 0); 
                __pyx_t_11 = PyList_GET_ITEM(sequence, 1); 
              }
              __Pyx_INCREF(__pyx_t_5);
              __Pyx_INCREF(__pyx_t_11);
              #else
              __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 458, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_5);
              __pyx_t_11 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 458, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_11);
              #endif
              __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_ERR(0, 458, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
              __pyx_t_12 = Py_TYPE(__pyx_t_6)->tp_iternext;
              index = 0; __pyx_t_5 = __pyx_t_12(__pyx_t_6); if (unlikely(!__pyx_t_5)) goto __pyx_L46_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_5);
              index = 1; __pyx_t_11 = __pyx_t_12(__pyx_t_6); if (unlikely(!__pyx_t_11)) goto __pyx_L46_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_11);
              if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_6), 2) < 0) __PYX_ERR(0, 458, __pyx_L1_error)
              __pyx_t_12 = NULL;
              __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
              goto __pyx_L47_unpacking_done;
              __pyx_L46_unpacking_failed:;
              __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
              __pyx_t_12 = NULL;
              if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
              __PYX_ERR(0, 458, __pyx_L1_error)
              __pyx_L47_unpacking_done:;
            }
            __Pyx_XDECREF_SET(__pyx_v_multiKey, __pyx_t_5);
            __pyx_t_5 = 0;
            __Pyx_XDECREF_SET(__pyx_v_recMulti, __pyx_t_11);
            __pyx_t_11 = 0;

            /* "lpu/smt/trans_models/triangulate.pyx":459
 *                     # first, filtering src-pvt-trg records including n-best src-trg records
 *                     for multiKey, recMulti in multiRecords.items():
 *                         for rec in records.values():             # <<<<<<<<<<<<<<
 *                             if multiKey.find(rec.trg + ' |COL|') == 0:
 *                                 bestTrgRecords.setdefault(rec.trg, [])
 */
            __pyx_t_3 = __Pyx_PyDict_Values(__pyx_v_records); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 459, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
              __pyx_t_11 = __pyx_t_3; __Pyx_INCREF(__pyx_t_11); __pyx_t_13 = 0;
              __pyx_t_15 = NULL;
            } else {
              __pyx_t_13 = -1; __pyx_t_11 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 459, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_11);
              __pyx_t_15 = Py_TYPE(__pyx_t_11)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 459, __pyx_L1_error)
            }
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            for (;;) {
              if (likely(!__pyx_t_15)) {
                if (likely(PyList_CheckExact(__pyx_t_11))) {
                  if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_11)) break;
                  #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                  __pyx_t_3 = PyList_GET_ITEM(__pyx_t_11, __pyx_t_13); __Pyx_INCREF(__pyx_t_3); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 459, __pyx_L1_error)
                  #else
                  __pyx_t_3 = PySequence_ITEM(__pyx_t_11, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 459, __pyx_L1_error)
                  __Pyx_GOTREF(__pyx_t_3);
                  #endif
                } else {
                  if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_11)) break;
                  #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                  __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_11, __pyx_t_13); __Pyx_INCREF(__pyx_t_3); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 459, __pyx_L1_error)
                  #else
                  __pyx_t_3 = PySequence_ITEM(__pyx_t_11, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 459, __pyx_L1_error)
                  __Pyx_GOTREF(__pyx_t_3);
                  #endif
                }
              } else {
                __pyx_t_3 = __pyx_t_15(__pyx_t_11);
                if (unlikely(!__pyx_t_3)) {
                  PyObject* exc_type = PyErr_Occurred();
                  if (exc_type) {
                    if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                    else __PYX_ERR(0, 459, __pyx_L1_error)
                  }
                  break;
                }
                __Pyx_GOTREF(__pyx_t_3);
              }
              __Pyx_XDECREF_SET(__pyx_v_rec, __pyx_t_3);
              __pyx_t_3 = 0;

              /* "lpu/smt/trans_models/triangulate.pyx":460
 *                     for multiKey, recMulti in multiRecords.items():
 *                         for rec in records.values():
 *                             if multiKey.find(rec.trg + ' |COL|') == 0:             # <<<<<<<<<<<<<<
 *                                 bestTrgRecords.setdefault(rec.trg, [])
 *                                 bestTrgRecords[rec.trg].append(recMulti)
 */
              __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_multiKey, __pyx_n_s_find); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 460, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_5);
              __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_trg); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 460, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_6);
              __pyx_t_7 = PyNumber_Add(__pyx_t_6, __pyx_kp_s_COL_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 460, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_7);
              __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
              __pyx_t_6 = NULL;
              if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
                __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
                if (likely(__pyx_t_6)) {
                  PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
                  __Pyx_INCREF(__pyx_t_6);
                  __Pyx_INCREF(function);
                  __Pyx_DECREF_SET(__pyx_t_5, function);
                }
              }
              if (!__pyx_t_6) {
                __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 460, __pyx_L1_error)
                __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
                __Pyx_GOTREF(__pyx_t_3);
              } else {
                #if CYTHON_FAST_PYCALL
                if (PyFunction_Check(__pyx_t_5)) {
                  PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_7};
                  __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 460, __pyx_L1_error)
                  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
                  __Pyx_GOTREF(__pyx_t_3);
                  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
                } else
                #endif
                #if CYTHON_FAST_PYCCALL
                if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
                  PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_t_7};
                  __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 460, __pyx_L1_error)
                  __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
                  __Pyx_GOTREF(__pyx_t_3);
                  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
                } else
                #endif
                {
                  __pyx_t_16 = PyTuple_New(1+1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 460, __pyx_L1_error)
                  __Pyx_GOTREF(__pyx_t_16);
                  __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_6); __pyx_t_6 = NULL;
                  __Pyx_GIVEREF(__pyx_t_7);
                  PyTuple_SET_ITEM(__pyx_t_16, 0+1, __pyx_t_7);
                  __pyx_t_7 = 0;
                  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_16, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 460, __pyx_L1_error)
                  __Pyx_GOTREF(__pyx_t_3);
                  __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
                }
              }
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
              __pyx_t_5 = __Pyx_PyInt_EqObjC(__pyx_t_3, __pyx_int_0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 460, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_5);
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
              __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 460, __pyx_L1_error)
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
              if (__pyx_t_8) {

                /* "lpu/smt/trans_models/triangulate.pyx":461
 *                         for rec in records.values():
 *                             if multiKey.find(rec.trg + ' |COL|') == 0:
 *                                 bestTrgRecords.setdefault(rec.trg, [])             # <<<<<<<<<<<<<<
 *                                 bestTrgRecords[rec.trg].append(recMulti)
 *                     bestMultiRecords = {}
 */
                __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_trg); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 461, __pyx_L1_error)
                __Pyx_GOTREF(__pyx_t_5);
                __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 461, __pyx_L1_error)
                __Pyx_GOTREF(__pyx_t_3);
                __pyx_t_16 = __Pyx_PyDict_SetDefault(__pyx_v_bestTrgRecords, __pyx_t_5, __pyx_t_3, -1L); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 461, __pyx_L1_error)
                __Pyx_GOTREF(__pyx_t_16);
                __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
                __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;

                /* "lpu/smt/trans_models/triangulate.pyx":462
 *                             if multiKey.find(rec.trg + ' |COL|') == 0:
 *                                 bestTrgRecords.setdefault(rec.trg, [])
 *                                 bestTrgRecords[rec.trg].append(recMulti)             # <<<<<<<<<<<<<<
 *                     bestMultiRecords = {}
 *                     # second, filtering n-best by forward joint trans probs
 */
                __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_trg); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 462, __pyx_L1_error)
                __Pyx_GOTREF(__pyx_t_16);
                __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_bestTrgRecords, __pyx_t_16); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 462, __pyx_L1_error)
                __Pyx_GOTREF(__pyx_t_3);
                __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
                __pyx_t_14 = __Pyx_PyObject_Append(__pyx_t_3, __pyx_v_recMulti); if (unlikely(__pyx_t_14 == -1)) __PYX_ERR(0, 462, __pyx_L1_error)
                __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

                /* "lpu/smt/trans_models/triangulate.pyx":460
 *                     for multiKey, recMulti in multiRecords.items():
 *                         for rec in records.values():
 *                             if multiKey.find(rec.trg + ' |COL|') == 0:             # <<<<<<<<<<<<<<
 *                                 bestTrgRecords.setdefault(rec.trg, [])
 *                                 bestTrgRecords[rec.trg].append(recMulti)
 */
              }

              /* "lpu/smt/trans_models/triangulate.pyx":459
 *                     # first, filtering src-pvt-trg records including n-best src-trg records
 *                     for multiKey, recMulti in multiRecords.items():
 *                         for rec in records.values():             # <<<<<<<<<<<<<<
 *                             if multiKey.find(rec.trg + ' |COL|') == 0:
 *                                 bestTrgRecords.setdefault(rec.trg, [])
 */
            }
            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

            /* "lpu/smt/trans_models/triangulate.pyx":458
 *                     bestTrgRecords = {}
 *                     # first, filtering src-pvt-trg records including n-best src-trg records
 *                     for multiKey, recMulti in multiRecords.items():             # <<<<<<<<<<<<<<
 *                         for rec in records.values():
 *                             if multiKey.find(rec.trg + ' |COL|') == 0:
 */
          }
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":463
 *                                 bestTrgRecords.setdefault(rec.trg, [])
 *                                 bestTrgRecords[rec.trg].append(recMulti)
 *                     bestMultiRecords = {}             # <<<<<<<<<<<<<<
 *                     # second, filtering n-best by forward joint trans probs
 *                     for trgKey, multiList in bestTrgRecords.items():
 */
          __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 463, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_v_bestMultiRecords = ((PyObject*)__pyx_t_10);
          __pyx_t_10 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":465
 *                     bestMultiRecords = {}
 *                     # second, filtering n-best by forward joint trans probs
 *                     for trgKey, multiList in bestTrgRecords.items():             # <<<<<<<<<<<<<<
 *                         bestMultiRec = None
 *                         bestForwardJointTransProb = 0
 */
          __pyx_t_10 = __Pyx_PyDict_Items(__pyx_v_bestTrgRecords); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 465, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          if (likely(PyList_CheckExact(__pyx_t_10)) || PyTuple_CheckExact(__pyx_t_10)) {
            __pyx_t_11 = __pyx_t_10; __Pyx_INCREF(__pyx_t_11); __pyx_t_1 = 0;
            __pyx_t_4 = NULL;
          } else {
            __pyx_t_1 = -1; __pyx_t_11 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 465, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_11);
            __pyx_t_4 = Py_TYPE(__pyx_t_11)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 465, __pyx_L1_error)
          }
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          for (;;) {
            if (likely(!__pyx_t_4)) {
              if (likely(PyList_CheckExact(__pyx_t_11))) {
                if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_11)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_10 = PyList_GET_ITEM(__pyx_t_11, __pyx_t_1); __Pyx_INCREF(__pyx_t_10); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 465, __pyx_L1_error)
                #else
                __pyx_t_10 = PySequence_ITEM(__pyx_t_11, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 465, __pyx_L1_error)
                __Pyx_GOTREF(__pyx_t_10);
                #endif
              } else {
                if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_11)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_10 = PyTuple_GET_ITEM(__pyx_t_11, __pyx_t_1); __Pyx_INCREF(__pyx_t_10); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 465, __pyx_L1_error)
                #else
                __pyx_t_10 = PySequence_ITEM(__pyx_t_11, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 465, __pyx_L1_error)
                __Pyx_GOTREF(__pyx_t_10);
                #endif
              }
            } else {
              __pyx_t_10 = __pyx_t_4(__pyx_t_11);
              if (unlikely(!__pyx_t_10)) {
                PyObject* exc_type = PyErr_Occurred();
                if (exc_type) {
                  if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                  else __PYX_ERR(0, 465, __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 !CYTHON_COMPILING_IN_PYPY
              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_ERR(0, 465, __pyx_L1_error)
              }
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              if (likely(PyTuple_CheckExact(sequence))) {
                __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
                __pyx_t_16 = PyTuple_GET_ITEM(sequence, 1); 
              } else {
                __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
                __pyx_t_16 = PyList_GET_ITEM(sequence, 1); 
              }
              __Pyx_INCREF(__pyx_t_3);
              __Pyx_INCREF(__pyx_t_16);
              #else
              __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 465, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_3);
              __pyx_t_16 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 465, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_16);
              #endif
              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
            } else {
              Py_ssize_t index = -1;
              __pyx_t_5 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 465, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_5);
              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
              __pyx_t_12 = Py_TYPE(__pyx_t_5)->tp_iternext;
              index = 0; __pyx_t_3 = __pyx_t_12(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L53_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_3);
              index = 1; __pyx_t_16 = __pyx_t_12(__pyx_t_5); if (unlikely(!__pyx_t_16)) goto __pyx_L53_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_16);
              if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_5), 2) < 0) __PYX_ERR(0, 465, __pyx_L1_error)
              __pyx_t_12 = NULL;
              __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;
              __pyx_t_12 = NULL;
              if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
              __PYX_ERR(0, 465, __pyx_L1_error)
              __pyx_L54_unpacking_done:;
            }
            __Pyx_XDECREF_SET(__pyx_v_trgKey, __pyx_t_3);
            __pyx_t_3 = 0;
            __Pyx_XDECREF_SET(__pyx_v_multiList, __pyx_t_16);
            __pyx_t_16 = 0;

            /* "lpu/smt/trans_models/triangulate.pyx":466
 *                     # second, filtering n-best by forward joint trans probs
 *                     for trgKey, multiList in bestTrgRecords.items():
 *                         bestMultiRec = None             # <<<<<<<<<<<<<<
 *                         bestForwardJointTransProb = 0
 *                         for multiRec in multiList:
 */
            __Pyx_INCREF(Py_None);
            __Pyx_XDECREF_SET(__pyx_v_bestMultiRec, Py_None);

            /* "lpu/smt/trans_models/triangulate.pyx":467
 *                     for trgKey, multiList in bestTrgRecords.items():
 *                         bestMultiRec = None
 *                         bestForwardJointTransProb = 0             # <<<<<<<<<<<<<<
 *                         for multiRec in multiList:
 *                             if multiRec.features['egfp'] > bestForwardJointTransProb:
 */
            __Pyx_INCREF(__pyx_int_0);
            __Pyx_XDECREF_SET(__pyx_v_bestForwardJointTransProb, __pyx_int_0);

            /* "lpu/smt/trans_models/triangulate.pyx":468
 *                         bestMultiRec = None
 *                         bestForwardJointTransProb = 0
 *                         for multiRec in multiList:             # <<<<<<<<<<<<<<
 *                             if multiRec.features['egfp'] > bestForwardJointTransProb:
 *                                 bestMultiRec = multiRec
 */
            if (likely(PyList_CheckExact(__pyx_v_multiList)) || PyTuple_CheckExact(__pyx_v_multiList)) {
              __pyx_t_10 = __pyx_v_multiList; __Pyx_INCREF(__pyx_t_10); __pyx_t_13 = 0;
              __pyx_t_15 = NULL;
            } else {
              __pyx_t_13 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_v_multiList); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 468, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_10);
              __pyx_t_15 = Py_TYPE(__pyx_t_10)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 468, __pyx_L1_error)
            }
            for (;;) {
              if (likely(!__pyx_t_15)) {
                if (likely(PyList_CheckExact(__pyx_t_10))) {
                  if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_10)) break;
                  #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                  __pyx_t_16 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_13); __Pyx_INCREF(__pyx_t_16); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 468, __pyx_L1_error)
                  #else
                  __pyx_t_16 = PySequence_ITEM(__pyx_t_10, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 468, __pyx_L1_error)
                  __Pyx_GOTREF(__pyx_t_16);
                  #endif
                } else {
                  if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_10)) break;
                  #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                  __pyx_t_16 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_13); __Pyx_INCREF(__pyx_t_16); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 468, __pyx_L1_error)
                  #else
                  __pyx_t_16 = PySequence_ITEM(__pyx_t_10, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 468, __pyx_L1_error)
                  __Pyx_GOTREF(__pyx_t_16);
                  #endif
                }
              } else {
                __pyx_t_16 = __pyx_t_15(__pyx_t_10);
                if (unlikely(!__pyx_t_16)) {
                  PyObject* exc_type = PyErr_Occurred();
                  if (exc_type) {
                    if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                    else __PYX_ERR(0, 468, __pyx_L1_error)
                  }
                  break;
                }
                __Pyx_GOTREF(__pyx_t_16);
              }
              __Pyx_XDECREF_SET(__pyx_v_multiRec, __pyx_t_16);
              __pyx_t_16 = 0;

              /* "lpu/smt/trans_models/triangulate.pyx":469
 *                         bestForwardJointTransProb = 0
 *                         for multiRec in multiList:
 *                             if multiRec.features['egfp'] > bestForwardJointTransProb:             # <<<<<<<<<<<<<<
 *                                 bestMultiRec = multiRec
 *                                 bestForwardJointTransProb = multiRec.features['egfp']
 */
              __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_v_multiRec, __pyx_n_s_features); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 469, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_16);
              __pyx_t_3 = PyObject_GetItem(__pyx_t_16, __pyx_n_s_egfp); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 469, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_3);
              __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
              __pyx_t_16 = PyObject_RichCompare(__pyx_t_3, __pyx_v_bestForwardJointTransProb, Py_GT); __Pyx_XGOTREF(__pyx_t_16); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 469, __pyx_L1_error)
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
              __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_16); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 469, __pyx_L1_error)
              __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
              if (__pyx_t_8) {

                /* "lpu/smt/trans_models/triangulate.pyx":470
 *                         for multiRec in multiList:
 *                             if multiRec.features['egfp'] > bestForwardJointTransProb:
 *                                 bestMultiRec = multiRec             # <<<<<<<<<<<<<<
 *                                 bestForwardJointTransProb = multiRec.features['egfp']
 *                         if bestMultiRec:
 */
                __Pyx_INCREF(__pyx_v_multiRec);
                __Pyx_DECREF_SET(__pyx_v_bestMultiRec, __pyx_v_multiRec);

                /* "lpu/smt/trans_models/triangulate.pyx":471
 *                             if multiRec.features['egfp'] > bestForwardJointTransProb:
 *                                 bestMultiRec = multiRec
 *                                 bestForwardJointTransProb = multiRec.features['egfp']             # <<<<<<<<<<<<<<
 *                         if bestMultiRec:
 *                             bestMultiRecords[bestMultiRec.trg] = bestMultiRec
 */
                __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_v_multiRec, __pyx_n_s_features); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 471, __pyx_L1_error)
                __Pyx_GOTREF(__pyx_t_16);
                __pyx_t_3 = PyObject_GetItem(__pyx_t_16, __pyx_n_s_egfp); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 471, __pyx_L1_error)
                __Pyx_GOTREF(__pyx_t_3);
                __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
                __Pyx_DECREF_SET(__pyx_v_bestForwardJointTransProb, __pyx_t_3);
                __pyx_t_3 = 0;

                /* "lpu/smt/trans_models/triangulate.pyx":469
 *                         bestForwardJointTransProb = 0
 *                         for multiRec in multiList:
 *                             if multiRec.features['egfp'] > bestForwardJointTransProb:             # <<<<<<<<<<<<<<
 *                                 bestMultiRec = multiRec
 *                                 bestForwardJointTransProb = multiRec.features['egfp']
 */
              }

              /* "lpu/smt/trans_models/triangulate.pyx":468
 *                         bestMultiRec = None
 *                         bestForwardJointTransProb = 0
 *                         for multiRec in multiList:             # <<<<<<<<<<<<<<
 *                             if multiRec.features['egfp'] > bestForwardJointTransProb:
 *                                 bestMultiRec = multiRec
 */
            }
            __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

            /* "lpu/smt/trans_models/triangulate.pyx":472
 *                                 bestMultiRec = multiRec
 *                                 bestForwardJointTransProb = multiRec.features['egfp']
 *                         if bestMultiRec:             # <<<<<<<<<<<<<<
 *                             bestMultiRecords[bestMultiRec.trg] = bestMultiRec
 *                     # filling n-best records by (s->t,s->t,p)
 */
            __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_bestMultiRec); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 472, __pyx_L1_error)
            if (__pyx_t_8) {

              /* "lpu/smt/trans_models/triangulate.pyx":473
 *                                 bestForwardJointTransProb = multiRec.features['egfp']
 *                         if bestMultiRec:
 *                             bestMultiRecords[bestMultiRec.trg] = bestMultiRec             # <<<<<<<<<<<<<<
 *                     # filling n-best records by (s->t,s->t,p)
 *                     scores = []
 */
              __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_bestMultiRec, __pyx_n_s_trg); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 473, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_10);
              if (unlikely(PyDict_SetItem(__pyx_v_bestMultiRecords, __pyx_t_10, __pyx_v_bestMultiRec) < 0)) __PYX_ERR(0, 473, __pyx_L1_error)
              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

              /* "lpu/smt/trans_models/triangulate.pyx":472
 *                                 bestMultiRec = multiRec
 *                                 bestForwardJointTransProb = multiRec.features['egfp']
 *                         if bestMultiRec:             # <<<<<<<<<<<<<<
 *                             bestMultiRecords[bestMultiRec.trg] = bestMultiRec
 *                     # filling n-best records by (s->t,s->t,p)
 */
            }

            /* "lpu/smt/trans_models/triangulate.pyx":465
 *                     bestMultiRecords = {}
 *                     # second, filtering n-best by forward joint trans probs
 *                     for trgKey, multiList in bestTrgRecords.items():             # <<<<<<<<<<<<<<
 *                         bestMultiRec = None
 *                         bestForwardJointTransProb = 0
 */
          }
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":475
 *                             bestMultiRecords[bestMultiRec.trg] = bestMultiRec
 *                     # filling n-best records by (s->t,s->t,p)
 *                     scores = []             # <<<<<<<<<<<<<<
 *                     for multiKey, recMulti in multiRecords.items():
 *                         scores.append( (recMulti.features['0egfp'],recMulti.features['egfp'],multiKey) )
 */
          __pyx_t_11 = PyList_New(0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 475, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_XDECREF_SET(__pyx_v_scores, ((PyObject*)__pyx_t_11));
          __pyx_t_11 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":476
 *                     # filling n-best records by (s->t,s->t,p)
 *                     scores = []
 *                     for multiKey, recMulti in multiRecords.items():             # <<<<<<<<<<<<<<
 *                         scores.append( (recMulti.features['0egfp'],recMulti.features['egfp'],multiKey) )
 *                     scores.sort(reverse = True)
 */
          if (unlikely(!__pyx_v_multiRecords)) { __Pyx_RaiseUnboundLocalError("multiRecords"); __PYX_ERR(0, 476, __pyx_L1_error) }
          __pyx_t_11 = __Pyx_PyDict_Items(__pyx_v_multiRecords); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 476, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          if (likely(PyList_CheckExact(__pyx_t_11)) || PyTuple_CheckExact(__pyx_t_11)) {
            __pyx_t_10 = __pyx_t_11; __Pyx_INCREF(__pyx_t_10); __pyx_t_1 = 0;
            __pyx_t_4 = NULL;
          } else {
            __pyx_t_1 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 476, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_10);
            __pyx_t_4 = Py_TYPE(__pyx_t_10)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 476, __pyx_L1_error)
          }
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          for (;;) {
            if (likely(!__pyx_t_4)) {
              if (likely(PyList_CheckExact(__pyx_t_10))) {
                if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_10)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_11 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_1); __Pyx_INCREF(__pyx_t_11); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 476, __pyx_L1_error)
                #else
                __pyx_t_11 = PySequence_ITEM(__pyx_t_10, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 476, __pyx_L1_error)
                __Pyx_GOTREF(__pyx_t_11);
                #endif
              } else {
                if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_10)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_11 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_1); __Pyx_INCREF(__pyx_t_11); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 476, __pyx_L1_error)
                #else
                __pyx_t_11 = PySequence_ITEM(__pyx_t_10, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 476, __pyx_L1_error)
                __Pyx_GOTREF(__pyx_t_11);
                #endif
              }
            } else {
              __pyx_t_11 = __pyx_t_4(__pyx_t_10);
              if (unlikely(!__pyx_t_11)) {
                PyObject* exc_type = PyErr_Occurred();
                if (exc_type) {
                  if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                  else __PYX_ERR(0, 476, __pyx_L1_error)
                }
                break;
              }
              __Pyx_GOTREF(__pyx_t_11);
            }
            if ((likely(PyTuple_CheckExact(__pyx_t_11))) || (PyList_CheckExact(__pyx_t_11))) {
              PyObject* sequence = __pyx_t_11;
              #if !CYTHON_COMPILING_IN_PYPY
              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_ERR(0, 476, __pyx_L1_error)
              }
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              if (likely(PyTuple_CheckExact(sequence))) {
                __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); 
                __pyx_t_16 = PyTuple_GET_ITEM(sequence, 1); 
              } else {
                __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
                __pyx_t_16 = PyList_GET_ITEM(sequence, 1); 
              }
              __Pyx_INCREF(__pyx_t_3);
              __Pyx_INCREF(__pyx_t_16);
              #else
              __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 476, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_3);
              __pyx_t_16 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 476, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_16);
              #endif
              __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
            } else {
              Py_ssize_t index = -1;
              __pyx_t_5 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 476, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_5);
              __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
              __pyx_t_12 = Py_TYPE(__pyx_t_5)->tp_iternext;
              index = 0; __pyx_t_3 = __pyx_t_12(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L61_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_3);
              index = 1; __pyx_t_16 = __pyx_t_12(__pyx_t_5); if (unlikely(!__pyx_t_16)) goto __pyx_L61_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_16);
              if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_5), 2) < 0) __PYX_ERR(0, 476, __pyx_L1_error)
              __pyx_t_12 = NULL;
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
              goto __pyx_L62_unpacking_done;
              __pyx_L61_unpacking_failed:;
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
              __pyx_t_12 = NULL;
              if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
              __PYX_ERR(0, 476, __pyx_L1_error)
              __pyx_L62_unpacking_done:;
            }
            __Pyx_XDECREF_SET(__pyx_v_multiKey, __pyx_t_3);
            __pyx_t_3 = 0;
            __Pyx_XDECREF_SET(__pyx_v_recMulti, __pyx_t_16);
            __pyx_t_16 = 0;

            /* "lpu/smt/trans_models/triangulate.pyx":477
 *                     scores = []
 *                     for multiKey, recMulti in multiRecords.items():
 *                         scores.append( (recMulti.features['0egfp'],recMulti.features['egfp'],multiKey) )             # <<<<<<<<<<<<<<
 *                     scores.sort(reverse = True)
 *                     for _, _, multiKey in scores:
 */
            __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_recMulti, __pyx_n_s_features); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 477, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_11);
            __pyx_t_16 = PyObject_GetItem(__pyx_t_11, __pyx_kp_s_0egfp); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 477, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_16);
            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
            __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_recMulti, __pyx_n_s_features); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 477, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_11);
            __pyx_t_3 = PyObject_GetItem(__pyx_t_11, __pyx_n_s_egfp); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 477, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
            __pyx_t_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 477, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_11);
            __Pyx_GIVEREF(__pyx_t_16);
            PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_16);
            __Pyx_GIVEREF(__pyx_t_3);
            PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_3);
            __Pyx_INCREF(__pyx_v_multiKey);
            __Pyx_GIVEREF(__pyx_v_multiKey);
            PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_v_multiKey);
            __pyx_t_16 = 0;
            __pyx_t_3 = 0;
            __pyx_t_14 = __Pyx_PyList_Append(__pyx_v_scores, __pyx_t_11); if (unlikely(__pyx_t_14 == -1)) __PYX_ERR(0, 477, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

            /* "lpu/smt/trans_models/triangulate.pyx":476
 *                     # filling n-best records by (s->t,s->t,p)
 *                     scores = []
 *                     for multiKey, recMulti in multiRecords.items():             # <<<<<<<<<<<<<<
 *                         scores.append( (recMulti.features['0egfp'],recMulti.features['egfp'],multiKey) )
 *                     scores.sort(reverse = True)
 */
          }
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":478
 *                     for multiKey, recMulti in multiRecords.items():
 *                         scores.append( (recMulti.features['0egfp'],recMulti.features['egfp'],multiKey) )
 *                     scores.sort(reverse = True)             # <<<<<<<<<<<<<<
 *                     for _, _, multiKey in scores:
 *                         if len(bestMultiRecords) >= workset.nbest:
 */
          __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_scores, __pyx_n_s_sort); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 478, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_11 = PyDict_New(); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 478, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_reverse, Py_True) < 0) __PYX_ERR(0, 478, __pyx_L1_error)
          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_empty_tuple, __pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 478, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":479
 *                         scores.append( (recMulti.features['0egfp'],recMulti.features['egfp'],multiKey) )
 *                     scores.sort(reverse = True)
 *                     for _, _, multiKey in scores:             # <<<<<<<<<<<<<<
 *                         if len(bestMultiRecords) >= workset.nbest:
 *                             break
 */
          __pyx_t_3 = __pyx_v_scores; __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = 0;
          for (;;) {
            if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_3)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_11 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_1); __Pyx_INCREF(__pyx_t_11); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 479, __pyx_L1_error)
            #else
            __pyx_t_11 = PySequence_ITEM(__pyx_t_3, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 479, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_11);
            #endif
            if ((likely(PyTuple_CheckExact(__pyx_t_11))) || (PyList_CheckExact(__pyx_t_11))) {
              PyObject* sequence = __pyx_t_11;
              #if !CYTHON_COMPILING_IN_PYPY
              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_ERR(0, 479, __pyx_L1_error)
              }
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              if (likely(PyTuple_CheckExact(sequence))) {
                __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); 
                __pyx_t_16 = PyTuple_GET_ITEM(sequence, 1); 
                __pyx_t_5 = PyTuple_GET_ITEM(sequence, 2); 
              } else {
                __pyx_t_10 = PyList_GET_ITEM(sequence, 0); 
                __pyx_t_16 = PyList_GET_ITEM(sequence, 1); 
                __pyx_t_5 = PyList_GET_ITEM(sequence, 2); 
              }
              __Pyx_INCREF(__pyx_t_10);
              __Pyx_INCREF(__pyx_t_16);
              __Pyx_INCREF(__pyx_t_5);
              #else
              __pyx_t_10 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 479, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_10);
              __pyx_t_16 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 479, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_16);
              __pyx_t_5 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 479, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_5);
              #endif
              __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
            } else {
              Py_ssize_t index = -1;
              __pyx_t_7 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 479, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_7);
              __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
              __pyx_t_12 = Py_TYPE(__pyx_t_7)->tp_iternext;
              index = 0; __pyx_t_10 = __pyx_t_12(__pyx_t_7); if (unlikely(!__pyx_t_10)) goto __pyx_L65_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_10);
              index = 1; __pyx_t_16 = __pyx_t_12(__pyx_t_7); if (unlikely(!__pyx_t_16)) goto __pyx_L65_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_16);
              index = 2; __pyx_t_5 = __pyx_t_12(__pyx_t_7); if (unlikely(!__pyx_t_5)) goto __pyx_L65_unpacking_failed;
              __Pyx_GOTREF(__pyx_t_5);
              if (__Pyx_IternextUnpackEndCheck(__pyx_t_12(__pyx_t_7), 3) < 0) __PYX_ERR(0, 479, __pyx_L1_error)
              __pyx_t_12 = NULL;
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
              goto __pyx_L66_unpacking_done;
              __pyx_L65_unpacking_failed:;
              __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
              __pyx_t_12 = NULL;
              if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
              __PYX_ERR(0, 479, __pyx_L1_error)
              __pyx_L66_unpacking_done:;
            }
            __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_10);
            __pyx_t_10 = 0;
            __Pyx_DECREF_SET(__pyx_v__, __pyx_t_16);
            __pyx_t_16 = 0;
            __Pyx_XDECREF_SET(__pyx_v_multiKey, __pyx_t_5);
            __pyx_t_5 = 0;

            /* "lpu/smt/trans_models/triangulate.pyx":480
 *                     scores.sort(reverse = True)
 *                     for _, _, multiKey in scores:
 *                         if len(bestMultiRecords) >= workset.nbest:             # <<<<<<<<<<<<<<
 *                             break
 *                         else:
 */
            __pyx_t_13 = PyDict_Size(__pyx_v_bestMultiRecords); if (unlikely(__pyx_t_13 == -1)) __PYX_ERR(0, 480, __pyx_L1_error)
            __pyx_t_11 = PyInt_FromSsize_t(__pyx_t_13); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 480, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_11);
            __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_nbest); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 480, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_5);
            __pyx_t_16 = PyObject_RichCompare(__pyx_t_11, __pyx_t_5, Py_GE); __Pyx_XGOTREF(__pyx_t_16); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 480, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_16); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 480, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
            if (__pyx_t_8) {

              /* "lpu/smt/trans_models/triangulate.pyx":481
 *                     for _, _, multiKey in scores:
 *                         if len(bestMultiRecords) >= workset.nbest:
 *                             break             # <<<<<<<<<<<<<<
 *                         else:
 *                             if multiKey in bestMultiRecords:
 */
              goto __pyx_L64_break;

              /* "lpu/smt/trans_models/triangulate.pyx":480
 *                     scores.sort(reverse = True)
 *                     for _, _, multiKey in scores:
 *                         if len(bestMultiRecords) >= workset.nbest:             # <<<<<<<<<<<<<<
 *                             break
 *                         else:
 */
            }

            /* "lpu/smt/trans_models/triangulate.pyx":483
 *                             break
 *                         else:
 *                             if multiKey in bestMultiRecords:             # <<<<<<<<<<<<<<
 *                                 pass
 *                             else:
 */
            /*else*/ {
              __pyx_t_8 = (__Pyx_PyDict_ContainsTF(__pyx_v_multiKey, __pyx_v_bestMultiRecords, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 483, __pyx_L1_error)
              __pyx_t_2 = (__pyx_t_8 != 0);
              if (__pyx_t_2) {
                goto __pyx_L68;
              }

              /* "lpu/smt/trans_models/triangulate.pyx":486
 *                                 pass
 *                             else:
 *                                 bestMultiRecords[multiKey] = multiRecords[multiKey]             # <<<<<<<<<<<<<<
 *                     multiRecords = bestMultiRecords
 *         if workset.multi_target:
 */
              /*else*/ {
                if (unlikely(!__pyx_v_multiRecords)) { __Pyx_RaiseUnboundLocalError("multiRecords"); __PYX_ERR(0, 486, __pyx_L1_error) }
                __pyx_t_16 = __Pyx_PyDict_GetItem(__pyx_v_multiRecords, __pyx_v_multiKey); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 486, __pyx_L1_error)
                __Pyx_GOTREF(__pyx_t_16);
                if (unlikely(PyDict_SetItem(__pyx_v_bestMultiRecords, __pyx_v_multiKey, __pyx_t_16) < 0)) __PYX_ERR(0, 486, __pyx_L1_error)
                __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
              }
              __pyx_L68:;
            }

            /* "lpu/smt/trans_models/triangulate.pyx":479
 *                         scores.append( (recMulti.features['0egfp'],recMulti.features['egfp'],multiKey) )
 *                     scores.sort(reverse = True)
 *                     for _, _, multiKey in scores:             # <<<<<<<<<<<<<<
 *                         if len(bestMultiRecords) >= workset.nbest:
 *                             break
 */
          }
          __pyx_L64_break:;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":487
 *                             else:
 *                                 bestMultiRecords[multiKey] = multiRecords[multiKey]
 *                     multiRecords = bestMultiRecords             # <<<<<<<<<<<<<<
 *         if workset.multi_target:
 *             records = multiRecords
 */
          __Pyx_INCREF(__pyx_v_bestMultiRecords);
          __Pyx_XDECREF_SET(__pyx_v_multiRecords, __pyx_v_bestMultiRecords);

          /* "lpu/smt/trans_models/triangulate.pyx":454
 *                 records = bestRecords
 *             if workset.multi_target:
 *                 if len(multiRecords) > workset.nbest:             # <<<<<<<<<<<<<<
 *                     # T1-filtering method
 *                     bestTrgRecords = {}
 */
        }

        /* "lpu/smt/trans_models/triangulate.pyx":453
 *                     bestRecords[key] = records[key]
 *                 records = bestRecords
 *             if workset.multi_target:             # <<<<<<<<<<<<<<
 *                 if len(multiRecords) > workset.nbest:
 *                     # T1-filtering method
 */
      }

      /* "lpu/smt/trans_models/triangulate.pyx":442
 *                 del records[key]
 *         # if limit number of records is set (non-zero), filter the n-best records by forward trans probs
 *         if workset.nbest > 0:             # <<<<<<<<<<<<<<
 *             if len(records) > workset.nbest:
 *                 scores = []
 */
    }

    /* "lpu/smt/trans_models/triangulate.pyx":488
 *                                 bestMultiRecords[multiKey] = multiRecords[multiKey]
 *                     multiRecords = bestMultiRecords
 *         if workset.multi_target:             # <<<<<<<<<<<<<<
 *             records = multiRecords
 *         # putting the records into outQueue, and other process will write them in table file
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_multi_target); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 488, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 488, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (__pyx_t_2) {

      /* "lpu/smt/trans_models/triangulate.pyx":489
 *                     multiRecords = bestMultiRecords
 *         if workset.multi_target:
 *             records = multiRecords             # <<<<<<<<<<<<<<
 *         # putting the records into outQueue, and other process will write them in table file
 *         if records:
 */
      if (unlikely(!__pyx_v_multiRecords)) { __Pyx_RaiseUnboundLocalError("multiRecords"); __PYX_ERR(0, 489, __pyx_L1_error) }
      __Pyx_INCREF(__pyx_v_multiRecords);
      __Pyx_DECREF_SET(__pyx_v_records, __pyx_v_multiRecords);

      /* "lpu/smt/trans_models/triangulate.pyx":488
 *                                 bestMultiRecords[multiKey] = multiRecords[multiKey]
 *                     multiRecords = bestMultiRecords
 *         if workset.multi_target:             # <<<<<<<<<<<<<<
 *             records = multiRecords
 *         # putting the records into outQueue, and other process will write them in table file
 */
    }

    /* "lpu/smt/trans_models/triangulate.pyx":491
 *             records = multiRecords
 *         # putting the records into outQueue, and other process will write them in table file
 *         if records:             # <<<<<<<<<<<<<<
 *             #workset.pivotCount.add( len(records) )
 *             for trgKey in sorted(records.keys()):
 */
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_records); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 491, __pyx_L1_error)
    if (__pyx_t_2) {

      /* "lpu/smt/trans_models/triangulate.pyx":493
 *         if records:
 *             #workset.pivotCount.add( len(records) )
 *             for trgKey in sorted(records.keys()):             # <<<<<<<<<<<<<<
 *                 rec = records[trgKey]
 *                 writeRecord(rec, workset)
 */
      __pyx_t_16 = __Pyx_PyDict_Keys(__pyx_v_records); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 493, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      __pyx_t_5 = PySequence_List(__pyx_t_16); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 493, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __pyx_t_3 = ((PyObject*)__pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_14 = PyList_Sort(__pyx_t_3); if (unlikely(__pyx_t_14 == -1)) __PYX_ERR(0, 493, __pyx_L1_error)
      if (unlikely(__pyx_t_3 == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
        __PYX_ERR(0, 493, __pyx_L1_error)
      }
      __pyx_t_5 = __pyx_t_3; __Pyx_INCREF(__pyx_t_5); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      for (;;) {
        if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_3 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_1); __Pyx_INCREF(__pyx_t_3); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 493, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_5, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 493, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
        __Pyx_XDECREF_SET(__pyx_v_trgKey, __pyx_t_3);
        __pyx_t_3 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":494
 *             #workset.pivotCount.add( len(records) )
 *             for trgKey in sorted(records.keys()):
 *                 rec = records[trgKey]             # <<<<<<<<<<<<<<
 *                 writeRecord(rec, workset)
 *     # exiting from while loop
 */
        __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_records, __pyx_v_trgKey); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 494, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_XDECREF_SET(__pyx_v_rec, __pyx_t_3);
        __pyx_t_3 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":495
 *             for trgKey in sorted(records.keys()):
 *                 rec = records[trgKey]
 *                 writeRecord(rec, workset)             # <<<<<<<<<<<<<<
 *     # exiting from while loop
 *     # terminate also writeRecords process
 */
        __pyx_t_16 = __Pyx_GetModuleGlobalName(__pyx_n_s_writeRecord); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 495, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_16);
        __pyx_t_11 = NULL;
        __pyx_t_9 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_16))) {
          __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_16);
          if (likely(__pyx_t_11)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
            __Pyx_INCREF(__pyx_t_11);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_16, function);
            __pyx_t_9 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_16)) {
          PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_rec, __pyx_v_workset};
          __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_16, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 495, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_GOTREF(__pyx_t_3);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_16)) {
          PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_rec, __pyx_v_workset};
          __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_16, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 495, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_GOTREF(__pyx_t_3);
        } else
        #endif
        {
          __pyx_t_10 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 495, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          if (__pyx_t_11) {
            __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_11); __pyx_t_11 = NULL;
          }
          __Pyx_INCREF(__pyx_v_rec);
          __Pyx_GIVEREF(__pyx_v_rec);
          PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_9, __pyx_v_rec);
          __Pyx_INCREF(__pyx_v_workset);
          __Pyx_GIVEREF(__pyx_v_workset);
          PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_9, __pyx_v_workset);
          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_t_10, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 495, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        }
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":493
 *         if records:
 *             #workset.pivotCount.add( len(records) )
 *             for trgKey in sorted(records.keys()):             # <<<<<<<<<<<<<<
 *                 rec = records[trgKey]
 *                 writeRecord(rec, workset)
 */
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":491
 *             records = multiRecords
 *         # putting the records into outQueue, and other process will write them in table file
 *         if records:             # <<<<<<<<<<<<<<
 *             #workset.pivotCount.add( len(records) )
 *             for trgKey in sorted(records.keys()):
 */
    }

    /* "lpu/smt/trans_models/triangulate.pyx":360
 *     #lexCounts = lex.PairCounter()
 * 
 *     if len(rows) > 0:             # <<<<<<<<<<<<<<
 *         records = {}
 *         if workset.multi_target:
 */
  }

  /* "lpu/smt/trans_models/triangulate.pyx":350
 *         assert False, "Invalid records"
 * 
 * def pivotRecPairs(rows, workset):             # <<<<<<<<<<<<<<
 *     '''combine the source-pivot and pivot-target records for common pivot phrases
 * 
 */

  /* function exit code */
  __pyx_r = Py_None; __Pyx_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_7);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.pivotRecPairs", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_records);
  __Pyx_XDECREF(__pyx_v_multiRecords);
  __Pyx_XDECREF(__pyx_v_recPair);
  __Pyx_XDECREF(__pyx_v_trgKey);
  __Pyx_XDECREF(__pyx_v_strMultiTrg);
  __Pyx_XDECREF(__pyx_v_multiKey);
  __Pyx_XDECREF(__pyx_v_recPivot);
  __Pyx_XDECREF(__pyx_v_recMulti);
  __Pyx_XDECREF(__pyx_v_trgPair);
  __Pyx_XDECREF(__pyx_v_featureKey);
  __Pyx_XDECREF(__pyx_v_ignoring);
  __Pyx_XDECREF(__pyx_v_key);
  __Pyx_XDECREF(__pyx_v_rec);
  __Pyx_XDECREF(__pyx_v_scores);
  __Pyx_XDECREF(__pyx_v_bestRecords);
  __Pyx_XDECREF(__pyx_v__);
  __Pyx_XDECREF(__pyx_v_bestTrgRecords);
  __Pyx_XDECREF(__pyx_v_bestMultiRecords);
  __Pyx_XDECREF(__pyx_v_multiList);
  __Pyx_XDECREF(__pyx_v_bestMultiRec);
  __Pyx_XDECREF(__pyx_v_bestForwardJointTransProb);
  __Pyx_XDECREF(__pyx_v_multiRec);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "lpu/smt/trans_models/triangulate.pyx":504
 * 
 * 
 * def writeRecords(fileObj, records):             # <<<<<<<<<<<<<<
 * #  for rec in flattenRecords(records):
 *   for rec in flattenRecords(records, sort = True):
 */

/* Python wrapper */
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_21writeRecords(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_3lpu_3smt_12trans_models_11triangulate_21writeRecords = {"writeRecords", (PyCFunction)__pyx_pw_3lpu_3smt_12trans_models_11triangulate_21writeRecords, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_21writeRecords(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_fileObj = 0;
  PyObject *__pyx_v_records = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("writeRecords (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_fileObj,&__pyx_n_s_records,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);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        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_fileObj)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_records)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("writeRecords", 1, 2, 2, 1); __PYX_ERR(0, 504, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "writeRecords") < 0)) __PYX_ERR(0, 504, __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_fileObj = values[0];
    __pyx_v_records = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("writeRecords", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 504, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.writeRecords", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_3lpu_3smt_12trans_models_11triangulate_20writeRecords(__pyx_self, __pyx_v_fileObj, __pyx_v_records);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_20writeRecords(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_fileObj, PyObject *__pyx_v_records) {
  PyObject *__pyx_v_rec = 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;
  Py_ssize_t __pyx_t_5;
  PyObject *(*__pyx_t_6)(PyObject *);
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *__pyx_t_9 = NULL;
  __Pyx_RefNannySetupContext("writeRecords", 0);

  /* "lpu/smt/trans_models/triangulate.pyx":506
 * def writeRecords(fileObj, records):
 * #  for rec in flattenRecords(records):
 *   for rec in flattenRecords(records, sort = True):             # <<<<<<<<<<<<<<
 *       if rec.counts.co > 0:
 *           fileObj.write( rec.to_str() )
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_flattenRecords); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_records);
  __Pyx_GIVEREF(__pyx_v_records);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_records);
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_sort, Py_True) < 0) __PYX_ERR(0, 506, __pyx_L1_error)
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 506, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __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;
  if (likely(PyList_CheckExact(__pyx_t_4)) || PyTuple_CheckExact(__pyx_t_4)) {
    __pyx_t_3 = __pyx_t_4; __Pyx_INCREF(__pyx_t_3); __pyx_t_5 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_5 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 506, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 506, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_3))) {
        if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 506, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 506, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      } else {
        if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_4); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 506, __pyx_L1_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 506, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_6(__pyx_t_3);
      if (unlikely(!__pyx_t_4)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 506, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XDECREF_SET(__pyx_v_rec, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":507
 * #  for rec in flattenRecords(records):
 *   for rec in flattenRecords(records, sort = True):
 *       if rec.counts.co > 0:             # <<<<<<<<<<<<<<
 *           fileObj.write( rec.to_str() )
 *           fileObj.write("\n")
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_counts); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 507, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_co); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 507, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyObject_RichCompare(__pyx_t_2, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 507, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 507, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (__pyx_t_7) {

      /* "lpu/smt/trans_models/triangulate.pyx":508
 *   for rec in flattenRecords(records, sort = True):
 *       if rec.counts.co > 0:
 *           fileObj.write( rec.to_str() )             # <<<<<<<<<<<<<<
 *           fileObj.write("\n")
 * 
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_fileObj, __pyx_n_s_write); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 508, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_to_str); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 508, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
        }
      }
      if (__pyx_t_9) {
        __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 508, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      } else {
        __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 508, __pyx_L1_error)
      }
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      if (!__pyx_t_8) {
        __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 508, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_GOTREF(__pyx_t_4);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_2)) {
          PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_1};
          __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 508, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
          PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_1};
          __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 508, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        } else
        #endif
        {
          __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 508, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_8); __pyx_t_8 = NULL;
          __Pyx_GIVEREF(__pyx_t_1);
          PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_1);
          __pyx_t_1 = 0;
          __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_9, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 508, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":509
 *       if rec.counts.co > 0:
 *           fileObj.write( rec.to_str() )
 *           fileObj.write("\n")             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_fileObj, __pyx_n_s_write); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 509, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__21, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 509, __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;

      /* "lpu/smt/trans_models/triangulate.pyx":507
 * #  for rec in flattenRecords(records):
 *   for rec in flattenRecords(records, sort = True):
 *       if rec.counts.co > 0:             # <<<<<<<<<<<<<<
 *           fileObj.write( rec.to_str() )
 *           fileObj.write("\n")
 */
    }

    /* "lpu/smt/trans_models/triangulate.pyx":506
 * def writeRecords(fileObj, records):
 * #  for rec in flattenRecords(records):
 *   for rec in flattenRecords(records, sort = True):             # <<<<<<<<<<<<<<
 *       if rec.counts.co > 0:
 *           fileObj.write( rec.to_str() )
 */
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":504
 * 
 * 
 * def writeRecords(fileObj, records):             # <<<<<<<<<<<<<<
 * #  for rec in flattenRecords(records):
 *   for rec in flattenRecords(records, sort = True):
 */

  /* function exit code */
  __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_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.writeRecords", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_rec);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "lpu/smt/trans_models/triangulate.pyx":512
 * 
 * 
 * def writeRecord(rec, workset):             # <<<<<<<<<<<<<<
 *     '''write the pivoted records in the queue into the table file'''
 *     if rec:
 */

/* Python wrapper */
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_23writeRecord(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_3lpu_3smt_12trans_models_11triangulate_22writeRecord[] = "write the pivoted records in the queue into the table file";
static PyMethodDef __pyx_mdef_3lpu_3smt_12trans_models_11triangulate_23writeRecord = {"writeRecord", (PyCFunction)__pyx_pw_3lpu_3smt_12trans_models_11triangulate_23writeRecord, METH_VARARGS|METH_KEYWORDS, __pyx_doc_3lpu_3smt_12trans_models_11triangulate_22writeRecord};
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_23writeRecord(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_rec = 0;
  PyObject *__pyx_v_workset = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("writeRecord (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_rec,&__pyx_n_s_workset,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);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        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_rec)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_workset)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("writeRecord", 1, 2, 2, 1); __PYX_ERR(0, 512, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "writeRecord") < 0)) __PYX_ERR(0, 512, __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_rec = values[0];
    __pyx_v_workset = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("writeRecord", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 512, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.writeRecord", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_3lpu_3smt_12trans_models_11triangulate_22writeRecord(__pyx_self, __pyx_v_rec, __pyx_v_workset);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_22writeRecord(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_rec, PyObject *__pyx_v_workset) {
  PyObject *__pyx_v_term = 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;
  PyObject *__pyx_t_6 = NULL;
  Py_ssize_t __pyx_t_7;
  PyObject *(*__pyx_t_8)(PyObject *);
  __Pyx_RefNannySetupContext("writeRecord", 0);

  /* "lpu/smt/trans_models/triangulate.pyx":514
 * def writeRecord(rec, workset):
 *     '''write the pivoted records in the queue into the table file'''
 *     if rec:             # <<<<<<<<<<<<<<
 *         if rec.counts.cooc > 0:
 *             workset.foutPivot.write( rec.to_str() )
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_rec); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 514, __pyx_L1_error)
  if (__pyx_t_1) {

    /* "lpu/smt/trans_models/triangulate.pyx":515
 *     '''write the pivoted records in the queue into the table file'''
 *     if rec:
 *         if rec.counts.cooc > 0:             # <<<<<<<<<<<<<<
 *             workset.foutPivot.write( rec.to_str() )
 *             workset.foutPivot.write( "\n" )
 */
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_counts); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 515, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_cooc); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 515, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_3, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 515, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 515, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_1) {

      /* "lpu/smt/trans_models/triangulate.pyx":516
 *     if rec:
 *         if rec.counts.cooc > 0:
 *             workset.foutPivot.write( rec.to_str() )             # <<<<<<<<<<<<<<
 *             workset.foutPivot.write( "\n" )
 *             workset.foutPivot.flush()
 */
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_foutPivot); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 516, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_write); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 516, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_to_str); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 516, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_6 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_6)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_6);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
        }
      }
      if (__pyx_t_6) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 516, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else {
        __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 516, __pyx_L1_error)
      }
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
        }
      }
      if (!__pyx_t_5) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 516, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_4)) {
          PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_3};
          __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 516, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
          PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_3};
          __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 516, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        {
          __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 516, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL;
          __Pyx_GIVEREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_3);
          __pyx_t_3 = 0;
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 516, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":517
 *         if rec.counts.cooc > 0:
 *             workset.foutPivot.write( rec.to_str() )
 *             workset.foutPivot.write( "\n" )             # <<<<<<<<<<<<<<
 *             workset.foutPivot.flush()
 *             workset.numRecSrcTrg += 1
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_foutPivot); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 517, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_write); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 517, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__22, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 517, __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;

      /* "lpu/smt/trans_models/triangulate.pyx":518
 *             workset.foutPivot.write( rec.to_str() )
 *             workset.foutPivot.write( "\n" )
 *             workset.foutPivot.flush()             # <<<<<<<<<<<<<<
 *             workset.numRecSrcTrg += 1
 *             workset.setPhrasesSrcTrg.add(rec.src)
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_foutPivot); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 518, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_flush); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 518, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      if (__pyx_t_4) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 518, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      } else {
        __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 518, __pyx_L1_error)
      }
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":519
 *             workset.foutPivot.write( "\n" )
 *             workset.foutPivot.flush()
 *             workset.numRecSrcTrg += 1             # <<<<<<<<<<<<<<
 *             workset.setPhrasesSrcTrg.add(rec.src)
 *             for term in rec.srcTerms:
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_numRecSrcTrg); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 519, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_6 = __Pyx_PyInt_AddObjC(__pyx_t_2, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 519, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      if (__Pyx_PyObject_SetAttrStr(__pyx_v_workset, __pyx_n_s_numRecSrcTrg, __pyx_t_6) < 0) __PYX_ERR(0, 519, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":520
 *             workset.foutPivot.flush()
 *             workset.numRecSrcTrg += 1
 *             workset.setPhrasesSrcTrg.add(rec.src)             # <<<<<<<<<<<<<<
 *             for term in rec.srcTerms:
 *                 workset.setWordsSrcTrg.add(term)
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_setPhrasesSrcTrg); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 520, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_add); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 520, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_src); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 520, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_3 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
        }
      }
      if (!__pyx_t_3) {
        __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 520, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GOTREF(__pyx_t_6);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_4)) {
          PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_2};
          __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 520, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
          PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_2};
          __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 520, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        } else
        #endif
        {
          __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 520, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL;
          __Pyx_GIVEREF(__pyx_t_2);
          PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_2);
          __pyx_t_2 = 0;
          __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_5, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 520, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":521
 *             workset.numRecSrcTrg += 1
 *             workset.setPhrasesSrcTrg.add(rec.src)
 *             for term in rec.srcTerms:             # <<<<<<<<<<<<<<
 *                 workset.setWordsSrcTrg.add(term)
 * 
 */
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_srcTerms); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 521, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      if (likely(PyList_CheckExact(__pyx_t_6)) || PyTuple_CheckExact(__pyx_t_6)) {
        __pyx_t_4 = __pyx_t_6; __Pyx_INCREF(__pyx_t_4); __pyx_t_7 = 0;
        __pyx_t_8 = NULL;
      } else {
        __pyx_t_7 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 521, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_8 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 521, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      for (;;) {
        if (likely(!__pyx_t_8)) {
          if (likely(PyList_CheckExact(__pyx_t_4))) {
            if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_4)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_7); __Pyx_INCREF(__pyx_t_6); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 521, __pyx_L1_error)
            #else
            __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 521, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            #endif
          } else {
            if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_7); __Pyx_INCREF(__pyx_t_6); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 521, __pyx_L1_error)
            #else
            __pyx_t_6 = PySequence_ITEM(__pyx_t_4, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 521, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            #endif
          }
        } else {
          __pyx_t_6 = __pyx_t_8(__pyx_t_4);
          if (unlikely(!__pyx_t_6)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 521, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_6);
        }
        __Pyx_XDECREF_SET(__pyx_v_term, __pyx_t_6);
        __pyx_t_6 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":522
 *             workset.setPhrasesSrcTrg.add(rec.src)
 *             for term in rec.srcTerms:
 *                 workset.setWordsSrcTrg.add(term)             # <<<<<<<<<<<<<<
 * 
 * def calcLexWeight(rec, lexCounts, reverse = False):
 */
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_setWordsSrcTrg); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 522, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_add); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 522, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_5 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
          __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
          if (likely(__pyx_t_5)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
            __Pyx_INCREF(__pyx_t_5);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_2, function);
          }
        }
        if (!__pyx_t_5) {
          __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_term); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 522, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
        } else {
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_2)) {
            PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_term};
            __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 522, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_GOTREF(__pyx_t_6);
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
            PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_term};
            __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 522, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_GOTREF(__pyx_t_6);
          } else
          #endif
          {
            __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 522, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5); __pyx_t_5 = NULL;
            __Pyx_INCREF(__pyx_v_term);
            __Pyx_GIVEREF(__pyx_v_term);
            PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_v_term);
            __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 522, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          }
        }
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":521
 *             workset.numRecSrcTrg += 1
 *             workset.setPhrasesSrcTrg.add(rec.src)
 *             for term in rec.srcTerms:             # <<<<<<<<<<<<<<
 *                 workset.setWordsSrcTrg.add(term)
 * 
 */
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":515
 *     '''write the pivoted records in the queue into the table file'''
 *     if rec:
 *         if rec.counts.cooc > 0:             # <<<<<<<<<<<<<<
 *             workset.foutPivot.write( rec.to_str() )
 *             workset.foutPivot.write( "\n" )
 */
    }

    /* "lpu/smt/trans_models/triangulate.pyx":514
 * def writeRecord(rec, workset):
 *     '''write the pivoted records in the queue into the table file'''
 *     if rec:             # <<<<<<<<<<<<<<
 *         if rec.counts.cooc > 0:
 *             workset.foutPivot.write( rec.to_str() )
 */
  }

  /* "lpu/smt/trans_models/triangulate.pyx":512
 * 
 * 
 * def writeRecord(rec, workset):             # <<<<<<<<<<<<<<
 *     '''write the pivoted records in the queue into the table file'''
 *     if rec:
 */

  /* function exit code */
  __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_6);
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.writeRecord", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_term);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "lpu/smt/trans_models/triangulate.pyx":524
 *                 workset.setWordsSrcTrg.add(term)
 * 
 * def calcLexWeight(rec, lexCounts, reverse = False):             # <<<<<<<<<<<<<<
 * #    minProb = 10 ** -2
 *     lexWeight = 1
 */

/* Python wrapper */
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_25calcLexWeight(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_3lpu_3smt_12trans_models_11triangulate_25calcLexWeight = {"calcLexWeight", (PyCFunction)__pyx_pw_3lpu_3smt_12trans_models_11triangulate_25calcLexWeight, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_25calcLexWeight(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_rec = 0;
  PyObject *__pyx_v_lexCounts = 0;
  PyObject *__pyx_v_reverse = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calcLexWeight (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_rec,&__pyx_n_s_lexCounts,&__pyx_n_s_reverse,0};
    PyObject* values[3] = {0,0,0};
    values[2] = ((PyObject *)Py_False);
    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);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        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_rec)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_lexCounts)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("calcLexWeight", 0, 2, 3, 1); __PYX_ERR(0, 524, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_reverse);
          if (value) { values[2] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "calcLexWeight") < 0)) __PYX_ERR(0, 524, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        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_rec = values[0];
    __pyx_v_lexCounts = values[1];
    __pyx_v_reverse = values[2];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("calcLexWeight", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 524, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.calcLexWeight", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_3lpu_3smt_12trans_models_11triangulate_24calcLexWeight(__pyx_self, __pyx_v_rec, __pyx_v_lexCounts, __pyx_v_reverse);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_24calcLexWeight(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_rec, PyObject *__pyx_v_lexCounts, PyObject *__pyx_v_reverse) {
  PyObject *__pyx_v_lexWeight = NULL;
  PyObject *__pyx_v_minProb = NULL;
  PyObject *__pyx_v_alignMap = NULL;
  PyObject *__pyx_v_srcTerms = NULL;
  PyObject *__pyx_v_trgTerms = NULL;
  Py_ssize_t __pyx_v_trgIndex;
  PyObject *__pyx_v_trgTerm = NULL;
  PyObject *__pyx_v_trgSumProb = NULL;
  PyObject *__pyx_v_srcIndices = NULL;
  PyObject *__pyx_v_srcIndex = NULL;
  PyObject *__pyx_v_srcTerm = NULL;
  PyObject *__pyx_v_lexProb = NULL;
  PyObject *__pyx_v_trgProb = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  int __pyx_t_1;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  PyObject *__pyx_t_4 = NULL;
  double __pyx_t_5;
  Py_ssize_t __pyx_t_6;
  Py_ssize_t __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_t_12;
  PyObject *__pyx_t_13 = NULL;
  __Pyx_RefNannySetupContext("calcLexWeight", 0);

  /* "lpu/smt/trans_models/triangulate.pyx":526
 * def calcLexWeight(rec, lexCounts, reverse = False):
 * #    minProb = 10 ** -2
 *     lexWeight = 1             # <<<<<<<<<<<<<<
 * #    alignMapRev = rec.alignMapRev
 *     if not reverse:
 */
  __Pyx_INCREF(__pyx_int_1);
  __pyx_v_lexWeight = __pyx_int_1;

  /* "lpu/smt/trans_models/triangulate.pyx":528
 *     lexWeight = 1
 * #    alignMapRev = rec.alignMapRev
 *     if not reverse:             # <<<<<<<<<<<<<<
 *         minProb  = 1 / float(lexCounts.trgCounts["NULL"])
 *         # for forward probs, using reversed alignment map
 */
  __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_reverse); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 528, __pyx_L1_error)
  __pyx_t_2 = ((!__pyx_t_1) != 0);
  if (__pyx_t_2) {

    /* "lpu/smt/trans_models/triangulate.pyx":529
 * #    alignMapRev = rec.alignMapRev
 *     if not reverse:
 *         minProb  = 1 / float(lexCounts.trgCounts["NULL"])             # <<<<<<<<<<<<<<
 *         # for forward probs, using reversed alignment map
 *         alignMap = rec.alignMapRev
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_lexCounts, __pyx_n_s_trgCounts); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 529, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyObject_GetItem(__pyx_t_3, __pyx_n_s_NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 529, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = __Pyx_PyObject_AsDouble(__pyx_t_4); if (unlikely(__pyx_t_5 == ((double)-1) && PyErr_Occurred())) __PYX_ERR(0, 529, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if (unlikely(__pyx_t_5 == 0)) {
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      __PYX_ERR(0, 529, __pyx_L1_error)
    }
    __pyx_t_4 = PyFloat_FromDouble((1.0 / __pyx_t_5)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 529, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_v_minProb = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":531
 *         minProb  = 1 / float(lexCounts.trgCounts["NULL"])
 *         # for forward probs, using reversed alignment map
 *         alignMap = rec.alignMapRev             # <<<<<<<<<<<<<<
 *         srcTerms = rec.srcTerms
 *         trgTerms = rec.trgTerms
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_alignMapRev); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 531, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_v_alignMap = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":532
 *         # for forward probs, using reversed alignment map
 *         alignMap = rec.alignMapRev
 *         srcTerms = rec.srcTerms             # <<<<<<<<<<<<<<
 *         trgTerms = rec.trgTerms
 *     else:
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_srcTerms); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 532, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_v_srcTerms = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":533
 *         alignMap = rec.alignMapRev
 *         srcTerms = rec.srcTerms
 *         trgTerms = rec.trgTerms             # <<<<<<<<<<<<<<
 *     else:
 *         minProb = 1 / float(lexCounts.srcCounts["NULL"])
 */
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_trgTerms); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 533, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_v_trgTerms = __pyx_t_4;
    __pyx_t_4 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":528
 *     lexWeight = 1
 * #    alignMapRev = rec.alignMapRev
 *     if not reverse:             # <<<<<<<<<<<<<<
 *         minProb  = 1 / float(lexCounts.trgCounts["NULL"])
 *         # for forward probs, using reversed alignment map
 */
    goto __pyx_L3;
  }

  /* "lpu/smt/trans_models/triangulate.pyx":535
 *         trgTerms = rec.trgTerms
 *     else:
 *         minProb = 1 / float(lexCounts.srcCounts["NULL"])             # <<<<<<<<<<<<<<
 *         alignMap = rec.alignMap
 *         srcTerms = rec.trgTerms
 */
  /*else*/ {
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_lexCounts, __pyx_n_s_srcCounts); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 535, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_3 = PyObject_GetItem(__pyx_t_4, __pyx_n_s_NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 535, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_5 = __Pyx_PyObject_AsDouble(__pyx_t_3); if (unlikely(__pyx_t_5 == ((double)-1) && PyErr_Occurred())) __PYX_ERR(0, 535, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    if (unlikely(__pyx_t_5 == 0)) {
      PyErr_SetString(PyExc_ZeroDivisionError, "float division");
      __PYX_ERR(0, 535, __pyx_L1_error)
    }
    __pyx_t_3 = PyFloat_FromDouble((1.0 / __pyx_t_5)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 535, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_minProb = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":536
 *     else:
 *         minProb = 1 / float(lexCounts.srcCounts["NULL"])
 *         alignMap = rec.alignMap             # <<<<<<<<<<<<<<
 *         srcTerms = rec.trgTerms
 *         trgTerms = rec.srcTerms
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_alignMap); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 536, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_alignMap = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":537
 *         minProb = 1 / float(lexCounts.srcCounts["NULL"])
 *         alignMap = rec.alignMap
 *         srcTerms = rec.trgTerms             # <<<<<<<<<<<<<<
 *         trgTerms = rec.srcTerms
 *     minProb = MINPROB
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_trgTerms); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 537, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_srcTerms = __pyx_t_3;
    __pyx_t_3 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":538
 *         alignMap = rec.alignMap
 *         srcTerms = rec.trgTerms
 *         trgTerms = rec.srcTerms             # <<<<<<<<<<<<<<
 *     minProb = MINPROB
 *     for trgIndex in range(len(trgTerms)):
 */
    __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_srcTerms); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 538, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_trgTerms = __pyx_t_3;
    __pyx_t_3 = 0;
  }
  __pyx_L3:;

  /* "lpu/smt/trans_models/triangulate.pyx":539
 *         srcTerms = rec.trgTerms
 *         trgTerms = rec.srcTerms
 *     minProb = MINPROB             # <<<<<<<<<<<<<<
 *     for trgIndex in range(len(trgTerms)):
 *         trgTerm = trgTerms[trgIndex]
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_MINPROB); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 539, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF_SET(__pyx_v_minProb, __pyx_t_3);
  __pyx_t_3 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":540
 *         trgTerms = rec.srcTerms
 *     minProb = MINPROB
 *     for trgIndex in range(len(trgTerms)):             # <<<<<<<<<<<<<<
 *         trgTerm = trgTerms[trgIndex]
 *         if trgIndex in alignMap:
 */
  __pyx_t_6 = PyObject_Length(__pyx_v_trgTerms); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 540, __pyx_L1_error)
  for (__pyx_t_7 = 0; __pyx_t_7 < __pyx_t_6; __pyx_t_7+=1) {
    __pyx_v_trgIndex = __pyx_t_7;

    /* "lpu/smt/trans_models/triangulate.pyx":541
 *     minProb = MINPROB
 *     for trgIndex in range(len(trgTerms)):
 *         trgTerm = trgTerms[trgIndex]             # <<<<<<<<<<<<<<
 *         if trgIndex in alignMap:
 *             trgSumProb = 0
 */
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_trgTerms, __pyx_v_trgIndex, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 541, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_XDECREF_SET(__pyx_v_trgTerm, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":542
 *     for trgIndex in range(len(trgTerms)):
 *         trgTerm = trgTerms[trgIndex]
 *         if trgIndex in alignMap:             # <<<<<<<<<<<<<<
 *             trgSumProb = 0
 *             srcIndices = alignMap[trgIndex]
 */
    __pyx_t_3 = PyInt_FromSsize_t(__pyx_v_trgIndex); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 542, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_t_3, __pyx_v_alignMap, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 542, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_1 = (__pyx_t_2 != 0);
    if (__pyx_t_1) {

      /* "lpu/smt/trans_models/triangulate.pyx":543
 *         trgTerm = trgTerms[trgIndex]
 *         if trgIndex in alignMap:
 *             trgSumProb = 0             # <<<<<<<<<<<<<<
 *             srcIndices = alignMap[trgIndex]
 *             for srcIndex in srcIndices:
 */
      __Pyx_INCREF(__pyx_int_0);
      __Pyx_XDECREF_SET(__pyx_v_trgSumProb, __pyx_int_0);

      /* "lpu/smt/trans_models/triangulate.pyx":544
 *         if trgIndex in alignMap:
 *             trgSumProb = 0
 *             srcIndices = alignMap[trgIndex]             # <<<<<<<<<<<<<<
 *             for srcIndex in srcIndices:
 *                 srcTerm = srcTerms[srcIndex]
 */
      __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_alignMap, __pyx_v_trgIndex, Py_ssize_t, 1, PyInt_FromSsize_t, 0, 1, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 544, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_v_srcIndices, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":545
 *             trgSumProb = 0
 *             srcIndices = alignMap[trgIndex]
 *             for srcIndex in srcIndices:             # <<<<<<<<<<<<<<
 *                 srcTerm = srcTerms[srcIndex]
 *                 if not reverse:
 */
      if (likely(PyList_CheckExact(__pyx_v_srcIndices)) || PyTuple_CheckExact(__pyx_v_srcIndices)) {
        __pyx_t_3 = __pyx_v_srcIndices; __Pyx_INCREF(__pyx_t_3); __pyx_t_8 = 0;
        __pyx_t_9 = NULL;
      } else {
        __pyx_t_8 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_srcIndices); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 545, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_9 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 545, __pyx_L1_error)
      }
      for (;;) {
        if (likely(!__pyx_t_9)) {
          if (likely(PyList_CheckExact(__pyx_t_3))) {
            if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_3)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_4 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_8); __Pyx_INCREF(__pyx_t_4); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 545, __pyx_L1_error)
            #else
            __pyx_t_4 = PySequence_ITEM(__pyx_t_3, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 545, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
            #endif
          } else {
            if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_8); __Pyx_INCREF(__pyx_t_4); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 545, __pyx_L1_error)
            #else
            __pyx_t_4 = PySequence_ITEM(__pyx_t_3, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 545, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
            #endif
          }
        } else {
          __pyx_t_4 = __pyx_t_9(__pyx_t_3);
          if (unlikely(!__pyx_t_4)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 545, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_4);
        }
        __Pyx_XDECREF_SET(__pyx_v_srcIndex, __pyx_t_4);
        __pyx_t_4 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":546
 *             srcIndices = alignMap[trgIndex]
 *             for srcIndex in srcIndices:
 *                 srcTerm = srcTerms[srcIndex]             # <<<<<<<<<<<<<<
 *                 if not reverse:
 *                     lexProb = lexCounts.calcLexProb(srcTerm, trgTerm)
 */
        __pyx_t_4 = PyObject_GetItem(__pyx_v_srcTerms, __pyx_v_srcIndex); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 546, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_XDECREF_SET(__pyx_v_srcTerm, __pyx_t_4);
        __pyx_t_4 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":547
 *             for srcIndex in srcIndices:
 *                 srcTerm = srcTerms[srcIndex]
 *                 if not reverse:             # <<<<<<<<<<<<<<
 *                     lexProb = lexCounts.calcLexProb(srcTerm, trgTerm)
 *                 else:
 */
        __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_reverse); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 547, __pyx_L1_error)
        __pyx_t_2 = ((!__pyx_t_1) != 0);
        if (__pyx_t_2) {

          /* "lpu/smt/trans_models/triangulate.pyx":548
 *                 srcTerm = srcTerms[srcIndex]
 *                 if not reverse:
 *                     lexProb = lexCounts.calcLexProb(srcTerm, trgTerm)             # <<<<<<<<<<<<<<
 *                 else:
 *                     lexProb = lexCounts.calcLexProbRev(trgTerm, srcTerm)
 */
          __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_lexCounts, __pyx_n_s_calcLexProb); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 548, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_11 = NULL;
          __pyx_t_12 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) {
            __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_10);
            if (likely(__pyx_t_11)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
              __Pyx_INCREF(__pyx_t_11);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_10, function);
              __pyx_t_12 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_10)) {
            PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_srcTerm, __pyx_v_trgTerm};
            __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 548, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
            __Pyx_GOTREF(__pyx_t_4);
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) {
            PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_srcTerm, __pyx_v_trgTerm};
            __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 548, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
            __Pyx_GOTREF(__pyx_t_4);
          } else
          #endif
          {
            __pyx_t_13 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 548, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_13);
            if (__pyx_t_11) {
              __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_11); __pyx_t_11 = NULL;
            }
            __Pyx_INCREF(__pyx_v_srcTerm);
            __Pyx_GIVEREF(__pyx_v_srcTerm);
            PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_12, __pyx_v_srcTerm);
            __Pyx_INCREF(__pyx_v_trgTerm);
            __Pyx_GIVEREF(__pyx_v_trgTerm);
            PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_12, __pyx_v_trgTerm);
            __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_13, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 548, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          }
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_XDECREF_SET(__pyx_v_lexProb, __pyx_t_4);
          __pyx_t_4 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":547
 *             for srcIndex in srcIndices:
 *                 srcTerm = srcTerms[srcIndex]
 *                 if not reverse:             # <<<<<<<<<<<<<<
 *                     lexProb = lexCounts.calcLexProb(srcTerm, trgTerm)
 *                 else:
 */
          goto __pyx_L9;
        }

        /* "lpu/smt/trans_models/triangulate.pyx":550
 *                     lexProb = lexCounts.calcLexProb(srcTerm, trgTerm)
 *                 else:
 *                     lexProb = lexCounts.calcLexProbRev(trgTerm, srcTerm)             # <<<<<<<<<<<<<<
 *                 trgSumProb += lexProb
 *             if type(rec) == MosesRecord:
 */
        /*else*/ {
          __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_lexCounts, __pyx_n_s_calcLexProbRev); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 550, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_13 = NULL;
          __pyx_t_12 = 0;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) {
            __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_10);
            if (likely(__pyx_t_13)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
              __Pyx_INCREF(__pyx_t_13);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_10, function);
              __pyx_t_12 = 1;
            }
          }
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_10)) {
            PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_v_trgTerm, __pyx_v_srcTerm};
            __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 550, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
            __Pyx_GOTREF(__pyx_t_4);
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) {
            PyObject *__pyx_temp[3] = {__pyx_t_13, __pyx_v_trgTerm, __pyx_v_srcTerm};
            __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 550, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
            __Pyx_GOTREF(__pyx_t_4);
          } else
          #endif
          {
            __pyx_t_11 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 550, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_11);
            if (__pyx_t_13) {
              __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_13); __pyx_t_13 = NULL;
            }
            __Pyx_INCREF(__pyx_v_trgTerm);
            __Pyx_GIVEREF(__pyx_v_trgTerm);
            PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_12, __pyx_v_trgTerm);
            __Pyx_INCREF(__pyx_v_srcTerm);
            __Pyx_GIVEREF(__pyx_v_srcTerm);
            PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_12, __pyx_v_srcTerm);
            __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_11, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 550, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_4);
            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          }
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_XDECREF_SET(__pyx_v_lexProb, __pyx_t_4);
          __pyx_t_4 = 0;
        }
        __pyx_L9:;

        /* "lpu/smt/trans_models/triangulate.pyx":551
 *                 else:
 *                     lexProb = lexCounts.calcLexProbRev(trgTerm, srcTerm)
 *                 trgSumProb += lexProb             # <<<<<<<<<<<<<<
 *             if type(rec) == MosesRecord:
 *                 trgProb = trgSumProb / len(srcIndices)
 */
        __pyx_t_4 = PyNumber_InPlaceAdd(__pyx_v_trgSumProb, __pyx_v_lexProb); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 551, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF_SET(__pyx_v_trgSumProb, __pyx_t_4);
        __pyx_t_4 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":545
 *             trgSumProb = 0
 *             srcIndices = alignMap[trgIndex]
 *             for srcIndex in srcIndices:             # <<<<<<<<<<<<<<
 *                 srcTerm = srcTerms[srcIndex]
 *                 if not reverse:
 */
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":552
 *                     lexProb = lexCounts.calcLexProbRev(trgTerm, srcTerm)
 *                 trgSumProb += lexProb
 *             if type(rec) == MosesRecord:             # <<<<<<<<<<<<<<
 *                 trgProb = trgSumProb / len(srcIndices)
 *             else:
 */
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_MosesRecord); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 552, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyObject_RichCompare(((PyObject *)Py_TYPE(__pyx_v_rec)), __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 552, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 552, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      if (__pyx_t_2) {

        /* "lpu/smt/trans_models/triangulate.pyx":553
 *                 trgSumProb += lexProb
 *             if type(rec) == MosesRecord:
 *                 trgProb = trgSumProb / len(srcIndices)             # <<<<<<<<<<<<<<
 *             else:
 *                 trgProb = trgSumProb / (len(srcIndices) + 1)
 */
        __pyx_t_8 = PyObject_Length(__pyx_v_srcIndices); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(0, 553, __pyx_L1_error)
        __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 553, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_3 = __Pyx_PyNumber_Divide(__pyx_v_trgSumProb, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 553, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_XDECREF_SET(__pyx_v_trgProb, __pyx_t_3);
        __pyx_t_3 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":552
 *                     lexProb = lexCounts.calcLexProbRev(trgTerm, srcTerm)
 *                 trgSumProb += lexProb
 *             if type(rec) == MosesRecord:             # <<<<<<<<<<<<<<
 *                 trgProb = trgSumProb / len(srcIndices)
 *             else:
 */
        goto __pyx_L10;
      }

      /* "lpu/smt/trans_models/triangulate.pyx":555
 *                 trgProb = trgSumProb / len(srcIndices)
 *             else:
 *                 trgProb = trgSumProb / (len(srcIndices) + 1)             # <<<<<<<<<<<<<<
 * #            lexWeight *= (trgSumProb / len(srcIndices))
 *         else:
 */
      /*else*/ {
        __pyx_t_8 = PyObject_Length(__pyx_v_srcIndices); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(0, 555, __pyx_L1_error)
        __pyx_t_3 = PyInt_FromSsize_t((__pyx_t_8 + 1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 555, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_4 = __Pyx_PyNumber_Divide(__pyx_v_trgSumProb, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 555, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF_SET(__pyx_v_trgProb, __pyx_t_4);
        __pyx_t_4 = 0;
      }
      __pyx_L10:;

      /* "lpu/smt/trans_models/triangulate.pyx":542
 *     for trgIndex in range(len(trgTerms)):
 *         trgTerm = trgTerms[trgIndex]
 *         if trgIndex in alignMap:             # <<<<<<<<<<<<<<
 *             trgSumProb = 0
 *             srcIndices = alignMap[trgIndex]
 */
      goto __pyx_L6;
    }

    /* "lpu/smt/trans_models/triangulate.pyx":558
 * #            lexWeight *= (trgSumProb / len(srcIndices))
 *         else:
 *           if not reverse:             # <<<<<<<<<<<<<<
 * #              lexWeight *= lexCounts.calcLexProb("NULL", trgTerm)
 *               trgProb = lexCounts.calcLexProb("NULL", trgTerm)
 */
    /*else*/ {
      __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_reverse); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 558, __pyx_L1_error)
      __pyx_t_1 = ((!__pyx_t_2) != 0);
      if (__pyx_t_1) {

        /* "lpu/smt/trans_models/triangulate.pyx":560
 *           if not reverse:
 * #              lexWeight *= lexCounts.calcLexProb("NULL", trgTerm)
 *               trgProb = lexCounts.calcLexProb("NULL", trgTerm)             # <<<<<<<<<<<<<<
 *           else:
 * #              lexWeight *= lexCounts.calcLexProb(trgTerm, "NULL")
 */
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_lexCounts, __pyx_n_s_calcLexProb); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 560, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_10 = NULL;
        __pyx_t_12 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_10)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_10);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
            __pyx_t_12 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_3)) {
          PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_n_s_NULL, __pyx_v_trgTerm};
          __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 560, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_GOTREF(__pyx_t_4);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
          PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_n_s_NULL, __pyx_v_trgTerm};
          __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 560, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_GOTREF(__pyx_t_4);
        } else
        #endif
        {
          __pyx_t_11 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 560, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          if (__pyx_t_10) {
            __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10); __pyx_t_10 = NULL;
          }
          __Pyx_INCREF(__pyx_n_s_NULL);
          __Pyx_GIVEREF(__pyx_n_s_NULL);
          PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_12, __pyx_n_s_NULL);
          __Pyx_INCREF(__pyx_v_trgTerm);
          __Pyx_GIVEREF(__pyx_v_trgTerm);
          PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_12, __pyx_v_trgTerm);
          __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_11, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 560, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        }
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF_SET(__pyx_v_trgProb, __pyx_t_4);
        __pyx_t_4 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":558
 * #            lexWeight *= (trgSumProb / len(srcIndices))
 *         else:
 *           if not reverse:             # <<<<<<<<<<<<<<
 * #              lexWeight *= lexCounts.calcLexProb("NULL", trgTerm)
 *               trgProb = lexCounts.calcLexProb("NULL", trgTerm)
 */
        goto __pyx_L11;
      }

      /* "lpu/smt/trans_models/triangulate.pyx":563
 *           else:
 * #              lexWeight *= lexCounts.calcLexProb(trgTerm, "NULL")
 *               trgProb = lexCounts.calcLexProb(trgTerm, "NULL")             # <<<<<<<<<<<<<<
 *         lexWeight *= max(trgProb, minProb)
 *     return lexWeight
 */
      /*else*/ {
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_lexCounts, __pyx_n_s_calcLexProb); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 563, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_11 = NULL;
        __pyx_t_12 = 0;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_11)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_11);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
            __pyx_t_12 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_3)) {
          PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_trgTerm, __pyx_n_s_NULL};
          __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 563, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_GOTREF(__pyx_t_4);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
          PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_v_trgTerm, __pyx_n_s_NULL};
          __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_12, 2+__pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 563, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_GOTREF(__pyx_t_4);
        } else
        #endif
        {
          __pyx_t_10 = PyTuple_New(2+__pyx_t_12); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 563, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          if (__pyx_t_11) {
            __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_11); __pyx_t_11 = NULL;
          }
          __Pyx_INCREF(__pyx_v_trgTerm);
          __Pyx_GIVEREF(__pyx_v_trgTerm);
          PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_12, __pyx_v_trgTerm);
          __Pyx_INCREF(__pyx_n_s_NULL);
          __Pyx_GIVEREF(__pyx_n_s_NULL);
          PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_12, __pyx_n_s_NULL);
          __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_10, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 563, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        }
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF_SET(__pyx_v_trgProb, __pyx_t_4);
        __pyx_t_4 = 0;
      }
      __pyx_L11:;
    }
    __pyx_L6:;

    /* "lpu/smt/trans_models/triangulate.pyx":564
 * #              lexWeight *= lexCounts.calcLexProb(trgTerm, "NULL")
 *               trgProb = lexCounts.calcLexProb(trgTerm, "NULL")
 *         lexWeight *= max(trgProb, minProb)             # <<<<<<<<<<<<<<
 *     return lexWeight
 * 
 */
    __Pyx_INCREF(__pyx_v_minProb);
    __pyx_t_4 = __pyx_v_minProb;
    __Pyx_INCREF(__pyx_v_trgProb);
    __pyx_t_3 = __pyx_v_trgProb;
    __pyx_t_11 = PyObject_RichCompare(__pyx_t_4, __pyx_t_3, Py_GT); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 564, __pyx_L1_error)
    __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 564, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    if (__pyx_t_1) {
      __Pyx_INCREF(__pyx_t_4);
      __pyx_t_10 = __pyx_t_4;
    } else {
      __Pyx_INCREF(__pyx_t_3);
      __pyx_t_10 = __pyx_t_3;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyNumber_InPlaceMultiply(__pyx_v_lexWeight, __pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 564, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF_SET(__pyx_v_lexWeight, __pyx_t_4);
    __pyx_t_4 = 0;
  }

  /* "lpu/smt/trans_models/triangulate.pyx":565
 *               trgProb = lexCounts.calcLexProb(trgTerm, "NULL")
 *         lexWeight *= max(trgProb, minProb)
 *     return lexWeight             # <<<<<<<<<<<<<<
 * 
 * def calcLexWeights(table_path, lexCounts, savePath, RecordClass = MosesRecord):
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_lexWeight);
  __pyx_r = __pyx_v_lexWeight;
  goto __pyx_L0;

  /* "lpu/smt/trans_models/triangulate.pyx":524
 *                 workset.setWordsSrcTrg.add(term)
 * 
 * def calcLexWeight(rec, lexCounts, reverse = False):             # <<<<<<<<<<<<<<
 * #    minProb = 10 ** -2
 *     lexWeight = 1
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.calcLexWeight", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_lexWeight);
  __Pyx_XDECREF(__pyx_v_minProb);
  __Pyx_XDECREF(__pyx_v_alignMap);
  __Pyx_XDECREF(__pyx_v_srcTerms);
  __Pyx_XDECREF(__pyx_v_trgTerms);
  __Pyx_XDECREF(__pyx_v_trgTerm);
  __Pyx_XDECREF(__pyx_v_trgSumProb);
  __Pyx_XDECREF(__pyx_v_srcIndices);
  __Pyx_XDECREF(__pyx_v_srcIndex);
  __Pyx_XDECREF(__pyx_v_srcTerm);
  __Pyx_XDECREF(__pyx_v_lexProb);
  __Pyx_XDECREF(__pyx_v_trgProb);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "lpu/smt/trans_models/triangulate.pyx":567
 *     return lexWeight
 * 
 * def calcLexWeights(table_path, lexCounts, savePath, RecordClass = MosesRecord):             # <<<<<<<<<<<<<<
 *     table_file = files.open(table_path, 'r')
 *     saveFile  = files.open(savePath, 'w')
 */

/* Python wrapper */
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_27calcLexWeights(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyMethodDef __pyx_mdef_3lpu_3smt_12trans_models_11triangulate_27calcLexWeights = {"calcLexWeights", (PyCFunction)__pyx_pw_3lpu_3smt_12trans_models_11triangulate_27calcLexWeights, METH_VARARGS|METH_KEYWORDS, 0};
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_27calcLexWeights(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_table_path = 0;
  PyObject *__pyx_v_lexCounts = 0;
  PyObject *__pyx_v_savePath = 0;
  PyObject *__pyx_v_RecordClass = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("calcLexWeights (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_table_path,&__pyx_n_s_lexCounts,&__pyx_n_s_savePath,&__pyx_n_s_RecordClass,0};
    PyObject* values[4] = {0,0,0,0};
    values[3] = __pyx_k__23;
    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);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        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_table_path)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_lexCounts)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("calcLexWeights", 0, 3, 4, 1); __PYX_ERR(0, 567, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_savePath)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("calcLexWeights", 0, 3, 4, 2); __PYX_ERR(0, 567, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_RecordClass);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "calcLexWeights") < 0)) __PYX_ERR(0, 567, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        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_table_path = values[0];
    __pyx_v_lexCounts = values[1];
    __pyx_v_savePath = values[2];
    __pyx_v_RecordClass = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("calcLexWeights", 0, 3, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 567, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.calcLexWeights", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_3lpu_3smt_12trans_models_11triangulate_26calcLexWeights(__pyx_self, __pyx_v_table_path, __pyx_v_lexCounts, __pyx_v_savePath, __pyx_v_RecordClass);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_26calcLexWeights(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table_path, PyObject *__pyx_v_lexCounts, PyObject *__pyx_v_savePath, PyObject *__pyx_v_RecordClass) {
  PyObject *__pyx_v_table_file = NULL;
  PyObject *__pyx_v_saveFile = NULL;
  PyObject *__pyx_v_line = NULL;
  PyObject *__pyx_v_rec = NULL;
  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;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  PyObject *(*__pyx_t_7)(PyObject *);
  PyObject *__pyx_t_8 = NULL;
  int __pyx_t_9;
  PyObject *__pyx_t_10 = NULL;
  __Pyx_RefNannySetupContext("calcLexWeights", 0);

  /* "lpu/smt/trans_models/triangulate.pyx":568
 * 
 * def calcLexWeights(table_path, lexCounts, savePath, RecordClass = MosesRecord):
 *     table_file = files.open(table_path, 'r')             # <<<<<<<<<<<<<<
 *     saveFile  = files.open(savePath, 'w')
 *     for line in table_file:
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_files); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 568, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_open); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 568, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = NULL;
  __pyx_t_4 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
      __pyx_t_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_table_path, __pyx_n_s_r};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 568, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_table_path, __pyx_n_s_r};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 568, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 568, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (__pyx_t_2) {
      __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL;
    }
    __Pyx_INCREF(__pyx_v_table_path);
    __Pyx_GIVEREF(__pyx_v_table_path);
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_v_table_path);
    __Pyx_INCREF(__pyx_n_s_r);
    __Pyx_GIVEREF(__pyx_n_s_r);
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_n_s_r);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 568, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_table_file = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":569
 * def calcLexWeights(table_path, lexCounts, savePath, RecordClass = MosesRecord):
 *     table_file = files.open(table_path, 'r')
 *     saveFile  = files.open(savePath, 'w')             # <<<<<<<<<<<<<<
 *     for line in table_file:
 *         rec = RecordClass(line)
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_files); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 569, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_open); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 569, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = NULL;
  __pyx_t_4 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_3)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
      __pyx_t_4 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_5)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_savePath, __pyx_n_s_w};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 569, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
    PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_savePath, __pyx_n_s_w};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 569, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_2 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 569, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    if (__pyx_t_3) {
      __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3); __pyx_t_3 = NULL;
    }
    __Pyx_INCREF(__pyx_v_savePath);
    __Pyx_GIVEREF(__pyx_v_savePath);
    PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_4, __pyx_v_savePath);
    __Pyx_INCREF(__pyx_n_s_w);
    __Pyx_GIVEREF(__pyx_n_s_w);
    PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_4, __pyx_n_s_w);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 569, __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_v_saveFile = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":570
 *     table_file = files.open(table_path, 'r')
 *     saveFile  = files.open(savePath, 'w')
 *     for line in table_file:             # <<<<<<<<<<<<<<
 *         rec = RecordClass(line)
 *         if rec.trg.find('|COL|') < 0:
 */
  if (likely(PyList_CheckExact(__pyx_v_table_file)) || PyTuple_CheckExact(__pyx_v_table_file)) {
    __pyx_t_1 = __pyx_v_table_file; __Pyx_INCREF(__pyx_t_1); __pyx_t_6 = 0;
    __pyx_t_7 = NULL;
  } else {
    __pyx_t_6 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_table_file); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 570, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 570, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_7)) {
      if (likely(PyList_CheckExact(__pyx_t_1))) {
        if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 570, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 570, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      } else {
        if (__pyx_t_6 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 570, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 570, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      }
    } else {
      __pyx_t_5 = __pyx_t_7(__pyx_t_1);
      if (unlikely(!__pyx_t_5)) {
        PyObject* exc_type = PyErr_Occurred();
        if (exc_type) {
          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
          else __PYX_ERR(0, 570, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_5);
    }
    __Pyx_XDECREF_SET(__pyx_v_line, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":571
 *     saveFile  = files.open(savePath, 'w')
 *     for line in table_file:
 *         rec = RecordClass(line)             # <<<<<<<<<<<<<<
 *         if rec.trg.find('|COL|') < 0:
 *             rec.features['egfl'] = calcLexWeight(rec, lexCounts, reverse = False)
 */
    __Pyx_INCREF(__pyx_v_RecordClass);
    __pyx_t_2 = __pyx_v_RecordClass; __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_2, function);
      }
    }
    if (!__pyx_t_3) {
      __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_line); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 571, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_line};
        __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 571, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_line};
        __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 571, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_5);
      } else
      #endif
      {
        __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 571, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_3); __pyx_t_3 = NULL;
        __Pyx_INCREF(__pyx_v_line);
        __Pyx_GIVEREF(__pyx_v_line);
        PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_line);
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_8, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 571, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF_SET(__pyx_v_rec, __pyx_t_5);
    __pyx_t_5 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":572
 *     for line in table_file:
 *         rec = RecordClass(line)
 *         if rec.trg.find('|COL|') < 0:             # <<<<<<<<<<<<<<
 *             rec.features['egfl'] = calcLexWeight(rec, lexCounts, reverse = False)
 *             rec.features['fgel'] = calcLexWeight(rec, lexCounts, reverse = True)
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_trg); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 572, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_find); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 572, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 572, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_2 = PyObject_RichCompare(__pyx_t_5, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 572, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_9 < 0)) __PYX_ERR(0, 572, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    if (__pyx_t_9) {

      /* "lpu/smt/trans_models/triangulate.pyx":573
 *         rec = RecordClass(line)
 *         if rec.trg.find('|COL|') < 0:
 *             rec.features['egfl'] = calcLexWeight(rec, lexCounts, reverse = False)             # <<<<<<<<<<<<<<
 *             rec.features['fgel'] = calcLexWeight(rec, lexCounts, reverse = True)
 *             saveFile.write( rec.to_str() )
 */
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_calcLexWeight); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 573, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 573, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_v_rec);
      __Pyx_GIVEREF(__pyx_v_rec);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_rec);
      __Pyx_INCREF(__pyx_v_lexCounts);
      __Pyx_GIVEREF(__pyx_v_lexCounts);
      PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_lexCounts);
      __pyx_t_8 = PyDict_New(); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 573, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_reverse, Py_False) < 0) __PYX_ERR(0, 573, __pyx_L1_error)
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 573, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_features); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 573, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      if (unlikely(PyObject_SetItem(__pyx_t_8, __pyx_n_s_egfl, __pyx_t_3) < 0)) __PYX_ERR(0, 573, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":574
 *         if rec.trg.find('|COL|') < 0:
 *             rec.features['egfl'] = calcLexWeight(rec, lexCounts, reverse = False)
 *             rec.features['fgel'] = calcLexWeight(rec, lexCounts, reverse = True)             # <<<<<<<<<<<<<<
 *             saveFile.write( rec.to_str() )
 *         else:
 */
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_calcLexWeight); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 574, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 574, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_INCREF(__pyx_v_rec);
      __Pyx_GIVEREF(__pyx_v_rec);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_rec);
      __Pyx_INCREF(__pyx_v_lexCounts);
      __Pyx_GIVEREF(__pyx_v_lexCounts);
      PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_lexCounts);
      __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 574, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_reverse, Py_True) < 0) __PYX_ERR(0, 574, __pyx_L1_error)
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_8, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 574, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_features); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 574, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (unlikely(PyObject_SetItem(__pyx_t_5, __pyx_n_s_fgel, __pyx_t_2) < 0)) __PYX_ERR(0, 574, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":575
 *             rec.features['egfl'] = calcLexWeight(rec, lexCounts, reverse = False)
 *             rec.features['fgel'] = calcLexWeight(rec, lexCounts, reverse = True)
 *             saveFile.write( rec.to_str() )             # <<<<<<<<<<<<<<
 *         else:
 *             rec.features['0egfl'] = calcLexWeight(rec, lexCounts, reverse = False)
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_saveFile, __pyx_n_s_write); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 575, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_to_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 575, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_10 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_10)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_10);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
        }
      }
      if (__pyx_t_10) {
        __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 575, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      } else {
        __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 575, __pyx_L1_error)
      }
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
        }
      }
      if (!__pyx_t_3) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 575, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_5)) {
          PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_8};
          __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 575, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
          PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_8};
          __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 575, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        } else
        #endif
        {
          __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 575, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_3); __pyx_t_3 = NULL;
          __Pyx_GIVEREF(__pyx_t_8);
          PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_8);
          __pyx_t_8 = 0;
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_10, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 575, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":572
 *     for line in table_file:
 *         rec = RecordClass(line)
 *         if rec.trg.find('|COL|') < 0:             # <<<<<<<<<<<<<<
 *             rec.features['egfl'] = calcLexWeight(rec, lexCounts, reverse = False)
 *             rec.features['fgel'] = calcLexWeight(rec, lexCounts, reverse = True)
 */
      goto __pyx_L5;
    }

    /* "lpu/smt/trans_models/triangulate.pyx":577
 *             saveFile.write( rec.to_str() )
 *         else:
 *             rec.features['0egfl'] = calcLexWeight(rec, lexCounts, reverse = False)             # <<<<<<<<<<<<<<
 *             rec.features['0fgel'] = calcLexWeight(rec, lexCounts, reverse = True)
 *             saveFile.write( rec.to_str() )
 */
    /*else*/ {
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_calcLexWeight); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 577, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 577, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_v_rec);
      __Pyx_GIVEREF(__pyx_v_rec);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_rec);
      __Pyx_INCREF(__pyx_v_lexCounts);
      __Pyx_GIVEREF(__pyx_v_lexCounts);
      PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_lexCounts);
      __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 577, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      if (PyDict_SetItem(__pyx_t_10, __pyx_n_s_reverse, Py_False) < 0) __PYX_ERR(0, 577, __pyx_L1_error)
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, __pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 577, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_features); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 577, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      if (unlikely(PyObject_SetItem(__pyx_t_10, __pyx_kp_s_0egfl, __pyx_t_8) < 0)) __PYX_ERR(0, 577, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":578
 *         else:
 *             rec.features['0egfl'] = calcLexWeight(rec, lexCounts, reverse = False)
 *             rec.features['0fgel'] = calcLexWeight(rec, lexCounts, reverse = True)             # <<<<<<<<<<<<<<
 *             saveFile.write( rec.to_str() )
 *     saveFile.close()
 */
      __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_calcLexWeight); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 578, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 578, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_INCREF(__pyx_v_rec);
      __Pyx_GIVEREF(__pyx_v_rec);
      PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_rec);
      __Pyx_INCREF(__pyx_v_lexCounts);
      __Pyx_GIVEREF(__pyx_v_lexCounts);
      PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_v_lexCounts);
      __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 578, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_reverse, Py_True) < 0) __PYX_ERR(0, 578, __pyx_L1_error)
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_10, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 578, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_features); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 578, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (unlikely(PyObject_SetItem(__pyx_t_5, __pyx_kp_s_0fgel, __pyx_t_2) < 0)) __PYX_ERR(0, 578, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":579
 *             rec.features['0egfl'] = calcLexWeight(rec, lexCounts, reverse = False)
 *             rec.features['0fgel'] = calcLexWeight(rec, lexCounts, reverse = True)
 *             saveFile.write( rec.to_str() )             # <<<<<<<<<<<<<<
 *     saveFile.close()
 *     table_file.close()
 */
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_saveFile, __pyx_n_s_write); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 579, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_rec, __pyx_n_s_to_str); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 579, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_3 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_8, function);
        }
      }
      if (__pyx_t_3) {
        __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 579, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      } else {
        __pyx_t_10 = __Pyx_PyObject_CallNoArg(__pyx_t_8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 579, __pyx_L1_error)
      }
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_8)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_8);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
        }
      }
      if (!__pyx_t_8) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 579, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_5)) {
          PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_10};
          __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 579, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
          PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_10};
          __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 579, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        } else
        #endif
        {
          __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 579, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8); __pyx_t_8 = NULL;
          __Pyx_GIVEREF(__pyx_t_10);
          PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_t_10);
          __pyx_t_10 = 0;
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 579, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __pyx_L5:;

    /* "lpu/smt/trans_models/triangulate.pyx":570
 *     table_file = files.open(table_path, 'r')
 *     saveFile  = files.open(savePath, 'w')
 *     for line in table_file:             # <<<<<<<<<<<<<<
 *         rec = RecordClass(line)
 *         if rec.trg.find('|COL|') < 0:
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":580
 *             rec.features['0fgel'] = calcLexWeight(rec, lexCounts, reverse = True)
 *             saveFile.write( rec.to_str() )
 *     saveFile.close()             # <<<<<<<<<<<<<<
 *     table_file.close()
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_saveFile, __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 580, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_5) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 580, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 580, __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;

  /* "lpu/smt/trans_models/triangulate.pyx":581
 *             saveFile.write( rec.to_str() )
 *     saveFile.close()
 *     table_file.close()             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_table_file, __pyx_n_s_close); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 581, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
    __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2);
    if (likely(__pyx_t_5)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_2, function);
    }
  }
  if (__pyx_t_5) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 581, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 581, __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;

  /* "lpu/smt/trans_models/triangulate.pyx":567
 *     return lexWeight
 * 
 * def calcLexWeights(table_path, lexCounts, savePath, RecordClass = MosesRecord):             # <<<<<<<<<<<<<<
 *     table_file = files.open(table_path, 'r')
 *     saveFile  = files.open(savePath, 'w')
 */

  /* function exit code */
  __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_5);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.calcLexWeights", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_table_file);
  __Pyx_XDECREF(__pyx_v_saveFile);
  __Pyx_XDECREF(__pyx_v_line);
  __Pyx_XDECREF(__pyx_v_rec);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "lpu/smt/trans_models/triangulate.pyx":584
 * 
 * 
 * def pivot(table1, table2, savefile="phrase-table.gz", workdir=".", **options):             # <<<<<<<<<<<<<<
 *     '''find pair of source-pivot and pivot-target records for common pivot phrase'''
 *     try:
 */

/* Python wrapper */
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_29pivot(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_3lpu_3smt_12trans_models_11triangulate_28pivot[] = "find pair of source-pivot and pivot-target records for common pivot phrase";
static PyMethodDef __pyx_mdef_3lpu_3smt_12trans_models_11triangulate_29pivot = {"pivot", (PyCFunction)__pyx_pw_3lpu_3smt_12trans_models_11triangulate_29pivot, METH_VARARGS|METH_KEYWORDS, __pyx_doc_3lpu_3smt_12trans_models_11triangulate_28pivot};
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_29pivot(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_table1 = 0;
  PyObject *__pyx_v_table2 = 0;
  PyObject *__pyx_v_savefile = 0;
  PyObject *__pyx_v_workdir = 0;
  PyObject *__pyx_v_options = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("pivot (wrapper)", 0);
  __pyx_v_options = PyDict_New(); if (unlikely(!__pyx_v_options)) return NULL;
  __Pyx_GOTREF(__pyx_v_options);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_table1,&__pyx_n_s_table2,&__pyx_n_s_savefile,&__pyx_n_s_workdir,0};
    PyObject* values[4] = {0,0,0,0};
    values[2] = ((PyObject *)__pyx_kp_s_phrase_table_gz);
    values[3] = ((PyObject *)__pyx_kp_s__25);
    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);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        CYTHON_FALLTHROUGH;
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        CYTHON_FALLTHROUGH;
        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_table1)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        CYTHON_FALLTHROUGH;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_table2)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("pivot", 0, 2, 4, 1); __PYX_ERR(0, 584, __pyx_L3_error)
        }
        CYTHON_FALLTHROUGH;
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_savefile);
          if (value) { values[2] = value; kw_args--; }
        }
        CYTHON_FALLTHROUGH;
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_workdir);
          if (value) { values[3] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, __pyx_v_options, values, pos_args, "pivot") < 0)) __PYX_ERR(0, 584, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        CYTHON_FALLTHROUGH;
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        CYTHON_FALLTHROUGH;
        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_table1 = values[0];
    __pyx_v_table2 = values[1];
    __pyx_v_savefile = values[2];
    __pyx_v_workdir = values[3];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("pivot", 0, 2, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 584, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_DECREF(__pyx_v_options); __pyx_v_options = 0;
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.pivot", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_3lpu_3smt_12trans_models_11triangulate_28pivot(__pyx_self, __pyx_v_table1, __pyx_v_table2, __pyx_v_savefile, __pyx_v_workdir, __pyx_v_options);

  /* function exit code */
  __Pyx_XDECREF(__pyx_v_options);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_28pivot(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_table1, PyObject *__pyx_v_table2, PyObject *__pyx_v_savefile, PyObject *__pyx_v_workdir, PyObject *__pyx_v_options) {
  PyObject *__pyx_v_RecordClass = NULL;
  PyObject *__pyx_v_prefix = NULL;
  PyObject *__pyx_v_threshold = NULL;
  PyObject *__pyx_v_alignLexPath = NULL;
  PyObject *__pyx_v_nbest = NULL;
  PyObject *__pyx_v_method = NULL;
  PyObject *__pyx_v_lexMethod = NULL;
  PyObject *__pyx_v_jointMethod = NULL;
  PyObject *__pyx_v_matchMethod = NULL;
  CYTHON_UNUSED PyObject *__pyx_v_numNulls = NULL;
  PyObject *__pyx_v_multi_target = NULL;
  PyObject *__pyx_v_logFile = NULL;
  PyObject *__pyx_v_showProgress = NULL;
  PyObject *__pyx_v_key_type = NULL;
  PyObject *__pyx_v_tableSrcPvt = NULL;
  PyObject *__pyx_v_tablePvtTrg = NULL;
  PyObject *__pyx_v_workOptions = NULL;
  PyObject *__pyx_v_workset = NULL;
  PyObject *__pyx_v_rows = NULL;
  PyObject *__pyx_v_lastSrc = NULL;
  PyObject *__pyx_v_recSrcPvt = NULL;
  PyObject *__pyx_v_src = NULL;
  PyObject *__pyx_v_term = NULL;
  PyObject *__pyx_v_recPvtTrg = NULL;
  PyObject *__pyx_v_fobj = 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;
  int __pyx_t_6;
  int __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  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;
  Py_ssize_t __pyx_t_14;
  PyObject *(*__pyx_t_15)(PyObject *);
  int __pyx_t_16;
  PyObject *__pyx_t_17 = NULL;
  Py_ssize_t __pyx_t_18;
  PyObject *(*__pyx_t_19)(PyObject *);
  int __pyx_t_20;
  PyObject *__pyx_t_21 = NULL;
  PyObject *__pyx_t_22 = NULL;
  PyObject *__pyx_t_23 = NULL;
  PyObject *__pyx_t_24 = NULL;
  PyObject *__pyx_t_25 = NULL;
  __Pyx_RefNannySetupContext("pivot", 0);

  /* "lpu/smt/trans_models/triangulate.pyx":586
 * def pivot(table1, table2, savefile="phrase-table.gz", workdir=".", **options):
 *     '''find pair of source-pivot and pivot-target records for common pivot phrase'''
 *     try:             # <<<<<<<<<<<<<<
 *         # initialize the options
 *         RecordClass = options.get('RecordClass', MosesRecord)
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3);
    __Pyx_XGOTREF(__pyx_t_1);
    __Pyx_XGOTREF(__pyx_t_2);
    __Pyx_XGOTREF(__pyx_t_3);
    /*try:*/ {

      /* "lpu/smt/trans_models/triangulate.pyx":588
 *     try:
 *         # initialize the options
 *         RecordClass = options.get('RecordClass', MosesRecord)             # <<<<<<<<<<<<<<
 *         prefix = options.get('prefix', 'phrase')
 *         threshold = options.get('threshold', THRESHOLD)
 */
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_MosesRecord); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 588, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_options, __pyx_n_s_RecordClass, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 588, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_v_RecordClass = __pyx_t_5;
      __pyx_t_5 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":589
 *         # initialize the options
 *         RecordClass = options.get('RecordClass', MosesRecord)
 *         prefix = options.get('prefix', 'phrase')             # <<<<<<<<<<<<<<
 *         threshold = options.get('threshold', THRESHOLD)
 *         alignLexPath   = options.get('alignlex', None)
 */
      __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_options, __pyx_n_s_prefix, __pyx_n_s_phrase); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 589, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_v_prefix = __pyx_t_5;
      __pyx_t_5 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":590
 *         RecordClass = options.get('RecordClass', MosesRecord)
 *         prefix = options.get('prefix', 'phrase')
 *         threshold = options.get('threshold', THRESHOLD)             # <<<<<<<<<<<<<<
 *         alignLexPath   = options.get('alignlex', None)
 *         nbest     = options.get('nbest', NBEST)
 */
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_THRESHOLD); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 590, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = __Pyx_PyDict_GetItemDefault(__pyx_v_options, __pyx_n_s_threshold, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 590, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_v_threshold = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":591
 *         prefix = options.get('prefix', 'phrase')
 *         threshold = options.get('threshold', THRESHOLD)
 *         alignLexPath   = options.get('alignlex', None)             # <<<<<<<<<<<<<<
 *         nbest     = options.get('nbest', NBEST)
 *         method    = options.get('method', METHOD)
 */
      __pyx_t_4 = __Pyx_PyDict_GetItemDefault(__pyx_v_options, __pyx_n_s_alignlex, Py_None); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 591, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_v_alignLexPath = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":592
 *         threshold = options.get('threshold', THRESHOLD)
 *         alignLexPath   = options.get('alignlex', None)
 *         nbest     = options.get('nbest', NBEST)             # <<<<<<<<<<<<<<
 *         method    = options.get('method', METHOD)
 *         lexMethod = options.get('lexmethod', LEX_METHOD)
 */
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_NBEST); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 592, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_options, __pyx_n_s_nbest, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 592, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_v_nbest = __pyx_t_5;
      __pyx_t_5 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":593
 *         alignLexPath   = options.get('alignlex', None)
 *         nbest     = options.get('nbest', NBEST)
 *         method    = options.get('method', METHOD)             # <<<<<<<<<<<<<<
 *         lexMethod = options.get('lexmethod', LEX_METHOD)
 *         jointMethod = options.get('jointmethod', JOINT_METHOD)
 */
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_METHOD); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 593, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = __Pyx_PyDict_GetItemDefault(__pyx_v_options, __pyx_n_s_method, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 593, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_v_method = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":594
 *         nbest     = options.get('nbest', NBEST)
 *         method    = options.get('method', METHOD)
 *         lexMethod = options.get('lexmethod', LEX_METHOD)             # <<<<<<<<<<<<<<
 *         jointMethod = options.get('jointmethod', JOINT_METHOD)
 *         matchMethod = options.get('matchmethod', MATCH_METHOD)
 */
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_LEX_METHOD); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 594, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_options, __pyx_n_s_lexmethod, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 594, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_v_lexMethod = __pyx_t_5;
      __pyx_t_5 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":595
 *         method    = options.get('method', METHOD)
 *         lexMethod = options.get('lexmethod', LEX_METHOD)
 *         jointMethod = options.get('jointmethod', JOINT_METHOD)             # <<<<<<<<<<<<<<
 *         matchMethod = options.get('matchmethod', MATCH_METHOD)
 *         numNulls  = options.get('nulls', NULLS)
 */
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_JOINT_METHOD); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 595, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = __Pyx_PyDict_GetItemDefault(__pyx_v_options, __pyx_n_s_jointmethod, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 595, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_v_jointMethod = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":596
 *         lexMethod = options.get('lexmethod', LEX_METHOD)
 *         jointMethod = options.get('jointmethod', JOINT_METHOD)
 *         matchMethod = options.get('matchmethod', MATCH_METHOD)             # <<<<<<<<<<<<<<
 *         numNulls  = options.get('nulls', NULLS)
 *         multi_target = options.get('multitarget', False)
 */
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_MATCH_METHOD); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 596, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = __Pyx_PyDict_GetItemDefault(__pyx_v_options, __pyx_n_s_matchmethod, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 596, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_v_matchMethod = __pyx_t_5;
      __pyx_t_5 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":597
 *         jointMethod = options.get('jointmethod', JOINT_METHOD)
 *         matchMethod = options.get('matchmethod', MATCH_METHOD)
 *         numNulls  = options.get('nulls', NULLS)             # <<<<<<<<<<<<<<
 *         multi_target = options.get('multitarget', False)
 *         logFile = options.get('log', '')
 */
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_NULLS); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 597, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_4 = __Pyx_PyDict_GetItemDefault(__pyx_v_options, __pyx_n_s_nulls, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 597, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_v_numNulls = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":598
 *         matchMethod = options.get('matchmethod', MATCH_METHOD)
 *         numNulls  = options.get('nulls', NULLS)
 *         multi_target = options.get('multitarget', False)             # <<<<<<<<<<<<<<
 *         logFile = options.get('log', '')
 *         showProgress = options.get('progress', True)
 */
      __pyx_t_4 = __Pyx_PyDict_GetItemDefault(__pyx_v_options, __pyx_n_s_multitarget, Py_False); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 598, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_v_multi_target = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":599
 *         numNulls  = options.get('nulls', NULLS)
 *         multi_target = options.get('multitarget', False)
 *         logFile = options.get('log', '')             # <<<<<<<<<<<<<<
 *         showProgress = options.get('progress', True)
 * 
 */
      __pyx_t_4 = __Pyx_PyDict_GetItemDefault(__pyx_v_options, __pyx_n_s_log, __pyx_kp_s__16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 599, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_v_logFile = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":600
 *         multi_target = options.get('multitarget', False)
 *         logFile = options.get('log', '')
 *         showProgress = options.get('progress', True)             # <<<<<<<<<<<<<<
 * 
 *         if lexMethod not in ('prodweight', 'table'):
 */
      __pyx_t_4 = __Pyx_PyDict_GetItemDefault(__pyx_v_options, __pyx_n_s_progress, Py_True); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 600, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_v_showProgress = __pyx_t_4;
      __pyx_t_4 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":602
 *         showProgress = options.get('progress', True)
 * 
 *         if lexMethod not in ('prodweight', 'table'):             # <<<<<<<<<<<<<<
 *             if alignLexPath == None:
 *                 logging.debug(lexMethod)
 */
      __Pyx_INCREF(__pyx_v_lexMethod);
      __pyx_t_4 = __pyx_v_lexMethod;
      __pyx_t_7 = (__Pyx_PyString_Equals(__pyx_t_4, __pyx_n_s_prodweight, Py_NE)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 602, __pyx_L3_error)
      if (__pyx_t_7) {
      } else {
        __pyx_t_6 = __pyx_t_7;
        goto __pyx_L10_bool_binop_done;
      }
      __pyx_t_7 = (__Pyx_PyString_Equals(__pyx_t_4, __pyx_n_s_table, Py_NE)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 602, __pyx_L3_error)
      __pyx_t_6 = __pyx_t_7;
      __pyx_L10_bool_binop_done:;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_7 = (__pyx_t_6 != 0);
      if (__pyx_t_7) {

        /* "lpu/smt/trans_models/triangulate.pyx":603
 * 
 *         if lexMethod not in ('prodweight', 'table'):
 *             if alignLexPath == None:             # <<<<<<<<<<<<<<
 *                 logging.debug(lexMethod)
 *                 assert False, "aligned lexfile is not given"
 */
        __pyx_t_4 = PyObject_RichCompare(__pyx_v_alignLexPath, Py_None, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 603, __pyx_L3_error)
        __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 603, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        if (__pyx_t_7) {

          /* "lpu/smt/trans_models/triangulate.pyx":604
 *         if lexMethod not in ('prodweight', 'table'):
 *             if alignLexPath == None:
 *                 logging.debug(lexMethod)             # <<<<<<<<<<<<<<
 *                 assert False, "aligned lexfile is not given"
 * 
 */
          __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_logging); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 604, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_debug); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 604, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __pyx_t_5 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
            __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_8);
            if (likely(__pyx_t_5)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
              __Pyx_INCREF(__pyx_t_5);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_8, function);
            }
          }
          if (!__pyx_t_5) {
            __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_lexMethod); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 604, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_4);
          } else {
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_8)) {
              PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_lexMethod};
              __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 604, __pyx_L3_error)
              __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
              __Pyx_GOTREF(__pyx_t_4);
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
              PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_lexMethod};
              __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 604, __pyx_L3_error)
              __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
              __Pyx_GOTREF(__pyx_t_4);
            } else
            #endif
            {
              __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 604, __pyx_L3_error)
              __Pyx_GOTREF(__pyx_t_9);
              __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_5); __pyx_t_5 = NULL;
              __Pyx_INCREF(__pyx_v_lexMethod);
              __Pyx_GIVEREF(__pyx_v_lexMethod);
              PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_lexMethod);
              __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_9, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 604, __pyx_L3_error)
              __Pyx_GOTREF(__pyx_t_4);
              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            }
          }
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":605
 *             if alignLexPath == None:
 *                 logging.debug(lexMethod)
 *                 assert False, "aligned lexfile is not given"             # <<<<<<<<<<<<<<
 * 
 *         if matchMethod == 'hiero':
 */
          #ifndef CYTHON_WITHOUT_ASSERTIONS
          if (unlikely(!Py_OptimizeFlag)) {
            if (unlikely(!0)) {
              PyErr_SetObject(PyExc_AssertionError, __pyx_kp_s_aligned_lexfile_is_not_given);
              __PYX_ERR(0, 605, __pyx_L3_error)
            }
          }
          #endif

          /* "lpu/smt/trans_models/triangulate.pyx":603
 * 
 *         if lexMethod not in ('prodweight', 'table'):
 *             if alignLexPath == None:             # <<<<<<<<<<<<<<
 *                 logging.debug(lexMethod)
 *                 assert False, "aligned lexfile is not given"
 */
        }

        /* "lpu/smt/trans_models/triangulate.pyx":602
 *         showProgress = options.get('progress', True)
 * 
 *         if lexMethod not in ('prodweight', 'table'):             # <<<<<<<<<<<<<<
 *             if alignLexPath == None:
 *                 logging.debug(lexMethod)
 */
      }

      /* "lpu/smt/trans_models/triangulate.pyx":607
 *                 assert False, "aligned lexfile is not given"
 * 
 *         if matchMethod == 'hiero':             # <<<<<<<<<<<<<<
 *             key_type = 'src_hiero'
 *         else:
 */
      __pyx_t_7 = (__Pyx_PyString_Equals(__pyx_v_matchMethod, __pyx_n_s_hiero, Py_EQ)); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 607, __pyx_L3_error)
      if (__pyx_t_7) {

        /* "lpu/smt/trans_models/triangulate.pyx":608
 * 
 *         if matchMethod == 'hiero':
 *             key_type = 'src_hiero'             # <<<<<<<<<<<<<<
 *         else:
 *             key_type = 'src_symbols'
 */
        __Pyx_INCREF(__pyx_n_s_src_hiero);
        __pyx_v_key_type = __pyx_n_s_src_hiero;

        /* "lpu/smt/trans_models/triangulate.pyx":607
 *                 assert False, "aligned lexfile is not given"
 * 
 *         if matchMethod == 'hiero':             # <<<<<<<<<<<<<<
 *             key_type = 'src_hiero'
 *         else:
 */
        goto __pyx_L13;
      }

      /* "lpu/smt/trans_models/triangulate.pyx":610
 *             key_type = 'src_hiero'
 *         else:
 *             key_type = 'src_symbols'             # <<<<<<<<<<<<<<
 *         logging.log("loading: %s" % table1)
 *         #tableSrcPvt = Table(table1, RecordClass, key_type=key_type, showProgress=showProgress)
 */
      /*else*/ {
        __Pyx_INCREF(__pyx_n_s_src_symbols);
        __pyx_v_key_type = __pyx_n_s_src_symbols;
      }
      __pyx_L13:;

      /* "lpu/smt/trans_models/triangulate.pyx":611
 *         else:
 *             key_type = 'src_symbols'
 *         logging.log("loading: %s" % table1)             # <<<<<<<<<<<<<<
 *         #tableSrcPvt = Table(table1, RecordClass, key_type=key_type, showProgress=showProgress)
 *         tableSrcPvt = Table(table1, RecordClass, showProgress=showProgress)
 */
      __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_logging); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 611, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_log); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 611, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyString_Format(__pyx_kp_s_loading_s, __pyx_v_table1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 611, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_5 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_9);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_9, function);
        }
      }
      if (!__pyx_t_5) {
        __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 611, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_GOTREF(__pyx_t_4);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_9)) {
          PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_8};
          __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 611, __pyx_L3_error)
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
          PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_8};
          __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 611, __pyx_L3_error)
          __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        } else
        #endif
        {
          __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 611, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_5); __pyx_t_5 = NULL;
          __Pyx_GIVEREF(__pyx_t_8);
          PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_8);
          __pyx_t_8 = 0;
          __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_10, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 611, __pyx_L3_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_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":613
 *         logging.log("loading: %s" % table1)
 *         #tableSrcPvt = Table(table1, RecordClass, key_type=key_type, showProgress=showProgress)
 *         tableSrcPvt = Table(table1, RecordClass, showProgress=showProgress)             # <<<<<<<<<<<<<<
 *         logging.log("loading: %s" % table2)
 *         tablePvtTrg = Table(table2, RecordClass, key_type=key_type, showProgress=showProgress)
 */
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_Table); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 613, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 613, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_INCREF(__pyx_v_table1);
      __Pyx_GIVEREF(__pyx_v_table1);
      PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_table1);
      __Pyx_INCREF(__pyx_v_RecordClass);
      __Pyx_GIVEREF(__pyx_v_RecordClass);
      PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_RecordClass);
      __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 613, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_10);
      if (PyDict_SetItem(__pyx_t_10, __pyx_n_s_showProgress, __pyx_v_showProgress) < 0) __PYX_ERR(0, 613, __pyx_L3_error)
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 613, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_v_tableSrcPvt = __pyx_t_8;
      __pyx_t_8 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":614
 *         #tableSrcPvt = Table(table1, RecordClass, key_type=key_type, showProgress=showProgress)
 *         tableSrcPvt = Table(table1, RecordClass, showProgress=showProgress)
 *         logging.log("loading: %s" % table2)             # <<<<<<<<<<<<<<
 *         tablePvtTrg = Table(table2, RecordClass, key_type=key_type, showProgress=showProgress)
 * 
 */
      __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_logging); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 614, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_log); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 614, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_10 = __Pyx_PyString_Format(__pyx_kp_s_loading_s, __pyx_v_table2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 614, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_4 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_9);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_9, function);
        }
      }
      if (!__pyx_t_4) {
        __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 614, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_GOTREF(__pyx_t_8);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_9)) {
          PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_10};
          __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 614, __pyx_L3_error)
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
          PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_10};
          __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 614, __pyx_L3_error)
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        } else
        #endif
        {
          __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 614, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
          __Pyx_GIVEREF(__pyx_t_10);
          PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_10);
          __pyx_t_10 = 0;
          __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_5, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 614, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":615
 *         tableSrcPvt = Table(table1, RecordClass, showProgress=showProgress)
 *         logging.log("loading: %s" % table2)
 *         tablePvtTrg = Table(table2, RecordClass, key_type=key_type, showProgress=showProgress)             # <<<<<<<<<<<<<<
 * 
 *         workOptions = {}
 */
      __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_Table); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 615, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 615, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_INCREF(__pyx_v_table2);
      __Pyx_GIVEREF(__pyx_v_table2);
      PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_table2);
      __Pyx_INCREF(__pyx_v_RecordClass);
      __Pyx_GIVEREF(__pyx_v_RecordClass);
      PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_RecordClass);
      __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 615, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_key_type, __pyx_v_key_type) < 0) __PYX_ERR(0, 615, __pyx_L3_error)
      if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_showProgress, __pyx_v_showProgress) < 0) __PYX_ERR(0, 615, __pyx_L3_error)
      __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_9, __pyx_t_5); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 615, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_v_tablePvtTrg = __pyx_t_10;
      __pyx_t_10 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":617
 *         tablePvtTrg = Table(table2, RecordClass, key_type=key_type, showProgress=showProgress)
 * 
 *         workOptions = {}             # <<<<<<<<<<<<<<
 *         workOptions['RecordClass'] = RecordClass
 *         workOptions['prefix'] = prefix
 */
      __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 617, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_v_workOptions = ((PyObject*)__pyx_t_10);
      __pyx_t_10 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":618
 * 
 *         workOptions = {}
 *         workOptions['RecordClass'] = RecordClass             # <<<<<<<<<<<<<<
 *         workOptions['prefix'] = prefix
 *         workOptions['multi_target'] = multi_target
 */
      if (unlikely(PyDict_SetItem(__pyx_v_workOptions, __pyx_n_s_RecordClass, __pyx_v_RecordClass) < 0)) __PYX_ERR(0, 618, __pyx_L3_error)

      /* "lpu/smt/trans_models/triangulate.pyx":619
 *         workOptions = {}
 *         workOptions['RecordClass'] = RecordClass
 *         workOptions['prefix'] = prefix             # <<<<<<<<<<<<<<
 *         workOptions['multi_target'] = multi_target
 *         workOptions['jointMethod'] = jointMethod
 */
      if (unlikely(PyDict_SetItem(__pyx_v_workOptions, __pyx_n_s_prefix, __pyx_v_prefix) < 0)) __PYX_ERR(0, 619, __pyx_L3_error)

      /* "lpu/smt/trans_models/triangulate.pyx":620
 *         workOptions['RecordClass'] = RecordClass
 *         workOptions['prefix'] = prefix
 *         workOptions['multi_target'] = multi_target             # <<<<<<<<<<<<<<
 *         workOptions['jointMethod'] = jointMethod
 *         workOptions['matchMethod'] = matchMethod
 */
      if (unlikely(PyDict_SetItem(__pyx_v_workOptions, __pyx_n_s_multi_target, __pyx_v_multi_target) < 0)) __PYX_ERR(0, 620, __pyx_L3_error)

      /* "lpu/smt/trans_models/triangulate.pyx":621
 *         workOptions['prefix'] = prefix
 *         workOptions['multi_target'] = multi_target
 *         workOptions['jointMethod'] = jointMethod             # <<<<<<<<<<<<<<
 *         workOptions['matchMethod'] = matchMethod
 *         workset = WorkSet(savefile, workdir, method, **workOptions)
 */
      if (unlikely(PyDict_SetItem(__pyx_v_workOptions, __pyx_n_s_jointMethod, __pyx_v_jointMethod) < 0)) __PYX_ERR(0, 621, __pyx_L3_error)

      /* "lpu/smt/trans_models/triangulate.pyx":622
 *         workOptions['multi_target'] = multi_target
 *         workOptions['jointMethod'] = jointMethod
 *         workOptions['matchMethod'] = matchMethod             # <<<<<<<<<<<<<<
 *         workset = WorkSet(savefile, workdir, method, **workOptions)
 *         workset.threshold = threshold
 */
      if (unlikely(PyDict_SetItem(__pyx_v_workOptions, __pyx_n_s_matchMethod, __pyx_v_matchMethod) < 0)) __PYX_ERR(0, 622, __pyx_L3_error)

      /* "lpu/smt/trans_models/triangulate.pyx":623
 *         workOptions['jointMethod'] = jointMethod
 *         workOptions['matchMethod'] = matchMethod
 *         workset = WorkSet(savefile, workdir, method, **workOptions)             # <<<<<<<<<<<<<<
 *         workset.threshold = threshold
 *         workset.nbest = nbest
 */
      __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_WorkSet); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 623, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 623, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_v_savefile);
      __Pyx_GIVEREF(__pyx_v_savefile);
      PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_savefile);
      __Pyx_INCREF(__pyx_v_workdir);
      __Pyx_GIVEREF(__pyx_v_workdir);
      PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_workdir);
      __Pyx_INCREF(__pyx_v_method);
      __Pyx_GIVEREF(__pyx_v_method);
      PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_method);
      __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_5, __pyx_v_workOptions); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 623, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_v_workset = __pyx_t_9;
      __pyx_t_9 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":624
 *         workOptions['matchMethod'] = matchMethod
 *         workset = WorkSet(savefile, workdir, method, **workOptions)
 *         workset.threshold = threshold             # <<<<<<<<<<<<<<
 *         workset.nbest = nbest
 * 
 */
      if (__Pyx_PyObject_SetAttrStr(__pyx_v_workset, __pyx_n_s_threshold, __pyx_v_threshold) < 0) __PYX_ERR(0, 624, __pyx_L3_error)

      /* "lpu/smt/trans_models/triangulate.pyx":625
 *         workset = WorkSet(savefile, workdir, method, **workOptions)
 *         workset.threshold = threshold
 *         workset.nbest = nbest             # <<<<<<<<<<<<<<
 * 
 *         rows = []
 */
      if (__Pyx_PyObject_SetAttrStr(__pyx_v_workset, __pyx_n_s_nbest, __pyx_v_nbest) < 0) __PYX_ERR(0, 625, __pyx_L3_error)

      /* "lpu/smt/trans_models/triangulate.pyx":627
 *         workset.nbest = nbest
 * 
 *         rows = []             # <<<<<<<<<<<<<<
 *         lastSrc = ''
 *         logging.log("beginning pivot\n")
 */
      __pyx_t_9 = PyList_New(0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 627, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_v_rows = ((PyObject*)__pyx_t_9);
      __pyx_t_9 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":628
 * 
 *         rows = []
 *         lastSrc = ''             # <<<<<<<<<<<<<<
 *         logging.log("beginning pivot\n")
 *         #for recSrcPvt in progress.view(tableSrcPvt.find(''),maxCount=len(tableSrcPvt)):
 */
      __Pyx_INCREF(__pyx_kp_s__16);
      __pyx_v_lastSrc = __pyx_kp_s__16;

      /* "lpu/smt/trans_models/triangulate.pyx":629
 *         rows = []
 *         lastSrc = ''
 *         logging.log("beginning pivot\n")             # <<<<<<<<<<<<<<
 *         #for recSrcPvt in progress.view(tableSrcPvt.find(''),maxCount=len(tableSrcPvt)):
 *         for recSrcPvt in progress.view(tableSrcPvt.find(''),'processing',max_count=len(tableSrcPvt)):
 */
      __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_logging); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 629, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_log); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 629, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 629, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":631
 *         logging.log("beginning pivot\n")
 *         #for recSrcPvt in progress.view(tableSrcPvt.find(''),maxCount=len(tableSrcPvt)):
 *         for recSrcPvt in progress.view(tableSrcPvt.find(''),'processing',max_count=len(tableSrcPvt)):             # <<<<<<<<<<<<<<
 *             src = recSrcPvt.src
 *             workset.numRecSrcPvt += 1
 */
      __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_progress); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 631, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_view); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 631, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_tableSrcPvt, __pyx_n_s_find); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 631, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__27, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 631, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 631, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_10);
      PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_10);
      __Pyx_INCREF(__pyx_n_s_processing);
      __Pyx_GIVEREF(__pyx_n_s_processing);
      PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_n_s_processing);
      __pyx_t_10 = 0;
      __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 631, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_11 = PyObject_Length(__pyx_v_tableSrcPvt); if (unlikely(__pyx_t_11 == -1)) __PYX_ERR(0, 631, __pyx_L3_error)
      __pyx_t_8 = PyInt_FromSsize_t(__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 631, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_8);
      if (PyDict_SetItem(__pyx_t_10, __pyx_n_s_max_count, __pyx_t_8) < 0) __PYX_ERR(0, 631, __pyx_L3_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 631, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      if (likely(PyList_CheckExact(__pyx_t_8)) || PyTuple_CheckExact(__pyx_t_8)) {
        __pyx_t_10 = __pyx_t_8; __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_8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 631, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_12 = Py_TYPE(__pyx_t_10)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 631, __pyx_L3_error)
      }
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      for (;;) {
        if (likely(!__pyx_t_12)) {
          if (likely(PyList_CheckExact(__pyx_t_10))) {
            if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_10)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_8 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_11); __Pyx_INCREF(__pyx_t_8); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 631, __pyx_L3_error)
            #else
            __pyx_t_8 = PySequence_ITEM(__pyx_t_10, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 631, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_8);
            #endif
          } else {
            if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_10)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_11); __Pyx_INCREF(__pyx_t_8); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 631, __pyx_L3_error)
            #else
            __pyx_t_8 = PySequence_ITEM(__pyx_t_10, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 631, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_8);
            #endif
          }
        } else {
          __pyx_t_8 = __pyx_t_12(__pyx_t_10);
          if (unlikely(!__pyx_t_8)) {
            PyObject* exc_type = PyErr_Occurred();
            if (exc_type) {
              if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
              else __PYX_ERR(0, 631, __pyx_L3_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_8);
        }
        __Pyx_XDECREF_SET(__pyx_v_recSrcPvt, __pyx_t_8);
        __pyx_t_8 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":632
 *         #for recSrcPvt in progress.view(tableSrcPvt.find(''),maxCount=len(tableSrcPvt)):
 *         for recSrcPvt in progress.view(tableSrcPvt.find(''),'processing',max_count=len(tableSrcPvt)):
 *             src = recSrcPvt.src             # <<<<<<<<<<<<<<
 *             workset.numRecSrcPvt += 1
 *             workset.setPhrasesSrcPvt.add(recSrcPvt.src)
 */
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_recSrcPvt, __pyx_n_s_src); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 632, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_XDECREF_SET(__pyx_v_src, __pyx_t_8);
        __pyx_t_8 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":633
 *         for recSrcPvt in progress.view(tableSrcPvt.find(''),'processing',max_count=len(tableSrcPvt)):
 *             src = recSrcPvt.src
 *             workset.numRecSrcPvt += 1             # <<<<<<<<<<<<<<
 *             workset.setPhrasesSrcPvt.add(recSrcPvt.src)
 *             for term in recSrcPvt.srcTerms:
 */
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_numRecSrcPvt); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 633, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_t_8, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 633, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        if (__Pyx_PyObject_SetAttrStr(__pyx_v_workset, __pyx_n_s_numRecSrcPvt, __pyx_t_9) < 0) __PYX_ERR(0, 633, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":634
 *             src = recSrcPvt.src
 *             workset.numRecSrcPvt += 1
 *             workset.setPhrasesSrcPvt.add(recSrcPvt.src)             # <<<<<<<<<<<<<<
 *             for term in recSrcPvt.srcTerms:
 *                 workset.setWordsSrcPvt.add(term)
 */
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_setPhrasesSrcPvt); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 634, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_add); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 634, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_recSrcPvt, __pyx_n_s_src); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 634, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_8);
        __pyx_t_4 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_5, function);
          }
        }
        if (!__pyx_t_4) {
          __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 634, __pyx_L3_error)
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_GOTREF(__pyx_t_9);
        } else {
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_5)) {
            PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_8};
            __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 634, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_GOTREF(__pyx_t_9);
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
            PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_8};
            __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 634, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
            __Pyx_GOTREF(__pyx_t_9);
            __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          } else
          #endif
          {
            __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 634, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_13);
            __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_4); __pyx_t_4 = NULL;
            __Pyx_GIVEREF(__pyx_t_8);
            PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_t_8);
            __pyx_t_8 = 0;
            __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_13, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 634, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_9);
            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          }
        }
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":635
 *             workset.numRecSrcPvt += 1
 *             workset.setPhrasesSrcPvt.add(recSrcPvt.src)
 *             for term in recSrcPvt.srcTerms:             # <<<<<<<<<<<<<<
 *                 workset.setWordsSrcPvt.add(term)
 *             if src != lastSrc:
 */
        __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_recSrcPvt, __pyx_n_s_srcTerms); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 635, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_9);
        if (likely(PyList_CheckExact(__pyx_t_9)) || PyTuple_CheckExact(__pyx_t_9)) {
          __pyx_t_5 = __pyx_t_9; __Pyx_INCREF(__pyx_t_5); __pyx_t_14 = 0;
          __pyx_t_15 = NULL;
        } else {
          __pyx_t_14 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 635, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_15 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 635, __pyx_L3_error)
        }
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        for (;;) {
          if (likely(!__pyx_t_15)) {
            if (likely(PyList_CheckExact(__pyx_t_5))) {
              if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_5)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_9 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_14); __Pyx_INCREF(__pyx_t_9); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 635, __pyx_L3_error)
              #else
              __pyx_t_9 = PySequence_ITEM(__pyx_t_5, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 635, __pyx_L3_error)
              __Pyx_GOTREF(__pyx_t_9);
              #endif
            } else {
              if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_14); __Pyx_INCREF(__pyx_t_9); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 635, __pyx_L3_error)
              #else
              __pyx_t_9 = PySequence_ITEM(__pyx_t_5, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 635, __pyx_L3_error)
              __Pyx_GOTREF(__pyx_t_9);
              #endif
            }
          } else {
            __pyx_t_9 = __pyx_t_15(__pyx_t_5);
            if (unlikely(!__pyx_t_9)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else __PYX_ERR(0, 635, __pyx_L3_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_9);
          }
          __Pyx_XDECREF_SET(__pyx_v_term, __pyx_t_9);
          __pyx_t_9 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":636
 *             workset.setPhrasesSrcPvt.add(recSrcPvt.src)
 *             for term in recSrcPvt.srcTerms:
 *                 workset.setWordsSrcPvt.add(term)             # <<<<<<<<<<<<<<
 *             if src != lastSrc:
 *                 if len(rows) > 0:
 */
          __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_setWordsSrcPvt); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 636, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_add); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 636, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          __pyx_t_13 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
            __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_8);
            if (likely(__pyx_t_13)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
              __Pyx_INCREF(__pyx_t_13);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_8, function);
            }
          }
          if (!__pyx_t_13) {
            __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_v_term); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 636, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_9);
          } else {
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_8)) {
              PyObject *__pyx_temp[2] = {__pyx_t_13, __pyx_v_term};
              __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 636, __pyx_L3_error)
              __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
              __Pyx_GOTREF(__pyx_t_9);
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
              PyObject *__pyx_temp[2] = {__pyx_t_13, __pyx_v_term};
              __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 636, __pyx_L3_error)
              __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
              __Pyx_GOTREF(__pyx_t_9);
            } else
            #endif
            {
              __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 636, __pyx_L3_error)
              __Pyx_GOTREF(__pyx_t_4);
              __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_13); __pyx_t_13 = NULL;
              __Pyx_INCREF(__pyx_v_term);
              __Pyx_GIVEREF(__pyx_v_term);
              PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_term);
              __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_4, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 636, __pyx_L3_error)
              __Pyx_GOTREF(__pyx_t_9);
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            }
          }
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":635
 *             workset.numRecSrcPvt += 1
 *             workset.setPhrasesSrcPvt.add(recSrcPvt.src)
 *             for term in recSrcPvt.srcTerms:             # <<<<<<<<<<<<<<
 *                 workset.setWordsSrcPvt.add(term)
 *             if src != lastSrc:
 */
        }
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":637
 *             for term in recSrcPvt.srcTerms:
 *                 workset.setWordsSrcPvt.add(term)
 *             if src != lastSrc:             # <<<<<<<<<<<<<<
 *                 if len(rows) > 0:
 *                     pivotRecPairs(rows, workset)
 */
        __pyx_t_5 = PyObject_RichCompare(__pyx_v_src, __pyx_v_lastSrc, Py_NE); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 637, __pyx_L3_error)
        __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 637, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        if (__pyx_t_7) {

          /* "lpu/smt/trans_models/triangulate.pyx":638
 *                 workset.setWordsSrcPvt.add(term)
 *             if src != lastSrc:
 *                 if len(rows) > 0:             # <<<<<<<<<<<<<<
 *                     pivotRecPairs(rows, workset)
 *                     rows = []
 */
          __pyx_t_14 = PyList_GET_SIZE(__pyx_v_rows); if (unlikely(__pyx_t_14 == -1)) __PYX_ERR(0, 638, __pyx_L3_error)
          __pyx_t_7 = ((__pyx_t_14 > 0) != 0);
          if (__pyx_t_7) {

            /* "lpu/smt/trans_models/triangulate.pyx":639
 *             if src != lastSrc:
 *                 if len(rows) > 0:
 *                     pivotRecPairs(rows, workset)             # <<<<<<<<<<<<<<
 *                     rows = []
 *             #pvtKey = str.join(' ', recSrcPvt.trgSymbols)
 */
            __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_pivotRecPairs); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 639, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_9);
            __pyx_t_8 = NULL;
            __pyx_t_16 = 0;
            if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
              __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
              if (likely(__pyx_t_8)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
                __Pyx_INCREF(__pyx_t_8);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_9, function);
                __pyx_t_16 = 1;
              }
            }
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_9)) {
              PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_rows, __pyx_v_workset};
              __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 639, __pyx_L3_error)
              __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
              __Pyx_GOTREF(__pyx_t_5);
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
              PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_v_rows, __pyx_v_workset};
              __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 639, __pyx_L3_error)
              __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
              __Pyx_GOTREF(__pyx_t_5);
            } else
            #endif
            {
              __pyx_t_4 = PyTuple_New(2+__pyx_t_16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 639, __pyx_L3_error)
              __Pyx_GOTREF(__pyx_t_4);
              if (__pyx_t_8) {
                __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_8); __pyx_t_8 = NULL;
              }
              __Pyx_INCREF(__pyx_v_rows);
              __Pyx_GIVEREF(__pyx_v_rows);
              PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_16, __pyx_v_rows);
              __Pyx_INCREF(__pyx_v_workset);
              __Pyx_GIVEREF(__pyx_v_workset);
              PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_16, __pyx_v_workset);
              __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 639, __pyx_L3_error)
              __Pyx_GOTREF(__pyx_t_5);
              __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
            }
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

            /* "lpu/smt/trans_models/triangulate.pyx":640
 *                 if len(rows) > 0:
 *                     pivotRecPairs(rows, workset)
 *                     rows = []             # <<<<<<<<<<<<<<
 *             #pvtKey = str.join(' ', recSrcPvt.trgSymbols)
 *             #if key_type == 'src_hiero':
 */
            __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 640, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_DECREF_SET(__pyx_v_rows, ((PyObject*)__pyx_t_5));
            __pyx_t_5 = 0;

            /* "lpu/smt/trans_models/triangulate.pyx":638
 *                 workset.setWordsSrcPvt.add(term)
 *             if src != lastSrc:
 *                 if len(rows) > 0:             # <<<<<<<<<<<<<<
 *                     pivotRecPairs(rows, workset)
 *                     rows = []
 */
          }

          /* "lpu/smt/trans_models/triangulate.pyx":637
 *             for term in recSrcPvt.srcTerms:
 *                 workset.setWordsSrcPvt.add(term)
 *             if src != lastSrc:             # <<<<<<<<<<<<<<
 *                 if len(rows) > 0:
 *                     pivotRecPairs(rows, workset)
 */
        }

        /* "lpu/smt/trans_models/triangulate.pyx":649
 *             #for recPvtTrg in tablePvtTrg.find(pvtKey):
 *             #for recPvtTrg in tablePvtTrg.find_src(pvtKey):
 *             for recPvtTrg in tablePvtTrg.find_src(recSrcPvt.trg):             # <<<<<<<<<<<<<<
 *                 workset.numRecPvtTrg += 1
 *                 workset.setPhrasesPvtTrg.add(recPvtTrg.src)
 */
        __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_tablePvtTrg, __pyx_n_s_find_src); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 649, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_recSrcPvt, __pyx_n_s_trg); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 649, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_4);
        __pyx_t_8 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
          __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_9);
          if (likely(__pyx_t_8)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
            __Pyx_INCREF(__pyx_t_8);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_9, function);
          }
        }
        if (!__pyx_t_8) {
          __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 649, __pyx_L3_error)
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_GOTREF(__pyx_t_5);
        } else {
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_9)) {
            PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_4};
            __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 649, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
            PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_4};
            __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 649, __pyx_L3_error)
            __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          } else
          #endif
          {
            __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 649, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_13);
            __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_8); __pyx_t_8 = NULL;
            __Pyx_GIVEREF(__pyx_t_4);
            PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_t_4);
            __pyx_t_4 = 0;
            __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_13, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 649, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          }
        }
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        if (likely(PyList_CheckExact(__pyx_t_5)) || PyTuple_CheckExact(__pyx_t_5)) {
          __pyx_t_9 = __pyx_t_5; __Pyx_INCREF(__pyx_t_9); __pyx_t_14 = 0;
          __pyx_t_15 = NULL;
        } else {
          __pyx_t_14 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 649, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_9);
          __pyx_t_15 = Py_TYPE(__pyx_t_9)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 649, __pyx_L3_error)
        }
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        for (;;) {
          if (likely(!__pyx_t_15)) {
            if (likely(PyList_CheckExact(__pyx_t_9))) {
              if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_9)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_5 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_14); __Pyx_INCREF(__pyx_t_5); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 649, __pyx_L3_error)
              #else
              __pyx_t_5 = PySequence_ITEM(__pyx_t_9, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 649, __pyx_L3_error)
              __Pyx_GOTREF(__pyx_t_5);
              #endif
            } else {
              if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_9)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_14); __Pyx_INCREF(__pyx_t_5); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 649, __pyx_L3_error)
              #else
              __pyx_t_5 = PySequence_ITEM(__pyx_t_9, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 649, __pyx_L3_error)
              __Pyx_GOTREF(__pyx_t_5);
              #endif
            }
          } else {
            __pyx_t_5 = __pyx_t_15(__pyx_t_9);
            if (unlikely(!__pyx_t_5)) {
              PyObject* exc_type = PyErr_Occurred();
              if (exc_type) {
                if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                else __PYX_ERR(0, 649, __pyx_L3_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_5);
          }
          __Pyx_XDECREF_SET(__pyx_v_recPvtTrg, __pyx_t_5);
          __pyx_t_5 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":650
 *             #for recPvtTrg in tablePvtTrg.find_src(pvtKey):
 *             for recPvtTrg in tablePvtTrg.find_src(recSrcPvt.trg):
 *                 workset.numRecPvtTrg += 1             # <<<<<<<<<<<<<<
 *                 workset.setPhrasesPvtTrg.add(recPvtTrg.src)
 *                 for term in recPvtTrg.srcTerms:
 */
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_numRecPvtTrg); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 650, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_13 = __Pyx_PyInt_AddObjC(__pyx_t_5, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 650, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_13);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          if (__Pyx_PyObject_SetAttrStr(__pyx_v_workset, __pyx_n_s_numRecPvtTrg, __pyx_t_13) < 0) __PYX_ERR(0, 650, __pyx_L3_error)
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":651
 *             for recPvtTrg in tablePvtTrg.find_src(recSrcPvt.trg):
 *                 workset.numRecPvtTrg += 1
 *                 workset.setPhrasesPvtTrg.add(recPvtTrg.src)             # <<<<<<<<<<<<<<
 *                 for term in recPvtTrg.srcTerms:
 *                     workset.setWordsPvtTrg.add(term)
 */
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_setPhrasesPvtTrg); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 651, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_add); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 651, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
          __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_recPvtTrg, __pyx_n_s_src); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 651, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_5);
          __pyx_t_8 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
            __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_4);
            if (likely(__pyx_t_8)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
              __Pyx_INCREF(__pyx_t_8);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_4, function);
            }
          }
          if (!__pyx_t_8) {
            __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 651, __pyx_L3_error)
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_GOTREF(__pyx_t_13);
          } else {
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_4)) {
              PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_5};
              __pyx_t_13 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 651, __pyx_L3_error)
              __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
              __Pyx_GOTREF(__pyx_t_13);
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
              PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_5};
              __pyx_t_13 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 651, __pyx_L3_error)
              __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
              __Pyx_GOTREF(__pyx_t_13);
              __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            } else
            #endif
            {
              __pyx_t_17 = PyTuple_New(1+1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 651, __pyx_L3_error)
              __Pyx_GOTREF(__pyx_t_17);
              __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_8); __pyx_t_8 = NULL;
              __Pyx_GIVEREF(__pyx_t_5);
              PyTuple_SET_ITEM(__pyx_t_17, 0+1, __pyx_t_5);
              __pyx_t_5 = 0;
              __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_17, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 651, __pyx_L3_error)
              __Pyx_GOTREF(__pyx_t_13);
              __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
            }
          }
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":652
 *                 workset.numRecPvtTrg += 1
 *                 workset.setPhrasesPvtTrg.add(recPvtTrg.src)
 *                 for term in recPvtTrg.srcTerms:             # <<<<<<<<<<<<<<
 *                     workset.setWordsPvtTrg.add(term)
 *                 rows.append( (recSrcPvt, recPvtTrg) )
 */
          __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_recPvtTrg, __pyx_n_s_srcTerms); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 652, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_13);
          if (likely(PyList_CheckExact(__pyx_t_13)) || PyTuple_CheckExact(__pyx_t_13)) {
            __pyx_t_4 = __pyx_t_13; __Pyx_INCREF(__pyx_t_4); __pyx_t_18 = 0;
            __pyx_t_19 = NULL;
          } else {
            __pyx_t_18 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_13); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 652, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_4);
            __pyx_t_19 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 652, __pyx_L3_error)
          }
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          for (;;) {
            if (likely(!__pyx_t_19)) {
              if (likely(PyList_CheckExact(__pyx_t_4))) {
                if (__pyx_t_18 >= PyList_GET_SIZE(__pyx_t_4)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_13 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_18); __Pyx_INCREF(__pyx_t_13); __pyx_t_18++; if (unlikely(0 < 0)) __PYX_ERR(0, 652, __pyx_L3_error)
                #else
                __pyx_t_13 = PySequence_ITEM(__pyx_t_4, __pyx_t_18); __pyx_t_18++; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 652, __pyx_L3_error)
                __Pyx_GOTREF(__pyx_t_13);
                #endif
              } else {
                if (__pyx_t_18 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_13 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_18); __Pyx_INCREF(__pyx_t_13); __pyx_t_18++; if (unlikely(0 < 0)) __PYX_ERR(0, 652, __pyx_L3_error)
                #else
                __pyx_t_13 = PySequence_ITEM(__pyx_t_4, __pyx_t_18); __pyx_t_18++; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 652, __pyx_L3_error)
                __Pyx_GOTREF(__pyx_t_13);
                #endif
              }
            } else {
              __pyx_t_13 = __pyx_t_19(__pyx_t_4);
              if (unlikely(!__pyx_t_13)) {
                PyObject* exc_type = PyErr_Occurred();
                if (exc_type) {
                  if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                  else __PYX_ERR(0, 652, __pyx_L3_error)
                }
                break;
              }
              __Pyx_GOTREF(__pyx_t_13);
            }
            __Pyx_XDECREF_SET(__pyx_v_term, __pyx_t_13);
            __pyx_t_13 = 0;

            /* "lpu/smt/trans_models/triangulate.pyx":653
 *                 workset.setPhrasesPvtTrg.add(recPvtTrg.src)
 *                 for term in recPvtTrg.srcTerms:
 *                     workset.setWordsPvtTrg.add(term)             # <<<<<<<<<<<<<<
 *                 rows.append( (recSrcPvt, recPvtTrg) )
 *             lastSrc = src
 */
            __pyx_t_17 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_setWordsPvtTrg); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 653, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_17);
            __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_17, __pyx_n_s_add); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 653, __pyx_L3_error)
            __Pyx_GOTREF(__pyx_t_5);
            __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
            __pyx_t_17 = NULL;
            if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
              __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_5);
              if (likely(__pyx_t_17)) {
                PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
                __Pyx_INCREF(__pyx_t_17);
                __Pyx_INCREF(function);
                __Pyx_DECREF_SET(__pyx_t_5, function);
              }
            }
            if (!__pyx_t_17) {
              __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_term); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 653, __pyx_L3_error)
              __Pyx_GOTREF(__pyx_t_13);
            } else {
              #if CYTHON_FAST_PYCALL
              if (PyFunction_Check(__pyx_t_5)) {
                PyObject *__pyx_temp[2] = {__pyx_t_17, __pyx_v_term};
                __pyx_t_13 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 653, __pyx_L3_error)
                __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
                __Pyx_GOTREF(__pyx_t_13);
              } else
              #endif
              #if CYTHON_FAST_PYCCALL
              if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
                PyObject *__pyx_temp[2] = {__pyx_t_17, __pyx_v_term};
                __pyx_t_13 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 653, __pyx_L3_error)
                __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
                __Pyx_GOTREF(__pyx_t_13);
              } else
              #endif
              {
                __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 653, __pyx_L3_error)
                __Pyx_GOTREF(__pyx_t_8);
                __Pyx_GIVEREF(__pyx_t_17); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_17); __pyx_t_17 = NULL;
                __Pyx_INCREF(__pyx_v_term);
                __Pyx_GIVEREF(__pyx_v_term);
                PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_term);
                __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_8, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 653, __pyx_L3_error)
                __Pyx_GOTREF(__pyx_t_13);
                __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
              }
            }
            __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
            __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

            /* "lpu/smt/trans_models/triangulate.pyx":652
 *                 workset.numRecPvtTrg += 1
 *                 workset.setPhrasesPvtTrg.add(recPvtTrg.src)
 *                 for term in recPvtTrg.srcTerms:             # <<<<<<<<<<<<<<
 *                     workset.setWordsPvtTrg.add(term)
 *                 rows.append( (recSrcPvt, recPvtTrg) )
 */
          }
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":654
 *                 for term in recPvtTrg.srcTerms:
 *                     workset.setWordsPvtTrg.add(term)
 *                 rows.append( (recSrcPvt, recPvtTrg) )             # <<<<<<<<<<<<<<
 *             lastSrc = src
 *         if len(rows) > 0:
 */
          __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 654, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_INCREF(__pyx_v_recSrcPvt);
          __Pyx_GIVEREF(__pyx_v_recSrcPvt);
          PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_recSrcPvt);
          __Pyx_INCREF(__pyx_v_recPvtTrg);
          __Pyx_GIVEREF(__pyx_v_recPvtTrg);
          PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_recPvtTrg);
          __pyx_t_20 = __Pyx_PyList_Append(__pyx_v_rows, __pyx_t_4); if (unlikely(__pyx_t_20 == -1)) __PYX_ERR(0, 654, __pyx_L3_error)
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

          /* "lpu/smt/trans_models/triangulate.pyx":649
 *             #for recPvtTrg in tablePvtTrg.find(pvtKey):
 *             #for recPvtTrg in tablePvtTrg.find_src(pvtKey):
 *             for recPvtTrg in tablePvtTrg.find_src(recSrcPvt.trg):             # <<<<<<<<<<<<<<
 *                 workset.numRecPvtTrg += 1
 *                 workset.setPhrasesPvtTrg.add(recPvtTrg.src)
 */
        }
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":655
 *                     workset.setWordsPvtTrg.add(term)
 *                 rows.append( (recSrcPvt, recPvtTrg) )
 *             lastSrc = src             # <<<<<<<<<<<<<<
 *         if len(rows) > 0:
 *             pivotRecPairs(rows, workset)
 */
        __Pyx_INCREF(__pyx_v_src);
        __Pyx_DECREF_SET(__pyx_v_lastSrc, __pyx_v_src);

        /* "lpu/smt/trans_models/triangulate.pyx":631
 *         logging.log("beginning pivot\n")
 *         #for recSrcPvt in progress.view(tableSrcPvt.find(''),maxCount=len(tableSrcPvt)):
 *         for recSrcPvt in progress.view(tableSrcPvt.find(''),'processing',max_count=len(tableSrcPvt)):             # <<<<<<<<<<<<<<
 *             src = recSrcPvt.src
 *             workset.numRecSrcPvt += 1
 */
      }
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":656
 *                 rows.append( (recSrcPvt, recPvtTrg) )
 *             lastSrc = src
 *         if len(rows) > 0:             # <<<<<<<<<<<<<<
 *             pivotRecPairs(rows, workset)
 *             rows = []
 */
      __pyx_t_11 = PyList_GET_SIZE(__pyx_v_rows); if (unlikely(__pyx_t_11 == -1)) __PYX_ERR(0, 656, __pyx_L3_error)
      __pyx_t_7 = ((__pyx_t_11 > 0) != 0);
      if (__pyx_t_7) {

        /* "lpu/smt/trans_models/triangulate.pyx":657
 *             lastSrc = src
 *         if len(rows) > 0:
 *             pivotRecPairs(rows, workset)             # <<<<<<<<<<<<<<
 *             rows = []
 *         if logFile:
 */
        __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_pivotRecPairs); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 657, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_9);
        __pyx_t_4 = NULL;
        __pyx_t_16 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
          __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_9);
          if (likely(__pyx_t_4)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
            __Pyx_INCREF(__pyx_t_4);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_9, function);
            __pyx_t_16 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_9)) {
          PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_rows, __pyx_v_workset};
          __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 657, __pyx_L3_error)
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_GOTREF(__pyx_t_10);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
          PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_rows, __pyx_v_workset};
          __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_16, 2+__pyx_t_16); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 657, __pyx_L3_error)
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_GOTREF(__pyx_t_10);
        } else
        #endif
        {
          __pyx_t_13 = PyTuple_New(2+__pyx_t_16); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 657, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_13);
          if (__pyx_t_4) {
            __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_4); __pyx_t_4 = NULL;
          }
          __Pyx_INCREF(__pyx_v_rows);
          __Pyx_GIVEREF(__pyx_v_rows);
          PyTuple_SET_ITEM(__pyx_t_13, 0+__pyx_t_16, __pyx_v_rows);
          __Pyx_INCREF(__pyx_v_workset);
          __Pyx_GIVEREF(__pyx_v_workset);
          PyTuple_SET_ITEM(__pyx_t_13, 1+__pyx_t_16, __pyx_v_workset);
          __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_13, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 657, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
        }
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":658
 *         if len(rows) > 0:
 *             pivotRecPairs(rows, workset)
 *             rows = []             # <<<<<<<<<<<<<<
 *         if logFile:
 *             with open(logFile, 'w') as fobj:
 */
        __pyx_t_10 = PyList_New(0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 658, __pyx_L3_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF_SET(__pyx_v_rows, ((PyObject*)__pyx_t_10));
        __pyx_t_10 = 0;

        /* "lpu/smt/trans_models/triangulate.pyx":656
 *                 rows.append( (recSrcPvt, recPvtTrg) )
 *             lastSrc = src
 *         if len(rows) > 0:             # <<<<<<<<<<<<<<
 *             pivotRecPairs(rows, workset)
 *             rows = []
 */
      }

      /* "lpu/smt/trans_models/triangulate.pyx":659
 *             pivotRecPairs(rows, workset)
 *             rows = []
 *         if logFile:             # <<<<<<<<<<<<<<
 *             with open(logFile, 'w') as fobj:
 *                 fobj.write("%s = %s\n" % ('numRecSrcPvt', workset.numRecSrcPvt))
 */
      __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_v_logFile); if (unlikely(__pyx_t_7 < 0)) __PYX_ERR(0, 659, __pyx_L3_error)
      if (__pyx_t_7) {

        /* "lpu/smt/trans_models/triangulate.pyx":660
 *             rows = []
 *         if logFile:
 *             with open(logFile, 'w') as fobj:             # <<<<<<<<<<<<<<
 *                 fobj.write("%s = %s\n" % ('numRecSrcPvt', workset.numRecSrcPvt))
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesSrcPvt', len(workset.setPhrasesSrcPvt)))
 */
        /*with:*/ {
          __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 660, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_INCREF(__pyx_v_logFile);
          __Pyx_GIVEREF(__pyx_v_logFile);
          PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_logFile);
          __Pyx_INCREF(__pyx_n_s_w);
          __Pyx_GIVEREF(__pyx_n_s_w);
          PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_n_s_w);
          __pyx_t_9 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_10, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 660, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_9);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __pyx_t_21 = __Pyx_PyObject_LookupSpecial(__pyx_t_9, __pyx_n_s_exit); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 660, __pyx_L3_error)
          __Pyx_GOTREF(__pyx_t_21);
          __pyx_t_13 = __Pyx_PyObject_LookupSpecial(__pyx_t_9, __pyx_n_s_enter); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 660, __pyx_L26_error)
          __Pyx_GOTREF(__pyx_t_13);
          __pyx_t_4 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) {
            __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_13);
            if (likely(__pyx_t_4)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
              __Pyx_INCREF(__pyx_t_4);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_13, function);
            }
          }
          if (__pyx_t_4) {
            __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_4); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 660, __pyx_L26_error)
            __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          } else {
            __pyx_t_10 = __Pyx_PyObject_CallNoArg(__pyx_t_13); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 660, __pyx_L26_error)
          }
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
          __pyx_t_13 = __pyx_t_10;
          __pyx_t_10 = 0;
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          /*try:*/ {
            {
              __Pyx_PyThreadState_declare
              __Pyx_PyThreadState_assign
              __Pyx_ExceptionSave(&__pyx_t_22, &__pyx_t_23, &__pyx_t_24);
              __Pyx_XGOTREF(__pyx_t_22);
              __Pyx_XGOTREF(__pyx_t_23);
              __Pyx_XGOTREF(__pyx_t_24);
              /*try:*/ {
                __pyx_v_fobj = __pyx_t_13;
                __pyx_t_13 = 0;

                /* "lpu/smt/trans_models/triangulate.pyx":661
 *         if logFile:
 *             with open(logFile, 'w') as fobj:
 *                 fobj.write("%s = %s\n" % ('numRecSrcPvt', workset.numRecSrcPvt))             # <<<<<<<<<<<<<<
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesSrcPvt', len(workset.setPhrasesSrcPvt)))
 *                 fobj.write("%s = %s\n" % ('uniqWordsSrcPvt', len(workset.setWordsSrcPvt)))
 */
                __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_fobj, __pyx_n_s_write); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 661, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_9);
                __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_numRecSrcPvt); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 661, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_10);
                __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 661, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_4);
                __Pyx_INCREF(__pyx_n_s_numRecSrcPvt);
                __Pyx_GIVEREF(__pyx_n_s_numRecSrcPvt);
                PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_n_s_numRecSrcPvt);
                __Pyx_GIVEREF(__pyx_t_10);
                PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_10);
                __pyx_t_10 = 0;
                __pyx_t_10 = __Pyx_PyString_Format(__pyx_kp_s_s_s_2, __pyx_t_4); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 661, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_10);
                __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                __pyx_t_4 = NULL;
                if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
                  __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_9);
                  if (likely(__pyx_t_4)) {
                    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
                    __Pyx_INCREF(__pyx_t_4);
                    __Pyx_INCREF(function);
                    __Pyx_DECREF_SET(__pyx_t_9, function);
                  }
                }
                if (!__pyx_t_4) {
                  __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 661, __pyx_L30_error)
                  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
                  __Pyx_GOTREF(__pyx_t_13);
                } else {
                  #if CYTHON_FAST_PYCALL
                  if (PyFunction_Check(__pyx_t_9)) {
                    PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_10};
                    __pyx_t_13 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 661, __pyx_L30_error)
                    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
                    __Pyx_GOTREF(__pyx_t_13);
                    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
                  } else
                  #endif
                  #if CYTHON_FAST_PYCCALL
                  if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
                    PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_10};
                    __pyx_t_13 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 661, __pyx_L30_error)
                    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
                    __Pyx_GOTREF(__pyx_t_13);
                    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
                  } else
                  #endif
                  {
                    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 661, __pyx_L30_error)
                    __Pyx_GOTREF(__pyx_t_5);
                    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
                    __Pyx_GIVEREF(__pyx_t_10);
                    PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_10);
                    __pyx_t_10 = 0;
                    __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_5, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 661, __pyx_L30_error)
                    __Pyx_GOTREF(__pyx_t_13);
                    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                  }
                }
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
                __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

                /* "lpu/smt/trans_models/triangulate.pyx":662
 *             with open(logFile, 'w') as fobj:
 *                 fobj.write("%s = %s\n" % ('numRecSrcPvt', workset.numRecSrcPvt))
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesSrcPvt', len(workset.setPhrasesSrcPvt)))             # <<<<<<<<<<<<<<
 *                 fobj.write("%s = %s\n" % ('uniqWordsSrcPvt', len(workset.setWordsSrcPvt)))
 *                 fobj.write("--\n")
 */
                __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_fobj, __pyx_n_s_write); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 662, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_9);
                __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_setPhrasesSrcPvt); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 662, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_5);
                __pyx_t_11 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_11 == -1)) __PYX_ERR(0, 662, __pyx_L30_error)
                __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 662, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_5);
                __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 662, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_10);
                __Pyx_INCREF(__pyx_n_s_uniqPhrasesSrcPvt);
                __Pyx_GIVEREF(__pyx_n_s_uniqPhrasesSrcPvt);
                PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_n_s_uniqPhrasesSrcPvt);
                __Pyx_GIVEREF(__pyx_t_5);
                PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_5);
                __pyx_t_5 = 0;
                __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_s_s_2, __pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 662, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_5);
                __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
                __pyx_t_10 = NULL;
                if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
                  __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9);
                  if (likely(__pyx_t_10)) {
                    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
                    __Pyx_INCREF(__pyx_t_10);
                    __Pyx_INCREF(function);
                    __Pyx_DECREF_SET(__pyx_t_9, function);
                  }
                }
                if (!__pyx_t_10) {
                  __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_5); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 662, __pyx_L30_error)
                  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                  __Pyx_GOTREF(__pyx_t_13);
                } else {
                  #if CYTHON_FAST_PYCALL
                  if (PyFunction_Check(__pyx_t_9)) {
                    PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_5};
                    __pyx_t_13 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 662, __pyx_L30_error)
                    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
                    __Pyx_GOTREF(__pyx_t_13);
                    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                  } else
                  #endif
                  #if CYTHON_FAST_PYCCALL
                  if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
                    PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_5};
                    __pyx_t_13 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 662, __pyx_L30_error)
                    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
                    __Pyx_GOTREF(__pyx_t_13);
                    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                  } else
                  #endif
                  {
                    __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 662, __pyx_L30_error)
                    __Pyx_GOTREF(__pyx_t_4);
                    __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_10); __pyx_t_10 = NULL;
                    __Pyx_GIVEREF(__pyx_t_5);
                    PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_5);
                    __pyx_t_5 = 0;
                    __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_4, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 662, __pyx_L30_error)
                    __Pyx_GOTREF(__pyx_t_13);
                    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                  }
                }
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
                __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

                /* "lpu/smt/trans_models/triangulate.pyx":663
 *                 fobj.write("%s = %s\n" % ('numRecSrcPvt', workset.numRecSrcPvt))
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesSrcPvt', len(workset.setPhrasesSrcPvt)))
 *                 fobj.write("%s = %s\n" % ('uniqWordsSrcPvt', len(workset.setWordsSrcPvt)))             # <<<<<<<<<<<<<<
 *                 fobj.write("--\n")
 *                 fobj.write("%s = %s\n" % ('numRecPvtTrg', workset.numRecPvtTrg))
 */
                __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_fobj, __pyx_n_s_write); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 663, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_9);
                __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_setWordsSrcPvt); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 663, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_4);
                __pyx_t_11 = PyObject_Length(__pyx_t_4); if (unlikely(__pyx_t_11 == -1)) __PYX_ERR(0, 663, __pyx_L30_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_ERR(0, 663, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_4);
                __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 663, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_5);
                __Pyx_INCREF(__pyx_n_s_uniqWordsSrcPvt);
                __Pyx_GIVEREF(__pyx_n_s_uniqWordsSrcPvt);
                PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_n_s_uniqWordsSrcPvt);
                __Pyx_GIVEREF(__pyx_t_4);
                PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
                __pyx_t_4 = 0;
                __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_s_s_2, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 663, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_4);
                __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                __pyx_t_5 = NULL;
                if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
                  __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_9);
                  if (likely(__pyx_t_5)) {
                    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
                    __Pyx_INCREF(__pyx_t_5);
                    __Pyx_INCREF(function);
                    __Pyx_DECREF_SET(__pyx_t_9, function);
                  }
                }
                if (!__pyx_t_5) {
                  __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 663, __pyx_L30_error)
                  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                  __Pyx_GOTREF(__pyx_t_13);
                } else {
                  #if CYTHON_FAST_PYCALL
                  if (PyFunction_Check(__pyx_t_9)) {
                    PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4};
                    __pyx_t_13 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 663, __pyx_L30_error)
                    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
                    __Pyx_GOTREF(__pyx_t_13);
                    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                  } else
                  #endif
                  #if CYTHON_FAST_PYCCALL
                  if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
                    PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4};
                    __pyx_t_13 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 663, __pyx_L30_error)
                    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
                    __Pyx_GOTREF(__pyx_t_13);
                    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                  } else
                  #endif
                  {
                    __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 663, __pyx_L30_error)
                    __Pyx_GOTREF(__pyx_t_10);
                    __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_5); __pyx_t_5 = NULL;
                    __Pyx_GIVEREF(__pyx_t_4);
                    PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_4);
                    __pyx_t_4 = 0;
                    __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_10, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 663, __pyx_L30_error)
                    __Pyx_GOTREF(__pyx_t_13);
                    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
                  }
                }
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
                __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

                /* "lpu/smt/trans_models/triangulate.pyx":664
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesSrcPvt', len(workset.setPhrasesSrcPvt)))
 *                 fobj.write("%s = %s\n" % ('uniqWordsSrcPvt', len(workset.setWordsSrcPvt)))
 *                 fobj.write("--\n")             # <<<<<<<<<<<<<<
 *                 fobj.write("%s = %s\n" % ('numRecPvtTrg', workset.numRecPvtTrg))
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesPvtTrg', len(workset.setPhrasesPvtTrg)))
 */
                __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_fobj, __pyx_n_s_write); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 664, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_13);
                __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_tuple__29, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 664, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_9);
                __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

                /* "lpu/smt/trans_models/triangulate.pyx":665
 *                 fobj.write("%s = %s\n" % ('uniqWordsSrcPvt', len(workset.setWordsSrcPvt)))
 *                 fobj.write("--\n")
 *                 fobj.write("%s = %s\n" % ('numRecPvtTrg', workset.numRecPvtTrg))             # <<<<<<<<<<<<<<
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesPvtTrg', len(workset.setPhrasesPvtTrg)))
 *                 fobj.write("%s = %s\n" % ('uniqWordsPvtTrg', len(workset.setWordsPvtTrg)))
 */
                __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_fobj, __pyx_n_s_write); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 665, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_13);
                __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_numRecPvtTrg); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 665, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_10);
                __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 665, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_4);
                __Pyx_INCREF(__pyx_n_s_numRecPvtTrg);
                __Pyx_GIVEREF(__pyx_n_s_numRecPvtTrg);
                PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_n_s_numRecPvtTrg);
                __Pyx_GIVEREF(__pyx_t_10);
                PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_10);
                __pyx_t_10 = 0;
                __pyx_t_10 = __Pyx_PyString_Format(__pyx_kp_s_s_s_2, __pyx_t_4); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 665, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_10);
                __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                __pyx_t_4 = NULL;
                if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) {
                  __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_13);
                  if (likely(__pyx_t_4)) {
                    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
                    __Pyx_INCREF(__pyx_t_4);
                    __Pyx_INCREF(function);
                    __Pyx_DECREF_SET(__pyx_t_13, function);
                  }
                }
                if (!__pyx_t_4) {
                  __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 665, __pyx_L30_error)
                  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
                  __Pyx_GOTREF(__pyx_t_9);
                } else {
                  #if CYTHON_FAST_PYCALL
                  if (PyFunction_Check(__pyx_t_13)) {
                    PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_10};
                    __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_13, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 665, __pyx_L30_error)
                    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
                    __Pyx_GOTREF(__pyx_t_9);
                    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
                  } else
                  #endif
                  #if CYTHON_FAST_PYCCALL
                  if (__Pyx_PyFastCFunction_Check(__pyx_t_13)) {
                    PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_10};
                    __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_13, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 665, __pyx_L30_error)
                    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
                    __Pyx_GOTREF(__pyx_t_9);
                    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
                  } else
                  #endif
                  {
                    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 665, __pyx_L30_error)
                    __Pyx_GOTREF(__pyx_t_5);
                    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
                    __Pyx_GIVEREF(__pyx_t_10);
                    PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_10);
                    __pyx_t_10 = 0;
                    __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_5, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 665, __pyx_L30_error)
                    __Pyx_GOTREF(__pyx_t_9);
                    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                  }
                }
                __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

                /* "lpu/smt/trans_models/triangulate.pyx":666
 *                 fobj.write("--\n")
 *                 fobj.write("%s = %s\n" % ('numRecPvtTrg', workset.numRecPvtTrg))
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesPvtTrg', len(workset.setPhrasesPvtTrg)))             # <<<<<<<<<<<<<<
 *                 fobj.write("%s = %s\n" % ('uniqWordsPvtTrg', len(workset.setWordsPvtTrg)))
 *                 fobj.write("--\n")
 */
                __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_fobj, __pyx_n_s_write); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 666, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_13);
                __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_setPhrasesPvtTrg); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 666, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_5);
                __pyx_t_11 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_11 == -1)) __PYX_ERR(0, 666, __pyx_L30_error)
                __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 666, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_5);
                __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 666, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_10);
                __Pyx_INCREF(__pyx_n_s_uniqPhrasesPvtTrg);
                __Pyx_GIVEREF(__pyx_n_s_uniqPhrasesPvtTrg);
                PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_n_s_uniqPhrasesPvtTrg);
                __Pyx_GIVEREF(__pyx_t_5);
                PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_5);
                __pyx_t_5 = 0;
                __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_s_s_2, __pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 666, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_5);
                __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
                __pyx_t_10 = NULL;
                if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) {
                  __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_13);
                  if (likely(__pyx_t_10)) {
                    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
                    __Pyx_INCREF(__pyx_t_10);
                    __Pyx_INCREF(function);
                    __Pyx_DECREF_SET(__pyx_t_13, function);
                  }
                }
                if (!__pyx_t_10) {
                  __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_5); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 666, __pyx_L30_error)
                  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                  __Pyx_GOTREF(__pyx_t_9);
                } else {
                  #if CYTHON_FAST_PYCALL
                  if (PyFunction_Check(__pyx_t_13)) {
                    PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_5};
                    __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_13, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 666, __pyx_L30_error)
                    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
                    __Pyx_GOTREF(__pyx_t_9);
                    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                  } else
                  #endif
                  #if CYTHON_FAST_PYCCALL
                  if (__Pyx_PyFastCFunction_Check(__pyx_t_13)) {
                    PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_5};
                    __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_13, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 666, __pyx_L30_error)
                    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
                    __Pyx_GOTREF(__pyx_t_9);
                    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                  } else
                  #endif
                  {
                    __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 666, __pyx_L30_error)
                    __Pyx_GOTREF(__pyx_t_4);
                    __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_10); __pyx_t_10 = NULL;
                    __Pyx_GIVEREF(__pyx_t_5);
                    PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_5);
                    __pyx_t_5 = 0;
                    __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_4, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 666, __pyx_L30_error)
                    __Pyx_GOTREF(__pyx_t_9);
                    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                  }
                }
                __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

                /* "lpu/smt/trans_models/triangulate.pyx":667
 *                 fobj.write("%s = %s\n" % ('numRecPvtTrg', workset.numRecPvtTrg))
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesPvtTrg', len(workset.setPhrasesPvtTrg)))
 *                 fobj.write("%s = %s\n" % ('uniqWordsPvtTrg', len(workset.setWordsPvtTrg)))             # <<<<<<<<<<<<<<
 *                 fobj.write("--\n")
 *                 fobj.write("%s = %s\n" % ('numRecSrcTrg', workset.numRecSrcTrg))
 */
                __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_fobj, __pyx_n_s_write); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 667, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_13);
                __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_setWordsPvtTrg); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 667, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_4);
                __pyx_t_11 = PyObject_Length(__pyx_t_4); if (unlikely(__pyx_t_11 == -1)) __PYX_ERR(0, 667, __pyx_L30_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_ERR(0, 667, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_4);
                __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 667, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_5);
                __Pyx_INCREF(__pyx_n_s_uniqWordsPvtTrg);
                __Pyx_GIVEREF(__pyx_n_s_uniqWordsPvtTrg);
                PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_n_s_uniqWordsPvtTrg);
                __Pyx_GIVEREF(__pyx_t_4);
                PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
                __pyx_t_4 = 0;
                __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_s_s_2, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 667, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_4);
                __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                __pyx_t_5 = NULL;
                if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) {
                  __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_13);
                  if (likely(__pyx_t_5)) {
                    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
                    __Pyx_INCREF(__pyx_t_5);
                    __Pyx_INCREF(function);
                    __Pyx_DECREF_SET(__pyx_t_13, function);
                  }
                }
                if (!__pyx_t_5) {
                  __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 667, __pyx_L30_error)
                  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                  __Pyx_GOTREF(__pyx_t_9);
                } else {
                  #if CYTHON_FAST_PYCALL
                  if (PyFunction_Check(__pyx_t_13)) {
                    PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4};
                    __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_13, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 667, __pyx_L30_error)
                    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
                    __Pyx_GOTREF(__pyx_t_9);
                    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                  } else
                  #endif
                  #if CYTHON_FAST_PYCCALL
                  if (__Pyx_PyFastCFunction_Check(__pyx_t_13)) {
                    PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4};
                    __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_13, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 667, __pyx_L30_error)
                    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
                    __Pyx_GOTREF(__pyx_t_9);
                    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                  } else
                  #endif
                  {
                    __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 667, __pyx_L30_error)
                    __Pyx_GOTREF(__pyx_t_10);
                    __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_5); __pyx_t_5 = NULL;
                    __Pyx_GIVEREF(__pyx_t_4);
                    PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_4);
                    __pyx_t_4 = 0;
                    __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_10, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 667, __pyx_L30_error)
                    __Pyx_GOTREF(__pyx_t_9);
                    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
                  }
                }
                __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

                /* "lpu/smt/trans_models/triangulate.pyx":668
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesPvtTrg', len(workset.setPhrasesPvtTrg)))
 *                 fobj.write("%s = %s\n" % ('uniqWordsPvtTrg', len(workset.setWordsPvtTrg)))
 *                 fobj.write("--\n")             # <<<<<<<<<<<<<<
 *                 fobj.write("%s = %s\n" % ('numRecSrcTrg', workset.numRecSrcTrg))
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesSrcTrg', len(workset.setPhrasesSrcTrg)))
 */
                __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_fobj, __pyx_n_s_write); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 668, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_9);
                __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__30, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 668, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_13);
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
                __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

                /* "lpu/smt/trans_models/triangulate.pyx":669
 *                 fobj.write("%s = %s\n" % ('uniqWordsPvtTrg', len(workset.setWordsPvtTrg)))
 *                 fobj.write("--\n")
 *                 fobj.write("%s = %s\n" % ('numRecSrcTrg', workset.numRecSrcTrg))             # <<<<<<<<<<<<<<
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesSrcTrg', len(workset.setPhrasesSrcTrg)))
 *                 fobj.write("%s = %s\n" % ('uniqWordsSrcTrg', len(workset.setWordsSrcTrg)))
 */
                __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_fobj, __pyx_n_s_write); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 669, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_9);
                __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_numRecSrcTrg); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 669, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_10);
                __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 669, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_4);
                __Pyx_INCREF(__pyx_n_s_numRecSrcTrg);
                __Pyx_GIVEREF(__pyx_n_s_numRecSrcTrg);
                PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_n_s_numRecSrcTrg);
                __Pyx_GIVEREF(__pyx_t_10);
                PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_10);
                __pyx_t_10 = 0;
                __pyx_t_10 = __Pyx_PyString_Format(__pyx_kp_s_s_s_2, __pyx_t_4); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 669, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_10);
                __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                __pyx_t_4 = NULL;
                if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
                  __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_9);
                  if (likely(__pyx_t_4)) {
                    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
                    __Pyx_INCREF(__pyx_t_4);
                    __Pyx_INCREF(function);
                    __Pyx_DECREF_SET(__pyx_t_9, function);
                  }
                }
                if (!__pyx_t_4) {
                  __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 669, __pyx_L30_error)
                  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
                  __Pyx_GOTREF(__pyx_t_13);
                } else {
                  #if CYTHON_FAST_PYCALL
                  if (PyFunction_Check(__pyx_t_9)) {
                    PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_10};
                    __pyx_t_13 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 669, __pyx_L30_error)
                    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
                    __Pyx_GOTREF(__pyx_t_13);
                    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
                  } else
                  #endif
                  #if CYTHON_FAST_PYCCALL
                  if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
                    PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_10};
                    __pyx_t_13 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 669, __pyx_L30_error)
                    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
                    __Pyx_GOTREF(__pyx_t_13);
                    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
                  } else
                  #endif
                  {
                    __pyx_t_5 = PyTuple_New(1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 669, __pyx_L30_error)
                    __Pyx_GOTREF(__pyx_t_5);
                    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
                    __Pyx_GIVEREF(__pyx_t_10);
                    PyTuple_SET_ITEM(__pyx_t_5, 0+1, __pyx_t_10);
                    __pyx_t_10 = 0;
                    __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_5, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 669, __pyx_L30_error)
                    __Pyx_GOTREF(__pyx_t_13);
                    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                  }
                }
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
                __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

                /* "lpu/smt/trans_models/triangulate.pyx":670
 *                 fobj.write("--\n")
 *                 fobj.write("%s = %s\n" % ('numRecSrcTrg', workset.numRecSrcTrg))
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesSrcTrg', len(workset.setPhrasesSrcTrg)))             # <<<<<<<<<<<<<<
 *                 fobj.write("%s = %s\n" % ('uniqWordsSrcTrg', len(workset.setWordsSrcTrg)))
 *                 fobj.write("--\n")
 */
                __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_fobj, __pyx_n_s_write); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 670, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_9);
                __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_setPhrasesSrcTrg); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 670, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_5);
                __pyx_t_11 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_11 == -1)) __PYX_ERR(0, 670, __pyx_L30_error)
                __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                __pyx_t_5 = PyInt_FromSsize_t(__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 670, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_5);
                __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 670, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_10);
                __Pyx_INCREF(__pyx_n_s_uniqPhrasesSrcTrg);
                __Pyx_GIVEREF(__pyx_n_s_uniqPhrasesSrcTrg);
                PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_n_s_uniqPhrasesSrcTrg);
                __Pyx_GIVEREF(__pyx_t_5);
                PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_5);
                __pyx_t_5 = 0;
                __pyx_t_5 = __Pyx_PyString_Format(__pyx_kp_s_s_s_2, __pyx_t_10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 670, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_5);
                __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
                __pyx_t_10 = NULL;
                if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
                  __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9);
                  if (likely(__pyx_t_10)) {
                    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
                    __Pyx_INCREF(__pyx_t_10);
                    __Pyx_INCREF(function);
                    __Pyx_DECREF_SET(__pyx_t_9, function);
                  }
                }
                if (!__pyx_t_10) {
                  __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_5); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 670, __pyx_L30_error)
                  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                  __Pyx_GOTREF(__pyx_t_13);
                } else {
                  #if CYTHON_FAST_PYCALL
                  if (PyFunction_Check(__pyx_t_9)) {
                    PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_5};
                    __pyx_t_13 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 670, __pyx_L30_error)
                    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
                    __Pyx_GOTREF(__pyx_t_13);
                    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                  } else
                  #endif
                  #if CYTHON_FAST_PYCCALL
                  if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
                    PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_5};
                    __pyx_t_13 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 670, __pyx_L30_error)
                    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
                    __Pyx_GOTREF(__pyx_t_13);
                    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                  } else
                  #endif
                  {
                    __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 670, __pyx_L30_error)
                    __Pyx_GOTREF(__pyx_t_4);
                    __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_10); __pyx_t_10 = NULL;
                    __Pyx_GIVEREF(__pyx_t_5);
                    PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_t_5);
                    __pyx_t_5 = 0;
                    __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_4, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 670, __pyx_L30_error)
                    __Pyx_GOTREF(__pyx_t_13);
                    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                  }
                }
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
                __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

                /* "lpu/smt/trans_models/triangulate.pyx":671
 *                 fobj.write("%s = %s\n" % ('numRecSrcTrg', workset.numRecSrcTrg))
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesSrcTrg', len(workset.setPhrasesSrcTrg)))
 *                 fobj.write("%s = %s\n" % ('uniqWordsSrcTrg', len(workset.setWordsSrcTrg)))             # <<<<<<<<<<<<<<
 *                 fobj.write("--\n")
 *                 if len(workset.setWordsSrcPvt) != len(workset.setWordsSrcTrg):
 */
                __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_fobj, __pyx_n_s_write); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 671, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_9);
                __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_setWordsSrcTrg); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 671, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_4);
                __pyx_t_11 = PyObject_Length(__pyx_t_4); if (unlikely(__pyx_t_11 == -1)) __PYX_ERR(0, 671, __pyx_L30_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_ERR(0, 671, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_4);
                __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 671, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_5);
                __Pyx_INCREF(__pyx_n_s_uniqWordsSrcTrg);
                __Pyx_GIVEREF(__pyx_n_s_uniqWordsSrcTrg);
                PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_n_s_uniqWordsSrcTrg);
                __Pyx_GIVEREF(__pyx_t_4);
                PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
                __pyx_t_4 = 0;
                __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_s_s_2, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 671, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_4);
                __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
                __pyx_t_5 = NULL;
                if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
                  __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_9);
                  if (likely(__pyx_t_5)) {
                    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
                    __Pyx_INCREF(__pyx_t_5);
                    __Pyx_INCREF(function);
                    __Pyx_DECREF_SET(__pyx_t_9, function);
                  }
                }
                if (!__pyx_t_5) {
                  __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_4); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 671, __pyx_L30_error)
                  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                  __Pyx_GOTREF(__pyx_t_13);
                } else {
                  #if CYTHON_FAST_PYCALL
                  if (PyFunction_Check(__pyx_t_9)) {
                    PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4};
                    __pyx_t_13 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 671, __pyx_L30_error)
                    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
                    __Pyx_GOTREF(__pyx_t_13);
                    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                  } else
                  #endif
                  #if CYTHON_FAST_PYCCALL
                  if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
                    PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4};
                    __pyx_t_13 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 671, __pyx_L30_error)
                    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
                    __Pyx_GOTREF(__pyx_t_13);
                    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                  } else
                  #endif
                  {
                    __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 671, __pyx_L30_error)
                    __Pyx_GOTREF(__pyx_t_10);
                    __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_5); __pyx_t_5 = NULL;
                    __Pyx_GIVEREF(__pyx_t_4);
                    PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_4);
                    __pyx_t_4 = 0;
                    __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_10, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 671, __pyx_L30_error)
                    __Pyx_GOTREF(__pyx_t_13);
                    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
                  }
                }
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
                __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

                /* "lpu/smt/trans_models/triangulate.pyx":672
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesSrcTrg', len(workset.setPhrasesSrcTrg)))
 *                 fobj.write("%s = %s\n" % ('uniqWordsSrcTrg', len(workset.setWordsSrcTrg)))
 *                 fobj.write("--\n")             # <<<<<<<<<<<<<<
 *                 if len(workset.setWordsSrcPvt) != len(workset.setWordsSrcTrg):
 *                     fobj.write("Lost Words:\n")
 */
                __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_fobj, __pyx_n_s_write); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 672, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_13);
                __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_tuple__31, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 672, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_9);
                __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

                /* "lpu/smt/trans_models/triangulate.pyx":673
 *                 fobj.write("%s = %s\n" % ('uniqWordsSrcTrg', len(workset.setWordsSrcTrg)))
 *                 fobj.write("--\n")
 *                 if len(workset.setWordsSrcPvt) != len(workset.setWordsSrcTrg):             # <<<<<<<<<<<<<<
 *                     fobj.write("Lost Words:\n")
 *                     for word in iter(workset.setWordsSrcPvt - workset.setWordsSrcTrg):
 */
                __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_setWordsSrcPvt); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 673, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_9);
                __pyx_t_11 = PyObject_Length(__pyx_t_9); if (unlikely(__pyx_t_11 == -1)) __PYX_ERR(0, 673, __pyx_L30_error)
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
                __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_setWordsSrcTrg); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 673, __pyx_L30_error)
                __Pyx_GOTREF(__pyx_t_9);
                __pyx_t_14 = PyObject_Length(__pyx_t_9); if (unlikely(__pyx_t_14 == -1)) __PYX_ERR(0, 673, __pyx_L30_error)
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
                __pyx_t_7 = ((__pyx_t_11 != __pyx_t_14) != 0);
                if (__pyx_t_7) {

                  /* "lpu/smt/trans_models/triangulate.pyx":674
 *                 fobj.write("--\n")
 *                 if len(workset.setWordsSrcPvt) != len(workset.setWordsSrcTrg):
 *                     fobj.write("Lost Words:\n")             # <<<<<<<<<<<<<<
 *                     for word in iter(workset.setWordsSrcPvt - workset.setWordsSrcTrg):
 *                         fobj.write("\t* \"%s\"\n" % word)
 */
                  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_fobj, __pyx_n_s_write); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 674, __pyx_L30_error)
                  __Pyx_GOTREF(__pyx_t_9);
                  __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__32, NULL); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 674, __pyx_L30_error)
                  __Pyx_GOTREF(__pyx_t_13);
                  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
                  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

                  /* "lpu/smt/trans_models/triangulate.pyx":675
 *                 if len(workset.setWordsSrcPvt) != len(workset.setWordsSrcTrg):
 *                     fobj.write("Lost Words:\n")
 *                     for word in iter(workset.setWordsSrcPvt - workset.setWordsSrcTrg):             # <<<<<<<<<<<<<<
 *                         fobj.write("\t* \"%s\"\n" % word)
 *         workset.close()
 */
                  __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_setWordsSrcPvt); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 675, __pyx_L30_error)
                  __Pyx_GOTREF(__pyx_t_13);
                  __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_setWordsSrcTrg); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 675, __pyx_L30_error)
                  __Pyx_GOTREF(__pyx_t_9);
                  __pyx_t_10 = PyNumber_Subtract(__pyx_t_13, __pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 675, __pyx_L30_error)
                  __Pyx_GOTREF(__pyx_t_10);
                  __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
                  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
                  __pyx_t_9 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 675, __pyx_L30_error)
                  __Pyx_GOTREF(__pyx_t_9);
                  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
                  if (likely(PyList_CheckExact(__pyx_t_9)) || PyTuple_CheckExact(__pyx_t_9)) {
                    __pyx_t_10 = __pyx_t_9; __Pyx_INCREF(__pyx_t_10); __pyx_t_14 = 0;
                    __pyx_t_12 = NULL;
                  } else {
                    __pyx_t_14 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 675, __pyx_L30_error)
                    __Pyx_GOTREF(__pyx_t_10);
                    __pyx_t_12 = Py_TYPE(__pyx_t_10)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 675, __pyx_L30_error)
                  }
                  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
                  for (;;) {
                    if (likely(!__pyx_t_12)) {
                      if (likely(PyList_CheckExact(__pyx_t_10))) {
                        if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_10)) break;
                        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                        __pyx_t_9 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_14); __Pyx_INCREF(__pyx_t_9); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 675, __pyx_L30_error)
                        #else
                        __pyx_t_9 = PySequence_ITEM(__pyx_t_10, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 675, __pyx_L30_error)
                        __Pyx_GOTREF(__pyx_t_9);
                        #endif
                      } else {
                        if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_10)) break;
                        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                        __pyx_t_9 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_14); __Pyx_INCREF(__pyx_t_9); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 675, __pyx_L30_error)
                        #else
                        __pyx_t_9 = PySequence_ITEM(__pyx_t_10, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 675, __pyx_L30_error)
                        __Pyx_GOTREF(__pyx_t_9);
                        #endif
                      }
                    } else {
                      __pyx_t_9 = __pyx_t_12(__pyx_t_10);
                      if (unlikely(!__pyx_t_9)) {
                        PyObject* exc_type = PyErr_Occurred();
                        if (exc_type) {
                          if (likely(exc_type == PyExc_StopIteration || PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear();
                          else __PYX_ERR(0, 675, __pyx_L30_error)
                        }
                        break;
                      }
                      __Pyx_GOTREF(__pyx_t_9);
                    }
                    __Pyx_XDECREF_SET(__pyx_v_word, __pyx_t_9);
                    __pyx_t_9 = 0;

                    /* "lpu/smt/trans_models/triangulate.pyx":676
 *                     fobj.write("Lost Words:\n")
 *                     for word in iter(workset.setWordsSrcPvt - workset.setWordsSrcTrg):
 *                         fobj.write("\t* \"%s\"\n" % word)             # <<<<<<<<<<<<<<
 *         workset.close()
 * #        # loading necessary word pair count files
 */
                    __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_fobj, __pyx_n_s_write); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 676, __pyx_L30_error)
                    __Pyx_GOTREF(__pyx_t_13);
                    __pyx_t_4 = __Pyx_PyString_Format(__pyx_kp_s_s, __pyx_v_word); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 676, __pyx_L30_error)
                    __Pyx_GOTREF(__pyx_t_4);
                    __pyx_t_5 = NULL;
                    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_13))) {
                      __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_13);
                      if (likely(__pyx_t_5)) {
                        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
                        __Pyx_INCREF(__pyx_t_5);
                        __Pyx_INCREF(function);
                        __Pyx_DECREF_SET(__pyx_t_13, function);
                      }
                    }
                    if (!__pyx_t_5) {
                      __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 676, __pyx_L30_error)
                      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                      __Pyx_GOTREF(__pyx_t_9);
                    } else {
                      #if CYTHON_FAST_PYCALL
                      if (PyFunction_Check(__pyx_t_13)) {
                        PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4};
                        __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_13, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 676, __pyx_L30_error)
                        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
                        __Pyx_GOTREF(__pyx_t_9);
                        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                      } else
                      #endif
                      #if CYTHON_FAST_PYCCALL
                      if (__Pyx_PyFastCFunction_Check(__pyx_t_13)) {
                        PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_4};
                        __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_13, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 676, __pyx_L30_error)
                        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
                        __Pyx_GOTREF(__pyx_t_9);
                        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
                      } else
                      #endif
                      {
                        __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 676, __pyx_L30_error)
                        __Pyx_GOTREF(__pyx_t_8);
                        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5); __pyx_t_5 = NULL;
                        __Pyx_GIVEREF(__pyx_t_4);
                        PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_t_4);
                        __pyx_t_4 = 0;
                        __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_8, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 676, __pyx_L30_error)
                        __Pyx_GOTREF(__pyx_t_9);
                        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
                      }
                    }
                    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
                    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

                    /* "lpu/smt/trans_models/triangulate.pyx":675
 *                 if len(workset.setWordsSrcPvt) != len(workset.setWordsSrcTrg):
 *                     fobj.write("Lost Words:\n")
 *                     for word in iter(workset.setWordsSrcPvt - workset.setWordsSrcTrg):             # <<<<<<<<<<<<<<
 *                         fobj.write("\t* \"%s\"\n" % word)
 *         workset.close()
 */
                  }
                  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

                  /* "lpu/smt/trans_models/triangulate.pyx":673
 *                 fobj.write("%s = %s\n" % ('uniqWordsSrcTrg', len(workset.setWordsSrcTrg)))
 *                 fobj.write("--\n")
 *                 if len(workset.setWordsSrcPvt) != len(workset.setWordsSrcTrg):             # <<<<<<<<<<<<<<
 *                     fobj.write("Lost Words:\n")
 *                     for word in iter(workset.setWordsSrcPvt - workset.setWordsSrcTrg):
 */
                }

                /* "lpu/smt/trans_models/triangulate.pyx":660
 *             rows = []
 *         if logFile:
 *             with open(logFile, 'w') as fobj:             # <<<<<<<<<<<<<<
 *                 fobj.write("%s = %s\n" % ('numRecSrcPvt', workset.numRecSrcPvt))
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesSrcPvt', len(workset.setPhrasesSrcPvt)))
 */
              }
              __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0;
              __Pyx_XDECREF(__pyx_t_23); __pyx_t_23 = 0;
              __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0;
              goto __pyx_L35_try_end;
              __pyx_L30_error:;
              __Pyx_PyThreadState_assign
              __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
              __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
              __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
              __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
              __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
              __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
              __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
              /*except:*/ {
                __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.pivot", __pyx_clineno, __pyx_lineno, __pyx_filename);
                if (__Pyx_GetException(&__pyx_t_10, &__pyx_t_9, &__pyx_t_13) < 0) __PYX_ERR(0, 660, __pyx_L32_except_error)
                __Pyx_GOTREF(__pyx_t_10);
                __Pyx_GOTREF(__pyx_t_9);
                __Pyx_GOTREF(__pyx_t_13);
                __pyx_t_8 = PyTuple_Pack(3, __pyx_t_10, __pyx_t_9, __pyx_t_13); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 660, __pyx_L32_except_error)
                __Pyx_GOTREF(__pyx_t_8);
                __pyx_t_25 = __Pyx_PyObject_Call(__pyx_t_21, __pyx_t_8, NULL);
                __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
                __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
                if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 660, __pyx_L32_except_error)
                __Pyx_GOTREF(__pyx_t_25);
                __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_25);
                __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0;
                if (__pyx_t_7 < 0) __PYX_ERR(0, 660, __pyx_L32_except_error)
                __pyx_t_6 = ((!(__pyx_t_7 != 0)) != 0);
                if (__pyx_t_6) {
                  __Pyx_GIVEREF(__pyx_t_10);
                  __Pyx_GIVEREF(__pyx_t_9);
                  __Pyx_XGIVEREF(__pyx_t_13);
                  __Pyx_ErrRestoreWithState(__pyx_t_10, __pyx_t_9, __pyx_t_13);
                  __pyx_t_10 = 0; __pyx_t_9 = 0; __pyx_t_13 = 0; 
                  __PYX_ERR(0, 660, __pyx_L32_except_error)
                }
                __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
                __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
                __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
                goto __pyx_L31_exception_handled;
              }
              __pyx_L32_except_error:;
              __Pyx_PyThreadState_assign
              __Pyx_XGIVEREF(__pyx_t_22);
              __Pyx_XGIVEREF(__pyx_t_23);
              __Pyx_XGIVEREF(__pyx_t_24);
              __Pyx_ExceptionReset(__pyx_t_22, __pyx_t_23, __pyx_t_24);
              goto __pyx_L3_error;
              __pyx_L31_exception_handled:;
              __Pyx_PyThreadState_assign
              __Pyx_XGIVEREF(__pyx_t_22);
              __Pyx_XGIVEREF(__pyx_t_23);
              __Pyx_XGIVEREF(__pyx_t_24);
              __Pyx_ExceptionReset(__pyx_t_22, __pyx_t_23, __pyx_t_24);
              __pyx_L35_try_end:;
            }
          }
          /*finally:*/ {
            /*normal exit:*/{
              if (__pyx_t_21) {
                __pyx_t_24 = __Pyx_PyObject_Call(__pyx_t_21, __pyx_tuple__33, NULL);
                __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
                if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 660, __pyx_L3_error)
                __Pyx_GOTREF(__pyx_t_24);
                __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0;
              }
              goto __pyx_L29;
            }
            __pyx_L29:;
          }
          goto __pyx_L42;
          __pyx_L26_error:;
          __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
          goto __pyx_L3_error;
          __pyx_L42:;
        }

        /* "lpu/smt/trans_models/triangulate.pyx":659
 *             pivotRecPairs(rows, workset)
 *             rows = []
 *         if logFile:             # <<<<<<<<<<<<<<
 *             with open(logFile, 'w') as fobj:
 *                 fobj.write("%s = %s\n" % ('numRecSrcPvt', workset.numRecSrcPvt))
 */
      }

      /* "lpu/smt/trans_models/triangulate.pyx":677
 *                     for word in iter(workset.setWordsSrcPvt - workset.setWordsSrcTrg):
 *                         fobj.write("\t* \"%s\"\n" % word)
 *         workset.close()             # <<<<<<<<<<<<<<
 * #        # loading necessary word pair count files
 * #        if lexMethod != 'prodweight':
 */
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_close); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 677, __pyx_L3_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_10 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_9))) {
        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_9);
        if (likely(__pyx_t_10)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
          __Pyx_INCREF(__pyx_t_10);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_9, function);
        }
      }
      if (__pyx_t_10) {
        __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 677, __pyx_L3_error)
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      } else {
        __pyx_t_13 = __Pyx_PyObject_CallNoArg(__pyx_t_9); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 677, __pyx_L3_error)
      }
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":586
 * def pivot(table1, table2, savefile="phrase-table.gz", workdir=".", **options):
 *     '''find pair of source-pivot and pivot-target records for common pivot phrase'''
 *     try:             # <<<<<<<<<<<<<<
 *         # initialize the options
 *         RecordClass = options.get('RecordClass', MosesRecord)
 */
    }
    __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;
    goto __pyx_L8_try_end;
    __pyx_L3_error:;
    __Pyx_PyThreadState_assign
    __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;

    /* "lpu/smt/trans_models/triangulate.pyx":744
 * #        else:
 * #            assert False, "Invalid method: %s" % method
 *     except KeyboardInterrupt:             # <<<<<<<<<<<<<<
 *         # catching exception, finish all the workset processes
 *         print('')
 */
    __pyx_t_16 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyboardInterrupt);
    if (__pyx_t_16) {
      __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.pivot", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_13, &__pyx_t_9, &__pyx_t_10) < 0) __PYX_ERR(0, 744, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_GOTREF(__pyx_t_10);

      /* "lpu/smt/trans_models/triangulate.pyx":746
 *     except KeyboardInterrupt:
 *         # catching exception, finish all the workset processes
 *         print('')             # <<<<<<<<<<<<<<
 *         print('Caught KeyboardInterrupt, terminating all the worker processes')
 *         workset.close()
 */
      if (__Pyx_PrintOne(0, __pyx_kp_s__16) < 0) __PYX_ERR(0, 746, __pyx_L5_except_error)

      /* "lpu/smt/trans_models/triangulate.pyx":747
 *         # catching exception, finish all the workset processes
 *         print('')
 *         print('Caught KeyboardInterrupt, terminating all the worker processes')             # <<<<<<<<<<<<<<
 *         workset.close()
 *         sys.exit(1)
 */
      if (__Pyx_PrintOne(0, __pyx_kp_s_Caught_KeyboardInterrupt_termina) < 0) __PYX_ERR(0, 747, __pyx_L5_except_error)

      /* "lpu/smt/trans_models/triangulate.pyx":748
 *         print('')
 *         print('Caught KeyboardInterrupt, terminating all the worker processes')
 *         workset.close()             # <<<<<<<<<<<<<<
 *         sys.exit(1)
 * 
 */
      if (unlikely(!__pyx_v_workset)) { __Pyx_RaiseUnboundLocalError("workset"); __PYX_ERR(0, 748, __pyx_L5_except_error) }
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_workset, __pyx_n_s_close); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 748, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_5)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_5);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
        }
      }
      if (__pyx_t_5) {
        __pyx_t_8 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 748, __pyx_L5_except_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      } else {
        __pyx_t_8 = __Pyx_PyObject_CallNoArg(__pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 748, __pyx_L5_except_error)
      }
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

      /* "lpu/smt/trans_models/triangulate.pyx":749
 *         print('Caught KeyboardInterrupt, terminating all the worker processes')
 *         workset.close()
 *         sys.exit(1)             # <<<<<<<<<<<<<<
 * 
 * def main():
 */
      __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_sys); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 749, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_exit_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 749, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__34, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 749, __pyx_L5_except_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      goto __pyx_L4_exception_handled;
    }
    goto __pyx_L5_except_error;
    __pyx_L5_except_error:;

    /* "lpu/smt/trans_models/triangulate.pyx":586
 * def pivot(table1, table2, savefile="phrase-table.gz", workdir=".", **options):
 *     '''find pair of source-pivot and pivot-target records for common pivot phrase'''
 *     try:             # <<<<<<<<<<<<<<
 *         # initialize the options
 *         RecordClass = options.get('RecordClass', MosesRecord)
 */
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    goto __pyx_L1_error;
    __pyx_L4_exception_handled:;
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_1);
    __Pyx_XGIVEREF(__pyx_t_2);
    __Pyx_XGIVEREF(__pyx_t_3);
    __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3);
    __pyx_L8_try_end:;
  }

  /* "lpu/smt/trans_models/triangulate.pyx":584
 * 
 * 
 * def pivot(table1, table2, savefile="phrase-table.gz", workdir=".", **options):             # <<<<<<<<<<<<<<
 *     '''find pair of source-pivot and pivot-target records for common pivot phrase'''
 *     try:
 */

  /* function exit code */
  __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_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_13);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_AddTraceback("lpu.smt.trans_models.triangulate.pivot", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_RecordClass);
  __Pyx_XDECREF(__pyx_v_prefix);
  __Pyx_XDECREF(__pyx_v_threshold);
  __Pyx_XDECREF(__pyx_v_alignLexPath);
  __Pyx_XDECREF(__pyx_v_nbest);
  __Pyx_XDECREF(__pyx_v_method);
  __Pyx_XDECREF(__pyx_v_lexMethod);
  __Pyx_XDECREF(__pyx_v_jointMethod);
  __Pyx_XDECREF(__pyx_v_matchMethod);
  __Pyx_XDECREF(__pyx_v_numNulls);
  __Pyx_XDECREF(__pyx_v_multi_target);
  __Pyx_XDECREF(__pyx_v_logFile);
  __Pyx_XDECREF(__pyx_v_showProgress);
  __Pyx_XDECREF(__pyx_v_key_type);
  __Pyx_XDECREF(__pyx_v_tableSrcPvt);
  __Pyx_XDECREF(__pyx_v_tablePvtTrg);
  __Pyx_XDECREF(__pyx_v_workOptions);
  __Pyx_XDECREF(__pyx_v_workset);
  __Pyx_XDECREF(__pyx_v_rows);
  __Pyx_XDECREF(__pyx_v_lastSrc);
  __Pyx_XDECREF(__pyx_v_recSrcPvt);
  __Pyx_XDECREF(__pyx_v_src);
  __Pyx_XDECREF(__pyx_v_term);
  __Pyx_XDECREF(__pyx_v_recPvtTrg);
  __Pyx_XDECREF(__pyx_v_fobj);
  __Pyx_XDECREF(__pyx_v_word);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "lpu/smt/trans_models/triangulate.pyx":751
 *         sys.exit(1)
 * 
 * def main():             # <<<<<<<<<<<<<<
 *     parser = argparse.ArgumentParser(description = 'load 2 rule tables and pivot into one travatar rule table')
 *     parser.add_argument('table1', help = 'rule table 1')
 */

/* Python wrapper */
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_31main(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static PyMethodDef __pyx_mdef_3lpu_3smt_12trans_models_11triangulate_31main = {"main", (PyCFunction)__pyx_pw_3lpu_3smt_12trans_models_11triangulate_31main, METH_NOARGS, 0};
static PyObject *__pyx_pw_3lpu_3smt_12trans_models_11triangulate_31main(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("main (wrapper)", 0);
  __pyx_r = __pyx_pf_3lpu_3smt_12trans_models_11triangulate_30main(__pyx_self);

  /* function exit code */
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_3lpu_3smt_12trans_models_11triangulate_30main(CYTHON_UNUSED PyObject *__pyx_self) {
  PyObject *__pyx_v_parser = NULL;
  PyObject *__pyx_v_args = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  PyObject *__pyx_t_3 = NULL;
  __Pyx_RefNannySetupContext("main", 0);

  /* "lpu/smt/trans_models/triangulate.pyx":752
 * 
 * def main():
 *     parser = argparse.ArgumentParser(description = 'load 2 rule tables and pivot into one travatar rule table')             # <<<<<<<<<<<<<<
 *     parser.add_argument('table1', help = 'rule table 1')
 *     parser.add_argument('table2', help = 'rule table 2')
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_argparse); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_ArgumentParser); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_description, __pyx_kp_s_load_2_rule_tables_and_pivot_int) < 0) __PYX_ERR(0, 752, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 752, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_parser = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":753
 * def main():
 *     parser = argparse.ArgumentParser(description = 'load 2 rule tables and pivot into one travatar rule table')
 *     parser.add_argument('table1', help = 'rule table 1')             # <<<<<<<<<<<<<<
 *     parser.add_argument('table2', help = 'rule table 2')
 *     parser.add_argument('savefile', help = 'path for saving travatar rule table file')
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_parser, __pyx_n_s_add_argument); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 753, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 753, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_help, __pyx_kp_s_rule_table_1) < 0) __PYX_ERR(0, 753, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__35, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 753, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":754
 *     parser = argparse.ArgumentParser(description = 'load 2 rule tables and pivot into one travatar rule table')
 *     parser.add_argument('table1', help = 'rule table 1')
 *     parser.add_argument('table2', help = 'rule table 2')             # <<<<<<<<<<<<<<
 *     parser.add_argument('savefile', help = 'path for saving travatar rule table file')
 *     parser.add_argument('--threshold', help = 'threshold for ignoring the phrase translation probability (real number)', type=float, default=THRESHOLD)
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_parser, __pyx_n_s_add_argument); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 754, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 754, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_help, __pyx_kp_s_rule_table_2) < 0) __PYX_ERR(0, 754, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__36, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 754, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":755
 *     parser.add_argument('table1', help = 'rule table 1')
 *     parser.add_argument('table2', help = 'rule table 2')
 *     parser.add_argument('savefile', help = 'path for saving travatar rule table file')             # <<<<<<<<<<<<<<
 *     parser.add_argument('--threshold', help = 'threshold for ignoring the phrase translation probability (real number)', type=float, default=THRESHOLD)
 *     parser.add_argument('--nbest', help = 'best n scores for rule pair filtering (default = 20)', type=int, default=NBEST)
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_parser, __pyx_n_s_add_argument); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 755, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 755, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_help, __pyx_kp_s_path_for_saving_travatar_rule_ta) < 0) __PYX_ERR(0, 755, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__37, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 755, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":756
 *     parser.add_argument('table2', help = 'rule table 2')
 *     parser.add_argument('savefile', help = 'path for saving travatar rule table file')
 *     parser.add_argument('--threshold', help = 'threshold for ignoring the phrase translation probability (real number)', type=float, default=THRESHOLD)             # <<<<<<<<<<<<<<
 *     parser.add_argument('--nbest', help = 'best n scores for rule pair filtering (default = 20)', type=int, default=NBEST)
 *     parser.add_argument('--method', help = 'triangulation method', choices=method_list, default=METHOD)
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_parser, __pyx_n_s_add_argument); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 756, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 756, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_help, __pyx_kp_s_threshold_for_ignoring_the_phras) < 0) __PYX_ERR(0, 756, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_type, ((PyObject *)(&PyFloat_Type))) < 0) __PYX_ERR(0, 756, __pyx_L1_error)
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_THRESHOLD); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 756, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_default, __pyx_t_3) < 0) __PYX_ERR(0, 756, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__38, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 756, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":757
 *     parser.add_argument('savefile', help = 'path for saving travatar rule table file')
 *     parser.add_argument('--threshold', help = 'threshold for ignoring the phrase translation probability (real number)', type=float, default=THRESHOLD)
 *     parser.add_argument('--nbest', help = 'best n scores for rule pair filtering (default = 20)', type=int, default=NBEST)             # <<<<<<<<<<<<<<
 *     parser.add_argument('--method', help = 'triangulation method', choices=method_list, default=METHOD)
 *     parser.add_argument('--lexmethod', help = 'lexical triangulation method', choices=lex_method_list, default=LEX_METHOD)
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_parser, __pyx_n_s_add_argument); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 757, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 757, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_help, __pyx_kp_s_best_n_scores_for_rule_pair_filt) < 0) __PYX_ERR(0, 757, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_type, ((PyObject *)(&PyInt_Type))) < 0) __PYX_ERR(0, 757, __pyx_L1_error)
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_NBEST); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 757, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_default, __pyx_t_2) < 0) __PYX_ERR(0, 757, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__39, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 757, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":758
 *     parser.add_argument('--threshold', help = 'threshold for ignoring the phrase translation probability (real number)', type=float, default=THRESHOLD)
 *     parser.add_argument('--nbest', help = 'best n scores for rule pair filtering (default = 20)', type=int, default=NBEST)
 *     parser.add_argument('--method', help = 'triangulation method', choices=method_list, default=METHOD)             # <<<<<<<<<<<<<<
 *     parser.add_argument('--lexmethod', help = 'lexical triangulation method', choices=lex_method_list, default=LEX_METHOD)
 *     parser.add_argument('--jointmethod', help = 'method to estimate joint trans probs', choices=joint_method_list, default=JOINT_METHOD)
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_parser, __pyx_n_s_add_argument); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 758, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 758, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_help, __pyx_kp_s_triangulation_method) < 0) __PYX_ERR(0, 758, __pyx_L1_error)
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_method_list); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 758, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_choices, __pyx_t_3) < 0) __PYX_ERR(0, 758, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_METHOD); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 758, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_default, __pyx_t_3) < 0) __PYX_ERR(0, 758, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__40, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 758, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":759
 *     parser.add_argument('--nbest', help = 'best n scores for rule pair filtering (default = 20)', type=int, default=NBEST)
 *     parser.add_argument('--method', help = 'triangulation method', choices=method_list, default=METHOD)
 *     parser.add_argument('--lexmethod', help = 'lexical triangulation method', choices=lex_method_list, default=LEX_METHOD)             # <<<<<<<<<<<<<<
 *     parser.add_argument('--jointmethod', help = 'method to estimate joint trans probs', choices=joint_method_list, default=JOINT_METHOD)
 *     parser.add_argument('--matchmethod', help = 'matching method', choices=match_method_list, default=MATCH_METHOD)
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_parser, __pyx_n_s_add_argument); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 759, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 759, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_help, __pyx_kp_s_lexical_triangulation_method) < 0) __PYX_ERR(0, 759, __pyx_L1_error)
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_lex_method_list); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 759, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_choices, __pyx_t_2) < 0) __PYX_ERR(0, 759, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_LEX_METHOD); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 759, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_default, __pyx_t_2) < 0) __PYX_ERR(0, 759, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__41, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 759, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":760
 *     parser.add_argument('--method', help = 'triangulation method', choices=method_list, default=METHOD)
 *     parser.add_argument('--lexmethod', help = 'lexical triangulation method', choices=lex_method_list, default=LEX_METHOD)
 *     parser.add_argument('--jointmethod', help = 'method to estimate joint trans probs', choices=joint_method_list, default=JOINT_METHOD)             # <<<<<<<<<<<<<<
 *     parser.add_argument('--matchmethod', help = 'matching method', choices=match_method_list, default=MATCH_METHOD)
 *     parser.add_argument('--workdir', help = 'working directory', default='.')
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_parser, __pyx_n_s_add_argument); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 760, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 760, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_help, __pyx_kp_s_method_to_estimate_joint_trans_p) < 0) __PYX_ERR(0, 760, __pyx_L1_error)
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_joint_method_list); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 760, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_choices, __pyx_t_3) < 0) __PYX_ERR(0, 760, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_JOINT_METHOD); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 760, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_default, __pyx_t_3) < 0) __PYX_ERR(0, 760, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__42, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 760, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":761
 *     parser.add_argument('--lexmethod', help = 'lexical triangulation method', choices=lex_method_list, default=LEX_METHOD)
 *     parser.add_argument('--jointmethod', help = 'method to estimate joint trans probs', choices=joint_method_list, default=JOINT_METHOD)
 *     parser.add_argument('--matchmethod', help = 'matching method', choices=match_method_list, default=MATCH_METHOD)             # <<<<<<<<<<<<<<
 *     parser.add_argument('--workdir', help = 'working directory', default='.')
 *     parser.add_argument('--alignlex', help = 'word pair counts file', default=None)
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_parser, __pyx_n_s_add_argument); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 761, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 761, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_help, __pyx_kp_s_matching_method) < 0) __PYX_ERR(0, 761, __pyx_L1_error)
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_match_method_list); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 761, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_choices, __pyx_t_2) < 0) __PYX_ERR(0, 761, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_MATCH_METHOD); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 761, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_default, __pyx_t_2) < 0) __PYX_ERR(0, 761, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__43, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 761, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":762
 *     parser.add_argument('--jointmethod', help = 'method to estimate joint trans probs', choices=joint_method_list, default=JOINT_METHOD)
 *     parser.add_argument('--matchmethod', help = 'matching method', choices=match_method_list, default=MATCH_METHOD)
 *     parser.add_argument('--workdir', help = 'working directory', default='.')             # <<<<<<<<<<<<<<
 *     parser.add_argument('--alignlex', help = 'word pair counts file', default=None)
 *     parser.add_argument('--nulls', help = 'number of NULLs (lines) for table lex', type = int, default=NULLS)
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_parser, __pyx_n_s_add_argument); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 762, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 762, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_help, __pyx_kp_s_working_directory) < 0) __PYX_ERR(0, 762, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_default, __pyx_kp_s__25) < 0) __PYX_ERR(0, 762, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__44, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 762, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":763
 *     parser.add_argument('--matchmethod', help = 'matching method', choices=match_method_list, default=MATCH_METHOD)
 *     parser.add_argument('--workdir', help = 'working directory', default='.')
 *     parser.add_argument('--alignlex', help = 'word pair counts file', default=None)             # <<<<<<<<<<<<<<
 *     parser.add_argument('--nulls', help = 'number of NULLs (lines) for table lex', type = int, default=NULLS)
 *     parser.add_argument('--noprefilter', help = 'No pre-filtering', type = bool, default=False)
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_parser, __pyx_n_s_add_argument); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 763, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 763, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_help, __pyx_kp_s_word_pair_counts_file) < 0) __PYX_ERR(0, 763, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_default, Py_None) < 0) __PYX_ERR(0, 763, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__45, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 763, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":764
 *     parser.add_argument('--workdir', help = 'working directory', default='.')
 *     parser.add_argument('--alignlex', help = 'word pair counts file', default=None)
 *     parser.add_argument('--nulls', help = 'number of NULLs (lines) for table lex', type = int, default=NULLS)             # <<<<<<<<<<<<<<
 *     parser.add_argument('--noprefilter', help = 'No pre-filtering', type = bool, default=False)
 *     parser.add_argument('--multitarget', help = 'enabling multi target model', action='store_true')
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_parser, __pyx_n_s_add_argument); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 764, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 764, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_help, __pyx_kp_s_number_of_NULLs_lines_for_table) < 0) __PYX_ERR(0, 764, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_type, ((PyObject *)(&PyInt_Type))) < 0) __PYX_ERR(0, 764, __pyx_L1_error)
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_NULLS); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 764, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_default, __pyx_t_3) < 0) __PYX_ERR(0, 764, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__46, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 764, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":765
 *     parser.add_argument('--alignlex', help = 'word pair counts file', default=None)
 *     parser.add_argument('--nulls', help = 'number of NULLs (lines) for table lex', type = int, default=NULLS)
 *     parser.add_argument('--noprefilter', help = 'No pre-filtering', type = bool, default=False)             # <<<<<<<<<<<<<<
 *     parser.add_argument('--multitarget', help = 'enabling multi target model', action='store_true')
 *     parser.add_argument('--progress', '-p', help = 'show progress', type = bool, default=True)
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_parser, __pyx_n_s_add_argument); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 765, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 765, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_help, __pyx_kp_s_No_pre_filtering) < 0) __PYX_ERR(0, 765, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_type, ((PyObject*)&PyBool_Type)) < 0) __PYX_ERR(0, 765, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_default, Py_False) < 0) __PYX_ERR(0, 765, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__47, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 765, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":766
 *     parser.add_argument('--nulls', help = 'number of NULLs (lines) for table lex', type = int, default=NULLS)
 *     parser.add_argument('--noprefilter', help = 'No pre-filtering', type = bool, default=False)
 *     parser.add_argument('--multitarget', help = 'enabling multi target model', action='store_true')             # <<<<<<<<<<<<<<
 *     parser.add_argument('--progress', '-p', help = 'show progress', type = bool, default=True)
 *     parser.add_argument('--log', help = 'log file (optional)', type = str, default='')
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_parser, __pyx_n_s_add_argument); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 766, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 766, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_help, __pyx_kp_s_enabling_multi_target_model) < 0) __PYX_ERR(0, 766, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_action, __pyx_n_s_store_true) < 0) __PYX_ERR(0, 766, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__48, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 766, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":767
 *     parser.add_argument('--noprefilter', help = 'No pre-filtering', type = bool, default=False)
 *     parser.add_argument('--multitarget', help = 'enabling multi target model', action='store_true')
 *     parser.add_argument('--progress', '-p', help = 'show progress', type = bool, default=True)             # <<<<<<<<<<<<<<
 *     parser.add_argument('--log', help = 'log file (optional)', type = str, default='')
 *     args = vars(parser.parse_args())
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_parser, __pyx_n_s_add_argument); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 767, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 767, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_help, __pyx_kp_s_show_progress) < 0) __PYX_ERR(0, 767, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_type, ((PyObject*)&PyBool_Type)) < 0) __PYX_ERR(0, 767, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_default, Py_True) < 0) __PYX_ERR(0, 767, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__49, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 767, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":768
 *     parser.add_argument('--multitarget', help = 'enabling multi target model', action='store_true')
 *     parser.add_argument('--progress', '-p', help = 'show progress', type = bool, default=True)
 *     parser.add_argument('--log', help = 'log file (optional)', type = str, default='')             # <<<<<<<<<<<<<<
 *     args = vars(parser.parse_args())
 * 
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_parser, __pyx_n_s_add_argument); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 768, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 768, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_help, __pyx_kp_s_log_file_optional) < 0) __PYX_ERR(0, 768, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_type, ((PyObject *)(&PyString_Type))) < 0) __PYX_ERR(0, 768, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_default, __pyx_kp_s__16) < 0) __PYX_ERR(0, 768, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__50, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 768, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":769
 *     parser.add_argument('--progress', '-p', help = 'show progress', type = bool, default=True)
 *     parser.add_argument('--log', help = 'log file (optional)', type = str, default='')
 *     args = vars(parser.parse_args())             # <<<<<<<<<<<<<<
 * 
 *     args['RecordClass'] = TravatarRecord
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_parser, __pyx_n_s_parse_args); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 769, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (__pyx_t_2) {
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 769, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 769, __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_ERR(0, 769, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_vars, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 769, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_args = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":771
 *     args = vars(parser.parse_args())
 * 
 *     args['RecordClass'] = TravatarRecord             # <<<<<<<<<<<<<<
 *     args['prefix'] = 'rule'
 *     #base.pivot(**args)
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_TravatarRecord); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (unlikely(PyObject_SetItem(__pyx_v_args, __pyx_n_s_RecordClass, __pyx_t_3) < 0)) __PYX_ERR(0, 771, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":772
 * 
 *     args['RecordClass'] = TravatarRecord
 *     args['prefix'] = 'rule'             # <<<<<<<<<<<<<<
 *     #base.pivot(**args)
 *     pivot(**args)
 */
  if (unlikely(PyObject_SetItem(__pyx_v_args, __pyx_n_s_prefix, __pyx_n_s_rule) < 0)) __PYX_ERR(0, 772, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":774
 *     args['prefix'] = 'rule'
 *     #base.pivot(**args)
 *     pivot(**args)             # <<<<<<<<<<<<<<
 * 
 * if __name__ == '__main__':
 */
  __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_pivot); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 774, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (unlikely(__pyx_v_args == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "argument after ** must be a mapping, not NoneType");
    __PYX_ERR(0, 774, __pyx_L1_error)
  }
  if (likely(PyDict_CheckExact(__pyx_v_args))) {
    __pyx_t_1 = PyDict_Copy(__pyx_v_args); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 774, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    __pyx_t_1 = PyObject_CallFunctionObjArgs((PyObject*)&PyDict_Type, __pyx_v_args, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 774, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  }
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 774, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":751
 *         sys.exit(1)
 * 
 * def main():             # <<<<<<<<<<<<<<
 *     parser = argparse.ArgumentParser(description = 'load 2 rule tables and pivot into one travatar rule table')
 *     parser.add_argument('table1', help = 'rule table 1')
 */

  /* function exit code */
  __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("lpu.smt.trans_models.triangulate.main", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_parser);
  __Pyx_XDECREF(__pyx_v_args);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};

#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef __pyx_moduledef = {
  #if PY_VERSION_HEX < 0x03020000
    { PyObject_HEAD_INIT(NULL) NULL, 0, NULL },
  #else
    PyModuleDef_HEAD_INIT,
  #endif
    "triangulate",
    __pyx_k_functions_to_triangulate_2_phras, /* 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_0, __pyx_k_0, sizeof(__pyx_k_0), 0, 0, 1, 0},
  {&__pyx_kp_s_0egfl, __pyx_k_0egfl, sizeof(__pyx_k_0egfl), 0, 0, 1, 0},
  {&__pyx_kp_s_0egfp, __pyx_k_0egfp, sizeof(__pyx_k_0egfp), 0, 0, 1, 0},
  {&__pyx_kp_s_0fgel, __pyx_k_0fgel, sizeof(__pyx_k_0fgel), 0, 0, 1, 0},
  {&__pyx_kp_s_0fgep, __pyx_k_0fgep, sizeof(__pyx_k_0fgep), 0, 0, 1, 0},
  {&__pyx_kp_s_0w, __pyx_k_0w, sizeof(__pyx_k_0w), 0, 0, 1, 0},
  {&__pyx_kp_s_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 0, 1, 0},
  {&__pyx_kp_s_1fgep, __pyx_k_1fgep, sizeof(__pyx_k_1fgep), 0, 0, 1, 0},
  {&__pyx_kp_s_1w, __pyx_k_1w, sizeof(__pyx_k_1w), 0, 0, 1, 0},
  {&__pyx_n_s_ArgumentParser, __pyx_k_ArgumentParser, sizeof(__pyx_k_ArgumentParser), 0, 0, 1, 1},
  {&__pyx_kp_s_COL, __pyx_k_COL, sizeof(__pyx_k_COL), 0, 0, 1, 0},
  {&__pyx_kp_s_COL_2, __pyx_k_COL_2, sizeof(__pyx_k_COL_2), 0, 0, 1, 0},
  {&__pyx_kp_s_COL_3, __pyx_k_COL_3, sizeof(__pyx_k_COL_3), 0, 0, 1, 0},
  {&__pyx_kp_s_Caught_KeyboardInterrupt_termina, __pyx_k_Caught_KeyboardInterrupt_termina, sizeof(__pyx_k_Caught_KeyboardInterrupt_termina), 0, 0, 1, 0},
  {&__pyx_kp_s_Invalid_Match_Method, __pyx_k_Invalid_Match_Method, sizeof(__pyx_k_Invalid_Match_Method), 0, 0, 1, 0},
  {&__pyx_kp_s_Invalid_method_s, __pyx_k_Invalid_method_s, sizeof(__pyx_k_Invalid_method_s), 0, 0, 1, 0},
  {&__pyx_kp_s_Invalid_records, __pyx_k_Invalid_records, sizeof(__pyx_k_Invalid_records), 0, 0, 1, 0},
  {&__pyx_n_s_JOINT_METHOD, __pyx_k_JOINT_METHOD, sizeof(__pyx_k_JOINT_METHOD), 0, 0, 1, 1},
  {&__pyx_n_s_KeyboardInterrupt, __pyx_k_KeyboardInterrupt, sizeof(__pyx_k_KeyboardInterrupt), 0, 0, 1, 1},
  {&__pyx_n_s_LEX_METHOD, __pyx_k_LEX_METHOD, sizeof(__pyx_k_LEX_METHOD), 0, 0, 1, 1},
  {&__pyx_kp_s_Lost_Words, __pyx_k_Lost_Words, sizeof(__pyx_k_Lost_Words), 0, 0, 1, 0},
  {&__pyx_n_s_MATCH_METHOD, __pyx_k_MATCH_METHOD, sizeof(__pyx_k_MATCH_METHOD), 0, 0, 1, 1},
  {&__pyx_n_s_METHOD, __pyx_k_METHOD, sizeof(__pyx_k_METHOD), 0, 0, 1, 1},
  {&__pyx_n_s_MINPROB, __pyx_k_MINPROB, sizeof(__pyx_k_MINPROB), 0, 0, 1, 1},
  {&__pyx_n_s_MosesRecord, __pyx_k_MosesRecord, sizeof(__pyx_k_MosesRecord), 0, 0, 1, 1},
  {&__pyx_n_s_NBEST, __pyx_k_NBEST, sizeof(__pyx_k_NBEST), 0, 0, 1, 1},
  {&__pyx_n_s_NOPREFILTER, __pyx_k_NOPREFILTER, sizeof(__pyx_k_NOPREFILTER), 0, 0, 1, 1},
  {&__pyx_n_s_NULL, __pyx_k_NULL, sizeof(__pyx_k_NULL), 0, 0, 1, 1},
  {&__pyx_n_s_NULLS, __pyx_k_NULLS, sizeof(__pyx_k_NULLS), 0, 0, 1, 1},
  {&__pyx_kp_s_No_pre_filtering, __pyx_k_No_pre_filtering, sizeof(__pyx_k_No_pre_filtering), 0, 0, 1, 0},
  {&__pyx_n_s_Record, __pyx_k_Record, sizeof(__pyx_k_Record), 0, 0, 1, 1},
  {&__pyx_n_s_RecordClass, __pyx_k_RecordClass, sizeof(__pyx_k_RecordClass), 0, 0, 1, 1},
  {&__pyx_n_s_THRESHOLD, __pyx_k_THRESHOLD, sizeof(__pyx_k_THRESHOLD), 0, 0, 1, 1},
  {&__pyx_n_s_Table, __pyx_k_Table, sizeof(__pyx_k_Table), 0, 0, 1, 1},
  {&__pyx_n_s_TravatarRecord, __pyx_k_TravatarRecord, sizeof(__pyx_k_TravatarRecord), 0, 0, 1, 1},
  {&__pyx_n_s_WorkSet, __pyx_k_WorkSet, sizeof(__pyx_k_WorkSet), 0, 0, 1, 1},
  {&__pyx_n_s_WorkSet___del, __pyx_k_WorkSet___del, sizeof(__pyx_k_WorkSet___del), 0, 0, 1, 1},
  {&__pyx_n_s_WorkSet___init, __pyx_k_WorkSet___init, sizeof(__pyx_k_WorkSet___init), 0, 0, 1, 1},
  {&__pyx_n_s_WorkSet_close, __pyx_k_WorkSet_close, sizeof(__pyx_k_WorkSet_close), 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__20, __pyx_k__20, sizeof(__pyx_k__20), 0, 0, 1, 0},
  {&__pyx_kp_s__25, __pyx_k__25, sizeof(__pyx_k__25), 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_n_s__75, __pyx_k__75, sizeof(__pyx_k__75), 0, 0, 1, 1},
  {&__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_action, __pyx_k_action, sizeof(__pyx_k_action), 0, 0, 1, 1},
  {&__pyx_n_s_add, __pyx_k_add, sizeof(__pyx_k_add), 0, 0, 1, 1},
  {&__pyx_n_s_addPair, __pyx_k_addPair, sizeof(__pyx_k_addPair), 0, 0, 1, 1},
  {&__pyx_n_s_add_argument, __pyx_k_add_argument, sizeof(__pyx_k_add_argument), 0, 0, 1, 1},
  {&__pyx_n_s_align, __pyx_k_align, sizeof(__pyx_k_align), 0, 0, 1, 1},
  {&__pyx_n_s_alignLexPath, __pyx_k_alignLexPath, sizeof(__pyx_k_alignLexPath), 0, 0, 1, 1},
  {&__pyx_n_s_alignMap, __pyx_k_alignMap, sizeof(__pyx_k_alignMap), 0, 0, 1, 1},
  {&__pyx_n_s_alignMapPvtTrg, __pyx_k_alignMapPvtTrg, sizeof(__pyx_k_alignMapPvtTrg), 0, 0, 1, 1},
  {&__pyx_n_s_alignMapRev, __pyx_k_alignMapRev, sizeof(__pyx_k_alignMapRev), 0, 0, 1, 1},
  {&__pyx_n_s_alignMapSrcPvt, __pyx_k_alignMapSrcPvt, sizeof(__pyx_k_alignMapSrcPvt), 0, 0, 1, 1},
  {&__pyx_kp_s_aligned_lexfile_is_not_given, __pyx_k_aligned_lexfile_is_not_given, sizeof(__pyx_k_aligned_lexfile_is_not_given), 0, 0, 1, 0},
  {&__pyx_n_s_alignlex, __pyx_k_alignlex, sizeof(__pyx_k_alignlex), 0, 0, 1, 1},
  {&__pyx_kp_s_alignlex_2, __pyx_k_alignlex_2, sizeof(__pyx_k_alignlex_2), 0, 0, 1, 0},
  {&__pyx_n_s_aligns, __pyx_k_aligns, sizeof(__pyx_k_aligns), 0, 0, 1, 1},
  {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1},
  {&__pyx_n_s_argparse, __pyx_k_argparse, sizeof(__pyx_k_argparse), 0, 0, 1, 1},
  {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1},
  {&__pyx_kp_s_beginning_pivot, __pyx_k_beginning_pivot, sizeof(__pyx_k_beginning_pivot), 0, 0, 1, 0},
  {&__pyx_n_s_bestForwardJointTransProb, __pyx_k_bestForwardJointTransProb, sizeof(__pyx_k_bestForwardJointTransProb), 0, 0, 1, 1},
  {&__pyx_n_s_bestMultiRec, __pyx_k_bestMultiRec, sizeof(__pyx_k_bestMultiRec), 0, 0, 1, 1},
  {&__pyx_n_s_bestMultiRecords, __pyx_k_bestMultiRecords, sizeof(__pyx_k_bestMultiRecords), 0, 0, 1, 1},
  {&__pyx_n_s_bestRecords, __pyx_k_bestRecords, sizeof(__pyx_k_bestRecords), 0, 0, 1, 1},
  {&__pyx_n_s_bestTrgRecords, __pyx_k_bestTrgRecords, sizeof(__pyx_k_bestTrgRecords), 0, 0, 1, 1},
  {&__pyx_kp_s_best_n_scores_for_rule_pair_filt, __pyx_k_best_n_scores_for_rule_pair_filt, sizeof(__pyx_k_best_n_scores_for_rule_pair_filt), 0, 0, 1, 0},
  {&__pyx_n_s_bidiravr, __pyx_k_bidiravr, sizeof(__pyx_k_bidiravr), 0, 0, 1, 1},
  {&__pyx_n_s_bidirgmean, __pyx_k_bidirgmean, sizeof(__pyx_k_bidirgmean), 0, 0, 1, 1},
  {&__pyx_kp_s_bidirgmean_table, __pyx_k_bidirgmean_table, sizeof(__pyx_k_bidirgmean_table), 0, 0, 1, 0},
  {&__pyx_n_s_bidirmax, __pyx_k_bidirmax, sizeof(__pyx_k_bidirmax), 0, 0, 1, 1},
  {&__pyx_n_s_bidirmin, __pyx_k_bidirmin, sizeof(__pyx_k_bidirmin), 0, 0, 1, 1},
  {&__pyx_kp_s_bidirmin_table, __pyx_k_bidirmin_table, sizeof(__pyx_k_bidirmin_table), 0, 0, 1, 0},
  {&__pyx_n_s_c, __pyx_k_c, sizeof(__pyx_k_c), 0, 0, 1, 1},
  {&__pyx_n_s_calcLexProb, __pyx_k_calcLexProb, sizeof(__pyx_k_calcLexProb), 0, 0, 1, 1},
  {&__pyx_n_s_calcLexProbRev, __pyx_k_calcLexProbRev, sizeof(__pyx_k_calcLexProbRev), 0, 0, 1, 1},
  {&__pyx_n_s_calcLexWeight, __pyx_k_calcLexWeight, sizeof(__pyx_k_calcLexWeight), 0, 0, 1, 1},
  {&__pyx_n_s_calcLexWeights, __pyx_k_calcLexWeights, sizeof(__pyx_k_calcLexWeights), 0, 0, 1, 1},
  {&__pyx_n_s_calcPhraseTransProbsByCounts, __pyx_k_calcPhraseTransProbsByCounts, sizeof(__pyx_k_calcPhraseTransProbsByCounts), 0, 0, 1, 1},
  {&__pyx_n_s_calcPhraseTransProbsOnTable, __pyx_k_calcPhraseTransProbsOnTable, sizeof(__pyx_k_calcPhraseTransProbsOnTable), 0, 0, 1, 1},
  {&__pyx_n_s_calcSrcCount, __pyx_k_calcSrcCount, sizeof(__pyx_k_calcSrcCount), 0, 0, 1, 1},
  {&__pyx_n_s_calcTreeEditDistance, __pyx_k_calcTreeEditDistance, sizeof(__pyx_k_calcTreeEditDistance), 0, 0, 1, 1},
  {&__pyx_n_s_choices, __pyx_k_choices, sizeof(__pyx_k_choices), 0, 0, 1, 1},
  {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1},
  {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1},
  {&__pyx_n_s_co, __pyx_k_co, sizeof(__pyx_k_co), 0, 0, 1, 1},
  {&__pyx_n_s_co1, __pyx_k_co1, sizeof(__pyx_k_co1), 0, 0, 1, 1},
  {&__pyx_n_s_co2, __pyx_k_co2, sizeof(__pyx_k_co2), 0, 0, 1, 1},
  {&__pyx_n_s_coMax, __pyx_k_coMax, sizeof(__pyx_k_coMax), 0, 0, 1, 1},
  {&__pyx_n_s_compat, __pyx_k_compat, sizeof(__pyx_k_compat), 0, 0, 1, 1},
  {&__pyx_n_s_cooc, __pyx_k_cooc, sizeof(__pyx_k_cooc), 0, 0, 1, 1},
  {&__pyx_n_s_cooc1, __pyx_k_cooc1, sizeof(__pyx_k_cooc1), 0, 0, 1, 1},
  {&__pyx_n_s_cooc2, __pyx_k_cooc2, sizeof(__pyx_k_cooc2), 0, 0, 1, 1},
  {&__pyx_n_s_countElements, __pyx_k_countElements, sizeof(__pyx_k_countElements), 0, 0, 1, 1},
  {&__pyx_n_s_countmin, __pyx_k_countmin, sizeof(__pyx_k_countmin), 0, 0, 1, 1},
  {&__pyx_kp_s_countmin_table, __pyx_k_countmin_table, sizeof(__pyx_k_countmin_table), 0, 0, 1, 0},
  {&__pyx_n_s_counts, __pyx_k_counts, sizeof(__pyx_k_counts), 0, 0, 1, 1},
  {&__pyx_n_s_counts1, __pyx_k_counts1, sizeof(__pyx_k_counts1), 0, 0, 1, 1},
  {&__pyx_n_s_counts2, __pyx_k_counts2, sizeof(__pyx_k_counts2), 0, 0, 1, 1},
  {&__pyx_kp_s_d_d, __pyx_k_d_d, sizeof(__pyx_k_d_d), 0, 0, 1, 0},
  {&__pyx_kp_s_data_set_for_multi_processing, __pyx_k_data_set_for_multi_processing, sizeof(__pyx_k_data_set_for_multi_processing), 0, 0, 1, 0},
  {&__pyx_n_s_debug, __pyx_k_debug, sizeof(__pyx_k_debug), 0, 0, 1, 1},
  {&__pyx_n_s_default, __pyx_k_default, sizeof(__pyx_k_default), 0, 0, 1, 1},
  {&__pyx_n_s_del, __pyx_k_del, sizeof(__pyx_k_del), 0, 0, 1, 1},
  {&__pyx_n_s_description, __pyx_k_description, sizeof(__pyx_k_description), 0, 0, 1, 1},
  {&__pyx_n_s_dist, __pyx_k_dist, sizeof(__pyx_k_dist), 0, 0, 1, 1},
  {&__pyx_n_s_div, __pyx_k_div, sizeof(__pyx_k_div), 0, 0, 1, 1},
  {&__pyx_n_s_doc, __pyx_k_doc, sizeof(__pyx_k_doc), 0, 0, 1, 1},
  {&__pyx_n_s_egfl, __pyx_k_egfl, sizeof(__pyx_k_egfl), 0, 0, 1, 1},
  {&__pyx_n_s_egfp, __pyx_k_egfp, sizeof(__pyx_k_egfp), 0, 0, 1, 1},
  {&__pyx_n_s_elems1, __pyx_k_elems1, sizeof(__pyx_k_elems1), 0, 0, 1, 1},
  {&__pyx_n_s_elems2, __pyx_k_elems2, sizeof(__pyx_k_elems2), 0, 0, 1, 1},
  {&__pyx_kp_s_enabling_multi_target_model, __pyx_k_enabling_multi_target_model, sizeof(__pyx_k_enabling_multi_target_model), 0, 0, 1, 0},
  {&__pyx_n_s_end, __pyx_k_end, sizeof(__pyx_k_end), 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_exit_2, __pyx_k_exit_2, sizeof(__pyx_k_exit_2), 0, 0, 1, 1},
  {&__pyx_n_s_exp, __pyx_k_exp, sizeof(__pyx_k_exp), 0, 0, 1, 1},
  {&__pyx_n_s_featureKey, __pyx_k_featureKey, sizeof(__pyx_k_featureKey), 0, 0, 1, 1},
  {&__pyx_n_s_features, __pyx_k_features, sizeof(__pyx_k_features), 0, 0, 1, 1},
  {&__pyx_n_s_fgel, __pyx_k_fgel, sizeof(__pyx_k_fgel), 0, 0, 1, 1},
  {&__pyx_n_s_fgep, __pyx_k_fgep, sizeof(__pyx_k_fgep), 0, 0, 1, 1},
  {&__pyx_n_s_file, __pyx_k_file, sizeof(__pyx_k_file), 0, 0, 1, 1},
  {&__pyx_n_s_fileObj, __pyx_k_fileObj, sizeof(__pyx_k_fileObj), 0, 0, 1, 1},
  {&__pyx_n_s_files, __pyx_k_files, sizeof(__pyx_k_files), 0, 0, 1, 1},
  {&__pyx_n_s_filterByCountRatioToMax, __pyx_k_filterByCountRatioToMax, sizeof(__pyx_k_filterByCountRatioToMax), 0, 0, 1, 1},
  {&__pyx_n_s_filterNBestBySrc, __pyx_k_filterNBestBySrc, sizeof(__pyx_k_filterNBestBySrc), 0, 0, 1, 1},
  {&__pyx_n_s_find, __pyx_k_find, sizeof(__pyx_k_find), 0, 0, 1, 1},
  {&__pyx_n_s_find_src, __pyx_k_find_src, sizeof(__pyx_k_find_src), 0, 0, 1, 1},
  {&__pyx_n_s_flattenRecords, __pyx_k_flattenRecords, sizeof(__pyx_k_flattenRecords), 0, 0, 1, 1},
  {&__pyx_n_s_flush, __pyx_k_flush, sizeof(__pyx_k_flush), 0, 0, 1, 1},
  {&__pyx_n_s_fobj, __pyx_k_fobj, sizeof(__pyx_k_fobj), 0, 0, 1, 1},
  {&__pyx_n_s_foutPivot, __pyx_k_foutPivot, sizeof(__pyx_k_foutPivot), 0, 0, 1, 1},
  {&__pyx_n_s_get, __pyx_k_get, sizeof(__pyx_k_get), 0, 0, 1, 1},
  {&__pyx_n_s_help, __pyx_k_help, sizeof(__pyx_k_help), 0, 0, 1, 1},
  {&__pyx_n_s_hiero, __pyx_k_hiero, sizeof(__pyx_k_hiero), 0, 0, 1, 1},
  {&__pyx_n_s_ignoring, __pyx_k_ignoring, sizeof(__pyx_k_ignoring), 0, 0, 1, 1},
  {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  {&__pyx_n_s_independent, __pyx_k_independent, sizeof(__pyx_k_independent), 0, 0, 1, 1},
  {&__pyx_n_s_init, __pyx_k_init, sizeof(__pyx_k_init), 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_jointMethod, __pyx_k_jointMethod, sizeof(__pyx_k_jointMethod), 0, 0, 1, 1},
  {&__pyx_n_s_joint_method_list, __pyx_k_joint_method_list, sizeof(__pyx_k_joint_method_list), 0, 0, 1, 1},
  {&__pyx_n_s_jointmethod, __pyx_k_jointmethod, sizeof(__pyx_k_jointmethod), 0, 0, 1, 1},
  {&__pyx_kp_s_jointmethod_2, __pyx_k_jointmethod_2, sizeof(__pyx_k_jointmethod_2), 0, 0, 1, 0},
  {&__pyx_n_s_key, __pyx_k_key, sizeof(__pyx_k_key), 0, 0, 1, 1},
  {&__pyx_n_s_key_type, __pyx_k_key_type, sizeof(__pyx_k_key_type), 0, 0, 1, 1},
  {&__pyx_n_s_keys, __pyx_k_keys, sizeof(__pyx_k_keys), 0, 0, 1, 1},
  {&__pyx_n_s_lastSrc, __pyx_k_lastSrc, sizeof(__pyx_k_lastSrc), 0, 0, 1, 1},
  {&__pyx_n_s_lexCounts, __pyx_k_lexCounts, sizeof(__pyx_k_lexCounts), 0, 0, 1, 1},
  {&__pyx_n_s_lexMethod, __pyx_k_lexMethod, sizeof(__pyx_k_lexMethod), 0, 0, 1, 1},
  {&__pyx_n_s_lexProb, __pyx_k_lexProb, sizeof(__pyx_k_lexProb), 0, 0, 1, 1},
  {&__pyx_n_s_lexWeight, __pyx_k_lexWeight, sizeof(__pyx_k_lexWeight), 0, 0, 1, 1},
  {&__pyx_n_s_lex_method_list, __pyx_k_lex_method_list, sizeof(__pyx_k_lex_method_list), 0, 0, 1, 1},
  {&__pyx_kp_s_lexical_triangulation_method, __pyx_k_lexical_triangulation_method, sizeof(__pyx_k_lexical_triangulation_method), 0, 0, 1, 0},
  {&__pyx_n_s_lexmethod, __pyx_k_lexmethod, sizeof(__pyx_k_lexmethod), 0, 0, 1, 1},
  {&__pyx_kp_s_lexmethod_2, __pyx_k_lexmethod_2, sizeof(__pyx_k_lexmethod_2), 0, 0, 1, 0},
  {&__pyx_n_s_line, __pyx_k_line, sizeof(__pyx_k_line), 0, 0, 1, 1},
  {&__pyx_kp_s_load_2_rule_tables_and_pivot_int, __pyx_k_load_2_rule_tables_and_pivot_int, sizeof(__pyx_k_load_2_rule_tables_and_pivot_int), 0, 0, 1, 0},
  {&__pyx_kp_s_loading_s, __pyx_k_loading_s, sizeof(__pyx_k_loading_s), 0, 0, 1, 0},
  {&__pyx_n_s_log, __pyx_k_log, sizeof(__pyx_k_log), 0, 0, 1, 1},
  {&__pyx_n_s_logFile, __pyx_k_logFile, sizeof(__pyx_k_logFile), 0, 0, 1, 1},
  {&__pyx_kp_s_log_2, __pyx_k_log_2, sizeof(__pyx_k_log_2), 0, 0, 1, 0},
  {&__pyx_kp_s_log_file_optional, __pyx_k_log_file_optional, sizeof(__pyx_k_log_file_optional), 0, 0, 1, 0},
  {&__pyx_n_s_logging, __pyx_k_logging, sizeof(__pyx_k_logging), 0, 0, 1, 1},
  {&__pyx_n_s_lpu_common, __pyx_k_lpu_common, sizeof(__pyx_k_lpu_common), 0, 0, 1, 1},
  {&__pyx_n_s_lpu_data_structs, __pyx_k_lpu_data_structs, sizeof(__pyx_k_lpu_data_structs), 0, 0, 1, 1},
  {&__pyx_n_s_lpu_smt_trans_models_records, __pyx_k_lpu_smt_trans_models_records, sizeof(__pyx_k_lpu_smt_trans_models_records), 0, 0, 1, 1},
  {&__pyx_n_s_lpu_smt_trans_models_tables, __pyx_k_lpu_smt_trans_models_tables, sizeof(__pyx_k_lpu_smt_trans_models_tables), 0, 0, 1, 1},
  {&__pyx_n_s_lpu_smt_trans_models_triangulate, __pyx_k_lpu_smt_trans_models_triangulate, sizeof(__pyx_k_lpu_smt_trans_models_triangulate), 0, 0, 1, 1},
  {&__pyx_kp_s_lpu_smt_trans_models_triangulate_2, __pyx_k_lpu_smt_trans_models_triangulate_2, sizeof(__pyx_k_lpu_smt_trans_models_triangulate_2), 0, 0, 1, 0},
  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  {&__pyx_n_s_main_2, __pyx_k_main_2, sizeof(__pyx_k_main_2), 0, 0, 1, 1},
  {&__pyx_n_s_matchMethod, __pyx_k_matchMethod, sizeof(__pyx_k_matchMethod), 0, 0, 1, 1},
  {&__pyx_n_s_match_method_list, __pyx_k_match_method_list, sizeof(__pyx_k_match_method_list), 0, 0, 1, 1},
  {&__pyx_kp_s_matching_method, __pyx_k_matching_method, sizeof(__pyx_k_matching_method), 0, 0, 1, 0},
  {&__pyx_n_s_matchmethod, __pyx_k_matchmethod, sizeof(__pyx_k_matchmethod), 0, 0, 1, 1},
  {&__pyx_kp_s_matchmethod_2, __pyx_k_matchmethod_2, sizeof(__pyx_k_matchmethod_2), 0, 0, 1, 0},
  {&__pyx_n_s_math, __pyx_k_math, sizeof(__pyx_k_math), 0, 0, 1, 1},
  {&__pyx_n_s_max_count, __pyx_k_max_count, sizeof(__pyx_k_max_count), 0, 0, 1, 1},
  {&__pyx_n_s_memoryless, __pyx_k_memoryless, sizeof(__pyx_k_memoryless), 0, 0, 1, 1},
  {&__pyx_n_s_mergeAligns, __pyx_k_mergeAligns, sizeof(__pyx_k_mergeAligns), 0, 0, 1, 1},
  {&__pyx_n_s_metaclass, __pyx_k_metaclass, sizeof(__pyx_k_metaclass), 0, 0, 1, 1},
  {&__pyx_n_s_method, __pyx_k_method, sizeof(__pyx_k_method), 0, 0, 1, 1},
  {&__pyx_kp_s_method_2, __pyx_k_method_2, sizeof(__pyx_k_method_2), 0, 0, 1, 0},
  {&__pyx_n_s_method_list, __pyx_k_method_list, sizeof(__pyx_k_method_list), 0, 0, 1, 1},
  {&__pyx_kp_s_method_to_estimate_joint_trans_p, __pyx_k_method_to_estimate_joint_trans_p, sizeof(__pyx_k_method_to_estimate_joint_trans_p), 0, 0, 1, 0},
  {&__pyx_n_s_minProb, __pyx_k_minProb, sizeof(__pyx_k_minProb), 0, 0, 1, 1},
  {&__pyx_n_s_module, __pyx_k_module, sizeof(__pyx_k_module), 0, 0, 1, 1},
  {&__pyx_n_s_multi, __pyx_k_multi, sizeof(__pyx_k_multi), 0, 0, 1, 1},
  {&__pyx_n_s_multiKey, __pyx_k_multiKey, sizeof(__pyx_k_multiKey), 0, 0, 1, 1},
  {&__pyx_n_s_multiList, __pyx_k_multiList, sizeof(__pyx_k_multiList), 0, 0, 1, 1},
  {&__pyx_n_s_multiRec, __pyx_k_multiRec, sizeof(__pyx_k_multiRec), 0, 0, 1, 1},
  {&__pyx_n_s_multiRecords, __pyx_k_multiRecords, sizeof(__pyx_k_multiRecords), 0, 0, 1, 1},
  {&__pyx_n_s_multi_target, __pyx_k_multi_target, sizeof(__pyx_k_multi_target), 0, 0, 1, 1},
  {&__pyx_n_s_multitarget, __pyx_k_multitarget, sizeof(__pyx_k_multitarget), 0, 0, 1, 1},
  {&__pyx_kp_s_multitarget_2, __pyx_k_multitarget_2, sizeof(__pyx_k_multitarget_2), 0, 0, 1, 0},
  {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1},
  {&__pyx_n_s_nbest, __pyx_k_nbest, sizeof(__pyx_k_nbest), 0, 0, 1, 1},
  {&__pyx_kp_s_nbest_2, __pyx_k_nbest_2, sizeof(__pyx_k_nbest_2), 0, 0, 1, 0},
  {&__pyx_n_s_newRecords, __pyx_k_newRecords, sizeof(__pyx_k_newRecords), 0, 0, 1, 1},
  {&__pyx_kp_s_noprefilter, __pyx_k_noprefilter, sizeof(__pyx_k_noprefilter), 0, 0, 1, 0},
  {&__pyx_n_s_nulls, __pyx_k_nulls, sizeof(__pyx_k_nulls), 0, 0, 1, 1},
  {&__pyx_kp_s_nulls_2, __pyx_k_nulls_2, sizeof(__pyx_k_nulls_2), 0, 0, 1, 0},
  {&__pyx_n_s_numElems, __pyx_k_numElems, sizeof(__pyx_k_numElems), 0, 0, 1, 1},
  {&__pyx_n_s_numNulls, __pyx_k_numNulls, sizeof(__pyx_k_numNulls), 0, 0, 1, 1},
  {&__pyx_n_s_numRecPvtTrg, __pyx_k_numRecPvtTrg, sizeof(__pyx_k_numRecPvtTrg), 0, 0, 1, 1},
  {&__pyx_n_s_numRecSrcPvt, __pyx_k_numRecSrcPvt, sizeof(__pyx_k_numRecSrcPvt), 0, 0, 1, 1},
  {&__pyx_n_s_numRecSrcTrg, __pyx_k_numRecSrcTrg, sizeof(__pyx_k_numRecSrcTrg), 0, 0, 1, 1},
  {&__pyx_n_s_numTerms, __pyx_k_numTerms, sizeof(__pyx_k_numTerms), 0, 0, 1, 1},
  {&__pyx_kp_s_number_of_NULLs_lines_for_table, __pyx_k_number_of_NULLs_lines_for_table, sizeof(__pyx_k_number_of_NULLs_lines_for_table), 0, 0, 1, 0},
  {&__pyx_n_s_open, __pyx_k_open, sizeof(__pyx_k_open), 0, 0, 1, 1},
  {&__pyx_n_s_options, __pyx_k_options, sizeof(__pyx_k_options), 0, 0, 1, 1},
  {&__pyx_n_s_p, __pyx_k_p, sizeof(__pyx_k_p), 0, 0, 1, 1},
  {&__pyx_kp_s_p_2, __pyx_k_p_2, sizeof(__pyx_k_p_2), 0, 0, 1, 0},
  {&__pyx_n_s_parseSExpression, __pyx_k_parseSExpression, sizeof(__pyx_k_parseSExpression), 0, 0, 1, 1},
  {&__pyx_n_s_parse_args, __pyx_k_parse_args, sizeof(__pyx_k_parse_args), 0, 0, 1, 1},
  {&__pyx_n_s_parser, __pyx_k_parser, sizeof(__pyx_k_parser), 0, 0, 1, 1},
  {&__pyx_kp_s_path_for_saving_travatar_rule_ta, __pyx_k_path_for_saving_travatar_rule_ta, sizeof(__pyx_k_path_for_saving_travatar_rule_ta), 0, 0, 1, 0},
  {&__pyx_n_s_phrase, __pyx_k_phrase, sizeof(__pyx_k_phrase), 0, 0, 1, 1},
  {&__pyx_kp_s_phrase_table_gz, __pyx_k_phrase_table_gz, sizeof(__pyx_k_phrase_table_gz), 0, 0, 1, 0},
  {&__pyx_n_s_pivot, __pyx_k_pivot, sizeof(__pyx_k_pivot), 0, 0, 1, 1},
  {&__pyx_n_s_pivotRecPairs, __pyx_k_pivotRecPairs, sizeof(__pyx_k_pivotRecPairs), 0, 0, 1, 1},
  {&__pyx_n_s_prefix, __pyx_k_prefix, sizeof(__pyx_k_prefix), 0, 0, 1, 1},
  {&__pyx_n_s_prepare, __pyx_k_prepare, sizeof(__pyx_k_prepare), 0, 0, 1, 1},
  {&__pyx_n_s_print, __pyx_k_print, sizeof(__pyx_k_print), 0, 0, 1, 1},
  {&__pyx_n_s_processing, __pyx_k_processing, sizeof(__pyx_k_processing), 0, 0, 1, 1},
  {&__pyx_n_s_prodprob, __pyx_k_prodprob, sizeof(__pyx_k_prodprob), 0, 0, 1, 1},
  {&__pyx_kp_s_prodprob_table, __pyx_k_prodprob_table, sizeof(__pyx_k_prodprob_table), 0, 0, 1, 0},
  {&__pyx_n_s_prodweight, __pyx_k_prodweight, sizeof(__pyx_k_prodweight), 0, 0, 1, 1},
  {&__pyx_n_s_progress, __pyx_k_progress, sizeof(__pyx_k_progress), 0, 0, 1, 1},
  {&__pyx_kp_s_progress_2, __pyx_k_progress_2, sizeof(__pyx_k_progress_2), 0, 0, 1, 0},
  {&__pyx_n_s_pvtIndex, __pyx_k_pvtIndex, sizeof(__pyx_k_pvtIndex), 0, 0, 1, 1},
  {&__pyx_n_s_pvtIndices, __pyx_k_pvtIndices, sizeof(__pyx_k_pvtIndices), 0, 0, 1, 1},
  {&__pyx_n_s_qualname, __pyx_k_qualname, sizeof(__pyx_k_qualname), 0, 0, 1, 1},
  {&__pyx_n_s_r, __pyx_k_r, sizeof(__pyx_k_r), 0, 0, 1, 1},
  {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
  {&__pyx_n_s_rate, __pyx_k_rate, sizeof(__pyx_k_rate), 0, 0, 1, 1},
  {&__pyx_n_s_rec, __pyx_k_rec, sizeof(__pyx_k_rec), 0, 0, 1, 1},
  {&__pyx_n_s_recMulti, __pyx_k_recMulti, sizeof(__pyx_k_recMulti), 0, 0, 1, 1},
  {&__pyx_n_s_recPair, __pyx_k_recPair, sizeof(__pyx_k_recPair), 0, 0, 1, 1},
  {&__pyx_n_s_recPivot, __pyx_k_recPivot, sizeof(__pyx_k_recPivot), 0, 0, 1, 1},
  {&__pyx_n_s_recPvtTrg, __pyx_k_recPvtTrg, sizeof(__pyx_k_recPvtTrg), 0, 0, 1, 1},
  {&__pyx_n_s_recSrcPvt, __pyx_k_recSrcPvt, sizeof(__pyx_k_recSrcPvt), 0, 0, 1, 1},
  {&__pyx_n_s_recordList, __pyx_k_recordList, sizeof(__pyx_k_recordList), 0, 0, 1, 1},
  {&__pyx_n_s_records, __pyx_k_records, sizeof(__pyx_k_records), 0, 0, 1, 1},
  {&__pyx_n_s_reverse, __pyx_k_reverse, sizeof(__pyx_k_reverse), 0, 0, 1, 1},
  {&__pyx_n_s_rows, __pyx_k_rows, sizeof(__pyx_k_rows), 0, 0, 1, 1},
  {&__pyx_n_s_rule, __pyx_k_rule, sizeof(__pyx_k_rule), 0, 0, 1, 1},
  {&__pyx_kp_s_rule_table_1, __pyx_k_rule_table_1, sizeof(__pyx_k_rule_table_1), 0, 0, 1, 0},
  {&__pyx_kp_s_rule_table_2, __pyx_k_rule_table_2, sizeof(__pyx_k_rule_table_2), 0, 0, 1, 0},
  {&__pyx_kp_s_s, __pyx_k_s, sizeof(__pyx_k_s), 0, 0, 1, 0},
  {&__pyx_kp_s_s_s, __pyx_k_s_s, sizeof(__pyx_k_s_s), 0, 0, 1, 0},
  {&__pyx_kp_s_s_s_2, __pyx_k_s_s_2, sizeof(__pyx_k_s_s_2), 0, 0, 1, 0},
  {&__pyx_n_s_saveFile, __pyx_k_saveFile, sizeof(__pyx_k_saveFile), 0, 0, 1, 1},
  {&__pyx_n_s_savePath, __pyx_k_savePath, sizeof(__pyx_k_savePath), 0, 0, 1, 1},
  {&__pyx_n_s_savefile, __pyx_k_savefile, sizeof(__pyx_k_savefile), 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_setPhrasesPvtTrg, __pyx_k_setPhrasesPvtTrg, sizeof(__pyx_k_setPhrasesPvtTrg), 0, 0, 1, 1},
  {&__pyx_n_s_setPhrasesSrcPvt, __pyx_k_setPhrasesSrcPvt, sizeof(__pyx_k_setPhrasesSrcPvt), 0, 0, 1, 1},
  {&__pyx_n_s_setPhrasesSrcTrg, __pyx_k_setPhrasesSrcTrg, sizeof(__pyx_k_setPhrasesSrcTrg), 0, 0, 1, 1},
  {&__pyx_n_s_setWordsPvtTrg, __pyx_k_setWordsPvtTrg, sizeof(__pyx_k_setWordsPvtTrg), 0, 0, 1, 1},
  {&__pyx_n_s_setWordsSrcPvt, __pyx_k_setWordsSrcPvt, sizeof(__pyx_k_setWordsSrcPvt), 0, 0, 1, 1},
  {&__pyx_n_s_setWordsSrcTrg, __pyx_k_setWordsSrcTrg, sizeof(__pyx_k_setWordsSrcTrg), 0, 0, 1, 1},
  {&__pyx_n_s_setdefault, __pyx_k_setdefault, sizeof(__pyx_k_setdefault), 0, 0, 1, 1},
  {&__pyx_n_s_showProgress, __pyx_k_showProgress, sizeof(__pyx_k_showProgress), 0, 0, 1, 1},
  {&__pyx_kp_s_show_progress, __pyx_k_show_progress, sizeof(__pyx_k_show_progress), 0, 0, 1, 0},
  {&__pyx_n_s_sort, __pyx_k_sort, sizeof(__pyx_k_sort), 0, 0, 1, 1},
  {&__pyx_n_s_split, __pyx_k_split, sizeof(__pyx_k_split), 0, 0, 1, 1},
  {&__pyx_n_s_sqrt, __pyx_k_sqrt, sizeof(__pyx_k_sqrt), 0, 0, 1, 1},
  {&__pyx_n_s_src, __pyx_k_src, sizeof(__pyx_k_src), 0, 0, 1, 1},
  {&__pyx_n_s_srcCount, __pyx_k_srcCount, sizeof(__pyx_k_srcCount), 0, 0, 1, 1},
  {&__pyx_n_s_srcCounts, __pyx_k_srcCounts, sizeof(__pyx_k_srcCounts), 0, 0, 1, 1},
  {&__pyx_n_s_srcFeatures, __pyx_k_srcFeatures, sizeof(__pyx_k_srcFeatures), 0, 0, 1, 1},
  {&__pyx_n_s_srcIndex, __pyx_k_srcIndex, sizeof(__pyx_k_srcIndex), 0, 0, 1, 1},
  {&__pyx_n_s_srcIndices, __pyx_k_srcIndices, sizeof(__pyx_k_srcIndices), 0, 0, 1, 1},
  {&__pyx_n_s_srcTerm, __pyx_k_srcTerm, sizeof(__pyx_k_srcTerm), 0, 0, 1, 1},
  {&__pyx_n_s_srcTerms, __pyx_k_srcTerms, sizeof(__pyx_k_srcTerms), 0, 0, 1, 1},
  {&__pyx_n_s_srcWord, __pyx_k_srcWord, sizeof(__pyx_k_srcWord), 0, 0, 1, 1},
  {&__pyx_n_s_src_hiero, __pyx_k_src_hiero, sizeof(__pyx_k_src_hiero), 0, 0, 1, 1},
  {&__pyx_n_s_src_symbols, __pyx_k_src_symbols, sizeof(__pyx_k_src_symbols), 0, 0, 1, 1},
  {&__pyx_n_s_store_true, __pyx_k_store_true, sizeof(__pyx_k_store_true), 0, 0, 1, 1},
  {&__pyx_n_s_strMultiTrg, __pyx_k_strMultiTrg, sizeof(__pyx_k_strMultiTrg), 0, 0, 1, 1},
  {&__pyx_n_s_symbols, __pyx_k_symbols, sizeof(__pyx_k_symbols), 0, 0, 1, 1},
  {&__pyx_n_s_sys, __pyx_k_sys, sizeof(__pyx_k_sys), 0, 0, 1, 1},
  {&__pyx_n_s_table, __pyx_k_table, sizeof(__pyx_k_table), 0, 0, 1, 1},
  {&__pyx_n_s_table1, __pyx_k_table1, sizeof(__pyx_k_table1), 0, 0, 1, 1},
  {&__pyx_n_s_table2, __pyx_k_table2, sizeof(__pyx_k_table2), 0, 0, 1, 1},
  {&__pyx_n_s_tablePvtTrg, __pyx_k_tablePvtTrg, sizeof(__pyx_k_tablePvtTrg), 0, 0, 1, 1},
  {&__pyx_n_s_tableSrcPvt, __pyx_k_tableSrcPvt, sizeof(__pyx_k_tableSrcPvt), 0, 0, 1, 1},
  {&__pyx_n_s_table_file, __pyx_k_table_file, sizeof(__pyx_k_table_file), 0, 0, 1, 1},
  {&__pyx_n_s_table_path, __pyx_k_table_path, sizeof(__pyx_k_table_path), 0, 0, 1, 1},
  {&__pyx_n_s_term, __pyx_k_term, sizeof(__pyx_k_term), 0, 0, 1, 1},
  {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  {&__pyx_n_s_threshold, __pyx_k_threshold, sizeof(__pyx_k_threshold), 0, 0, 1, 1},
  {&__pyx_kp_s_threshold_2, __pyx_k_threshold_2, sizeof(__pyx_k_threshold_2), 0, 0, 1, 0},
  {&__pyx_kp_s_threshold_for_ignoring_the_phras, __pyx_k_threshold_for_ignoring_the_phras, sizeof(__pyx_k_threshold_for_ignoring_the_phras), 0, 0, 1, 0},
  {&__pyx_n_s_to_str, __pyx_k_to_str, sizeof(__pyx_k_to_str), 0, 0, 1, 1},
  {&__pyx_n_s_total, __pyx_k_total, sizeof(__pyx_k_total), 0, 0, 1, 1},
  {&__pyx_n_s_tree1, __pyx_k_tree1, sizeof(__pyx_k_tree1), 0, 0, 1, 1},
  {&__pyx_n_s_tree2, __pyx_k_tree2, sizeof(__pyx_k_tree2), 0, 0, 1, 1},
  {&__pyx_n_s_treecomp, __pyx_k_treecomp, sizeof(__pyx_k_treecomp), 0, 0, 1, 1},
  {&__pyx_n_s_treedist, __pyx_k_treedist, sizeof(__pyx_k_treedist), 0, 0, 1, 1},
  {&__pyx_n_s_treedistexp, __pyx_k_treedistexp, sizeof(__pyx_k_treedistexp), 0, 0, 1, 1},
  {&__pyx_n_s_trees, __pyx_k_trees, sizeof(__pyx_k_trees), 0, 0, 1, 1},
  {&__pyx_n_s_trg, __pyx_k_trg, sizeof(__pyx_k_trg), 0, 0, 1, 1},
  {&__pyx_n_s_trgCounts, __pyx_k_trgCounts, sizeof(__pyx_k_trgCounts), 0, 0, 1, 1},
  {&__pyx_n_s_trgFeatures, __pyx_k_trgFeatures, sizeof(__pyx_k_trgFeatures), 0, 0, 1, 1},
  {&__pyx_n_s_trgIndex, __pyx_k_trgIndex, sizeof(__pyx_k_trgIndex), 0, 0, 1, 1},
  {&__pyx_n_s_trgKey, __pyx_k_trgKey, sizeof(__pyx_k_trgKey), 0, 0, 1, 1},
  {&__pyx_n_s_trgPair, __pyx_k_trgPair, sizeof(__pyx_k_trgPair), 0, 0, 1, 1},
  {&__pyx_n_s_trgProb, __pyx_k_trgProb, sizeof(__pyx_k_trgProb), 0, 0, 1, 1},
  {&__pyx_n_s_trgSumProb, __pyx_k_trgSumProb, sizeof(__pyx_k_trgSumProb), 0, 0, 1, 1},
  {&__pyx_n_s_trgSymbols, __pyx_k_trgSymbols, sizeof(__pyx_k_trgSymbols), 0, 0, 1, 1},
  {&__pyx_n_s_trgTerm, __pyx_k_trgTerm, sizeof(__pyx_k_trgTerm), 0, 0, 1, 1},
  {&__pyx_n_s_trgTerms, __pyx_k_trgTerms, sizeof(__pyx_k_trgTerms), 0, 0, 1, 1},
  {&__pyx_kp_s_triangulation_method, __pyx_k_triangulation_method, sizeof(__pyx_k_triangulation_method), 0, 0, 1, 0},
  {&__pyx_n_s_type, __pyx_k_type, sizeof(__pyx_k_type), 0, 0, 1, 1},
  {&__pyx_n_s_uniqPhrasesPvtTrg, __pyx_k_uniqPhrasesPvtTrg, sizeof(__pyx_k_uniqPhrasesPvtTrg), 0, 0, 1, 1},
  {&__pyx_n_s_uniqPhrasesSrcPvt, __pyx_k_uniqPhrasesSrcPvt, sizeof(__pyx_k_uniqPhrasesSrcPvt), 0, 0, 1, 1},
  {&__pyx_n_s_uniqPhrasesSrcTrg, __pyx_k_uniqPhrasesSrcTrg, sizeof(__pyx_k_uniqPhrasesSrcTrg), 0, 0, 1, 1},
  {&__pyx_n_s_uniqWordsPvtTrg, __pyx_k_uniqWordsPvtTrg, sizeof(__pyx_k_uniqWordsPvtTrg), 0, 0, 1, 1},
  {&__pyx_n_s_uniqWordsSrcPvt, __pyx_k_uniqWordsSrcPvt, sizeof(__pyx_k_uniqWordsSrcPvt), 0, 0, 1, 1},
  {&__pyx_n_s_uniqWordsSrcTrg, __pyx_k_uniqWordsSrcTrg, sizeof(__pyx_k_uniqWordsSrcTrg), 0, 0, 1, 1},
  {&__pyx_n_s_updateCounts, __pyx_k_updateCounts, sizeof(__pyx_k_updateCounts), 0, 0, 1, 1},
  {&__pyx_n_s_updateFeatures, __pyx_k_updateFeatures, sizeof(__pyx_k_updateFeatures), 0, 0, 1, 1},
  {&__pyx_n_s_updateWordPairCounts, __pyx_k_updateWordPairCounts, sizeof(__pyx_k_updateWordPairCounts), 0, 0, 1, 1},
  {&__pyx_n_s_values, __pyx_k_values, sizeof(__pyx_k_values), 0, 0, 1, 1},
  {&__pyx_n_s_vars, __pyx_k_vars, sizeof(__pyx_k_vars), 0, 0, 1, 1},
  {&__pyx_n_s_view, __pyx_k_view, sizeof(__pyx_k_view), 0, 0, 1, 1},
  {&__pyx_n_s_w, __pyx_k_w, sizeof(__pyx_k_w), 0, 0, 1, 1},
  {&__pyx_n_s_word, __pyx_k_word, sizeof(__pyx_k_word), 0, 0, 1, 1},
  {&__pyx_kp_s_word_pair_counts_file, __pyx_k_word_pair_counts_file, sizeof(__pyx_k_word_pair_counts_file), 0, 0, 1, 0},
  {&__pyx_n_s_workOptions, __pyx_k_workOptions, sizeof(__pyx_k_workOptions), 0, 0, 1, 1},
  {&__pyx_n_s_workdir, __pyx_k_workdir, sizeof(__pyx_k_workdir), 0, 0, 1, 1},
  {&__pyx_kp_s_workdir_2, __pyx_k_workdir_2, sizeof(__pyx_k_workdir_2), 0, 0, 1, 0},
  {&__pyx_kp_s_working_directory, __pyx_k_working_directory, sizeof(__pyx_k_working_directory), 0, 0, 1, 0},
  {&__pyx_n_s_workset, __pyx_k_workset, sizeof(__pyx_k_workset), 0, 0, 1, 1},
  {&__pyx_n_s_write, __pyx_k_write, sizeof(__pyx_k_write), 0, 0, 1, 1},
  {&__pyx_n_s_writeRecord, __pyx_k_writeRecord, sizeof(__pyx_k_writeRecord), 0, 0, 1, 1},
  {&__pyx_n_s_writeRecords, __pyx_k_writeRecords, sizeof(__pyx_k_writeRecords), 0, 0, 1, 1},
  {&__pyx_n_s_wt, __pyx_k_wt, sizeof(__pyx_k_wt), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 540, __pyx_L1_error)
  __pyx_builtin_open = __Pyx_GetBuiltinName(__pyx_n_s_open); if (!__pyx_builtin_open) __PYX_ERR(0, 660, __pyx_L1_error)
  __pyx_builtin_KeyboardInterrupt = __Pyx_GetBuiltinName(__pyx_n_s_KeyboardInterrupt); if (!__pyx_builtin_KeyboardInterrupt) __PYX_ERR(0, 744, __pyx_L1_error)
  __pyx_builtin_vars = __Pyx_GetBuiltinName(__pyx_n_s_vars); if (!__pyx_builtin_vars) __PYX_ERR(0, 769, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

static int __Pyx_InitCachedConstants(void) {
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0);

  /* "lpu/smt/trans_models/triangulate.pyx":125
 *     #logging.debug(trgFeatures)
 *     #if method.find('prodprob') >= 0:
 *     if workset.method.find('prodprob') >= 0:             # <<<<<<<<<<<<<<
 *         # multiplying scores and marginalizing
 *         if not multi_target:
 */
  __pyx_tuple_ = PyTuple_Pack(1, __pyx_n_s_prodprob); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 125, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple_);
  __Pyx_GIVEREF(__pyx_tuple_);

  /* "lpu/smt/trans_models/triangulate.pyx":128
 *         # multiplying scores and marginalizing
 *         if not multi_target:
 *             for key in ['egfl', 'egfp', 'fgel', 'fgep']:             # <<<<<<<<<<<<<<
 *                 features.setdefault(key, 0)
 *                 if workset.matchMethod == 'hiero':
 */
  __pyx_tuple__2 = PyTuple_Pack(4, __pyx_n_s_egfl, __pyx_n_s_egfp, __pyx_n_s_fgel, __pyx_n_s_fgep); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 128, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__2);
  __Pyx_GIVEREF(__pyx_tuple__2);

  /* "lpu/smt/trans_models/triangulate.pyx":137
 *                     features[key] += (srcFeatures[key] * trgFeatures[key])
 *                 elif workset.matchMethod == 'treedist':
 *                     elems1 = recPair[0].trg.split(' ')[0:-1]             # <<<<<<<<<<<<<<
 *                     elems2 = recPair[1].src.split(' ')[0:-1]
 *                     tree1 = trees.parseSExpression('(' + str.join(' ', elems1) + ')')[0]
 */
  __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s__3); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 137, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__4);
  __Pyx_GIVEREF(__pyx_tuple__4);
  __pyx_slice__5 = PySlice_New(__pyx_int_0, __pyx_int_neg_1, Py_None); if (unlikely(!__pyx_slice__5)) __PYX_ERR(0, 137, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__5);
  __Pyx_GIVEREF(__pyx_slice__5);

  /* "lpu/smt/trans_models/triangulate.pyx":138
 *                 elif workset.matchMethod == 'treedist':
 *                     elems1 = recPair[0].trg.split(' ')[0:-1]
 *                     elems2 = recPair[1].src.split(' ')[0:-1]             # <<<<<<<<<<<<<<
 *                     tree1 = trees.parseSExpression('(' + str.join(' ', elems1) + ')')[0]
 *                     tree2 = trees.parseSExpression('(' + str.join(' ', elems2) + ')')[0]
 */
  __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_s__3); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 138, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__6);
  __Pyx_GIVEREF(__pyx_tuple__6);
  __pyx_slice__7 = PySlice_New(__pyx_int_0, __pyx_int_neg_1, Py_None); if (unlikely(!__pyx_slice__7)) __PYX_ERR(0, 138, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__7);
  __Pyx_GIVEREF(__pyx_slice__7);

  /* "lpu/smt/trans_models/triangulate.pyx":147
 *                     features[key] += (rate * srcFeatures[key] * trgFeatures[key])
 *                 elif workset.matchMethod == 'treedistexp':
 *                     elems1 = recPair[0].trg.split(' ')[0:-1]             # <<<<<<<<<<<<<<
 *                     elems2 = recPair[1].src.split(' ')[0:-1]
 *                     tree1 = trees.parseSExpression('(' + str.join(' ', elems1) + ')')[0]
 */
  __pyx_tuple__10 = PyTuple_Pack(1, __pyx_kp_s__3); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 147, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__10);
  __Pyx_GIVEREF(__pyx_tuple__10);
  __pyx_slice__11 = PySlice_New(__pyx_int_0, __pyx_int_neg_1, Py_None); if (unlikely(!__pyx_slice__11)) __PYX_ERR(0, 147, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__11);
  __Pyx_GIVEREF(__pyx_slice__11);

  /* "lpu/smt/trans_models/triangulate.pyx":148
 *                 elif workset.matchMethod == 'treedistexp':
 *                     elems1 = recPair[0].trg.split(' ')[0:-1]
 *                     elems2 = recPair[1].src.split(' ')[0:-1]             # <<<<<<<<<<<<<<
 *                     tree1 = trees.parseSExpression('(' + str.join(' ', elems1) + ')')[0]
 *                     tree2 = trees.parseSExpression('(' + str.join(' ', elems2) + ')')[0]
 */
  __pyx_tuple__12 = PyTuple_Pack(1, __pyx_kp_s__3); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 148, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__12);
  __Pyx_GIVEREF(__pyx_tuple__12);
  __pyx_slice__13 = PySlice_New(__pyx_int_0, __pyx_int_neg_1, Py_None); if (unlikely(!__pyx_slice__13)) __PYX_ERR(0, 148, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__13);
  __Pyx_GIVEREF(__pyx_slice__13);

  /* "lpu/smt/trans_models/triangulate.pyx":171
 * #            # P(src|pvt,trg) ~ P(src|pvt)
 * #            features['fgep'] = srcFeatures['fgep']
 *             for key in ['egfl', 'egfp', 'fgel', 'fgep']:             # <<<<<<<<<<<<<<
 *                 features['1'+key] = srcFeatures[key]
 *     else:
 */
  __pyx_tuple__14 = PyTuple_Pack(4, __pyx_n_s_egfl, __pyx_n_s_egfp, __pyx_n_s_fgel, __pyx_n_s_fgep); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(0, 171, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__14);
  __Pyx_GIVEREF(__pyx_tuple__14);

  /* "lpu/smt/trans_models/triangulate.pyx":175
 *     else:
 *         # multiplying only lexical weights and marginalizing
 *         for key in ['egfl', 'fgel']:             # <<<<<<<<<<<<<<
 *             features.setdefault(key, 0)
 *             features[key] += (srcFeatures[key] * trgFeatures[key])
 */
  __pyx_tuple__15 = PyTuple_Pack(2, __pyx_n_s_egfl, __pyx_n_s_fgel); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 175, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__15);
  __Pyx_GIVEREF(__pyx_tuple__15);

  /* "lpu/smt/trans_models/triangulate.pyx":407
 *             # copying the estimated features of source-target records to source-target-pivot records
 *             for multiKey, recMulti in multiRecords.items():
 *                 trgPair = recMulti.trg.split(' |COL| ')             # <<<<<<<<<<<<<<
 *                 recPivot = records[trgPair[0]+' |||']
 *                 for featureKey in ['egfl', 'egfp', 'fgel', 'fgep']:
 */
  __pyx_tuple__18 = PyTuple_Pack(1, __pyx_kp_s_COL); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 407, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__18);
  __Pyx_GIVEREF(__pyx_tuple__18);

  /* "lpu/smt/trans_models/triangulate.pyx":409
 *                 trgPair = recMulti.trg.split(' |COL| ')
 *                 recPivot = records[trgPair[0]+' |||']
 *                 for featureKey in ['egfl', 'egfp', 'fgel', 'fgep']:             # <<<<<<<<<<<<<<
 *                     recMulti.features['0'+featureKey] = recPivot.features[featureKey]
 *                 if workset.jointMethod == 'independent':
 */
  __pyx_tuple__19 = PyTuple_Pack(4, __pyx_n_s_egfl, __pyx_n_s_egfp, __pyx_n_s_fgel, __pyx_n_s_fgep); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 409, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__19);
  __Pyx_GIVEREF(__pyx_tuple__19);

  /* "lpu/smt/trans_models/triangulate.pyx":509
 *       if rec.counts.co > 0:
 *           fileObj.write( rec.to_str() )
 *           fileObj.write("\n")             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_tuple__21 = PyTuple_Pack(1, __pyx_kp_s__20); if (unlikely(!__pyx_tuple__21)) __PYX_ERR(0, 509, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__21);
  __Pyx_GIVEREF(__pyx_tuple__21);

  /* "lpu/smt/trans_models/triangulate.pyx":517
 *         if rec.counts.cooc > 0:
 *             workset.foutPivot.write( rec.to_str() )
 *             workset.foutPivot.write( "\n" )             # <<<<<<<<<<<<<<
 *             workset.foutPivot.flush()
 *             workset.numRecSrcTrg += 1
 */
  __pyx_tuple__22 = PyTuple_Pack(1, __pyx_kp_s__20); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 517, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__22);
  __Pyx_GIVEREF(__pyx_tuple__22);

  /* "lpu/smt/trans_models/triangulate.pyx":572
 *     for line in table_file:
 *         rec = RecordClass(line)
 *         if rec.trg.find('|COL|') < 0:             # <<<<<<<<<<<<<<
 *             rec.features['egfl'] = calcLexWeight(rec, lexCounts, reverse = False)
 *             rec.features['fgel'] = calcLexWeight(rec, lexCounts, reverse = True)
 */
  __pyx_tuple__24 = PyTuple_Pack(1, __pyx_kp_s_COL_3); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 572, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__24);
  __Pyx_GIVEREF(__pyx_tuple__24);

  /* "lpu/smt/trans_models/triangulate.pyx":629
 *         rows = []
 *         lastSrc = ''
 *         logging.log("beginning pivot\n")             # <<<<<<<<<<<<<<
 *         #for recSrcPvt in progress.view(tableSrcPvt.find(''),maxCount=len(tableSrcPvt)):
 *         for recSrcPvt in progress.view(tableSrcPvt.find(''),'processing',max_count=len(tableSrcPvt)):
 */
  __pyx_tuple__26 = PyTuple_Pack(1, __pyx_kp_s_beginning_pivot); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 629, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__26);
  __Pyx_GIVEREF(__pyx_tuple__26);

  /* "lpu/smt/trans_models/triangulate.pyx":631
 *         logging.log("beginning pivot\n")
 *         #for recSrcPvt in progress.view(tableSrcPvt.find(''),maxCount=len(tableSrcPvt)):
 *         for recSrcPvt in progress.view(tableSrcPvt.find(''),'processing',max_count=len(tableSrcPvt)):             # <<<<<<<<<<<<<<
 *             src = recSrcPvt.src
 *             workset.numRecSrcPvt += 1
 */
  __pyx_tuple__27 = PyTuple_Pack(1, __pyx_kp_s__16); if (unlikely(!__pyx_tuple__27)) __PYX_ERR(0, 631, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__27);
  __Pyx_GIVEREF(__pyx_tuple__27);

  /* "lpu/smt/trans_models/triangulate.pyx":664
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesSrcPvt', len(workset.setPhrasesSrcPvt)))
 *                 fobj.write("%s = %s\n" % ('uniqWordsSrcPvt', len(workset.setWordsSrcPvt)))
 *                 fobj.write("--\n")             # <<<<<<<<<<<<<<
 *                 fobj.write("%s = %s\n" % ('numRecPvtTrg', workset.numRecPvtTrg))
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesPvtTrg', len(workset.setPhrasesPvtTrg)))
 */
  __pyx_tuple__29 = PyTuple_Pack(1, __pyx_kp_s__28); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 664, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__29);
  __Pyx_GIVEREF(__pyx_tuple__29);

  /* "lpu/smt/trans_models/triangulate.pyx":668
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesPvtTrg', len(workset.setPhrasesPvtTrg)))
 *                 fobj.write("%s = %s\n" % ('uniqWordsPvtTrg', len(workset.setWordsPvtTrg)))
 *                 fobj.write("--\n")             # <<<<<<<<<<<<<<
 *                 fobj.write("%s = %s\n" % ('numRecSrcTrg', workset.numRecSrcTrg))
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesSrcTrg', len(workset.setPhrasesSrcTrg)))
 */
  __pyx_tuple__30 = PyTuple_Pack(1, __pyx_kp_s__28); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 668, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__30);
  __Pyx_GIVEREF(__pyx_tuple__30);

  /* "lpu/smt/trans_models/triangulate.pyx":672
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesSrcTrg', len(workset.setPhrasesSrcTrg)))
 *                 fobj.write("%s = %s\n" % ('uniqWordsSrcTrg', len(workset.setWordsSrcTrg)))
 *                 fobj.write("--\n")             # <<<<<<<<<<<<<<
 *                 if len(workset.setWordsSrcPvt) != len(workset.setWordsSrcTrg):
 *                     fobj.write("Lost Words:\n")
 */
  __pyx_tuple__31 = PyTuple_Pack(1, __pyx_kp_s__28); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 672, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__31);
  __Pyx_GIVEREF(__pyx_tuple__31);

  /* "lpu/smt/trans_models/triangulate.pyx":674
 *                 fobj.write("--\n")
 *                 if len(workset.setWordsSrcPvt) != len(workset.setWordsSrcTrg):
 *                     fobj.write("Lost Words:\n")             # <<<<<<<<<<<<<<
 *                     for word in iter(workset.setWordsSrcPvt - workset.setWordsSrcTrg):
 *                         fobj.write("\t* \"%s\"\n" % word)
 */
  __pyx_tuple__32 = PyTuple_Pack(1, __pyx_kp_s_Lost_Words); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 674, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__32);
  __Pyx_GIVEREF(__pyx_tuple__32);

  /* "lpu/smt/trans_models/triangulate.pyx":660
 *             rows = []
 *         if logFile:
 *             with open(logFile, 'w') as fobj:             # <<<<<<<<<<<<<<
 *                 fobj.write("%s = %s\n" % ('numRecSrcPvt', workset.numRecSrcPvt))
 *                 fobj.write("%s = %s\n" % ('uniqPhrasesSrcPvt', len(workset.setPhrasesSrcPvt)))
 */
  __pyx_tuple__33 = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(0, 660, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__33);
  __Pyx_GIVEREF(__pyx_tuple__33);

  /* "lpu/smt/trans_models/triangulate.pyx":749
 *         print('Caught KeyboardInterrupt, terminating all the worker processes')
 *         workset.close()
 *         sys.exit(1)             # <<<<<<<<<<<<<<
 * 
 * def main():
 */
  __pyx_tuple__34 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 749, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__34);
  __Pyx_GIVEREF(__pyx_tuple__34);

  /* "lpu/smt/trans_models/triangulate.pyx":753
 * def main():
 *     parser = argparse.ArgumentParser(description = 'load 2 rule tables and pivot into one travatar rule table')
 *     parser.add_argument('table1', help = 'rule table 1')             # <<<<<<<<<<<<<<
 *     parser.add_argument('table2', help = 'rule table 2')
 *     parser.add_argument('savefile', help = 'path for saving travatar rule table file')
 */
  __pyx_tuple__35 = PyTuple_Pack(1, __pyx_n_s_table1); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(0, 753, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__35);
  __Pyx_GIVEREF(__pyx_tuple__35);

  /* "lpu/smt/trans_models/triangulate.pyx":754
 *     parser = argparse.ArgumentParser(description = 'load 2 rule tables and pivot into one travatar rule table')
 *     parser.add_argument('table1', help = 'rule table 1')
 *     parser.add_argument('table2', help = 'rule table 2')             # <<<<<<<<<<<<<<
 *     parser.add_argument('savefile', help = 'path for saving travatar rule table file')
 *     parser.add_argument('--threshold', help = 'threshold for ignoring the phrase translation probability (real number)', type=float, default=THRESHOLD)
 */
  __pyx_tuple__36 = PyTuple_Pack(1, __pyx_n_s_table2); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(0, 754, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__36);
  __Pyx_GIVEREF(__pyx_tuple__36);

  /* "lpu/smt/trans_models/triangulate.pyx":755
 *     parser.add_argument('table1', help = 'rule table 1')
 *     parser.add_argument('table2', help = 'rule table 2')
 *     parser.add_argument('savefile', help = 'path for saving travatar rule table file')             # <<<<<<<<<<<<<<
 *     parser.add_argument('--threshold', help = 'threshold for ignoring the phrase translation probability (real number)', type=float, default=THRESHOLD)
 *     parser.add_argument('--nbest', help = 'best n scores for rule pair filtering (default = 20)', type=int, default=NBEST)
 */
  __pyx_tuple__37 = PyTuple_Pack(1, __pyx_n_s_savefile); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 755, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__37);
  __Pyx_GIVEREF(__pyx_tuple__37);

  /* "lpu/smt/trans_models/triangulate.pyx":756
 *     parser.add_argument('table2', help = 'rule table 2')
 *     parser.add_argument('savefile', help = 'path for saving travatar rule table file')
 *     parser.add_argument('--threshold', help = 'threshold for ignoring the phrase translation probability (real number)', type=float, default=THRESHOLD)             # <<<<<<<<<<<<<<
 *     parser.add_argument('--nbest', help = 'best n scores for rule pair filtering (default = 20)', type=int, default=NBEST)
 *     parser.add_argument('--method', help = 'triangulation method', choices=method_list, default=METHOD)
 */
  __pyx_tuple__38 = PyTuple_Pack(1, __pyx_kp_s_threshold_2); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(0, 756, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__38);
  __Pyx_GIVEREF(__pyx_tuple__38);

  /* "lpu/smt/trans_models/triangulate.pyx":757
 *     parser.add_argument('savefile', help = 'path for saving travatar rule table file')
 *     parser.add_argument('--threshold', help = 'threshold for ignoring the phrase translation probability (real number)', type=float, default=THRESHOLD)
 *     parser.add_argument('--nbest', help = 'best n scores for rule pair filtering (default = 20)', type=int, default=NBEST)             # <<<<<<<<<<<<<<
 *     parser.add_argument('--method', help = 'triangulation method', choices=method_list, default=METHOD)
 *     parser.add_argument('--lexmethod', help = 'lexical triangulation method', choices=lex_method_list, default=LEX_METHOD)
 */
  __pyx_tuple__39 = PyTuple_Pack(1, __pyx_kp_s_nbest_2); if (unlikely(!__pyx_tuple__39)) __PYX_ERR(0, 757, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__39);
  __Pyx_GIVEREF(__pyx_tuple__39);

  /* "lpu/smt/trans_models/triangulate.pyx":758
 *     parser.add_argument('--threshold', help = 'threshold for ignoring the phrase translation probability (real number)', type=float, default=THRESHOLD)
 *     parser.add_argument('--nbest', help = 'best n scores for rule pair filtering (default = 20)', type=int, default=NBEST)
 *     parser.add_argument('--method', help = 'triangulation method', choices=method_list, default=METHOD)             # <<<<<<<<<<<<<<
 *     parser.add_argument('--lexmethod', help = 'lexical triangulation method', choices=lex_method_list, default=LEX_METHOD)
 *     parser.add_argument('--jointmethod', help = 'method to estimate joint trans probs', choices=joint_method_list, default=JOINT_METHOD)
 */
  __pyx_tuple__40 = PyTuple_Pack(1, __pyx_kp_s_method_2); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(0, 758, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__40);
  __Pyx_GIVEREF(__pyx_tuple__40);

  /* "lpu/smt/trans_models/triangulate.pyx":759
 *     parser.add_argument('--nbest', help = 'best n scores for rule pair filtering (default = 20)', type=int, default=NBEST)
 *     parser.add_argument('--method', help = 'triangulation method', choices=method_list, default=METHOD)
 *     parser.add_argument('--lexmethod', help = 'lexical triangulation method', choices=lex_method_list, default=LEX_METHOD)             # <<<<<<<<<<<<<<
 *     parser.add_argument('--jointmethod', help = 'method to estimate joint trans probs', choices=joint_method_list, default=JOINT_METHOD)
 *     parser.add_argument('--matchmethod', help = 'matching method', choices=match_method_list, default=MATCH_METHOD)
 */
  __pyx_tuple__41 = PyTuple_Pack(1, __pyx_kp_s_lexmethod_2); if (unlikely(!__pyx_tuple__41)) __PYX_ERR(0, 759, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__41);
  __Pyx_GIVEREF(__pyx_tuple__41);

  /* "lpu/smt/trans_models/triangulate.pyx":760
 *     parser.add_argument('--method', help = 'triangulation method', choices=method_list, default=METHOD)
 *     parser.add_argument('--lexmethod', help = 'lexical triangulation method', choices=lex_method_list, default=LEX_METHOD)
 *     parser.add_argument('--jointmethod', help = 'method to estimate joint trans probs', choices=joint_method_list, default=JOINT_METHOD)             # <<<<<<<<<<<<<<
 *     parser.add_argument('--matchmethod', help = 'matching method', choices=match_method_list, default=MATCH_METHOD)
 *     parser.add_argument('--workdir', help = 'working directory', default='.')
 */
  __pyx_tuple__42 = PyTuple_Pack(1, __pyx_kp_s_jointmethod_2); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(0, 760, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__42);
  __Pyx_GIVEREF(__pyx_tuple__42);

  /* "lpu/smt/trans_models/triangulate.pyx":761
 *     parser.add_argument('--lexmethod', help = 'lexical triangulation method', choices=lex_method_list, default=LEX_METHOD)
 *     parser.add_argument('--jointmethod', help = 'method to estimate joint trans probs', choices=joint_method_list, default=JOINT_METHOD)
 *     parser.add_argument('--matchmethod', help = 'matching method', choices=match_method_list, default=MATCH_METHOD)             # <<<<<<<<<<<<<<
 *     parser.add_argument('--workdir', help = 'working directory', default='.')
 *     parser.add_argument('--alignlex', help = 'word pair counts file', default=None)
 */
  __pyx_tuple__43 = PyTuple_Pack(1, __pyx_kp_s_matchmethod_2); if (unlikely(!__pyx_tuple__43)) __PYX_ERR(0, 761, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__43);
  __Pyx_GIVEREF(__pyx_tuple__43);

  /* "lpu/smt/trans_models/triangulate.pyx":762
 *     parser.add_argument('--jointmethod', help = 'method to estimate joint trans probs', choices=joint_method_list, default=JOINT_METHOD)
 *     parser.add_argument('--matchmethod', help = 'matching method', choices=match_method_list, default=MATCH_METHOD)
 *     parser.add_argument('--workdir', help = 'working directory', default='.')             # <<<<<<<<<<<<<<
 *     parser.add_argument('--alignlex', help = 'word pair counts file', default=None)
 *     parser.add_argument('--nulls', help = 'number of NULLs (lines) for table lex', type = int, default=NULLS)
 */
  __pyx_tuple__44 = PyTuple_Pack(1, __pyx_kp_s_workdir_2); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(0, 762, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__44);
  __Pyx_GIVEREF(__pyx_tuple__44);

  /* "lpu/smt/trans_models/triangulate.pyx":763
 *     parser.add_argument('--matchmethod', help = 'matching method', choices=match_method_list, default=MATCH_METHOD)
 *     parser.add_argument('--workdir', help = 'working directory', default='.')
 *     parser.add_argument('--alignlex', help = 'word pair counts file', default=None)             # <<<<<<<<<<<<<<
 *     parser.add_argument('--nulls', help = 'number of NULLs (lines) for table lex', type = int, default=NULLS)
 *     parser.add_argument('--noprefilter', help = 'No pre-filtering', type = bool, default=False)
 */
  __pyx_tuple__45 = PyTuple_Pack(1, __pyx_kp_s_alignlex_2); if (unlikely(!__pyx_tuple__45)) __PYX_ERR(0, 763, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__45);
  __Pyx_GIVEREF(__pyx_tuple__45);

  /* "lpu/smt/trans_models/triangulate.pyx":764
 *     parser.add_argument('--workdir', help = 'working directory', default='.')
 *     parser.add_argument('--alignlex', help = 'word pair counts file', default=None)
 *     parser.add_argument('--nulls', help = 'number of NULLs (lines) for table lex', type = int, default=NULLS)             # <<<<<<<<<<<<<<
 *     parser.add_argument('--noprefilter', help = 'No pre-filtering', type = bool, default=False)
 *     parser.add_argument('--multitarget', help = 'enabling multi target model', action='store_true')
 */
  __pyx_tuple__46 = PyTuple_Pack(1, __pyx_kp_s_nulls_2); if (unlikely(!__pyx_tuple__46)) __PYX_ERR(0, 764, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__46);
  __Pyx_GIVEREF(__pyx_tuple__46);

  /* "lpu/smt/trans_models/triangulate.pyx":765
 *     parser.add_argument('--alignlex', help = 'word pair counts file', default=None)
 *     parser.add_argument('--nulls', help = 'number of NULLs (lines) for table lex', type = int, default=NULLS)
 *     parser.add_argument('--noprefilter', help = 'No pre-filtering', type = bool, default=False)             # <<<<<<<<<<<<<<
 *     parser.add_argument('--multitarget', help = 'enabling multi target model', action='store_true')
 *     parser.add_argument('--progress', '-p', help = 'show progress', type = bool, default=True)
 */
  __pyx_tuple__47 = PyTuple_Pack(1, __pyx_kp_s_noprefilter); if (unlikely(!__pyx_tuple__47)) __PYX_ERR(0, 765, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__47);
  __Pyx_GIVEREF(__pyx_tuple__47);

  /* "lpu/smt/trans_models/triangulate.pyx":766
 *     parser.add_argument('--nulls', help = 'number of NULLs (lines) for table lex', type = int, default=NULLS)
 *     parser.add_argument('--noprefilter', help = 'No pre-filtering', type = bool, default=False)
 *     parser.add_argument('--multitarget', help = 'enabling multi target model', action='store_true')             # <<<<<<<<<<<<<<
 *     parser.add_argument('--progress', '-p', help = 'show progress', type = bool, default=True)
 *     parser.add_argument('--log', help = 'log file (optional)', type = str, default='')
 */
  __pyx_tuple__48 = PyTuple_Pack(1, __pyx_kp_s_multitarget_2); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(0, 766, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__48);
  __Pyx_GIVEREF(__pyx_tuple__48);

  /* "lpu/smt/trans_models/triangulate.pyx":767
 *     parser.add_argument('--noprefilter', help = 'No pre-filtering', type = bool, default=False)
 *     parser.add_argument('--multitarget', help = 'enabling multi target model', action='store_true')
 *     parser.add_argument('--progress', '-p', help = 'show progress', type = bool, default=True)             # <<<<<<<<<<<<<<
 *     parser.add_argument('--log', help = 'log file (optional)', type = str, default='')
 *     args = vars(parser.parse_args())
 */
  __pyx_tuple__49 = PyTuple_Pack(2, __pyx_kp_s_progress_2, __pyx_kp_s_p_2); if (unlikely(!__pyx_tuple__49)) __PYX_ERR(0, 767, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__49);
  __Pyx_GIVEREF(__pyx_tuple__49);

  /* "lpu/smt/trans_models/triangulate.pyx":768
 *     parser.add_argument('--multitarget', help = 'enabling multi target model', action='store_true')
 *     parser.add_argument('--progress', '-p', help = 'show progress', type = bool, default=True)
 *     parser.add_argument('--log', help = 'log file (optional)', type = str, default='')             # <<<<<<<<<<<<<<
 *     args = vars(parser.parse_args())
 * 
 */
  __pyx_tuple__50 = PyTuple_Pack(1, __pyx_kp_s_log_2); if (unlikely(!__pyx_tuple__50)) __PYX_ERR(0, 768, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__50);
  __Pyx_GIVEREF(__pyx_tuple__50);

  /* "lpu/smt/trans_models/triangulate.pyx":57
 * class WorkSet:
 *     '''data set for multi-processing'''
 *     def __init__(self, savefile, workdir, method, **options):             # <<<<<<<<<<<<<<
 *         prefix = options.get('prefix', 'phrase')
 *         self.multi_target = options.get('multi_target', False)
 */
  __pyx_tuple__51 = PyTuple_Pack(6, __pyx_n_s_self, __pyx_n_s_savefile, __pyx_n_s_workdir, __pyx_n_s_method, __pyx_n_s_options, __pyx_n_s_prefix); if (unlikely(!__pyx_tuple__51)) __PYX_ERR(0, 57, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__51);
  __Pyx_GIVEREF(__pyx_tuple__51);
  __pyx_codeobj__52 = (PyObject*)__Pyx_PyCode_New(4, 0, 6, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__51, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_lpu_smt_trans_models_triangulate_2, __pyx_n_s_init, 57, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__52)) __PYX_ERR(0, 57, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":84
 *         self.setWordsSrcTrg = set()
 * 
 *     def __del__(self):             # <<<<<<<<<<<<<<
 *         self.close()
 * 
 */
  __pyx_tuple__53 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__53)) __PYX_ERR(0, 84, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__53);
  __Pyx_GIVEREF(__pyx_tuple__53);
  __pyx_codeobj__54 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__53, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_lpu_smt_trans_models_triangulate_2, __pyx_n_s_del, 84, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__54)) __PYX_ERR(0, 84, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":87
 *         self.close()
 * 
 *     def close(self):             # <<<<<<<<<<<<<<
 *         if self.foutPivot:
 *             self.foutPivot.close()
 */
  __pyx_tuple__55 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__55)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__55);
  __Pyx_GIVEREF(__pyx_tuple__55);
  __pyx_codeobj__56 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__55, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_lpu_smt_trans_models_triangulate_2, __pyx_n_s_close, 87, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__56)) __PYX_ERR(0, 87, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":116
 * 
 * #def updateFeatures(recPivot, recPair, method, multi_target = False, jointMethod = 'memoryless'):
 * def updateFeatures(recPivot, recPair, workset, multi_target = False):             # <<<<<<<<<<<<<<
 *     '''update features'''
 *     features = recPivot.features
 */
  __pyx_tuple__57 = PyTuple_Pack(16, __pyx_n_s_recPivot, __pyx_n_s_recPair, __pyx_n_s_workset, __pyx_n_s_multi_target, __pyx_n_s_features, __pyx_n_s_srcFeatures, __pyx_n_s_trgFeatures, __pyx_n_s_key, __pyx_n_s_elems1, __pyx_n_s_elems2, __pyx_n_s_tree1, __pyx_n_s_tree2, __pyx_n_s_dist, __pyx_n_s_numTerms, __pyx_n_s_numElems, __pyx_n_s_rate); if (unlikely(!__pyx_tuple__57)) __PYX_ERR(0, 116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__57);
  __Pyx_GIVEREF(__pyx_tuple__57);
  __pyx_codeobj__58 = (PyObject*)__Pyx_PyCode_New(4, 0, 16, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__57, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_lpu_smt_trans_models_triangulate_2, __pyx_n_s_updateFeatures, 116, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__58)) __PYX_ERR(0, 116, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":191
 * 
 * 
 * def updateCounts(recPivot, recPair, method):             # <<<<<<<<<<<<<<
 *     '''update occurrence counts of phrase'''
 *     counts = recPivot.counts
 */
  __pyx_tuple__59 = PyTuple_Pack(12, __pyx_n_s_recPivot, __pyx_n_s_recPair, __pyx_n_s_method, __pyx_n_s_counts, __pyx_n_s_features, __pyx_n_s_c, __pyx_n_s_counts1, __pyx_n_s_counts2, __pyx_n_s_cooc1, __pyx_n_s_cooc2, __pyx_n_s_co1, __pyx_n_s_co2); if (unlikely(!__pyx_tuple__59)) __PYX_ERR(0, 191, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__59);
  __Pyx_GIVEREF(__pyx_tuple__59);
  __pyx_codeobj__60 = (PyObject*)__Pyx_PyCode_New(3, 0, 12, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__59, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_lpu_smt_trans_models_triangulate_2, __pyx_n_s_updateCounts, 191, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__60)) __PYX_ERR(0, 191, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":240
 * 
 * 
 * def mergeAligns(recPivot, recPair):             # <<<<<<<<<<<<<<
 *     '''merge word alignments'''
 * #    if recPivot.aligns:
 */
  __pyx_tuple__61 = PyTuple_Pack(9, __pyx_n_s_recPivot, __pyx_n_s_recPair, __pyx_n_s_alignMapSrcPvt, __pyx_n_s_alignMapPvtTrg, __pyx_n_s_srcIndex, __pyx_n_s_pvtIndices, __pyx_n_s_pvtIndex, __pyx_n_s_trgIndex, __pyx_n_s_align); if (unlikely(!__pyx_tuple__61)) __PYX_ERR(0, 240, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__61);
  __Pyx_GIVEREF(__pyx_tuple__61);
  __pyx_codeobj__62 = (PyObject*)__Pyx_PyCode_New(2, 0, 9, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__61, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_lpu_smt_trans_models_triangulate_2, __pyx_n_s_mergeAligns, 240, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__62)) __PYX_ERR(0, 240, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":256
 * 
 * 
 * def filterByCountRatioToMax(records, div = 100):             # <<<<<<<<<<<<<<
 *     coMax = 0
 *     for rec in flattenRecords(records):
 */
  __pyx_tuple__63 = PyTuple_Pack(6, __pyx_n_s_records, __pyx_n_s_div, __pyx_n_s_coMax, __pyx_n_s_rec, __pyx_n_s_newRecords, __pyx_n_s_key); if (unlikely(!__pyx_tuple__63)) __PYX_ERR(0, 256, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__63);
  __Pyx_GIVEREF(__pyx_tuple__63);
  __pyx_codeobj__64 = (PyObject*)__Pyx_PyCode_New(2, 0, 6, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__63, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_lpu_smt_trans_models_triangulate_2, __pyx_n_s_filterByCountRatioToMax, 256, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__64)) __PYX_ERR(0, 256, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":275
 * 
 * 
 * def calcPhraseTransProbsByCounts(records):             # <<<<<<<<<<<<<<
 *     '''calculate forward phrase trans probs by occurrence counts of the phrases'''
 *     srcCount = calcSrcCount(records)
 */
  __pyx_tuple__65 = PyTuple_Pack(4, __pyx_n_s_records, __pyx_n_s_srcCount, __pyx_n_s_rec, __pyx_n_s_counts); if (unlikely(!__pyx_tuple__65)) __PYX_ERR(0, 275, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__65);
  __Pyx_GIVEREF(__pyx_tuple__65);
  __pyx_codeobj__66 = (PyObject*)__Pyx_PyCode_New(1, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__65, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_lpu_smt_trans_models_triangulate_2, __pyx_n_s_calcPhraseTransProbsByCounts, 275, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__66)) __PYX_ERR(0, 275, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":288
 * 
 * 
 * def calcPhraseTransProbsOnTable(table_path, savePath, **options):             # <<<<<<<<<<<<<<
 *     '''calculate phrase trans probs on the table in which co-occurrence counts are estimated'''
 *     method = options.get('method', METHOD)
 */
  __pyx_tuple__67 = PyTuple_Pack(12, __pyx_n_s_table_path, __pyx_n_s_savePath, __pyx_n_s_options, __pyx_n_s_method, __pyx_n_s_RecordClass, __pyx_n_s_table_file, __pyx_n_s_saveFile, __pyx_n_s_records, __pyx_n_s_lastSrc, __pyx_n_s_line, __pyx_n_s_rec, __pyx_n_s_key); if (unlikely(!__pyx_tuple__67)) __PYX_ERR(0, 288, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__67);
  __Pyx_GIVEREF(__pyx_tuple__67);
  __pyx_codeobj__68 = (PyObject*)__Pyx_PyCode_New(2, 0, 12, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__67, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_lpu_smt_trans_models_triangulate_2, __pyx_n_s_calcPhraseTransProbsOnTable, 288, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__68)) __PYX_ERR(0, 288, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":314
 * 
 * 
 * def calcSrcCount(records):             # <<<<<<<<<<<<<<
 *     '''calculate source phrase occurrence counts by co-occurrence counts'''
 *     total = 0
 */
  __pyx_tuple__69 = PyTuple_Pack(3, __pyx_n_s_records, __pyx_n_s_total, __pyx_n_s_rec); if (unlikely(!__pyx_tuple__69)) __PYX_ERR(0, 314, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__69);
  __Pyx_GIVEREF(__pyx_tuple__69);
  __pyx_codeobj__70 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__69, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_lpu_smt_trans_models_triangulate_2, __pyx_n_s_calcSrcCount, 314, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__70)) __PYX_ERR(0, 314, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":321
 *     return total
 * 
 * def updateWordPairCounts(lexCounts, records):             # <<<<<<<<<<<<<<
 *     '''find word pairs in phrase pairs, and update the counts of word pairs'''
 *     if len(records) > 0:
 */
  __pyx_tuple__71 = PyTuple_Pack(5, __pyx_n_s_lexCounts, __pyx_n_s_records, __pyx_n_s_src_symbols, __pyx_n_s_rec, __pyx_n_s_trgSymbols); if (unlikely(!__pyx_tuple__71)) __PYX_ERR(0, 321, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__71);
  __Pyx_GIVEREF(__pyx_tuple__71);
  __pyx_codeobj__72 = (PyObject*)__Pyx_PyCode_New(2, 0, 5, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__71, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_lpu_smt_trans_models_triangulate_2, __pyx_n_s_updateWordPairCounts, 321, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__72)) __PYX_ERR(0, 321, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":332
 *         lexCounts.filterNBestBySrc(srcWord = src_symbols[0])
 * 
 * def flattenRecords(records, sort = False):             # <<<<<<<<<<<<<<
 *     '''if records are type of dict, return them as a list'''
 *     if type(records) == dict:
 */
  __pyx_tuple__73 = PyTuple_Pack(4, __pyx_n_s_records, __pyx_n_s_sort, __pyx_n_s_recordList, __pyx_n_s_key); if (unlikely(!__pyx_tuple__73)) __PYX_ERR(0, 332, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__73);
  __Pyx_GIVEREF(__pyx_tuple__73);
  __pyx_codeobj__74 = (PyObject*)__Pyx_PyCode_New(2, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__73, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_lpu_smt_trans_models_triangulate_2, __pyx_n_s_flattenRecords, 332, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__74)) __PYX_ERR(0, 332, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":350
 *         assert False, "Invalid records"
 * 
 * def pivotRecPairs(rows, workset):             # <<<<<<<<<<<<<<
 *     '''combine the source-pivot and pivot-target records for common pivot phrases
 * 
 */
  __pyx_tuple__76 = PyTuple_Pack(24, __pyx_n_s_rows, __pyx_n_s_workset, __pyx_n_s_records, __pyx_n_s_multiRecords, __pyx_n_s_recPair, __pyx_n_s_trgKey, __pyx_n_s_strMultiTrg, __pyx_n_s_multiKey, __pyx_n_s_recPivot, __pyx_n_s_recMulti, __pyx_n_s_trgPair, __pyx_n_s_featureKey, __pyx_n_s_ignoring, __pyx_n_s_key, __pyx_n_s_rec, __pyx_n_s_scores, __pyx_n_s_bestRecords, __pyx_n_s__75, __pyx_n_s_bestTrgRecords, __pyx_n_s_bestMultiRecords, __pyx_n_s_multiList, __pyx_n_s_bestMultiRec, __pyx_n_s_bestForwardJointTransProb, __pyx_n_s_multiRec); if (unlikely(!__pyx_tuple__76)) __PYX_ERR(0, 350, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__76);
  __Pyx_GIVEREF(__pyx_tuple__76);
  __pyx_codeobj__77 = (PyObject*)__Pyx_PyCode_New(2, 0, 24, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__76, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_lpu_smt_trans_models_triangulate_2, __pyx_n_s_pivotRecPairs, 350, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__77)) __PYX_ERR(0, 350, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":504
 * 
 * 
 * def writeRecords(fileObj, records):             # <<<<<<<<<<<<<<
 * #  for rec in flattenRecords(records):
 *   for rec in flattenRecords(records, sort = True):
 */
  __pyx_tuple__78 = PyTuple_Pack(3, __pyx_n_s_fileObj, __pyx_n_s_records, __pyx_n_s_rec); if (unlikely(!__pyx_tuple__78)) __PYX_ERR(0, 504, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__78);
  __Pyx_GIVEREF(__pyx_tuple__78);
  __pyx_codeobj__79 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__78, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_lpu_smt_trans_models_triangulate_2, __pyx_n_s_writeRecords, 504, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__79)) __PYX_ERR(0, 504, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":512
 * 
 * 
 * def writeRecord(rec, workset):             # <<<<<<<<<<<<<<
 *     '''write the pivoted records in the queue into the table file'''
 *     if rec:
 */
  __pyx_tuple__80 = PyTuple_Pack(3, __pyx_n_s_rec, __pyx_n_s_workset, __pyx_n_s_term); if (unlikely(!__pyx_tuple__80)) __PYX_ERR(0, 512, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__80);
  __Pyx_GIVEREF(__pyx_tuple__80);
  __pyx_codeobj__81 = (PyObject*)__Pyx_PyCode_New(2, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__80, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_lpu_smt_trans_models_triangulate_2, __pyx_n_s_writeRecord, 512, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__81)) __PYX_ERR(0, 512, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":524
 *                 workset.setWordsSrcTrg.add(term)
 * 
 * def calcLexWeight(rec, lexCounts, reverse = False):             # <<<<<<<<<<<<<<
 * #    minProb = 10 ** -2
 *     lexWeight = 1
 */
  __pyx_tuple__82 = PyTuple_Pack(16, __pyx_n_s_rec, __pyx_n_s_lexCounts, __pyx_n_s_reverse, __pyx_n_s_lexWeight, __pyx_n_s_minProb, __pyx_n_s_alignMap, __pyx_n_s_srcTerms, __pyx_n_s_trgTerms, __pyx_n_s_trgIndex, __pyx_n_s_trgTerm, __pyx_n_s_trgSumProb, __pyx_n_s_srcIndices, __pyx_n_s_srcIndex, __pyx_n_s_srcTerm, __pyx_n_s_lexProb, __pyx_n_s_trgProb); if (unlikely(!__pyx_tuple__82)) __PYX_ERR(0, 524, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__82);
  __Pyx_GIVEREF(__pyx_tuple__82);
  __pyx_codeobj__83 = (PyObject*)__Pyx_PyCode_New(3, 0, 16, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__82, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_lpu_smt_trans_models_triangulate_2, __pyx_n_s_calcLexWeight, 524, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__83)) __PYX_ERR(0, 524, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":567
 *     return lexWeight
 * 
 * def calcLexWeights(table_path, lexCounts, savePath, RecordClass = MosesRecord):             # <<<<<<<<<<<<<<
 *     table_file = files.open(table_path, 'r')
 *     saveFile  = files.open(savePath, 'w')
 */
  __pyx_tuple__84 = PyTuple_Pack(8, __pyx_n_s_table_path, __pyx_n_s_lexCounts, __pyx_n_s_savePath, __pyx_n_s_RecordClass, __pyx_n_s_table_file, __pyx_n_s_saveFile, __pyx_n_s_line, __pyx_n_s_rec); if (unlikely(!__pyx_tuple__84)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__84);
  __Pyx_GIVEREF(__pyx_tuple__84);
  __pyx_codeobj__85 = (PyObject*)__Pyx_PyCode_New(4, 0, 8, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__84, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_lpu_smt_trans_models_triangulate_2, __pyx_n_s_calcLexWeights, 567, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__85)) __PYX_ERR(0, 567, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":584
 * 
 * 
 * def pivot(table1, table2, savefile="phrase-table.gz", workdir=".", **options):             # <<<<<<<<<<<<<<
 *     '''find pair of source-pivot and pivot-target records for common pivot phrase'''
 *     try:
 */
  __pyx_tuple__86 = PyTuple_Pack(31, __pyx_n_s_table1, __pyx_n_s_table2, __pyx_n_s_savefile, __pyx_n_s_workdir, __pyx_n_s_options, __pyx_n_s_RecordClass, __pyx_n_s_prefix, __pyx_n_s_threshold, __pyx_n_s_alignLexPath, __pyx_n_s_nbest, __pyx_n_s_method, __pyx_n_s_lexMethod, __pyx_n_s_jointMethod, __pyx_n_s_matchMethod, __pyx_n_s_numNulls, __pyx_n_s_multi_target, __pyx_n_s_logFile, __pyx_n_s_showProgress, __pyx_n_s_key_type, __pyx_n_s_tableSrcPvt, __pyx_n_s_tablePvtTrg, __pyx_n_s_workOptions, __pyx_n_s_workset, __pyx_n_s_rows, __pyx_n_s_lastSrc, __pyx_n_s_recSrcPvt, __pyx_n_s_src, __pyx_n_s_term, __pyx_n_s_recPvtTrg, __pyx_n_s_fobj, __pyx_n_s_word); if (unlikely(!__pyx_tuple__86)) __PYX_ERR(0, 584, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__86);
  __Pyx_GIVEREF(__pyx_tuple__86);
  __pyx_codeobj__87 = (PyObject*)__Pyx_PyCode_New(4, 0, 31, 0, CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__86, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_lpu_smt_trans_models_triangulate_2, __pyx_n_s_pivot, 584, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__87)) __PYX_ERR(0, 584, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":751
 *         sys.exit(1)
 * 
 * def main():             # <<<<<<<<<<<<<<
 *     parser = argparse.ArgumentParser(description = 'load 2 rule tables and pivot into one travatar rule table')
 *     parser.add_argument('table1', help = 'rule table 1')
 */
  __pyx_tuple__88 = PyTuple_Pack(2, __pyx_n_s_parser, __pyx_n_s_args); if (unlikely(!__pyx_tuple__88)) __PYX_ERR(0, 751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__88);
  __Pyx_GIVEREF(__pyx_tuple__88);
  __pyx_codeobj__89 = (PyObject*)__Pyx_PyCode_New(0, 0, 2, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__88, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_lpu_smt_trans_models_triangulate_2, __pyx_n_s_main_2, 751, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__89)) __PYX_ERR(0, 751, __pyx_L1_error)
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_InitGlobals(void) {
  __pyx_umethod_PyDict_Type_items.type = (PyObject*)&PyDict_Type;
  __pyx_umethod_PyDict_Type_keys.type = (PyObject*)&PyDict_Type;
  __pyx_umethod_PyDict_Type_values.type = (PyObject*)&PyDict_Type;
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  __pyx_float_0_5 = PyFloat_FromDouble(0.5); if (unlikely(!__pyx_float_0_5)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_float_1_0 = PyFloat_FromDouble(1.0); if (unlikely(!__pyx_float_1_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_20 = PyInt_FromLong(20); if (unlikely(!__pyx_int_20)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_100 = PyInt_FromLong(100); if (unlikely(!__pyx_int_100)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_10000 = PyInt_FromLong(10000L); if (unlikely(!__pyx_int_10000)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_neg_1 = PyInt_FromLong(-1); if (unlikely(!__pyx_int_neg_1)) __PYX_ERR(0, 1, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

#if PY_MAJOR_VERSION < 3
PyMODINIT_FUNC inittriangulate(void); /*proto*/
PyMODINIT_FUNC inittriangulate(void)
#else
PyMODINIT_FUNC PyInit_triangulate(void); /*proto*/
PyMODINIT_FUNC PyInit_triangulate(void)
#endif
{
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  __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_triangulate(void)", 0);
  if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error)
  #ifdef __Pyx_CyFunction_USED
  if (__pyx_CyFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_FusedFunction_USED
  if (__pyx_FusedFunction_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Coroutine_USED
  if (__pyx_Coroutine_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_Generator_USED
  if (__pyx_Generator_init() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  #ifdef __Pyx_StopAsyncIteration_USED
  if (__pyx_StopAsyncIteration_init() < 0) __PYX_ERR(0, 1, __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("triangulate", __pyx_methods, __pyx_k_functions_to_triangulate_2_phras, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m);
  #else
  __pyx_m = PyModule_Create(&__pyx_moduledef);
  #endif
  if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_INCREF(__pyx_d);
  __pyx_b = PyImport_AddModule(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_cython_runtime = PyImport_AddModule((char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error)
  #if CYTHON_COMPILING_IN_PYPY
  Py_INCREF(__pyx_b);
  #endif
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error);
  /*--- Initialize various global constants etc. ---*/
  if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
  if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif
  if (__pyx_module_is_main_lpu__smt__trans_models__triangulate) {
    if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  }
  #if PY_MAJOR_VERSION >= 3
  {
    PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error)
    if (!PyDict_GetItemString(modules, "lpu.smt.trans_models.triangulate")) {
      if (unlikely(PyDict_SetItemString(modules, "lpu.smt.trans_models.triangulate", __pyx_m) < 0)) __PYX_ERR(0, 1, __pyx_L1_error)
    }
  }
  #endif
  /*--- Builtin init code ---*/
  if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Constants init code ---*/
  if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  /*--- Global init code ---*/
  /*--- Variable export code ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  /*--- Type import code ---*/
  /*--- Variable import code ---*/
  /*--- Function import code ---*/
  /*--- Execution code ---*/
  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif

  /* "lpu/smt/trans_models/triangulate.pyx":8
 * 
 * # Standarde libraries
 * import argparse             # <<<<<<<<<<<<<<
 * import math
 * import sys
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_argparse, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_argparse, __pyx_t_1) < 0) __PYX_ERR(0, 8, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":9
 * # Standarde libraries
 * import argparse
 * import math             # <<<<<<<<<<<<<<
 * import sys
 * 
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_math, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_math, __pyx_t_1) < 0) __PYX_ERR(0, 9, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":10
 * import argparse
 * import math
 * import sys             # <<<<<<<<<<<<<<
 * 
 * # Local libraries
 */
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_sys, 0, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 10, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_sys, __pyx_t_1) < 0) __PYX_ERR(0, 10, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":13
 * 
 * # Local libraries
 * from lpu.common import compat             # <<<<<<<<<<<<<<
 * from lpu.common import files
 * from lpu.common import logging
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 13, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_compat);
  __Pyx_GIVEREF(__pyx_n_s_compat);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_compat);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_lpu_common, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 13, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_compat); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 13, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_compat, __pyx_t_1) < 0) __PYX_ERR(0, 13, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":14
 * # Local libraries
 * from lpu.common import compat
 * from lpu.common import files             # <<<<<<<<<<<<<<
 * from lpu.common import logging
 * from lpu.common import progress
 */
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 14, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_files);
  __Pyx_GIVEREF(__pyx_n_s_files);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_files);
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_lpu_common, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 14, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_files); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 14, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_files, __pyx_t_2) < 0) __PYX_ERR(0, 14, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":15
 * from lpu.common import compat
 * from lpu.common import files
 * from lpu.common import logging             # <<<<<<<<<<<<<<
 * from lpu.common import progress
 * from lpu.smt.trans_models.records import MosesRecord, TravatarRecord
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 15, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_logging);
  __Pyx_GIVEREF(__pyx_n_s_logging);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_logging);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_lpu_common, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 15, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_logging); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 15, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_logging, __pyx_t_1) < 0) __PYX_ERR(0, 15, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":16
 * from lpu.common import files
 * from lpu.common import logging
 * from lpu.common import progress             # <<<<<<<<<<<<<<
 * from lpu.smt.trans_models.records import MosesRecord, TravatarRecord
 * from lpu.smt.trans_models.tables import Table
 */
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 16, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_progress);
  __Pyx_GIVEREF(__pyx_n_s_progress);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_progress);
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_lpu_common, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 16, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_progress); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 16, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_progress, __pyx_t_2) < 0) __PYX_ERR(0, 16, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":17
 * from lpu.common import logging
 * from lpu.common import progress
 * from lpu.smt.trans_models.records import MosesRecord, TravatarRecord             # <<<<<<<<<<<<<<
 * from lpu.smt.trans_models.tables import Table
 * 
 */
  __pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 17, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_MosesRecord);
  __Pyx_GIVEREF(__pyx_n_s_MosesRecord);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_MosesRecord);
  __Pyx_INCREF(__pyx_n_s_TravatarRecord);
  __Pyx_GIVEREF(__pyx_n_s_TravatarRecord);
  PyList_SET_ITEM(__pyx_t_1, 1, __pyx_n_s_TravatarRecord);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_lpu_smt_trans_models_records, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 17, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_MosesRecord); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 17, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_MosesRecord, __pyx_t_1) < 0) __PYX_ERR(0, 17, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_TravatarRecord); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 17, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_TravatarRecord, __pyx_t_1) < 0) __PYX_ERR(0, 17, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":18
 * from lpu.common import progress
 * from lpu.smt.trans_models.records import MosesRecord, TravatarRecord
 * from lpu.smt.trans_models.tables import Table             # <<<<<<<<<<<<<<
 * 
 * from lpu.data_structs import trees
 */
  __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 18, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_Table);
  __Pyx_GIVEREF(__pyx_n_s_Table);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_Table);
  __pyx_t_1 = __Pyx_Import(__pyx_n_s_lpu_smt_trans_models_tables, __pyx_t_2, -1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 18, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_1, __pyx_n_s_Table); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 18, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_Table, __pyx_t_2) < 0) __PYX_ERR(0, 18, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":20
 * from lpu.smt.trans_models.tables import Table
 * 
 * from lpu.data_structs import trees             # <<<<<<<<<<<<<<
 * 
 * # lower threshold of trans probs to abort
 */
  __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 20, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_n_s_trees);
  __Pyx_GIVEREF(__pyx_n_s_trees);
  PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_trees);
  __pyx_t_2 = __Pyx_Import(__pyx_n_s_lpu_data_structs, __pyx_t_1, -1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 20, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_trees); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 20, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_trees, __pyx_t_1) < 0) __PYX_ERR(0, 20, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":24
 * # lower threshold of trans probs to abort
 * #THRESHOLD = 1e-3
 * THRESHOLD = 0 # not aborting             # <<<<<<<<<<<<<<
 * 
 * # lower guarantee for lexical trans probs
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_THRESHOLD, __pyx_int_0) < 0) __PYX_ERR(0, 24, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":27
 * 
 * # lower guarantee for lexical trans probs
 * MINPROB = 10 ** -10             # <<<<<<<<<<<<<<
 * 
 * # limit number of records for the same source phrase
 */
  __pyx_t_2 = __Pyx_PyInt_From_long(__Pyx_pow_long(10, -10L)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 27, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_MINPROB, __pyx_t_2) < 0) __PYX_ERR(0, 27, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":30
 * 
 * # limit number of records for the same source phrase
 * NBEST = 20             # <<<<<<<<<<<<<<
 * 
 * # methods to estimate trans probs (countmin/prodprob/bidirmin/bidirgmean/bidirmax/bidiravr)
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_NBEST, __pyx_int_20) < 0) __PYX_ERR(0, 30, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":33
 * 
 * # methods to estimate trans probs (countmin/prodprob/bidirmin/bidirgmean/bidirmax/bidiravr)
 * method_list = ['countmin', 'prodprob', 'bidirmin', 'bidirgmean', 'bidirmax', 'bidiravr']             # <<<<<<<<<<<<<<
 * #METHOD = 'counts'
 * #METHOD = 'hybrid'
 */
  __pyx_t_2 = PyList_New(6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 33, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_countmin);
  __Pyx_GIVEREF(__pyx_n_s_countmin);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_countmin);
  __Pyx_INCREF(__pyx_n_s_prodprob);
  __Pyx_GIVEREF(__pyx_n_s_prodprob);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_prodprob);
  __Pyx_INCREF(__pyx_n_s_bidirmin);
  __Pyx_GIVEREF(__pyx_n_s_bidirmin);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_n_s_bidirmin);
  __Pyx_INCREF(__pyx_n_s_bidirgmean);
  __Pyx_GIVEREF(__pyx_n_s_bidirgmean);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_n_s_bidirgmean);
  __Pyx_INCREF(__pyx_n_s_bidirmax);
  __Pyx_GIVEREF(__pyx_n_s_bidirmax);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_n_s_bidirmax);
  __Pyx_INCREF(__pyx_n_s_bidiravr);
  __Pyx_GIVEREF(__pyx_n_s_bidiravr);
  PyList_SET_ITEM(__pyx_t_2, 5, __pyx_n_s_bidiravr);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_method_list, __pyx_t_2) < 0) __PYX_ERR(0, 33, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":37
 * #METHOD = 'hybrid'
 * #METHOD = 'countmin'
 * METHOD = 'prodprob'             # <<<<<<<<<<<<<<
 * 
 * # methods to estimate lexical weight
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_METHOD, __pyx_n_s_prodprob) < 0) __PYX_ERR(0, 37, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":40
 * 
 * # methods to estimate lexical weight
 * lex_method_list = ['prodweight', 'countmin', 'prodprob', 'bidirmin', 'bidirgmean', 'bidirmax', 'bidiravr', 'table', 'countmin+table', 'prodprob+table', 'bidirmin+table', 'bidirgmean+table']             # <<<<<<<<<<<<<<
 * LEX_METHOD = 'prodweight'
 * 
 */
  __pyx_t_2 = PyList_New(12); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_prodweight);
  __Pyx_GIVEREF(__pyx_n_s_prodweight);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_prodweight);
  __Pyx_INCREF(__pyx_n_s_countmin);
  __Pyx_GIVEREF(__pyx_n_s_countmin);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_countmin);
  __Pyx_INCREF(__pyx_n_s_prodprob);
  __Pyx_GIVEREF(__pyx_n_s_prodprob);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_n_s_prodprob);
  __Pyx_INCREF(__pyx_n_s_bidirmin);
  __Pyx_GIVEREF(__pyx_n_s_bidirmin);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_n_s_bidirmin);
  __Pyx_INCREF(__pyx_n_s_bidirgmean);
  __Pyx_GIVEREF(__pyx_n_s_bidirgmean);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_n_s_bidirgmean);
  __Pyx_INCREF(__pyx_n_s_bidirmax);
  __Pyx_GIVEREF(__pyx_n_s_bidirmax);
  PyList_SET_ITEM(__pyx_t_2, 5, __pyx_n_s_bidirmax);
  __Pyx_INCREF(__pyx_n_s_bidiravr);
  __Pyx_GIVEREF(__pyx_n_s_bidiravr);
  PyList_SET_ITEM(__pyx_t_2, 6, __pyx_n_s_bidiravr);
  __Pyx_INCREF(__pyx_n_s_table);
  __Pyx_GIVEREF(__pyx_n_s_table);
  PyList_SET_ITEM(__pyx_t_2, 7, __pyx_n_s_table);
  __Pyx_INCREF(__pyx_kp_s_countmin_table);
  __Pyx_GIVEREF(__pyx_kp_s_countmin_table);
  PyList_SET_ITEM(__pyx_t_2, 8, __pyx_kp_s_countmin_table);
  __Pyx_INCREF(__pyx_kp_s_prodprob_table);
  __Pyx_GIVEREF(__pyx_kp_s_prodprob_table);
  PyList_SET_ITEM(__pyx_t_2, 9, __pyx_kp_s_prodprob_table);
  __Pyx_INCREF(__pyx_kp_s_bidirmin_table);
  __Pyx_GIVEREF(__pyx_kp_s_bidirmin_table);
  PyList_SET_ITEM(__pyx_t_2, 10, __pyx_kp_s_bidirmin_table);
  __Pyx_INCREF(__pyx_kp_s_bidirgmean_table);
  __Pyx_GIVEREF(__pyx_kp_s_bidirgmean_table);
  PyList_SET_ITEM(__pyx_t_2, 11, __pyx_kp_s_bidirgmean_table);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_lex_method_list, __pyx_t_2) < 0) __PYX_ERR(0, 40, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":41
 * # methods to estimate lexical weight
 * lex_method_list = ['prodweight', 'countmin', 'prodprob', 'bidirmin', 'bidirgmean', 'bidirmax', 'bidiravr', 'table', 'countmin+table', 'prodprob+table', 'bidirmin+table', 'bidirgmean+table']
 * LEX_METHOD = 'prodweight'             # <<<<<<<<<<<<<<
 * 
 * # methods to estimate joint trans probs
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_LEX_METHOD, __pyx_n_s_prodweight) < 0) __PYX_ERR(0, 41, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":44
 * 
 * # methods to estimate joint trans probs
 * joint_method_list = ['memoryless', 'independent']             # <<<<<<<<<<<<<<
 * JOINT_METHOD = 'memoryless'
 * 
 */
  __pyx_t_2 = PyList_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_memoryless);
  __Pyx_GIVEREF(__pyx_n_s_memoryless);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_memoryless);
  __Pyx_INCREF(__pyx_n_s_independent);
  __Pyx_GIVEREF(__pyx_n_s_independent);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_independent);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_joint_method_list, __pyx_t_2) < 0) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":45
 * # methods to estimate joint trans probs
 * joint_method_list = ['memoryless', 'independent']
 * JOINT_METHOD = 'memoryless'             # <<<<<<<<<<<<<<
 * 
 * # matching methods
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_JOINT_METHOD, __pyx_n_s_memoryless) < 0) __PYX_ERR(0, 45, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":48
 * 
 * # matching methods
 * match_method_list = ['hiero', 'symbols', 'treecomp', 'treedist', 'treedistexp']             # <<<<<<<<<<<<<<
 * MATCH_METHOD = 'symbols'
 * 
 */
  __pyx_t_2 = PyList_New(5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 48, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_n_s_hiero);
  __Pyx_GIVEREF(__pyx_n_s_hiero);
  PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_hiero);
  __Pyx_INCREF(__pyx_n_s_symbols);
  __Pyx_GIVEREF(__pyx_n_s_symbols);
  PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_symbols);
  __Pyx_INCREF(__pyx_n_s_treecomp);
  __Pyx_GIVEREF(__pyx_n_s_treecomp);
  PyList_SET_ITEM(__pyx_t_2, 2, __pyx_n_s_treecomp);
  __Pyx_INCREF(__pyx_n_s_treedist);
  __Pyx_GIVEREF(__pyx_n_s_treedist);
  PyList_SET_ITEM(__pyx_t_2, 3, __pyx_n_s_treedist);
  __Pyx_INCREF(__pyx_n_s_treedistexp);
  __Pyx_GIVEREF(__pyx_n_s_treedistexp);
  PyList_SET_ITEM(__pyx_t_2, 4, __pyx_n_s_treedistexp);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_match_method_list, __pyx_t_2) < 0) __PYX_ERR(0, 48, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":49
 * # matching methods
 * match_method_list = ['hiero', 'symbols', 'treecomp', 'treedist', 'treedistexp']
 * MATCH_METHOD = 'symbols'             # <<<<<<<<<<<<<<
 * 
 * NULLS = 10**4
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_MATCH_METHOD, __pyx_n_s_symbols) < 0) __PYX_ERR(0, 49, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":51
 * MATCH_METHOD = 'symbols'
 * 
 * NULLS = 10**4             # <<<<<<<<<<<<<<
 * 
 * NOPREFILTER = False
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_NULLS, __pyx_int_10000) < 0) __PYX_ERR(0, 51, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":53
 * NULLS = 10**4
 * 
 * NOPREFILTER = False             # <<<<<<<<<<<<<<
 * 
 * class WorkSet:
 */
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_NOPREFILTER, Py_False) < 0) __PYX_ERR(0, 53, __pyx_L1_error)

  /* "lpu/smt/trans_models/triangulate.pyx":55
 * NOPREFILTER = False
 * 
 * class WorkSet:             # <<<<<<<<<<<<<<
 *     '''data set for multi-processing'''
 *     def __init__(self, savefile, workdir, method, **options):
 */
  __pyx_t_2 = __Pyx_Py3MetaclassPrepare((PyObject *) NULL, __pyx_empty_tuple, __pyx_n_s_WorkSet, __pyx_n_s_WorkSet, (PyObject *) NULL, __pyx_n_s_lpu_smt_trans_models_triangulate, __pyx_kp_s_data_set_for_multi_processing); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 55, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);

  /* "lpu/smt/trans_models/triangulate.pyx":57
 * class WorkSet:
 *     '''data set for multi-processing'''
 *     def __init__(self, savefile, workdir, method, **options):             # <<<<<<<<<<<<<<
 *         prefix = options.get('prefix', 'phrase')
 *         self.multi_target = options.get('multi_target', False)
 */
  __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_3lpu_3smt_12trans_models_11triangulate_7WorkSet_1__init__, 0, __pyx_n_s_WorkSet___init, NULL, __pyx_n_s_lpu_smt_trans_models_triangulate, __pyx_d, ((PyObject *)__pyx_codeobj__52)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 57, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetItem(__pyx_t_2, __pyx_n_s_init, __pyx_t_1) < 0) __PYX_ERR(0, 57, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":84
 *         self.setWordsSrcTrg = set()
 * 
 *     def __del__(self):             # <<<<<<<<<<<<<<
 *         self.close()
 * 
 */
  __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_3lpu_3smt_12trans_models_11triangulate_7WorkSet_3__del__, 0, __pyx_n_s_WorkSet___del, NULL, __pyx_n_s_lpu_smt_trans_models_triangulate, __pyx_d, ((PyObject *)__pyx_codeobj__54)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 84, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetItem(__pyx_t_2, __pyx_n_s_del, __pyx_t_1) < 0) __PYX_ERR(0, 84, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":87
 *         self.close()
 * 
 *     def close(self):             # <<<<<<<<<<<<<<
 *         if self.foutPivot:
 *             self.foutPivot.close()
 */
  __pyx_t_1 = __Pyx_CyFunction_NewEx(&__pyx_mdef_3lpu_3smt_12trans_models_11triangulate_7WorkSet_5close, 0, __pyx_n_s_WorkSet_close, NULL, __pyx_n_s_lpu_smt_trans_models_triangulate, __pyx_d, ((PyObject *)__pyx_codeobj__56)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyObject_SetItem(__pyx_t_2, __pyx_n_s_close, __pyx_t_1) < 0) __PYX_ERR(0, 87, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":55
 * NOPREFILTER = False
 * 
 * class WorkSet:             # <<<<<<<<<<<<<<
 *     '''data set for multi-processing'''
 *     def __init__(self, savefile, workdir, method, **options):
 */
  __pyx_t_1 = __Pyx_Py3ClassCreate(((PyObject*)&__Pyx_DefaultClassType), __pyx_n_s_WorkSet, __pyx_empty_tuple, __pyx_t_2, NULL, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 55, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_WorkSet, __pyx_t_1) < 0) __PYX_ERR(0, 55, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":116
 * 
 * #def updateFeatures(recPivot, recPair, method, multi_target = False, jointMethod = 'memoryless'):
 * def updateFeatures(recPivot, recPair, workset, multi_target = False):             # <<<<<<<<<<<<<<
 *     '''update features'''
 *     features = recPivot.features
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_3lpu_3smt_12trans_models_11triangulate_1updateFeatures, NULL, __pyx_n_s_lpu_smt_trans_models_triangulate); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 116, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_updateFeatures, __pyx_t_2) < 0) __PYX_ERR(0, 116, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":191
 * 
 * 
 * def updateCounts(recPivot, recPair, method):             # <<<<<<<<<<<<<<
 *     '''update occurrence counts of phrase'''
 *     counts = recPivot.counts
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_3lpu_3smt_12trans_models_11triangulate_3updateCounts, NULL, __pyx_n_s_lpu_smt_trans_models_triangulate); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 191, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_updateCounts, __pyx_t_2) < 0) __PYX_ERR(0, 191, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":240
 * 
 * 
 * def mergeAligns(recPivot, recPair):             # <<<<<<<<<<<<<<
 *     '''merge word alignments'''
 * #    if recPivot.aligns:
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_3lpu_3smt_12trans_models_11triangulate_5mergeAligns, NULL, __pyx_n_s_lpu_smt_trans_models_triangulate); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 240, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_mergeAligns, __pyx_t_2) < 0) __PYX_ERR(0, 240, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":256
 * 
 * 
 * def filterByCountRatioToMax(records, div = 100):             # <<<<<<<<<<<<<<
 *     coMax = 0
 *     for rec in flattenRecords(records):
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_3lpu_3smt_12trans_models_11triangulate_7filterByCountRatioToMax, NULL, __pyx_n_s_lpu_smt_trans_models_triangulate); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 256, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_filterByCountRatioToMax, __pyx_t_2) < 0) __PYX_ERR(0, 256, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":275
 * 
 * 
 * def calcPhraseTransProbsByCounts(records):             # <<<<<<<<<<<<<<
 *     '''calculate forward phrase trans probs by occurrence counts of the phrases'''
 *     srcCount = calcSrcCount(records)
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_3lpu_3smt_12trans_models_11triangulate_9calcPhraseTransProbsByCounts, NULL, __pyx_n_s_lpu_smt_trans_models_triangulate); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 275, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_calcPhraseTransProbsByCounts, __pyx_t_2) < 0) __PYX_ERR(0, 275, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":288
 * 
 * 
 * def calcPhraseTransProbsOnTable(table_path, savePath, **options):             # <<<<<<<<<<<<<<
 *     '''calculate phrase trans probs on the table in which co-occurrence counts are estimated'''
 *     method = options.get('method', METHOD)
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_3lpu_3smt_12trans_models_11triangulate_11calcPhraseTransProbsOnTable, NULL, __pyx_n_s_lpu_smt_trans_models_triangulate); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 288, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_calcPhraseTransProbsOnTable, __pyx_t_2) < 0) __PYX_ERR(0, 288, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":314
 * 
 * 
 * def calcSrcCount(records):             # <<<<<<<<<<<<<<
 *     '''calculate source phrase occurrence counts by co-occurrence counts'''
 *     total = 0
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_3lpu_3smt_12trans_models_11triangulate_13calcSrcCount, NULL, __pyx_n_s_lpu_smt_trans_models_triangulate); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 314, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_calcSrcCount, __pyx_t_2) < 0) __PYX_ERR(0, 314, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":321
 *     return total
 * 
 * def updateWordPairCounts(lexCounts, records):             # <<<<<<<<<<<<<<
 *     '''find word pairs in phrase pairs, and update the counts of word pairs'''
 *     if len(records) > 0:
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_3lpu_3smt_12trans_models_11triangulate_15updateWordPairCounts, NULL, __pyx_n_s_lpu_smt_trans_models_triangulate); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 321, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_updateWordPairCounts, __pyx_t_2) < 0) __PYX_ERR(0, 321, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":332
 *         lexCounts.filterNBestBySrc(srcWord = src_symbols[0])
 * 
 * def flattenRecords(records, sort = False):             # <<<<<<<<<<<<<<
 *     '''if records are type of dict, return them as a list'''
 *     if type(records) == dict:
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_3lpu_3smt_12trans_models_11triangulate_17flattenRecords, NULL, __pyx_n_s_lpu_smt_trans_models_triangulate); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 332, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_flattenRecords, __pyx_t_2) < 0) __PYX_ERR(0, 332, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":350
 *         assert False, "Invalid records"
 * 
 * def pivotRecPairs(rows, workset):             # <<<<<<<<<<<<<<
 *     '''combine the source-pivot and pivot-target records for common pivot phrases
 * 
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_3lpu_3smt_12trans_models_11triangulate_19pivotRecPairs, NULL, __pyx_n_s_lpu_smt_trans_models_triangulate); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 350, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pivotRecPairs, __pyx_t_2) < 0) __PYX_ERR(0, 350, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":504
 * 
 * 
 * def writeRecords(fileObj, records):             # <<<<<<<<<<<<<<
 * #  for rec in flattenRecords(records):
 *   for rec in flattenRecords(records, sort = True):
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_3lpu_3smt_12trans_models_11triangulate_21writeRecords, NULL, __pyx_n_s_lpu_smt_trans_models_triangulate); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 504, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_writeRecords, __pyx_t_2) < 0) __PYX_ERR(0, 504, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":512
 * 
 * 
 * def writeRecord(rec, workset):             # <<<<<<<<<<<<<<
 *     '''write the pivoted records in the queue into the table file'''
 *     if rec:
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_3lpu_3smt_12trans_models_11triangulate_23writeRecord, NULL, __pyx_n_s_lpu_smt_trans_models_triangulate); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 512, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_writeRecord, __pyx_t_2) < 0) __PYX_ERR(0, 512, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":524
 *                 workset.setWordsSrcTrg.add(term)
 * 
 * def calcLexWeight(rec, lexCounts, reverse = False):             # <<<<<<<<<<<<<<
 * #    minProb = 10 ** -2
 *     lexWeight = 1
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_3lpu_3smt_12trans_models_11triangulate_25calcLexWeight, NULL, __pyx_n_s_lpu_smt_trans_models_triangulate); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 524, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_calcLexWeight, __pyx_t_2) < 0) __PYX_ERR(0, 524, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":567
 *     return lexWeight
 * 
 * def calcLexWeights(table_path, lexCounts, savePath, RecordClass = MosesRecord):             # <<<<<<<<<<<<<<
 *     table_file = files.open(table_path, 'r')
 *     saveFile  = files.open(savePath, 'w')
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_MosesRecord); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_k__23 = __pyx_t_2;
  __Pyx_GIVEREF(__pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_3lpu_3smt_12trans_models_11triangulate_27calcLexWeights, NULL, __pyx_n_s_lpu_smt_trans_models_triangulate); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_calcLexWeights, __pyx_t_2) < 0) __PYX_ERR(0, 567, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":584
 * 
 * 
 * def pivot(table1, table2, savefile="phrase-table.gz", workdir=".", **options):             # <<<<<<<<<<<<<<
 *     '''find pair of source-pivot and pivot-target records for common pivot phrase'''
 *     try:
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_3lpu_3smt_12trans_models_11triangulate_29pivot, NULL, __pyx_n_s_lpu_smt_trans_models_triangulate); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 584, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pivot, __pyx_t_2) < 0) __PYX_ERR(0, 584, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":751
 *         sys.exit(1)
 * 
 * def main():             # <<<<<<<<<<<<<<
 *     parser = argparse.ArgumentParser(description = 'load 2 rule tables and pivot into one travatar rule table')
 *     parser.add_argument('table1', help = 'rule table 1')
 */
  __pyx_t_2 = PyCFunction_NewEx(&__pyx_mdef_3lpu_3smt_12trans_models_11triangulate_31main, NULL, __pyx_n_s_lpu_smt_trans_models_triangulate); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 751, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_main_2, __pyx_t_2) < 0) __PYX_ERR(0, 751, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "lpu/smt/trans_models/triangulate.pyx":776
 *     pivot(**args)
 * 
 * if __name__ == '__main__':             # <<<<<<<<<<<<<<
 *     main()
 * 
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 776, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_n_s_main, Py_EQ)); if (unlikely(__pyx_t_3 < 0)) __PYX_ERR(0, 776, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_3) {

    /* "lpu/smt/trans_models/triangulate.pyx":777
 * 
 * if __name__ == '__main__':
 *     main()             # <<<<<<<<<<<<<<
 * 
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_main_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 777, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    if (__pyx_t_4) {
      __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 777, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else {
      __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 777, __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;

    /* "lpu/smt/trans_models/triangulate.pyx":776
 *     pivot(**args)
 * 
 * if __name__ == '__main__':             # <<<<<<<<<<<<<<
 *     main()
 * 
 */
  }

  /* "lpu/smt/trans_models/triangulate.pyx":1
 * #!/usr/bin/env python             # <<<<<<<<<<<<<<
 * # -*- coding: utf-8 -*-
 * 
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /*--- Wrapped vars code ---*/

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_4);
  if (__pyx_m) {
    if (__pyx_d) {
      __Pyx_AddTraceback("init lpu.smt.trans_models.triangulate", 0, __pyx_lineno, __pyx_filename);
    }
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init lpu.smt.trans_models.triangulate");
  }
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  #if PY_MAJOR_VERSION < 3
  return;
  #else
  return __pyx_m;
  #endif
}

/* --- Runtime support code --- */
/* Refnanny */
#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

/* GetBuiltinName */
static PyObject *__Pyx_GetBuiltinName(PyObject *name) {
    PyObject* result = __Pyx_PyObject_GetAttrStr(__pyx_b, name);
    if (unlikely(!result)) {
        PyErr_Format(PyExc_NameError,
#if PY_MAJOR_VERSION >= 3
            "name '%U' is not defined", name);
#else
            "name '%.200s' is not defined", PyString_AS_STRING(name));
#endif
    }
    return result;
}

/* RaiseArgTupleInvalid */
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,
                 "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)",
                 func_name, more_or_less, num_expected,
                 (num_expected == 1) ? "" : "s", num_found);
}

/* RaiseDoubleKeywords */
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_AsString(kw_name));
        #endif
}

/* ParseKeywords */
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;
            continue;
        }
        name = first_kw_arg;
        #if PY_MAJOR_VERSION < 3
        if (likely(PyString_CheckExact(key)) || likely(PyString_Check(key))) {
            while (*name) {
                if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key))
                        && _PyString_Eq(**name, key)) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    if ((**argname == key) || (
                            (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key))
                             && _PyString_Eq(**argname, key))) {
                        goto arg_passed_twice;
                    }
                    argname++;
                }
            }
        } else
        #endif
        if (likely(PyUnicode_Check(key))) {
            while (*name) {
                int cmp = (**name == key) ? 0 :
                #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                    (PyUnicode_GET_SIZE(**name) != PyUnicode_GET_SIZE(key)) ? 1 :
                #endif
                    PyUnicode_Compare(**name, key);
                if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                if (cmp == 0) {
                    values[name-argnames] = value;
                    break;
                }
                name++;
            }
            if (*name) continue;
            else {
                PyObject*** argname = argnames;
                while (argname != first_kw_arg) {
                    int cmp = (**argname == key) ? 0 :
                    #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3
                        (PyUnicode_GET_SIZE(**argname) != PyUnicode_GET_SIZE(key)) ? 1 :
                    #endif
                        PyUnicode_Compare(**argname, key);
                    if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad;
                    if (cmp == 0) goto arg_passed_twice;
                    argname++;
                }
            }
        } else
            goto invalid_keyword_type;
        if (kwds2) {
            if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad;
        } else {
            goto invalid_keyword;
        }
    }
    return 0;
arg_passed_twice:
    __Pyx_RaiseDoubleKeywordsError(function_name, key);
    goto bad;
invalid_keyword_type:
    PyErr_Format(PyExc_TypeError,
        "%.200s() keywords must be strings", function_name);
    goto bad;
invalid_keyword:
    PyErr_Format(PyExc_TypeError,
    #if PY_MAJOR_VERSION < 3
        "%.200s() got an unexpected keyword argument '%.200s'",
        function_name, PyString_AsString(key));
    #else
        "%s() got an unexpected keyword argument '%U'",
        function_name, key);
    #endif
bad:
    return -1;
}

/* dict_getitem_default */
static PyObject* __Pyx_PyDict_GetItemDefault(PyObject* d, PyObject* key, PyObject* default_value) {
    PyObject* value;
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
    value = PyDict_GetItemWithError(d, key);
    if (unlikely(!value)) {
        if (unlikely(PyErr_Occurred()))
            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)) {
            value = default_value;
        }
        Py_INCREF(value);
    } else {
        if (default_value == Py_None)
            default_value = NULL;
        value = PyObject_CallMethodObjArgs(
            d, __pyx_n_s_get, key, default_value, NULL);
    }
#endif
    return value;
}

/* GetModuleGlobalName */
static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) {
    PyObject *result;
#if !CYTHON_AVOID_BORROWED_REFS
    result = PyDict_GetItem(__pyx_d, name);
    if (likely(result)) {
        Py_INCREF(result);
    } else {
#else
    result = PyObject_GetItem(__pyx_d, name);
    if (!result) {
        PyErr_Clear();
#endif
        result = __Pyx_GetBuiltinName(name);
    }
    return result;
}

/* PyFunctionFastCall */
  #if CYTHON_FAST_PYCALL
#include "frameobject.h"
static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na,
                                               PyObject *globals) {
    PyFrameObject *f;
    PyThreadState *tstate = PyThreadState_GET();
    PyObject **fastlocals;
    Py_ssize_t i;
    PyObject *result;
    assert(globals != NULL);
    /* XXX Perhaps we should create a specialized
       PyFrame_New() that doesn't take locals, but does
       take builtins without sanity checking them.
       */
    assert(tstate != NULL);
    f = PyFrame_New(tstate, co, globals, NULL);
    if (f == NULL) {
        return NULL;
    }
    fastlocals = f->f_localsplus;
    for (i = 0; i < na; i++) {
        Py_INCREF(*args);
        fastlocals[i] = *args++;
    }
    result = PyEval_EvalFrameEx(f,0);
    ++tstate->recursion_depth;
    Py_DECREF(f);
    --tstate->recursion_depth;
    return result;
}
#if 1 || PY_VERSION_HEX < 0x030600B1
static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, int nargs, PyObject *kwargs) {
    PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func);
    PyObject *globals = PyFunction_GET_GLOBALS(func);
    PyObject *argdefs = PyFunction_GET_DEFAULTS(func);
    PyObject *closure;
#if PY_MAJOR_VERSION >= 3
    PyObject *kwdefs;
#endif
    PyObject *kwtuple, **k;
    PyObject **d;
    Py_ssize_t nd;
    Py_ssize_t nk;
    PyObject *result;
    assert(kwargs == NULL || PyDict_Check(kwargs));
    nk = kwargs ? PyDict_Size(kwargs) : 0;
    if (Py_EnterRecursiveCall((char*)" while calling a Python object")) {
        return NULL;
    }
    if (
#if PY_MAJOR_VERSION >= 3
            co->co_kwonlyargcount == 0 &&
#endif
            likely(kwargs == NULL || nk == 0) &&
            co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) {
        if (argdefs == NULL && co->co_argcount == nargs) {
            result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals);
            goto done;
        }
        else if (nargs == 0 && argdefs != NULL
                 && co->co_argcount == Py_SIZE(argdefs)) {
            /* function called with no arguments, but all parameters have
               a default value: use default values as arguments .*/
            args = &PyTuple_GET_ITEM(argdefs, 0);
            result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals);
            goto done;
        }
    }
    if (kwargs != NULL) {
        Py_ssize_t pos, i;
        kwtuple = PyTuple_New(2 * nk);
        if (kwtuple == NULL) {
            result = NULL;
            goto done;
        }
        k = &PyTuple_GET_ITEM(kwtuple, 0);
        pos = i = 0;
        while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) {
            Py_INCREF(k[i]);
            Py_INCREF(k[i+1]);
            i += 2;
        }
        nk = i / 2;
    }
    else {
        kwtuple = NULL;
        k = NULL;
    }
    closure = PyFunction_GET_CLOSURE(func);
#if PY_MAJOR_VERSION >= 3
    kwdefs = PyFunction_GET_KW_DEFAULTS(func);
#endif
    if (argdefs != NULL) {
        d = &PyTuple_GET_ITEM(argdefs, 0);
        nd = Py_SIZE(argdefs);
    }
    else {
        d = NULL;
        nd = 0;
    }
#if PY_MAJOR_VERSION >= 3
    result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL,
                               args, nargs,
                               k, (int)nk,
                               d, (int)nd, kwdefs, closure);
#else
    result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL,
                               args, nargs,
                               k, (int)nk,
                               d, (int)nd, closure);
#endif
    Py_XDECREF(kwtuple);
done:
    Py_LeaveRecursiveCall();
    return result;
}
#endif
#endif

/* PyCFunctionFastCall */
  #if CYTHON_FAST_PYCCALL
static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, PyObject **args, Py_ssize_t nargs) {
    PyCFunctionObject *func = (PyCFunctionObject*)func_obj;
    PyCFunction meth = PyCFunction_GET_FUNCTION(func);
    PyObject *self = PyCFunction_GET_SELF(func);
    int flags = PyCFunction_GET_FLAGS(func);
    assert(PyCFunction_Check(func));
    assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS)));
    assert(nargs >= 0);
    assert(nargs == 0 || args != NULL);
    /* _PyCFunction_FastCallDict() must not be called with an exception set,
       because it may clear it (directly or indirectly) and so the
       caller loses its exception */
    assert(!PyErr_Occurred());
    if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) {
        return (*((__Pyx_PyCFunctionFastWithKeywords)meth)) (self, args, nargs, NULL);
    } else {
        return (*((__Pyx_PyCFunctionFast)meth)) (self, args, nargs);
    }
}
#endif

/* PyObjectCall */
  #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    PyObject *result;
    ternaryfunc call = func->ob_type->tp_call;
    if (unlikely(!call))
        return PyObject_Call(func, arg, kw);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = (*call)(func, arg, kw);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyObjectCallMethO */
  #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) {
    PyObject *self, *result;
    PyCFunction cfunc;
    cfunc = PyCFunction_GET_FUNCTION(func);
    self = PyCFunction_GET_SELF(func);
    if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object")))
        return NULL;
    result = cfunc(self, arg);
    Py_LeaveRecursiveCall();
    if (unlikely(!result) && unlikely(!PyErr_Occurred())) {
        PyErr_SetString(
            PyExc_SystemError,
            "NULL result without error in PyObject_Call");
    }
    return result;
}
#endif

/* PyObjectCallOneArg */
  #if CYTHON_COMPILING_IN_CPYTHON
static PyObject* __Pyx__PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_New(1);
    if (unlikely(!args)) return NULL;
    Py_INCREF(arg);
    PyTuple_SET_ITEM(args, 0, arg);
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
#if CYTHON_FAST_PYCALL
    if (PyFunction_Check(func)) {
        return __Pyx_PyFunction_FastCall(func, &arg, 1);
    }
#endif
    if (likely(PyCFunction_Check(func))) {
        if (likely(PyCFunction_GET_FLAGS(func) & METH_O)) {
            return __Pyx_PyObject_CallMethO(func, arg);
#if CYTHON_FAST_PYCCALL
        } else if (PyCFunction_GET_FLAGS(func) & METH_FASTCALL) {
            return __Pyx_PyCFunction_FastCall(func, &arg, 1);
#endif
        }
    }
    return __Pyx__PyObject_CallOneArg(func, arg);
}
#else
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) {
    PyObject *result;
    PyObject *args = PyTuple_Pack(1, arg);
    if (unlikely(!args)) return NULL;
    result = __Pyx_PyObject_Call(func, args, NULL);
    Py_DECREF(args);
    return result;
}
#endif

/* PyObjectCallNoArg */
  #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) {
#if CYTHON_FAST_PYCALL
    if (PyFunction_Check(func)) {
        return __Pyx_PyFunction_FastCall(func, NULL, 0);
    }
#endif
#ifdef __Pyx_CyFunction_USED
    if (likely(PyCFunction_Check(func) || PyObject_TypeCheck(func, __pyx_CyFunctionType))) {
#else
    if (likely(PyCFunction_Check(func))) {
#endif
        if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) {
            return __Pyx_PyObject_CallMethO(func, NULL);
        }
    }
    return __Pyx_PyObject_Call(func, __pyx_empty_tuple, NULL);
}
#endif

/* GetItemInt */
    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;
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    Py_ssize_t wrapped_i = i;
    if (wraparound & unlikely(i < 0)) {
        wrapped_i += PyList_GET_SIZE(o);
    }
    if ((!boundscheck) || likely((0 <= wrapped_i) & (wrapped_i < PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, wrapped_i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i,
                                                              CYTHON_NCP_UNUSED int wraparound,
                                                              CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    Py_ssize_t wrapped_i = i;
    if (wraparound & unlikely(i < 0)) {
        wrapped_i += PyTuple_GET_SIZE(o);
    }
    if ((!boundscheck) || likely((0 <= wrapped_i) & (wrapped_i < PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, wrapped_i);
        Py_INCREF(r);
        return r;
    }
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
#else
    return PySequence_GetItem(o, i);
#endif
}
static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list,
                                                     CYTHON_NCP_UNUSED int wraparound,
                                                     CYTHON_NCP_UNUSED int boundscheck) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS
    if (is_list || PyList_CheckExact(o)) {
        Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o);
        if ((!boundscheck) || (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 = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o);
        if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) {
            PyObject *r = PyTuple_GET_ITEM(o, n);
            Py_INCREF(r);
            return r;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_item)) {
            if (wraparound && unlikely(i < 0) && likely(m->sq_length)) {
                Py_ssize_t l = m->sq_length(o);
                if (likely(l >= 0)) {
                    i += l;
                } else {
                    if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                        return NULL;
                    PyErr_Clear();
                }
            }
            return m->sq_item(o, i);
        }
    }
#else
    if (is_list || PySequence_Check(o)) {
        return PySequence_GetItem(o, i);
    }
#endif
    return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i));
}

/* BytesEquals */
    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)) {
        const char *ps1, *ps2;
        Py_ssize_t length = PyBytes_GET_SIZE(s1);
        if (length != PyBytes_GET_SIZE(s2))
            return (equals == Py_NE);
        ps1 = PyBytes_AS_STRING(s1);
        ps2 = PyBytes_AS_STRING(s2);
        if (ps1[0] != ps2[0]) {
            return (equals == Py_NE);
        } else if (length == 1) {
            return (equals == Py_EQ);
        } else {
            int result;
#if CYTHON_USE_UNICODE_INTERNALS
            Py_hash_t hash1, hash2;
            hash1 = ((PyBytesObject*)s1)->ob_shash;
            hash2 = ((PyBytesObject*)s2)->ob_shash;
            if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
                return (equals == Py_NE);
            }
#endif
            result = memcmp(ps1, ps2, (size_t)length);
            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
}

/* UnicodeEquals */
    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 PY_MAJOR_VERSION < 3
    PyObject* owned_ref = NULL;
#endif
    int s1_is_unicode, s2_is_unicode;
    if (s1 == s2) {
        goto return_eq;
    }
    s1_is_unicode = PyUnicode_CheckExact(s1);
    s2_is_unicode = PyUnicode_CheckExact(s2);
#if PY_MAJOR_VERSION < 3
    if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) {
        owned_ref = PyUnicode_FromObject(s2);
        if (unlikely(!owned_ref))
            return -1;
        s2 = owned_ref;
        s2_is_unicode = 1;
    } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) {
        owned_ref = PyUnicode_FromObject(s1);
        if (unlikely(!owned_ref))
            return -1;
        s1 = owned_ref;
        s1_is_unicode = 1;
    } else if (((!s2_is_unicode) & (!s1_is_unicode))) {
        return __Pyx_PyBytes_Equals(s1, s2, equals);
    }
#endif
    if (s1_is_unicode & s2_is_unicode) {
        Py_ssize_t length;
        int kind;
        void *data1, *data2;
        if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0))
            return -1;
        length = __Pyx_PyUnicode_GET_LENGTH(s1);
        if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) {
            goto return_ne;
        }
#if CYTHON_USE_UNICODE_INTERNALS
        {
            Py_hash_t hash1, hash2;
        #if CYTHON_PEP393_ENABLED
            hash1 = ((PyASCIIObject*)s1)->hash;
            hash2 = ((PyASCIIObject*)s2)->hash;
        #else
            hash1 = ((PyUnicodeObject*)s1)->hash;
            hash2 = ((PyUnicodeObject*)s2)->hash;
        #endif
            if (hash1 != hash2 && hash1 != -1 && hash2 != -1) {
                goto return_ne;
            }
        }
#endif
        kind = __Pyx_PyUnicode_KIND(s1);
        if (kind != __Pyx_PyUnicode_KIND(s2)) {
            goto return_ne;
        }
        data1 = __Pyx_PyUnicode_DATA(s1);
        data2 = __Pyx_PyUnicode_DATA(s2);
        if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) {
            goto return_ne;
        } else if (length == 1) {
            goto return_eq;
        } else {
            int result = memcmp(data1, data2, (size_t)(length * kind));
            #if PY_MAJOR_VERSION < 3
            Py_XDECREF(owned_ref);
            #endif
            return (equals == Py_EQ) ? (result == 0) : (result != 0);
        }
    } else if ((s1 == Py_None) & s2_is_unicode) {
        goto return_ne;
    } else if ((s2 == Py_None) & s1_is_unicode) {
        goto return_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;
    }
return_eq:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_EQ);
return_ne:
    #if PY_MAJOR_VERSION < 3
    Py_XDECREF(owned_ref);
    #endif
    return (equals == Py_NE);
#endif
}

/* SliceObject */
    static CYTHON_INLINE PyObject* __Pyx_PyObject_GetSlice(PyObject* obj,
        Py_ssize_t cstart, Py_ssize_t cstop,
        PyObject** _py_start, PyObject** _py_stop, PyObject** _py_slice,
        int has_cstart, int has_cstop, CYTHON_UNUSED int wraparound) {
#if CYTHON_USE_TYPE_SLOTS
    PyMappingMethods* mp;
#if PY_MAJOR_VERSION < 3
    PySequenceMethods* ms = Py_TYPE(obj)->tp_as_sequence;
    if (likely(ms && ms->sq_slice)) {
        if (!has_cstart) {
            if (_py_start && (*_py_start != Py_None)) {
                cstart = __Pyx_PyIndex_AsSsize_t(*_py_start);
                if ((cstart == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstart = 0;
        }
        if (!has_cstop) {
            if (_py_stop && (*_py_stop != Py_None)) {
                cstop = __Pyx_PyIndex_AsSsize_t(*_py_stop);
                if ((cstop == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad;
            } else
                cstop = PY_SSIZE_T_MAX;
        }
        if (wraparound && unlikely((cstart < 0) | (cstop < 0)) && likely(ms->sq_length)) {
            Py_ssize_t l = ms->sq_length(obj);
            if (likely(l >= 0)) {
                if (cstop < 0) {
                    cstop += l;
                    if (cstop < 0) cstop = 0;
                }
                if (cstart < 0) {
                    cstart += l;
                    if (cstart < 0) cstart = 0;
                }
            } else {
                if (!PyErr_ExceptionMatches(PyExc_OverflowError))
                    goto bad;
                PyErr_Clear();
            }
        }
        return ms->sq_slice(obj, cstart, cstop);
    }
#endif
    mp = Py_TYPE(obj)->tp_as_mapping;
    if (likely(mp && mp->mp_subscript))
#endif
    {
        PyObject* result;
        PyObject *py_slice, *py_start, *py_stop;
        if (_py_slice) {
            py_slice = *_py_slice;
        } else {
            PyObject* owned_start = NULL;
            PyObject* owned_stop = NULL;
            if (_py_start) {
                py_start = *_py_start;
            } else {
                if (has_cstart) {
                    owned_start = py_start = PyInt_FromSsize_t(cstart);
                    if (unlikely(!py_start)) goto bad;
                } else
                    py_start = Py_None;
            }
            if (_py_stop) {
                py_stop = *_py_stop;
            } else {
                if (has_cstop) {
                    owned_stop = py_stop = PyInt_FromSsize_t(cstop);
                    if (unlikely(!py_stop)) {
                        Py_XDECREF(owned_start);
                        goto bad;
                    }
                } else
                    py_stop = Py_None;
            }
            py_slice = PySlice_New(py_start, py_stop, Py_None);
            Py_XDECREF(owned_start);
            Py_XDECREF(owned_stop);
            if (unlikely(!py_slice)) goto bad;
        }
#if CYTHON_USE_TYPE_SLOTS
        result = mp->mp_subscript(obj, py_slice);
#else
        result = PyObject_GetItem(obj, py_slice);
#endif
        if (!_py_slice) {
            Py_DECREF(py_slice);
        }
        return result;
    }
    PyErr_Format(PyExc_TypeError,
        "'%.200s' object is unsliceable", Py_TYPE(obj)->tp_name);
bad:
    return NULL;
}

/* StringJoin */
    #if !CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE PyObject* __Pyx_PyBytes_Join(PyObject* sep, PyObject* values) {
    return PyObject_CallMethodObjArgs(sep, __pyx_n_s_join, values, NULL);
}
#endif

/* PyIntBinop */
    #if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddCObj(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op2))) {
        const long a = intval;
        long x;
        long b = PyInt_AS_LONG(op2);
            x = (long)((unsigned long)a + b);
            if (likely((x^a) >= 0 || (x^b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_add(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op2))) {
        const long a = intval;
        long b, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG lla = intval;
        PY_LONG_LONG llb, llx;
#endif
        const digit* digits = ((PyLongObject*)op2)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op2);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            b = likely(size) ? digits[0] : 0;
            if (size == -1) b = -b;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        b = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        llb = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        b = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        llb = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        b = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        llb = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        b = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        llb = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        b = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        llb = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        b = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        llb = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
            }
        }
                x = a + b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla + llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    if (PyFloat_CheckExact(op2)) {
        const long a = intval;
        double b = PyFloat_AS_DOUBLE(op2);
            double result;
            PyFPE_START_PROTECT("add", return NULL)
            result = ((double)a) + (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
}
#endif

/* RaiseTooManyValuesToUnpack */
    static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) {
    PyErr_Format(PyExc_ValueError,
                 "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected);
}

/* RaiseNeedMoreValuesToUnpack */
    static CYTHON_INLINE void __Pyx_RaiseNeedMoreValuesError(Py_ssize_t index) {
    PyErr_Format(PyExc_ValueError,
                 "need more than %" CYTHON_FORMAT_SSIZE_T "d value%.1s to unpack",
                 index, (index == 1) ? "" : "s");
}

/* IterFinish */
    static CYTHON_INLINE int __Pyx_IterFinish(void) {
#if CYTHON_FAST_THREAD_STATE
    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
}

/* UnpackItemEndCheck */
    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;
}

/* PyObjectCallMethod1 */
    static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) {
    PyObject *method, *result = NULL;
    method = __Pyx_PyObject_GetAttrStr(obj, method_name);
    if (unlikely(!method)) goto done;
#if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(method))) {
        PyObject *self = PyMethod_GET_SELF(method);
        if (likely(self)) {
            PyObject *args;
            PyObject *function = PyMethod_GET_FUNCTION(method);
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(function)) {
                PyObject *args[2] = {self, arg};
                result = __Pyx_PyFunction_FastCall(function, args, 2);
                goto done;
            }
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(function)) {
                PyObject *args[2] = {self, arg};
                result = __Pyx_PyCFunction_FastCall(function, args, 2);
                goto done;
            }
            #endif
            args = PyTuple_New(2);
            if (unlikely(!args)) goto done;
            Py_INCREF(self);
            PyTuple_SET_ITEM(args, 0, self);
            Py_INCREF(arg);
            PyTuple_SET_ITEM(args, 1, arg);
            Py_INCREF(function);
            Py_DECREF(method); method = NULL;
            result = __Pyx_PyObject_Call(function, args, NULL);
            Py_DECREF(args);
            Py_DECREF(function);
            return result;
        }
    }
#endif
    result = __Pyx_PyObject_CallOneArg(method, arg);
done:
    Py_XDECREF(method);
    return result;
}

/* append */
    static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) {
    if (likely(PyList_CheckExact(L))) {
        if (unlikely(__Pyx_PyList_Append(L, x) < 0)) return -1;
    } else {
        PyObject* retval = __Pyx_PyObject_CallMethod1(L, __pyx_n_s_append, x);
        if (unlikely(!retval))
            return -1;
        Py_DECREF(retval);
    }
    return 0;
}

/* PyIntBinop */
    #if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_EqObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    if (op1 == op2) {
        Py_RETURN_TRUE;
    }
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long a = PyInt_AS_LONG(op1);
        if (a == b) {
            Py_RETURN_TRUE;
        } else {
            Py_RETURN_FALSE;
        }
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a;
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
                    }
                #if PyLong_SHIFT < 30 && PyLong_SHIFT != 15
                default: return PyLong_Type.tp_richcompare(op1, op2, Py_EQ);
                #else
                default: Py_RETURN_FALSE;
                #endif
            }
        }
            if (a == b) {
                Py_RETURN_TRUE;
            } else {
                Py_RETURN_FALSE;
            }
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            if ((double)a == (double)b) {
                Py_RETURN_TRUE;
            } else {
                Py_RETURN_FALSE;
            }
    }
    return PyObject_RichCompare(op1, op2, Py_EQ);
}
#endif

/* None */
    static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) {
    PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname);
}

/* UnpackUnboundCMethod */
    static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) {
    PyObject *method;
    method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name);
    if (unlikely(!method))
        return -1;
    target->method = method;
#if CYTHON_COMPILING_IN_CPYTHON
    #if PY_MAJOR_VERSION >= 3
    if (likely(PyObject_TypeCheck(method, &PyMethodDescr_Type)))
    #endif
    {
        PyMethodDescrObject *descr = (PyMethodDescrObject*) method;
        target->func = descr->d_method->ml_meth;
        target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST);
    }
#endif
    return 0;
}

/* CallUnboundCMethod0 */
    static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self) {
    PyObject *args, *result = NULL;
    if (unlikely(!cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL;
#if CYTHON_ASSUME_SAFE_MACROS
    args = PyTuple_New(1);
    if (unlikely(!args)) goto bad;
    Py_INCREF(self);
    PyTuple_SET_ITEM(args, 0, self);
#else
    args = PyTuple_Pack(1, self);
    if (unlikely(!args)) goto bad;
#endif
    result = __Pyx_PyObject_Call(cfunc->method, args, NULL);
    Py_DECREF(args);
bad:
    return result;
}

/* py_dict_items */
    static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d) {
    if (PY_MAJOR_VERSION >= 3)
        return __Pyx_CallUnboundCMethod0(&__pyx_umethod_PyDict_Type_items, d);
    else
        return PyDict_Items(d);
}

/* PyIntBinop */
    #if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_SubtractCObj(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op2))) {
        const long a = intval;
        long x;
        long b = PyInt_AS_LONG(op2);
            x = (long)((unsigned long)a - b);
            if (likely((x^a) >= 0 || (x^~b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op2))) {
        const long a = intval;
        long b, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG lla = intval;
        PY_LONG_LONG llb, llx;
#endif
        const digit* digits = ((PyLongObject*)op2)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op2);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            b = likely(size) ? digits[0] : 0;
            if (size == -1) b = -b;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        b = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        llb = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        b = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        llb = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        b = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        llb = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        b = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        llb = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        b = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        llb = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        b = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        llb = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                default: return PyLong_Type.tp_as_number->nb_subtract(op1, op2);
            }
        }
                x = a - b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla - llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    if (PyFloat_CheckExact(op2)) {
        const long a = intval;
        double b = PyFloat_AS_DOUBLE(op2);
            double result;
            PyFPE_START_PROTECT("subtract", return NULL)
            result = ((double)a) - (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceSubtract : PyNumber_Subtract)(op1, op2);
}
#endif

/* SliceTupleAndList */
    #if CYTHON_COMPILING_IN_CPYTHON
static CYTHON_INLINE void __Pyx_crop_slice(Py_ssize_t* _start, Py_ssize_t* _stop, Py_ssize_t* _length) {
    Py_ssize_t start = *_start, stop = *_stop, length = *_length;
    if (start < 0) {
        start += length;
        if (start < 0)
            start = 0;
    }
    if (stop < 0)
        stop += length;
    else if (stop > length)
        stop = length;
    *_length = stop - start;
    *_start = start;
    *_stop = stop;
}
static CYTHON_INLINE void __Pyx_copy_object_array(PyObject** CYTHON_RESTRICT src, PyObject** CYTHON_RESTRICT dest, Py_ssize_t length) {
    PyObject *v;
    Py_ssize_t i;
    for (i = 0; i < length; i++) {
        v = dest[i] = src[i];
        Py_INCREF(v);
    }
}
static CYTHON_INLINE PyObject* __Pyx_PyList_GetSlice(
            PyObject* src, Py_ssize_t start, Py_ssize_t stop) {
    PyObject* dest;
    Py_ssize_t length = PyList_GET_SIZE(src);
    __Pyx_crop_slice(&start, &stop, &length);
    if (unlikely(length <= 0))
        return PyList_New(0);
    dest = PyList_New(length);
    if (unlikely(!dest))
        return NULL;
    __Pyx_copy_object_array(
        ((PyListObject*)src)->ob_item + start,
        ((PyListObject*)dest)->ob_item,
        length);
    return dest;
}
static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice(
            PyObject* src, Py_ssize_t start, Py_ssize_t stop) {
    PyObject* dest;
    Py_ssize_t length = PyTuple_GET_SIZE(src);
    __Pyx_crop_slice(&start, &stop, &length);
    if (unlikely(length <= 0))
        return PyTuple_New(0);
    dest = PyTuple_New(length);
    if (unlikely(!dest))
        return NULL;
    __Pyx_copy_object_array(
        ((PyTupleObject*)src)->ob_item + start,
        ((PyTupleObject*)dest)->ob_item,
        length);
    return dest;
}
#endif

/* py_dict_values */
    static CYTHON_INLINE PyObject* __Pyx_PyDict_Values(PyObject* d) {
    if (PY_MAJOR_VERSION >= 3)
        return __Pyx_CallUnboundCMethod0(&__pyx_umethod_PyDict_Type_values, d);
    else
        return PyDict_Values(d);
}

/* PyObjectCallMethod2 */
    static PyObject* __Pyx_PyObject_CallMethod2(PyObject* obj, PyObject* method_name, PyObject* arg1, PyObject* arg2) {
    PyObject *args, *method, *result = NULL;
    method = __Pyx_PyObject_GetAttrStr(obj, method_name);
    if (unlikely(!method)) return NULL;
#if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(method)) && likely(PyMethod_GET_SELF(method))) {
        PyObject *self, *function;
        self = PyMethod_GET_SELF(method);
        function = PyMethod_GET_FUNCTION(method);
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(function)) {
            PyObject *args[3] = {self, arg1, arg2};
            result = __Pyx_PyFunction_FastCall(function, args, 3);
            goto done;
        }
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(function)) {
            PyObject *args[3] = {self, arg1, arg2};
            result = __Pyx_PyFunction_FastCall(function, args, 3);
            goto done;
        }
        #endif
        args = PyTuple_New(3);
        if (unlikely(!args)) goto done;
        Py_INCREF(self);
        PyTuple_SET_ITEM(args, 0, self);
        Py_INCREF(arg1);
        PyTuple_SET_ITEM(args, 1, arg1);
        Py_INCREF(arg2);
        PyTuple_SET_ITEM(args, 2, arg2);
        Py_INCREF(function);
        Py_DECREF(method);
        method = function;
    } else
#endif
#if CYTHON_FAST_PYCALL
    if (PyFunction_Check(method)) {
        PyObject *args[2] = {arg1, arg2};
        result = __Pyx_PyFunction_FastCall(method, args, 2);
        goto done;
    } else
#endif
#if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(method)) {
        PyObject *args[2] = {arg1, arg2};
        result = __Pyx_PyCFunction_FastCall(method, args, 2);
        goto done;
    } else
#endif
    {
        args = PyTuple_New(2);
        if (unlikely(!args)) goto done;
        Py_INCREF(arg1);
        PyTuple_SET_ITEM(args, 0, arg1);
        Py_INCREF(arg2);
        PyTuple_SET_ITEM(args, 1, arg2);
    }
    result = __Pyx_PyObject_Call(method, args, NULL);
    Py_DECREF(args);
done:
    Py_DECREF(method);
    return result;
}

/* dict_setdefault */
    static CYTHON_INLINE PyObject *__Pyx_PyDict_SetDefault(PyObject *d, PyObject *key, PyObject *default_value,
                                                       CYTHON_UNUSED int is_safe_type) {
    PyObject* value;
#if PY_VERSION_HEX >= 0x030400A0
    if ((1)) {
        value = PyDict_SetDefault(d, key, default_value);
        if (unlikely(!value)) return NULL;
        Py_INCREF(value);
#else
    if (is_safe_type == 1 || (is_safe_type == -1 &&
#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY
            (PyUnicode_CheckExact(key) || PyString_CheckExact(key) || PyLong_CheckExact(key)))) {
        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
            (PyString_CheckExact(key) || PyUnicode_CheckExact(key) || PyInt_CheckExact(key) || PyLong_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);
#endif
#endif
    } else {
        value = __Pyx_PyObject_CallMethod2(d, __pyx_n_s_setdefault, key, default_value);
    }
    return value;
}

/* py_dict_keys */
        static CYTHON_INLINE PyObject* __Pyx_PyDict_Keys(PyObject* d) {
    if (PY_MAJOR_VERSION >= 3)
        return __Pyx_CallUnboundCMethod0(&__pyx_umethod_PyDict_Type_keys, d);
    else
        return PyDict_Keys(d);
}

/* PyIntBinop */
        #if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED long intval, CYTHON_UNUSED int inplace) {
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        const long b = intval;
        long x;
        long a = PyInt_AS_LONG(op1);
            x = (long)((unsigned long)a + b);
            if (likely((x^a) >= 0 || (x^b) >= 0))
                return PyInt_FromLong(x);
            return PyLong_Type.tp_as_number->nb_add(op1, op2);
    }
    #endif
    #if CYTHON_USE_PYLONG_INTERNALS
    if (likely(PyLong_CheckExact(op1))) {
        const long b = intval;
        long a, x;
#ifdef HAVE_LONG_LONG
        const PY_LONG_LONG llb = intval;
        PY_LONG_LONG lla, llx;
#endif
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        if (likely(__Pyx_sst_abs(size) <= 1)) {
            a = likely(size) ? digits[0] : 0;
            if (size == -1) a = -a;
        } else {
            switch (size) {
                case -2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                case 2:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                case -3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                case 3:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                case -4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                case 4:
                    if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                        a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                        break;
#ifdef HAVE_LONG_LONG
                    } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) {
                        lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0]));
                        goto long_long;
#endif
                    }
                default: return PyLong_Type.tp_as_number->nb_add(op1, op2);
            }
        }
                x = a + b;
            return PyLong_FromLong(x);
#ifdef HAVE_LONG_LONG
        long_long:
                llx = lla + llb;
            return PyLong_FromLongLong(llx);
#endif
        
        
    }
    #endif
    if (PyFloat_CheckExact(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            double result;
            PyFPE_START_PROTECT("add", return NULL)
            result = ((double)a) + (double)b;
            PyFPE_END_PROTECT(result)
            return PyFloat_FromDouble(result);
    }
    return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
}
#endif

/* pyobject_as_double */
        static double __Pyx__PyObject_AsDouble(PyObject* obj) {
    PyObject* float_value;
#if !CYTHON_USE_TYPE_SLOTS
    float_value = PyNumber_Float(obj);  if (0) goto bad;
#else
    PyNumberMethods *nb = Py_TYPE(obj)->tp_as_number;
    if (likely(nb) && likely(nb->nb_float)) {
        float_value = nb->nb_float(obj);
        if (likely(float_value) && unlikely(!PyFloat_Check(float_value))) {
            PyErr_Format(PyExc_TypeError,
                "__float__ returned non-float (type %.200s)",
                Py_TYPE(float_value)->tp_name);
            Py_DECREF(float_value);
            goto bad;
        }
    } 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;
}

/* SaveResetException */
        #if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    *type = tstate->exc_type;
    *value = tstate->exc_value;
    *tb = tstate->exc_traceback;
    Py_XINCREF(*type);
    Py_XINCREF(*value);
    Py_XINCREF(*tb);
}
static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    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);
}
#endif

/* GetException */
        #if CYTHON_FAST_THREAD_STATE
static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
#else
static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) {
#endif
    PyObject *local_type, *local_value, *local_tb;
#if CYTHON_FAST_THREAD_STATE
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    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_FAST_THREAD_STATE
    if (unlikely(tstate->curexc_type))
#else
    if (unlikely(PyErr_Occurred()))
#endif
        goto bad;
    #if PY_MAJOR_VERSION >= 3
    if (local_tb) {
        if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0))
            goto bad;
    }
    #endif
    Py_XINCREF(local_tb);
    Py_XINCREF(local_type);
    Py_XINCREF(local_value);
    *type = local_type;
    *value = local_value;
    *tb = local_tb;
#if CYTHON_FAST_THREAD_STATE
    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;
    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;
}

/* PyErrFetchRestore */
          #if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    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);
}
static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) {
    *type = tstate->curexc_type;
    *value = tstate->curexc_value;
    *tb = tstate->curexc_traceback;
    tstate->curexc_type = 0;
    tstate->curexc_value = 0;
    tstate->curexc_traceback = 0;
}
#endif

/* PyErrExceptionMatches */
          #if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err) {
    PyObject *exc_type = tstate->curexc_type;
    if (exc_type == err) return 1;
    if (unlikely(!exc_type)) return 0;
    return PyErr_GivenExceptionMatches(exc_type, err);
}
#endif

/* Import */
          static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) {
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    #if PY_VERSION_HEX < 0x03030000
    PyObject *py_import;
    py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import);
    if (!py_import)
        goto bad;
    #endif
    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_MAJOR_VERSION >= 3
        if (level == -1) {
            if (strchr(__Pyx_MODULE_NAME, '.')) {
                #if PY_VERSION_HEX < 0x03030000
                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);
                #else
                module = PyImport_ImportModuleLevelObject(
                    name, global_dict, empty_dict, list, 1);
                #endif
                if (!module) {
                    if (!PyErr_ExceptionMatches(PyExc_ImportError))
                        goto bad;
                    PyErr_Clear();
                }
            }
            level = 0;
        }
        #endif
        if (!module) {
            #if PY_VERSION_HEX < 0x03030000
            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
            module = PyImport_ImportModuleLevelObject(
                name, global_dict, empty_dict, list, level);
            #endif
        }
    }
bad:
    #if PY_VERSION_HEX < 0x03030000
    Py_XDECREF(py_import);
    #endif
    Py_XDECREF(empty_list);
    Py_XDECREF(empty_dict);
    return module;
}

/* ImportFrom */
          static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) {
    PyObject* value = __Pyx_PyObject_GetAttrStr(module, name);
    if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Format(PyExc_ImportError,
        #if PY_MAJOR_VERSION < 3
            "cannot import name %.230s", PyString_AS_STRING(name));
        #else
            "cannot import name %S", name);
        #endif
    }
    return value;
}

/* FetchCommonType */
          static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) {
    PyObject* fake_module;
    PyTypeObject* cached_type = NULL;
    fake_module = PyImport_AddModule((char*) "_cython_" CYTHON_ABI);
    if (!fake_module) return NULL;
    Py_INCREF(fake_module);
    cached_type = (PyTypeObject*) PyObject_GetAttrString(fake_module, type->tp_name);
    if (cached_type) {
        if (!PyType_Check((PyObject*)cached_type)) {
            PyErr_Format(PyExc_TypeError,
                "Shared Cython type %.200s is not a type object",
                type->tp_name);
            goto bad;
        }
        if (cached_type->tp_basicsize != type->tp_basicsize) {
            PyErr_Format(PyExc_TypeError,
                "Shared Cython type %.200s has the wrong size, try recompiling",
                type->tp_name);
            goto bad;
        }
    } else {
        if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad;
        PyErr_Clear();
        if (PyType_Ready(type) < 0) goto bad;
        if (PyObject_SetAttrString(fake_module, type->tp_name, (PyObject*) type) < 0)
            goto bad;
        Py_INCREF(type);
        cached_type = type;
    }
done:
    Py_DECREF(fake_module);
    return cached_type;
bad:
    Py_XDECREF(cached_type);
    cached_type = NULL;
    goto done;
}

/* CythonFunction */
          static PyObject *
__Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, CYTHON_UNUSED void *closure)
{
    if (unlikely(op->func_doc == NULL)) {
        if (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 (unlikely(op->func_doc == NULL))
                return NULL;
        } else {
            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) {
        value = Py_None;
    }
    Py_INCREF(value);
    op->func_doc = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op)
{
    if (unlikely(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
        if (unlikely(op->func_name == NULL))
            return NULL;
    }
    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 (unlikely(value == NULL || !PyUnicode_Check(value))) {
#else
    if (unlikely(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_qualname(__pyx_CyFunctionObject *op)
{
    Py_INCREF(op->func_qualname);
    return op->func_qualname;
}
static int
__Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value)
{
    PyObject *tmp;
#if PY_MAJOR_VERSION >= 3
    if (unlikely(value == NULL || !PyUnicode_Check(value))) {
#else
    if (unlikely(value == NULL || !PyString_Check(value))) {
#endif
        PyErr_SetString(PyExc_TypeError,
                        "__qualname__ must be set to a string object");
        return -1;
    }
    tmp = op->func_qualname;
    Py_INCREF(value);
    op->func_qualname = 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 (unlikely(op->func_dict == NULL)) {
        op->func_dict = PyDict_New();
        if (unlikely(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 (unlikely(value == NULL)) {
        PyErr_SetString(PyExc_TypeError,
               "function's dictionary may not be deleted");
        return -1;
    }
    if (unlikely(!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(__pyx_CyFunctionObject *op)
{
    Py_INCREF(op->func_globals);
    return op->func_globals;
}
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 int
__Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) {
    int result = 0;
    PyObject *res = op->defaults_getter((PyObject *) op);
    if (unlikely(!res))
        return -1;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    op->defaults_tuple = PyTuple_GET_ITEM(res, 0);
    Py_INCREF(op->defaults_tuple);
    op->defaults_kwdict = PyTuple_GET_ITEM(res, 1);
    Py_INCREF(op->defaults_kwdict);
    #else
    op->defaults_tuple = PySequence_ITEM(res, 0);
    if (unlikely(!op->defaults_tuple)) result = -1;
    else {
        op->defaults_kwdict = PySequence_ITEM(res, 1);
        if (unlikely(!op->defaults_kwdict)) result = -1;
    }
    #endif
    Py_DECREF(res);
    return result;
}
static int
__Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value) {
    PyObject* tmp;
    if (!value) {
        value = Py_None;
    } else if (value != Py_None && !PyTuple_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "__defaults__ must be set to a tuple object");
        return -1;
    }
    Py_INCREF(value);
    tmp = op->defaults_tuple;
    op->defaults_tuple = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op) {
    PyObject* result = op->defaults_tuple;
    if (unlikely(!result)) {
        if (op->defaults_getter) {
            if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
            result = op->defaults_tuple;
        } else {
            result = Py_None;
        }
    }
    Py_INCREF(result);
    return result;
}
static int
__Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value) {
    PyObject* tmp;
    if (!value) {
        value = Py_None;
    } else if (value != Py_None && !PyDict_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "__kwdefaults__ must be set to a dict object");
        return -1;
    }
    Py_INCREF(value);
    tmp = op->defaults_kwdict;
    op->defaults_kwdict = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op) {
    PyObject* result = op->defaults_kwdict;
    if (unlikely(!result)) {
        if (op->defaults_getter) {
            if (__Pyx_CyFunction_init_defaults(op) < 0) return NULL;
            result = op->defaults_kwdict;
        } else {
            result = Py_None;
        }
    }
    Py_INCREF(result);
    return result;
}
static int
__Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value) {
    PyObject* tmp;
    if (!value || value == Py_None) {
        value = NULL;
    } else if (!PyDict_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "__annotations__ must be set to a dict object");
        return -1;
    }
    Py_XINCREF(value);
    tmp = op->func_annotations;
    op->func_annotations = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op) {
    PyObject* result = op->func_annotations;
    if (unlikely(!result)) {
        result = PyDict_New();
        if (unlikely(!result)) return NULL;
        op->func_annotations = result;
    }
    Py_INCREF(result);
    return result;
}
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 *) "__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 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, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
    {(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0},
    {(char *) "__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0},
    {(char *) "__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0},
    {0, 0, 0, 0, 0}
};
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[] = {
    {"__reduce__", (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0},
    {0, 0, 0, 0}
};
#if PY_VERSION_HEX < 0x030500A0
#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func_weakreflist)
#else
#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func.m_weakreflist)
#endif
static PyObject *__Pyx_CyFunction_New(PyTypeObject *type, PyMethodDef *ml, int flags, PyObject* qualname,
                                      PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) {
    __pyx_CyFunctionObject *op = PyObject_GC_New(__pyx_CyFunctionObject, type);
    if (op == NULL)
        return NULL;
    op->flags = flags;
    __Pyx_CyFunction_weakreflist(op) = 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;
    Py_INCREF(qualname);
    op->func_qualname = qualname;
    op->func_doc = NULL;
    op->func_classobj = NULL;
    op->func_globals = globals;
    Py_INCREF(op->func_globals);
    Py_XINCREF(code);
    op->func_code = code;
    op->defaults_pyobjects = 0;
    op->defaults = NULL;
    op->defaults_tuple = NULL;
    op->defaults_kwdict = NULL;
    op->defaults_getter = NULL;
    op->func_annotations = 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_qualname);
    Py_CLEAR(m->func_doc);
    Py_CLEAR(m->func_globals);
    Py_CLEAR(m->func_code);
    Py_CLEAR(m->func_classobj);
    Py_CLEAR(m->defaults_tuple);
    Py_CLEAR(m->defaults_kwdict);
    Py_CLEAR(m->func_annotations);
    if (m->defaults) {
        PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m);
        int i;
        for (i = 0; i < m->defaults_pyobjects; i++)
            Py_XDECREF(pydefaults[i]);
        PyObject_Free(m->defaults);
        m->defaults = NULL;
    }
    return 0;
}
static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m)
{
    PyObject_GC_UnTrack(m);
    if (__Pyx_CyFunction_weakreflist(m) != 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_qualname);
    Py_VISIT(m->func_doc);
    Py_VISIT(m->func_globals);
    Py_VISIT(m->func_code);
    Py_VISIT(m->func_classobj);
    Py_VISIT(m->defaults_tuple);
    Py_VISIT(m->defaults_kwdict);
    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 __Pyx_PyMethod_New(func, type, (PyObject *)(Py_TYPE(type)));
    }
    if (obj == Py_None)
        obj = NULL;
    return __Pyx_PyMethod_New(func, obj, type);
}
static PyObject*
__Pyx_CyFunction_repr(__pyx_CyFunctionObject *op)
{
#if PY_MAJOR_VERSION >= 3
    return PyUnicode_FromFormat("<cyfunction %U at %p>",
                                op->func_qualname, (void *)op);
#else
    return PyString_FromFormat("<cyfunction %s at %p>",
                               PyString_AsString(op->func_qualname), (void *)op);
#endif
}
static PyObject * __Pyx_CyFunction_CallMethod(PyObject *func, PyObject *self, PyObject *arg, PyObject *kw) {
    PyCFunctionObject* f = (PyCFunctionObject*)func;
    PyCFunction meth = f->m_ml->ml_meth;
    Py_ssize_t size;
    switch (f->m_ml->ml_flags & (METH_VARARGS | METH_KEYWORDS | METH_NOARGS | METH_O)) {
    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 (likely(size == 0))
                return (*meth)(self, NULL);
            PyErr_Format(PyExc_TypeError,
                "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d 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 (likely(size == 1)) {
                PyObject *result, *arg0 = PySequence_ITEM(arg, 0);
                if (unlikely(!arg0)) return NULL;
                result = (*meth)(self, arg0);
                Py_DECREF(arg0);
                return result;
            }
            PyErr_Format(PyExc_TypeError,
                "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d 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;
}
static CYTHON_INLINE PyObject *__Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) {
    return __Pyx_CyFunction_CallMethod(func, ((PyCFunctionObject*)func)->m_self, arg, kw);
}
static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, PyObject *kw) {
    PyObject *result;
    __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *) func;
    if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) {
        Py_ssize_t argc;
        PyObject *new_args;
        PyObject *self;
        argc = PyTuple_GET_SIZE(args);
        new_args = PyTuple_GetSlice(args, 1, argc);
        if (unlikely(!new_args))
            return NULL;
        self = PyTuple_GetItem(args, 0);
        if (unlikely(!self)) {
            Py_DECREF(new_args);
            return NULL;
        }
        result = __Pyx_CyFunction_CallMethod(func, self, new_args, kw);
        Py_DECREF(new_args);
    } else {
        result = __Pyx_CyFunction_Call(func, args, kw);
    }
    return result;
}
static PyTypeObject __pyx_CyFunctionType_type = {
    PyVarObject_HEAD_INIT(0, 0)
    "cython_function_or_method",
    sizeof(__pyx_CyFunctionObject),
    0,
    (destructor) __Pyx_CyFunction_dealloc,
    0,
    0,
    0,
#if PY_MAJOR_VERSION < 3
    0,
#else
    0,
#endif
    (reprfunc) __Pyx_CyFunction_repr,
    0,
    0,
    0,
    0,
    __Pyx_CyFunction_CallAsMethod,
    0,
    0,
    0,
    0,
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
    0,
    (traverseproc) __Pyx_CyFunction_traverse,
    (inquiry) __Pyx_CyFunction_clear,
    0,
#if PY_VERSION_HEX < 0x030500A0
    offsetof(__pyx_CyFunctionObject, func_weakreflist),
#else
    offsetof(PyCFunctionObject, m_weakreflist),
#endif
    0,
    0,
    __pyx_CyFunction_methods,
    __pyx_CyFunction_members,
    __pyx_CyFunction_getsets,
    0,
    0,
    __Pyx_CyFunction_descr_get,
    0,
    offsetof(__pyx_CyFunctionObject, func_dict),
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
#if PY_VERSION_HEX >= 0x030400a1
    0,
#endif
};
static int __pyx_CyFunction_init(void) {
    __pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type);
    if (__pyx_CyFunctionType == NULL) {
        return -1;
    }
    return 0;
}
static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->defaults = PyObject_Malloc(size);
    if (!m->defaults)
        return PyErr_NoMemory();
    memset(m->defaults, 0, size);
    m->defaults_pyobjects = pyobjects;
    return m->defaults;
}
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 void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->defaults_kwdict = dict;
    Py_INCREF(dict);
}
static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) {
    __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func;
    m->func_annotations = dict;
    Py_INCREF(dict);
}

/* CalculateMetaclass */
              static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases) {
    Py_ssize_t i, nbases = PyTuple_GET_SIZE(bases);
    for (i=0; i < nbases; i++) {
        PyTypeObject *tmptype;
        PyObject *tmp = PyTuple_GET_ITEM(bases, i);
        tmptype = Py_TYPE(tmp);
#if PY_MAJOR_VERSION < 3
        if (tmptype == &PyClass_Type)
            continue;
#endif
        if (!metaclass) {
            metaclass = tmptype;
            continue;
        }
        if (PyType_IsSubtype(metaclass, tmptype))
            continue;
        if (PyType_IsSubtype(tmptype, metaclass)) {
            metaclass = tmptype;
            continue;
        }
        PyErr_SetString(PyExc_TypeError,
                        "metaclass conflict: "
                        "the metaclass of a derived class "
                        "must be a (non-strict) subclass "
                        "of the metaclasses of all its bases");
        return NULL;
    }
    if (!metaclass) {
#if PY_MAJOR_VERSION < 3
        metaclass = &PyClass_Type;
#else
        metaclass = &PyType_Type;
#endif
    }
    Py_INCREF((PyObject*) metaclass);
    return (PyObject*) metaclass;
}

/* Py3ClassCreate */
              static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name,
                                           PyObject *qualname, PyObject *mkw, PyObject *modname, PyObject *doc) {
    PyObject *ns;
    if (metaclass) {
        PyObject *prep = __Pyx_PyObject_GetAttrStr(metaclass, __pyx_n_s_prepare);
        if (prep) {
            PyObject *pargs = PyTuple_Pack(2, name, bases);
            if (unlikely(!pargs)) {
                Py_DECREF(prep);
                return NULL;
            }
            ns = PyObject_Call(prep, pargs, mkw);
            Py_DECREF(prep);
            Py_DECREF(pargs);
        } else {
            if (unlikely(!PyErr_ExceptionMatches(PyExc_AttributeError)))
                return NULL;
            PyErr_Clear();
            ns = PyDict_New();
        }
    } else {
        ns = PyDict_New();
    }
    if (unlikely(!ns))
        return NULL;
    if (unlikely(PyObject_SetItem(ns, __pyx_n_s_module, modname) < 0)) goto bad;
    if (unlikely(PyObject_SetItem(ns, __pyx_n_s_qualname, qualname) < 0)) goto bad;
    if (unlikely(doc && PyObject_SetItem(ns, __pyx_n_s_doc, doc) < 0)) goto bad;
    return ns;
bad:
    Py_DECREF(ns);
    return NULL;
}
static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases,
                                      PyObject *dict, PyObject *mkw,
                                      int calculate_metaclass, int allow_py2_metaclass) {
    PyObject *result, *margs;
    PyObject *owned_metaclass = NULL;
    if (allow_py2_metaclass) {
        owned_metaclass = PyObject_GetItem(dict, __pyx_n_s_metaclass);
        if (owned_metaclass) {
            metaclass = owned_metaclass;
        } else if (likely(PyErr_ExceptionMatches(PyExc_KeyError))) {
            PyErr_Clear();
        } else {
            return NULL;
        }
    }
    if (calculate_metaclass && (!metaclass || PyType_Check(metaclass))) {
        metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases);
        Py_XDECREF(owned_metaclass);
        if (unlikely(!metaclass))
            return NULL;
        owned_metaclass = metaclass;
    }
    margs = PyTuple_Pack(3, name, bases, dict);
    if (unlikely(!margs)) {
        result = NULL;
    } else {
        result = PyObject_Call(metaclass, margs, mkw);
        Py_DECREF(margs);
    }
    Py_XDECREF(owned_metaclass);
    return result;
}

/* CLineInTraceback */
              static int __Pyx_CLineForTraceback(int c_line) {
#ifdef CYTHON_CLINE_IN_TRACEBACK
    return ((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0;
#else
    PyObject *use_cline;
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject **cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime);
    if (likely(cython_runtime_dict)) {
      use_cline = PyDict_GetItem(*cython_runtime_dict, __pyx_n_s_cline_in_traceback);
    } else
#endif
    {
      PyObject *ptype, *pvalue, *ptraceback;
      PyObject *use_cline_obj;
      PyErr_Fetch(&ptype, &pvalue, &ptraceback);
      use_cline_obj = __Pyx_PyObject_GetAttrStr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback);
      if (use_cline_obj) {
        use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True;
        Py_DECREF(use_cline_obj);
      } else {
        use_cline = NULL;
      }
      PyErr_Restore(ptype, pvalue, ptraceback);
    }
    if (!use_cline) {
        c_line = 0;
        PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False);
    }
    else if (PyObject_Not(use_cline) != 0) {
        c_line = 0;
    }
    return c_line;
#endif
}

/* CodeObjectCache */
              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 - start) / 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, (size_t)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);
}

/* AddTraceback */
              #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,
        0,
        0,
        0,
        0,
        __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,
        __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;
    PyFrameObject *py_frame = 0;
    if (c_line) {
        c_line = __Pyx_CLineForTraceback(c_line);
    }
    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_frame = PyFrame_New(
        PyThreadState_GET(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        __pyx_d,      /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    __Pyx_PyFrame_SetLineNumber(py_frame, py_line);
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}

/* None */
              static CYTHON_INLINE long __Pyx_pow_long(long b, long e) {
    long t = b;
    switch (e) {
        case 3:
            t *= b;
        case 2:
            t *= b;
        case 1:
            return t;
        case 0:
            return 1;
    }
    #if 1
    if (unlikely(e<0)) return 0;
    #endif
    t = 1;
    while (likely(e)) {
        t *= (b * (e&1)) | ((~e)&1);
        b *= b;
        e >>= 1;
    }
    return t;
}

/* CIntToPy */
              static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) {
    const long neg_one = (long) -1, const_zero = (long) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(long) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(long) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(long) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
            return PyLong_FromLongLong((PY_LONG_LONG) value);
#endif
        }
    }
    {
        int one = 1; int little = (int)*(unsigned char *)&one;
        unsigned char *bytes = (unsigned char *)&value;
        return _PyLong_FromByteArray(bytes, sizeof(long),
                                     little, !is_unsigned);
    }
}

/* Print */
              #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3
static PyObject *__Pyx_GetStdout(void) {
    PyObject *f = PySys_GetObject((char *)"stdout");
    if (!f) {
        PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
    }
    return f;
}
static int __Pyx_Print(PyObject* f, PyObject *arg_tuple, int newline) {
    int i;
    if (!f) {
        if (!(f = __Pyx_GetStdout()))
            return -1;
    }
    Py_INCREF(f);
    for (i=0; i < PyTuple_GET_SIZE(arg_tuple); i++) {
        PyObject* v;
        if (PyFile_SoftSpace(f, 1)) {
            if (PyFile_WriteString(" ", f) < 0)
                goto error;
        }
        v = PyTuple_GET_ITEM(arg_tuple, i);
        if (PyFile_WriteObject(v, f, Py_PRINT_RAW) < 0)
            goto error;
        if (PyString_Check(v)) {
            char *s = PyString_AsString(v);
            Py_ssize_t len = PyString_Size(v);
            if (len > 0) {
                switch (s[len-1]) {
                    case ' ': break;
                    case '\f': case '\r': case '\n': case '\t': case '\v':
                        PyFile_SoftSpace(f, 0);
                        break;
                    default:  break;
                }
            }
        }
    }
    if (newline) {
        if (PyFile_WriteString("\n", f) < 0)
            goto error;
        PyFile_SoftSpace(f, 0);
    }
    Py_DECREF(f);
    return 0;
error:
    Py_DECREF(f);
    return -1;
}
#else
static int __Pyx_Print(PyObject* stream, PyObject *arg_tuple, int newline) {
    PyObject* kwargs = 0;
    PyObject* result = 0;
    PyObject* end_string;
    if (unlikely(!__pyx_print)) {
        __pyx_print = PyObject_GetAttr(__pyx_b, __pyx_n_s_print);
        if (!__pyx_print)
            return -1;
    }
    if (stream) {
        kwargs = PyDict_New();
        if (unlikely(!kwargs))
            return -1;
        if (unlikely(PyDict_SetItem(kwargs, __pyx_n_s_file, stream) < 0))
            goto bad;
        if (!newline) {
            end_string = PyUnicode_FromStringAndSize(" ", 1);
            if (unlikely(!end_string))
                goto bad;
            if (PyDict_SetItem(kwargs, __pyx_n_s_end, end_string) < 0) {
                Py_DECREF(end_string);
                goto bad;
            }
            Py_DECREF(end_string);
        }
    } else if (!newline) {
        if (unlikely(!__pyx_print_kwargs)) {
            __pyx_print_kwargs = PyDict_New();
            if (unlikely(!__pyx_print_kwargs))
                return -1;
            end_string = PyUnicode_FromStringAndSize(" ", 1);
            if (unlikely(!end_string))
                return -1;
            if (PyDict_SetItem(__pyx_print_kwargs, __pyx_n_s_end, end_string) < 0) {
                Py_DECREF(end_string);
                return -1;
            }
            Py_DECREF(end_string);
        }
        kwargs = __pyx_print_kwargs;
    }
    result = PyObject_Call(__pyx_print, arg_tuple, kwargs);
    if (unlikely(kwargs) && (kwargs != __pyx_print_kwargs))
        Py_DECREF(kwargs);
    if (!result)
        return -1;
    Py_DECREF(result);
    return 0;
bad:
    if (kwargs != __pyx_print_kwargs)
        Py_XDECREF(kwargs);
    return -1;
}
#endif

/* PrintOne */
              #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION < 3
static int __Pyx_PrintOne(PyObject* f, PyObject *o) {
    if (!f) {
        if (!(f = __Pyx_GetStdout()))
            return -1;
    }
    Py_INCREF(f);
    if (PyFile_SoftSpace(f, 0)) {
        if (PyFile_WriteString(" ", f) < 0)
            goto error;
    }
    if (PyFile_WriteObject(o, f, Py_PRINT_RAW) < 0)
        goto error;
    if (PyFile_WriteString("\n", f) < 0)
        goto error;
    Py_DECREF(f);
    return 0;
error:
    Py_DECREF(f);
    return -1;
    /* the line below is just to avoid C compiler
     * warnings about unused functions */
    return __Pyx_Print(f, NULL, 0);
}
#else
static int __Pyx_PrintOne(PyObject* stream, PyObject *o) {
    int res;
    PyObject* arg_tuple = PyTuple_Pack(1, o);
    if (unlikely(!arg_tuple))
        return -1;
    res = __Pyx_Print(stream, arg_tuple, 1);
    Py_DECREF(arg_tuple);
    return res;
}
#endif

/* CIntFromPyVerify */
              #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0)
#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\
    __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1)
#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\
    {\
        func_type value = func_value;\
        if (sizeof(target_type) < sizeof(func_type)) {\
            if (unlikely(value != (func_type) (target_type) value)) {\
                func_type zero = 0;\
                if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\
                    return (target_type) -1;\
                if (is_unsigned && unlikely(value < zero))\
                    goto raise_neg_overflow;\
                else\
                    goto raise_overflow;\
            }\
        }\
        return (target_type) value;\
    }

/* CIntFromPy */
              static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) {
    const long neg_one = (long) -1, const_zero = (long) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(long) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (long) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case  1: __PYX_VERIFY_RETURN_INT(long, digit, digits[0])
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 2 * PyLong_SHIFT) {
                            return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 3 * PyLong_SHIFT) {
                            return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) >= 4 * PyLong_SHIFT) {
                            return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (long) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(long) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (long) 0;
                case -1: __PYX_VERIFY_RETURN_INT(long, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(long,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(long) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(long) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                            return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(long) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                            return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(long) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) {
                            return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(long) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            long val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            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;
            }
#endif
            return (long) -1;
        }
    } else {
        long val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (long) -1;
        val = __Pyx_PyInt_As_long(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to long");
    return (long) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to long");
    return (long) -1;
}

/* CIntFromPy */
              static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) {
    const int neg_one = (int) -1, const_zero = (int) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(int) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (int) val;
        }
    } else
#endif
    if (likely(PyLong_Check(x))) {
        if (is_unsigned) {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case  1: __PYX_VERIFY_RETURN_INT(int, digit, digits[0])
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 2 * PyLong_SHIFT) {
                            return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 3 * PyLong_SHIFT) {
                            return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) >= 4 * PyLong_SHIFT) {
                            return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]));
                        }
                    }
                    break;
            }
#endif
#if CYTHON_COMPILING_IN_CPYTHON
            if (unlikely(Py_SIZE(x) < 0)) {
                goto raise_neg_overflow;
            }
#else
            {
                int result = PyObject_RichCompareBool(x, Py_False, Py_LT);
                if (unlikely(result < 0))
                    return (int) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(int) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x))
#endif
            }
        } else {
#if CYTHON_USE_PYLONG_INTERNALS
            const digit* digits = ((PyLongObject*)x)->ob_digit;
            switch (Py_SIZE(x)) {
                case  0: return (int) 0;
                case -1: __PYX_VERIFY_RETURN_INT(int, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(int,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(int) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(int) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                            return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(int) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(int) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                            return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(int) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(int) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(int) - 1 > 4 * PyLong_SHIFT) {
                            return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(int) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x))
#endif
            }
        }
        {
#if CYTHON_COMPILING_IN_PYPY && !defined(_PyLong_AsByteArray)
            PyErr_SetString(PyExc_RuntimeError,
                            "_PyLong_AsByteArray() not available in PyPy, cannot convert large numbers");
#else
            int val;
            PyObject *v = __Pyx_PyNumber_IntOrLong(x);
 #if PY_MAJOR_VERSION < 3
            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;
            }
#endif
            return (int) -1;
        }
    } else {
        int val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (int) -1;
        val = __Pyx_PyInt_As_int(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to int");
    return (int) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to int");
    return (int) -1;
}

/* CheckBinaryVersion */
              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);
        return PyErr_WarnEx(NULL, message, 1);
    }
    return 0;
}

/* InitStrings */
              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
        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;
        if (PyObject_Hash(*t->p) == -1)
            PyErr_Clear();
        ++t;
    }
    return 0;
}

static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) {
    return __Pyx_PyUnicode_FromStringAndSize(c_str, (Py_ssize_t)strlen(c_str));
}
static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) {
    Py_ssize_t ignore;
    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) {
#if CYTHON_COMPILING_IN_CPYTHON && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT)
    if (
#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
            __Pyx_sys_getdefaultencoding_not_ascii &&
#endif
            PyUnicode_Check(o)) {
#if PY_VERSION_HEX < 0x03030000
        char* defenc_c;
        PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL);
        if (!defenc) return NULL;
        defenc_c = PyBytes_AS_STRING(defenc);
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        {
            char* end = defenc_c + PyBytes_GET_SIZE(defenc);
            char* c;
            for (c = defenc_c; c < end; c++) {
                if ((unsigned char) (*c) >= 128) {
                    PyUnicode_AsASCIIString(o);
                    return NULL;
                }
            }
        }
#endif
        *length = PyBytes_GET_SIZE(defenc);
        return defenc_c;
#else
        if (__Pyx_PyUnicode_READY(o) == -1) return NULL;
#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII
        if (PyUnicode_IS_ASCII(o)) {
            *length = PyUnicode_GET_LENGTH(o);
            return PyUnicode_AsUTF8(o);
        } else {
            PyUnicode_AsASCIIString(o);
            return NULL;
        }
#else
        return PyUnicode_AsUTF8AndSize(o, length);
#endif
#endif
    } else
#endif
#if (!CYTHON_COMPILING_IN_PYPY) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE))
    if (PyByteArray_Check(o)) {
        *length = PyByteArray_GET_SIZE(o);
        return PyByteArray_AS_STRING(o);
    } else
#endif
    {
        char* result;
        int r = PyBytes_AsStringAndSize(o, &result, length);
        if (unlikely(r < 0)) {
            return NULL;
        } else {
            return result;
        }
    }
}
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_IntOrLong(PyObject* x) {
#if CYTHON_USE_TYPE_SLOTS
  PyNumberMethods *m;
#endif
  const char *name = NULL;
  PyObject *res = NULL;
#if PY_MAJOR_VERSION < 3
  if (PyInt_Check(x) || PyLong_Check(x))
#else
  if (PyLong_Check(x))
#endif
    return __Pyx_NewRef(x);
#if CYTHON_USE_TYPE_SLOTS
  m = Py_TYPE(x)->tp_as_number;
  #if PY_MAJOR_VERSION < 3
  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
#else
  res = PyNumber_Int(x);
#endif
  if (res) {
#if PY_MAJOR_VERSION < 3
    if (!PyInt_Check(res) && !PyLong_Check(res)) {
#else
    if (!PyLong_Check(res)) {
#endif
      PyErr_Format(PyExc_TypeError,
                   "__%.4s__ returned non-%.4s (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;
#if PY_MAJOR_VERSION < 3
  if (likely(PyInt_CheckExact(b))) {
    if (sizeof(Py_ssize_t) >= sizeof(long))
        return PyInt_AS_LONG(b);
    else
        return PyInt_AsSsize_t(x);
  }
#endif
  if (likely(PyLong_CheckExact(b))) {
    #if CYTHON_USE_PYLONG_INTERNALS
    const digit* digits = ((PyLongObject*)b)->ob_digit;
    const Py_ssize_t size = Py_SIZE(b);
    if (likely(__Pyx_sst_abs(size) <= 1)) {
        ival = likely(size) ? digits[0] : 0;
        if (size == -1) ival = -ival;
        return ival;
    } else {
      switch (size) {
         case 2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -2:
           if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -3:
           if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case 4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
         case -4:
           if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) {
             return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
           }
           break;
      }
    }
    #endif
    return PyLong_AsSsize_t(b);
  }
  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) {
    return PyInt_FromSize_t(ival);
}


#endif /* Py_PYTHON_H */
