/* Generated by Cython 0.25.2 */

/* BEGIN: Cython Metadata
{
    "distutils": {
        "depends": [
            "discodop/bitcount.h",
            "discodop/macros.h"
        ],
        "extra_compile_args": [
            "-O3",
            "-march=native",
            "-DNDEBUG",
            "-Wno-strict-prototypes",
            "-Wno-unused-function",
            "-Wno-unreachable-code",
            "-DPY2=0"
        ],
        "extra_link_args": [
            "-DNDEBUG"
        ]
    },
    "module_name": "discodop.disambiguation"
}
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_25_2"
#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
#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_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_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_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
#ifndef METH_FASTCALL
  #define METH_FASTCALL 0x80
  typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject **args,
                                              Py_ssize_t nargs, PyObject *kwnames);
#else
  #define __Pyx_PyCFunctionFast _PyCFunctionFast
#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)))))
#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
#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)

#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_TrueDivide(x,y)
  #define __Pyx_PyNumber_InPlaceDivide(x,y)  PyNumber_InPlaceTrueDivide(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__discodop__disambiguation
#define __PYX_HAVE_API__discodop__disambiguation
#include <stdint.h>
#include "macros.h"
#include "bitcount.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#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 char* __Pyx_PyObject_AsString(PyObject*);
static CYTHON_INLINE 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_AsSString(s)    ((signed char*) __Pyx_PyObject_AsString(s))
#define __Pyx_PyObject_AsUString(s)    ((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 PyObject *__pyx_m;
static PyObject *__pyx_d;
static PyObject *__pyx_b;
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[] = {
  "discodop/disambiguation.pyx",
  "discodop/containers.pxd",
  "array.pxd",
  "discodop/plcfrs.pxd",
  "type.pxd",
};

/* "containers.pxd":11
 * 
 * # NB: For PCFG parsing sentences longer than 256 words, change this to uint16_t
 * ctypedef uint8_t Idx             # <<<<<<<<<<<<<<
 * 
 * 
 */
typedef uint8_t __pyx_t_8discodop_10containers_Idx;

/*--- Type declarations ---*/
#ifndef _ARRAYARRAY_H
struct arrayobject;
typedef struct arrayobject arrayobject;
#endif
struct __pyx_obj_8discodop_10containers_Grammar;
struct __pyx_obj_8discodop_10containers_Chart;
struct __pyx_obj_8discodop_10containers_LexicalRule;
struct __pyx_obj_8discodop_10containers_ChartItem;
struct __pyx_obj_8discodop_10containers_SmallChartItem;
struct __pyx_obj_8discodop_10containers_FatChartItem;
struct __pyx_obj_8discodop_10containers_Edges;
struct __pyx_obj_8discodop_10containers_RankedEdge;
struct __pyx_obj_8discodop_10containers_Ctrees;
struct __pyx_obj_8discodop_10containers_Vocabulary;
struct __pyx_obj_8discodop_10containers_FixedVocabulary;
struct __pyx_obj_8discodop_6plcfrs_LCFRSChart;
struct __pyx_obj_8discodop_6plcfrs_SmallLCFRSChart;
struct __pyx_obj_8discodop_6plcfrs_FatLCFRSChart;
struct __pyx_obj_8discodop_6plcfrs_Entry;
struct __pyx_obj_8discodop_6plcfrs_DoubleEntry;
struct __pyx_obj_8discodop_6plcfrs_Agenda;
struct __pyx_obj_8discodop_6plcfrs_DoubleAgenda;
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct__doprerank;
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank;
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_2_genexpr;
struct __pyx_t_8discodop_10containers_ProbRule;
union __pyx_t_8discodop_10containers_Position;
struct __pyx_t_8discodop_10containers_Edge;
struct __pyx_t_8discodop_10containers_EdgesStruct;
struct __pyx_t_8discodop_10containers_MoreEdges;
struct __pyx_t_8discodop_10containers_Node;
struct __pyx_t_8discodop_10containers_NodeArray;
struct __pyx_t_8discodop_10containers_Rule;
union __pyx_t_8discodop_10containers_ItemType;
struct __pyx_t_8discodop_10containers_DArray;

/* "containers.pxd":103
 * 
 * 
 * cdef struct ProbRule:  # total: 32 bytes.             # <<<<<<<<<<<<<<
 * 	double prob  # 8 bytes
 * 	uint32_t lhs  # 4 bytes
 */
struct __pyx_t_8discodop_10containers_ProbRule {
  double prob;
  uint32_t lhs;
  uint32_t rhs1;
  uint32_t rhs2;
  uint32_t args;
  uint32_t lengths;
  uint32_t no;
};

/* "containers.pxd":142
 * 
 * 
 * cdef union Position:  # 8 bytes             # <<<<<<<<<<<<<<
 * 	short mid  # CFG, end index of left child
 * 	uint64_t lvec  # LCFRS, bit vector of left child
 */
union __pyx_t_8discodop_10containers_Position {
  short mid;
  uint64_t lvec;
  uint64_t *lvec_fat;
};

/* "containers.pxd":149
 * 
 * 
 * cdef struct Edge:  # 16 bytes             # <<<<<<<<<<<<<<
 * 	ProbRule *rule  # ruleno may take less space than pointer, but not convenient
 * 	Position pos
 */
struct __pyx_t_8discodop_10containers_Edge {
  struct __pyx_t_8discodop_10containers_ProbRule *rule;
  union __pyx_t_8discodop_10containers_Position pos;
};

/* "containers.pxd":160
 * 
 * 
 * cdef struct EdgesStruct:             # <<<<<<<<<<<<<<
 * 	short len  # the number of edges in the head of the linked list
 * 	MoreEdges *head  # head of linked list
 */
struct __pyx_t_8discodop_10containers_EdgesStruct {
  short len;
  struct __pyx_t_8discodop_10containers_MoreEdges *head;
};

/* "containers.pxd":165
 * 
 * 
 * cdef struct MoreEdges:  # An unrolled linked list             # <<<<<<<<<<<<<<
 * 	MoreEdges *prev
 * 	Edge data[EDGES_SIZE]
 */
struct __pyx_t_8discodop_10containers_MoreEdges {
  struct __pyx_t_8discodop_10containers_MoreEdges *prev;
  struct __pyx_t_8discodop_10containers_Edge data[15];
};

/* "containers.pxd":220
 * # start fragments stuff
 * 
 * cdef struct Node:  # a node of a binary tree             # <<<<<<<<<<<<<<
 * 	int prod  # non-negative, ID of a phrasal or lexical production
 * 	short left  # >= 0: array idx to child Node; <0: idx sent[-left - 1];
 */
struct __pyx_t_8discodop_10containers_Node {
  int prod;
  short left;
  short right;
};

/* "containers.pxd":226
 * 
 * 
 * cdef struct NodeArray:  # a tree as an array of Node structs             # <<<<<<<<<<<<<<
 * 	unsigned int offset  # index to Node array where this tree starts
 * 	short len, root  # number of nodes, index to root node
 */
struct __pyx_t_8discodop_10containers_NodeArray {
  unsigned int offset;
  short len;
  short root;
};

/* "containers.pxd":246
 * 
 * 
 * cdef struct Rule:             # <<<<<<<<<<<<<<
 * 	uint32_t lhs, rhs1, rhs2, lengths, args
 * 
 */
struct __pyx_t_8discodop_10containers_Rule {
  uint32_t lhs;
  uint32_t rhs1;
  uint32_t rhs2;
  uint32_t lengths;
  uint32_t args;
};

/* "containers.pxd":250
 * 
 * 
 * cdef union ItemType:             # <<<<<<<<<<<<<<
 * 	void *ptr
 * 	char *aschar
 */
union __pyx_t_8discodop_10containers_ItemType {
  void *ptr;
  char *aschar;
  uint32_t *asint;
};

/* "containers.pxd":256
 * 
 * 
 * cdef struct DArray:             # <<<<<<<<<<<<<<
 * 	uint8_t itemsize
 * 	uint32_t len
 */
struct __pyx_t_8discodop_10containers_DArray {
  uint8_t itemsize;
  uint32_t len;
  uint32_t capacity;
  union __pyx_t_8discodop_10containers_ItemType d;
};
struct __pyx_opt_args_8discodop_14disambiguation_getderivations;
struct __pyx_opt_args_8discodop_14disambiguation_marginalize;
struct __pyx_opt_args_8discodop_14disambiguation_maxconstituentscorrect;

/* "discodop/disambiguation.pyx":48
 * cdef str NEGATIVECONSTLABEL = '-#-'
 * 
 * cpdef getderivations(Chart chart, int k, bint kbest=True, bint sample=False,             # <<<<<<<<<<<<<<
 * 		derivstrings=True):
 * 	"""Get *k*-best and/or sampled derivations from chart.
 */
struct __pyx_opt_args_8discodop_14disambiguation_getderivations {
  int __pyx_n;
  int kbest;
  int sample;
  PyObject *derivstrings;
};

/* "discodop/disambiguation.pyx":80
 * 
 * 
 * cpdef marginalize(method, list derivations, list entries, Chart chart,             # <<<<<<<<<<<<<<
 * 		list backtransform=None, list sent=None, list tags=None,
 * 		int k=1000, int sldop_n=7, double mcc_labda=1.0, set mcc_labels=None,
 */
struct __pyx_opt_args_8discodop_14disambiguation_marginalize {
  int __pyx_n;
  PyObject *backtransform;
  PyObject *sent;
  PyObject *tags;
  int k;
  int sldop_n;
  double mcc_labda;
  PyObject *mcc_labels;
  int bitpar;
};

/* "discodop/disambiguation.pyx":243
 * 
 * 
 * cdef maxconstituentscorrect(list derivations, Chart chart,             # <<<<<<<<<<<<<<
 * 		list backtransform, double labda, set labels=None):
 * 	"""Approximate the Most Constituents Correct (MCC) parse from n-best list.
 */
struct __pyx_opt_args_8discodop_14disambiguation_maxconstituentscorrect {
  int __pyx_n;
  PyObject *labels;
};

/* "containers.pxd":29
 * 
 * @cython.final
 * cdef class Grammar:             # <<<<<<<<<<<<<<
 * 	cdef ProbRule **bylhs
 * 	cdef ProbRule **unary
 */
struct __pyx_obj_8discodop_10containers_Grammar {
  PyObject_HEAD
  struct __pyx_vtabstruct_8discodop_10containers_Grammar *__pyx_vtab;
  struct __pyx_t_8discodop_10containers_ProbRule **bylhs;
  struct __pyx_t_8discodop_10containers_ProbRule **unary;
  struct __pyx_t_8discodop_10containers_ProbRule **lbinary;
  struct __pyx_t_8discodop_10containers_ProbRule **rbinary;
  uint32_t *mapping;
  uint32_t *revmap;
  uint32_t **splitmapping;
  uint8_t *fanout;
  uint64_t *chainvec;
  uint64_t *mask;
  int currentmodel;
  size_t nonterminals;
  size_t phrasalnonterminals;
  size_t numrules;
  size_t numunary;
  size_t numbinary;
  size_t maxfanout;
  int logprob;
  int bitpar;
  int binarized;
  PyObject *models;
  PyObject *origrules;
  PyObject *origlexicon;
  PyObject *start;
  PyObject *tolabel;
  PyObject *lexical;
  PyObject *modelnames;
  PyObject *rulemapping;
  PyObject *toid;
  PyObject *lexicalbyword;
  PyObject *lexicalbylhs;
  PyObject *lexicalbynum;
  PyObject *rulenos;
};


/* "containers.pxd":78
 * # 		to pack the parse forest?
 * # [ ] is it useful to have a recognition phase before making parse forest?
 * cdef class Chart:             # <<<<<<<<<<<<<<
 * 	cdef readonly dict rankededges  # [item][n] => DoubleEntry(RankedEdge, prob)
 * 	cdef object itemsinorder  # array or list
 */
struct __pyx_obj_8discodop_10containers_Chart {
  PyObject_HEAD
  struct __pyx_vtabstruct_8discodop_10containers_Chart *__pyx_vtab;
  PyObject *rankededges;
  PyObject *itemsinorder;
  PyObject *inside;
  PyObject *outside;
  struct __pyx_obj_8discodop_10containers_Grammar *grammar;
  PyObject *sent;
  short lensent;
  uint32_t start;
  int logprob;
  int viterbi;
};


/* "containers.pxd":114
 * 
 * @cython.final
 * cdef class LexicalRule:             # <<<<<<<<<<<<<<
 * 	cdef readonly double prob
 * 	cdef readonly uint32_t lhs
 */
struct __pyx_obj_8discodop_10containers_LexicalRule {
  PyObject_HEAD
  double prob;
  uint32_t lhs;
  PyObject *word;
};


/* "containers.pxd":121
 * 
 * @cython.freelist(1000)
 * cdef class ChartItem:             # <<<<<<<<<<<<<<
 * 	cdef uint32_t label
 * 	cdef double prob
 */
struct __pyx_obj_8discodop_10containers_ChartItem {
  PyObject_HEAD
  uint32_t label;
  double prob;
};


/* "containers.pxd":127
 * 
 * @cython.final
 * cdef class SmallChartItem(ChartItem):             # <<<<<<<<<<<<<<
 * 	cdef uint64_t vec
 * 	cdef copy(self)
 */
struct __pyx_obj_8discodop_10containers_SmallChartItem {
  struct __pyx_obj_8discodop_10containers_ChartItem __pyx_base;
  struct __pyx_vtabstruct_8discodop_10containers_SmallChartItem *__pyx_vtab;
  uint64_t vec;
};


/* "containers.pxd":133
 * 
 * @cython.final
 * cdef class FatChartItem(ChartItem):             # <<<<<<<<<<<<<<
 * 	cdef uint64_t vec[SLOTS]
 * 	cdef copy(self)
 */
struct __pyx_obj_8discodop_10containers_FatChartItem {
  struct __pyx_obj_8discodop_10containers_ChartItem __pyx_base;
  struct __pyx_vtabstruct_8discodop_10containers_FatChartItem *__pyx_vtab;
  uint64_t vec[4];
};


/* "containers.pxd":155
 * 
 * @cython.final
 * cdef class Edges:             # <<<<<<<<<<<<<<
 * 	cdef short len  # the number of edges in the head of the linked list
 * 	cdef MoreEdges *head  # head of linked list
 */
struct __pyx_obj_8discodop_10containers_Edges {
  PyObject_HEAD
  short len;
  struct __pyx_t_8discodop_10containers_MoreEdges *head;
};


/* "containers.pxd":173
 * 
 * @cython.final
 * cdef class RankedEdge:             # <<<<<<<<<<<<<<
 * 	# NB: 'head' is unnecessary because the head will also be the dictionary
 * 	# key for a ranked edge, but having it as part of the object is convenient.
 */
struct __pyx_obj_8discodop_10containers_RankedEdge {
  PyObject_HEAD
  struct __pyx_t_8discodop_10containers_Edge *edge;
  PyObject *head;
  int left;
  int right;
};


/* "containers.pxd":232
 * 
 * @cython.final
 * cdef class Ctrees:             # <<<<<<<<<<<<<<
 * 	cdef Node *nodes
 * 	cdef NodeArray *trees
 */
struct __pyx_obj_8discodop_10containers_Ctrees {
  PyObject_HEAD
  struct __pyx_vtabstruct_8discodop_10containers_Ctrees *__pyx_vtab;
  struct __pyx_t_8discodop_10containers_Node *nodes;
  struct __pyx_t_8discodop_10containers_NodeArray *trees;
  long nodesleft;
  long max;
  size_t numnodes;
  size_t numwords;
  short maxnodes;
  int len;
  PyObject *prodindex;
  PyObject *_state;
};


/* "containers.pxd":263
 * 
 * 
 * cdef class Vocabulary:             # <<<<<<<<<<<<<<
 * 	cdef readonly dict prods  # production str. => int
 * 	cdef readonly dict labels  # label/word str => int
 */
struct __pyx_obj_8discodop_10containers_Vocabulary {
  PyObject_HEAD
  struct __pyx_vtabstruct_8discodop_10containers_Vocabulary *__pyx_vtab;
  PyObject *prods;
  PyObject *labels;
  struct __pyx_t_8discodop_10containers_DArray prodbuf;
  struct __pyx_t_8discodop_10containers_DArray labelbuf;
  struct __pyx_t_8discodop_10containers_DArray labelidx;
};


/* "containers.pxd":280
 * 
 * 
 * cdef class FixedVocabulary(Vocabulary):             # <<<<<<<<<<<<<<
 * 	cdef object state  # to keep buffer alive
 * 
 */
struct __pyx_obj_8discodop_10containers_FixedVocabulary {
  struct __pyx_obj_8discodop_10containers_Vocabulary __pyx_base;
  PyObject *state;
};


/* "plcfrs.pxd":30
 * 	FatChartItem
 * 
 * cdef class LCFRSChart(Chart):             # <<<<<<<<<<<<<<
 * 	cdef readonly dict parseforest  # chartitem => Edges(...)
 * 	cdef list probs
 */
struct __pyx_obj_8discodop_6plcfrs_LCFRSChart {
  struct __pyx_obj_8discodop_10containers_Chart __pyx_base;
  PyObject *parseforest;
  PyObject *probs;
};


/* "plcfrs.pxd":41
 * 
 * @cython.final
 * cdef class SmallLCFRSChart(LCFRSChart):             # <<<<<<<<<<<<<<
 * 	cdef SmallChartItem tmpitem
 * 	cdef void addedge(self, SmallChartItem item, SmallChartItem left,
 */
struct __pyx_obj_8discodop_6plcfrs_SmallLCFRSChart {
  struct __pyx_obj_8discodop_6plcfrs_LCFRSChart __pyx_base;
  struct __pyx_obj_8discodop_10containers_SmallChartItem *tmpitem;
};


/* "plcfrs.pxd":48
 * 
 * @cython.final
 * cdef class FatLCFRSChart(LCFRSChart):             # <<<<<<<<<<<<<<
 * 	cdef FatChartItem tmpitem
 * 	cdef void addedge(self, FatChartItem item, FatChartItem left,
 */
struct __pyx_obj_8discodop_6plcfrs_FatLCFRSChart {
  struct __pyx_obj_8discodop_6plcfrs_LCFRSChart __pyx_base;
  struct __pyx_obj_8discodop_10containers_FatChartItem *tmpitem;
};


/* "plcfrs.pxd":56
 * # FIXME: Entry/Agenda are used in multiple modules; put in containers?
 * @cython.final
 * cdef class Entry:             # <<<<<<<<<<<<<<
 * 	cdef readonly object key
 * 	cdef readonly object value
 */
struct __pyx_obj_8discodop_6plcfrs_Entry {
  PyObject_HEAD
  PyObject *key;
  PyObject *value;
  uint64_t count;
};


/* "plcfrs.pxd":63
 * 
 * @cython.final
 * cdef class DoubleEntry:             # <<<<<<<<<<<<<<
 * 	cdef readonly object key
 * 	cdef readonly double value
 */
struct __pyx_obj_8discodop_6plcfrs_DoubleEntry {
  PyObject_HEAD
  PyObject *key;
  double value;
  uint64_t count;
};


/* "plcfrs.pxd":90
 * 
 * 
 * cdef class Agenda:             # <<<<<<<<<<<<<<
 * 	cdef uint64_t length, counter
 * 	cdef readonly list heap
 */
struct __pyx_obj_8discodop_6plcfrs_Agenda {
  PyObject_HEAD
  uint64_t length;
  uint64_t counter;
  PyObject *heap;
  PyObject *mapping;
};


/* "plcfrs.pxd":97
 * 
 * @cython.final
 * cdef class DoubleAgenda(Agenda):             # <<<<<<<<<<<<<<
 * 	cdef inline void setitem(self, key, double value)
 * 	cdef inline void setifbetter(self, key, double value)
 */
struct __pyx_obj_8discodop_6plcfrs_DoubleAgenda {
  struct __pyx_obj_8discodop_6plcfrs_Agenda __pyx_base;
  struct __pyx_vtabstruct_8discodop_6plcfrs_DoubleAgenda *__pyx_vtab;
};


/* "discodop/disambiguation.pyx":899
 * 
 * 
 * def doprerank(parsetrees, sent, k, Grammar coarse, Grammar fine):             # <<<<<<<<<<<<<<
 * 	"""Rerank *k*-best coarse trees w/parse probabilities of DOP reduction.
 * 
 */
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct__doprerank {
  PyObject_HEAD
  PyObject *__pyx_v_results;
};


/* "discodop/disambiguation.pyx":995
 * 
 * 
 * def mcrerank(parsetrees, sent, k, trees, vocab):             # <<<<<<<<<<<<<<
 * 	"""Rerank *k*-best trees using tree fragments from training treebank.
 * 
 */
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank {
  PyObject_HEAD
  PyObject *__pyx_v_i;
  PyObject *__pyx_v_results;
  PyObject *__pyx_v_rev;
};


/* "discodop/disambiguation.pyx":1021
 * 				# score is the total number of nodes
 * 				# of the common fragments consisting of at least 2 parts
 * 				score += sum(frag[0].count('(') for frag in rev[i])             # <<<<<<<<<<<<<<
 * 		# divide by number of nodes in derivation to avoid preferring
 * 		# larger derivations
 */
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_2_genexpr {
  PyObject_HEAD
  struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank *__pyx_outer_scope;
  PyObject *__pyx_v_frag;
  PyObject *__pyx_t_0;
  Py_ssize_t __pyx_t_1;
  PyObject *(*__pyx_t_2)(PyObject *);
};



/* "containers.pxd":29
 * 
 * @cython.final
 * cdef class Grammar:             # <<<<<<<<<<<<<<
 * 	cdef ProbRule **bylhs
 * 	cdef ProbRule **unary
 */

struct __pyx_vtabstruct_8discodop_10containers_Grammar {
  PyObject *(*_convertrules)(struct __pyx_obj_8discodop_10containers_Grammar *, PyObject *, PyObject *);
  PyObject *(*_indexrules)(struct __pyx_obj_8discodop_10containers_Grammar *, struct __pyx_t_8discodop_10containers_ProbRule **, int, int);
  PyObject *(*rulestr)(struct __pyx_obj_8discodop_10containers_Grammar *, int, int __pyx_skip_dispatch);
  PyObject *(*yfstr)(struct __pyx_obj_8discodop_10containers_Grammar *, struct __pyx_t_8discodop_10containers_ProbRule);
};
static struct __pyx_vtabstruct_8discodop_10containers_Grammar *__pyx_vtabptr_8discodop_10containers_Grammar;


/* "containers.pxd":78
 * # 		to pack the parse forest?
 * # [ ] is it useful to have a recognition phase before making parse forest?
 * cdef class Chart:             # <<<<<<<<<<<<<<
 * 	cdef readonly dict rankededges  # [item][n] => DoubleEntry(RankedEdge, prob)
 * 	cdef object itemsinorder  # array or list
 */

struct __pyx_vtabstruct_8discodop_10containers_Chart {
  double (*subtreeprob)(struct __pyx_obj_8discodop_10containers_Chart *, PyObject *);
  int (*lexidx)(struct __pyx_obj_8discodop_10containers_Chart *, struct __pyx_t_8discodop_10containers_Edge *);
  double (*lexprob)(struct __pyx_obj_8discodop_10containers_Chart *, PyObject *, struct __pyx_t_8discodop_10containers_Edge *);
  PyObject *(*edgestr)(struct __pyx_obj_8discodop_10containers_Chart *, PyObject *, struct __pyx_t_8discodop_10containers_Edge *);
  PyObject *(*_left)(struct __pyx_obj_8discodop_10containers_Chart *, PyObject *, struct __pyx_t_8discodop_10containers_Edge *);
  PyObject *(*_right)(struct __pyx_obj_8discodop_10containers_Chart *, PyObject *, struct __pyx_t_8discodop_10containers_Edge *);
  PyObject *(*left)(struct __pyx_obj_8discodop_10containers_Chart *, struct __pyx_obj_8discodop_10containers_RankedEdge *);
  PyObject *(*right)(struct __pyx_obj_8discodop_10containers_Chart *, struct __pyx_obj_8discodop_10containers_RankedEdge *);
  PyObject *(*copy)(struct __pyx_obj_8discodop_10containers_Chart *, PyObject *);
  uint32_t (*label)(struct __pyx_obj_8discodop_10containers_Chart *, PyObject *);
  struct __pyx_obj_8discodop_10containers_ChartItem *(*asChartItem)(struct __pyx_obj_8discodop_10containers_Chart *, PyObject *);
  size_t (*asCFGspan)(struct __pyx_obj_8discodop_10containers_Chart *, PyObject *, size_t);
  struct __pyx_obj_8discodop_10containers_Edges *(*getedges)(struct __pyx_obj_8discodop_10containers_Chart *, PyObject *);
};
static struct __pyx_vtabstruct_8discodop_10containers_Chart *__pyx_vtabptr_8discodop_10containers_Chart;


/* "containers.pxd":127
 * 
 * @cython.final
 * cdef class SmallChartItem(ChartItem):             # <<<<<<<<<<<<<<
 * 	cdef uint64_t vec
 * 	cdef copy(self)
 */

struct __pyx_vtabstruct_8discodop_10containers_SmallChartItem {
  PyObject *(*copy)(struct __pyx_obj_8discodop_10containers_SmallChartItem *);
};
static struct __pyx_vtabstruct_8discodop_10containers_SmallChartItem *__pyx_vtabptr_8discodop_10containers_SmallChartItem;


/* "containers.pxd":133
 * 
 * @cython.final
 * cdef class FatChartItem(ChartItem):             # <<<<<<<<<<<<<<
 * 	cdef uint64_t vec[SLOTS]
 * 	cdef copy(self)
 */

struct __pyx_vtabstruct_8discodop_10containers_FatChartItem {
  PyObject *(*copy)(struct __pyx_obj_8discodop_10containers_FatChartItem *);
};
static struct __pyx_vtabstruct_8discodop_10containers_FatChartItem *__pyx_vtabptr_8discodop_10containers_FatChartItem;


/* "containers.pxd":232
 * 
 * @cython.final
 * cdef class Ctrees:             # <<<<<<<<<<<<<<
 * 	cdef Node *nodes
 * 	cdef NodeArray *trees
 */

struct __pyx_vtabstruct_8discodop_10containers_Ctrees {
  PyObject *(*alloc)(struct __pyx_obj_8discodop_10containers_Ctrees *, int, long, int __pyx_skip_dispatch);
  PyObject *(*realloc)(struct __pyx_obj_8discodop_10containers_Ctrees *, int, int);
  PyObject *(*addnodes)(struct __pyx_obj_8discodop_10containers_Ctrees *, struct __pyx_t_8discodop_10containers_Node *, int, int);
};
static struct __pyx_vtabstruct_8discodop_10containers_Ctrees *__pyx_vtabptr_8discodop_10containers_Ctrees;


/* "containers.pxd":263
 * 
 * 
 * cdef class Vocabulary:             # <<<<<<<<<<<<<<
 * 	cdef readonly dict prods  # production str. => int
 * 	cdef readonly dict labels  # label/word str => int
 */

struct __pyx_vtabstruct_8discodop_10containers_Vocabulary {
  PyObject *(*idtolabel)(struct __pyx_obj_8discodop_10containers_Vocabulary *, uint32_t);
  PyObject *(*getlabel)(struct __pyx_obj_8discodop_10containers_Vocabulary *, int);
  PyObject *(*getword)(struct __pyx_obj_8discodop_10containers_Vocabulary *, int);
  int (*islexical)(struct __pyx_obj_8discodop_10containers_Vocabulary *, int);
  int (*getprod)(struct __pyx_obj_8discodop_10containers_Vocabulary *, PyObject *, PyObject *);
  int (*_getprodid)(struct __pyx_obj_8discodop_10containers_Vocabulary *, PyObject *);
  int (*_getlabelid)(struct __pyx_obj_8discodop_10containers_Vocabulary *, PyObject *);
};
static struct __pyx_vtabstruct_8discodop_10containers_Vocabulary *__pyx_vtabptr_8discodop_10containers_Vocabulary;


/* "containers.pxd":280
 * 
 * 
 * cdef class FixedVocabulary(Vocabulary):             # <<<<<<<<<<<<<<
 * 	cdef object state  # to keep buffer alive
 * 
 */

struct __pyx_vtabstruct_8discodop_10containers_FixedVocabulary {
  struct __pyx_vtabstruct_8discodop_10containers_Vocabulary __pyx_base;
};
static struct __pyx_vtabstruct_8discodop_10containers_FixedVocabulary *__pyx_vtabptr_8discodop_10containers_FixedVocabulary;


/* "plcfrs.pxd":30
 * 	FatChartItem
 * 
 * cdef class LCFRSChart(Chart):             # <<<<<<<<<<<<<<
 * 	cdef readonly dict parseforest  # chartitem => Edges(...)
 * 	cdef list probs
 */

struct __pyx_vtabstruct_8discodop_6plcfrs_LCFRSChart {
  struct __pyx_vtabstruct_8discodop_10containers_Chart __pyx_base;
  void (*addlexedge)(struct __pyx_obj_8discodop_6plcfrs_LCFRSChart *, PyObject *, short);
  void (*updateprob)(struct __pyx_obj_8discodop_6plcfrs_LCFRSChart *, struct __pyx_obj_8discodop_10containers_ChartItem *, double);
  void (*addprob)(struct __pyx_obj_8discodop_6plcfrs_LCFRSChart *, struct __pyx_obj_8discodop_10containers_ChartItem *, double);
  double (*_subtreeprob)(struct __pyx_obj_8discodop_6plcfrs_LCFRSChart *, struct __pyx_obj_8discodop_10containers_ChartItem *);
  PyObject *(*hasitem)(struct __pyx_obj_8discodop_6plcfrs_LCFRSChart *, struct __pyx_obj_8discodop_10containers_ChartItem *, int __pyx_skip_dispatch);
};
static struct __pyx_vtabstruct_8discodop_6plcfrs_LCFRSChart *__pyx_vtabptr_8discodop_6plcfrs_LCFRSChart;


/* "plcfrs.pxd":41
 * 
 * @cython.final
 * cdef class SmallLCFRSChart(LCFRSChart):             # <<<<<<<<<<<<<<
 * 	cdef SmallChartItem tmpitem
 * 	cdef void addedge(self, SmallChartItem item, SmallChartItem left,
 */

struct __pyx_vtabstruct_8discodop_6plcfrs_SmallLCFRSChart {
  struct __pyx_vtabstruct_8discodop_6plcfrs_LCFRSChart __pyx_base;
  void (*addedge)(struct __pyx_obj_8discodop_6plcfrs_SmallLCFRSChart *, struct __pyx_obj_8discodop_10containers_SmallChartItem *, struct __pyx_obj_8discodop_10containers_SmallChartItem *, struct __pyx_t_8discodop_10containers_ProbRule *);
};
static struct __pyx_vtabstruct_8discodop_6plcfrs_SmallLCFRSChart *__pyx_vtabptr_8discodop_6plcfrs_SmallLCFRSChart;


/* "plcfrs.pxd":48
 * 
 * @cython.final
 * cdef class FatLCFRSChart(LCFRSChart):             # <<<<<<<<<<<<<<
 * 	cdef FatChartItem tmpitem
 * 	cdef void addedge(self, FatChartItem item, FatChartItem left,
 */

struct __pyx_vtabstruct_8discodop_6plcfrs_FatLCFRSChart {
  struct __pyx_vtabstruct_8discodop_6plcfrs_LCFRSChart __pyx_base;
  void (*addedge)(struct __pyx_obj_8discodop_6plcfrs_FatLCFRSChart *, struct __pyx_obj_8discodop_10containers_FatChartItem *, struct __pyx_obj_8discodop_10containers_FatChartItem *, struct __pyx_t_8discodop_10containers_ProbRule *);
};
static struct __pyx_vtabstruct_8discodop_6plcfrs_FatLCFRSChart *__pyx_vtabptr_8discodop_6plcfrs_FatLCFRSChart;


/* "plcfrs.pxd":97
 * 
 * @cython.final
 * cdef class DoubleAgenda(Agenda):             # <<<<<<<<<<<<<<
 * 	cdef inline void setitem(self, key, double value)
 * 	cdef inline void setifbetter(self, key, double value)
 */

struct __pyx_vtabstruct_8discodop_6plcfrs_DoubleAgenda {
  void (*setitem)(struct __pyx_obj_8discodop_6plcfrs_DoubleAgenda *, PyObject *, double);
  void (*setifbetter)(struct __pyx_obj_8discodop_6plcfrs_DoubleAgenda *, PyObject *, double);
  double (*getitem)(struct __pyx_obj_8discodop_6plcfrs_DoubleAgenda *, PyObject *);
  double (*replace)(struct __pyx_obj_8discodop_6plcfrs_DoubleAgenda *, PyObject *, double);
  struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *(*popentry)(struct __pyx_obj_8discodop_6plcfrs_DoubleAgenda *);
  struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *(*peekentry)(struct __pyx_obj_8discodop_6plcfrs_DoubleAgenda *);
  PyObject *(*update_entries)(struct __pyx_obj_8discodop_6plcfrs_DoubleAgenda *, PyObject *);
};
static struct __pyx_vtabstruct_8discodop_6plcfrs_DoubleAgenda *__pyx_vtabptr_8discodop_6plcfrs_DoubleAgenda;

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

/* 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

/* 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

/* 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

/* RaiseException.proto */
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause);

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

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

/* 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

/* 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

/* 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

/* 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

/* ListExtend.proto */
static CYTHON_INLINE int __Pyx_PyList_Extend(PyObject* L, PyObject* v) {
#if CYTHON_COMPILING_IN_CPYTHON
    PyObject* none = _PyList_Extend((PyListObject*)L, v);
    if (unlikely(!none))
        return -1;
    Py_DECREF(none);
    return 0;
#else
    return PyList_SetSlice(L, PY_SSIZE_T_MAX, PY_SSIZE_T_MAX, v);
#endif
}

/* py_dict_values.proto */
static CYTHON_INLINE PyObject* __Pyx_PyDict_Values(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 ?  (*(__Pyx_PyCFunctionFast)(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

/* SliceObject.proto */
#define __Pyx_PyObject_DelSlice(obj, cstart, cstop, py_start, py_stop, py_slice, has_cstart, has_cstop, wraparound)\
    __Pyx_PyObject_SetSlice(obj, (PyObject*)NULL, cstart, cstop, py_start, py_stop, py_slice, has_cstart, has_cstop, wraparound)
static CYTHON_INLINE int __Pyx_PyObject_SetSlice(
        PyObject* obj, PyObject* value, 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);

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

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

/* ArgTypeTest.proto */
static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact);

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

/* ExtTypeTest.proto */
static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type);

/* ListCompAppend.proto */
#if CYTHON_USE_PYLIST_INTERNALS && CYTHON_ASSUME_SAFE_MACROS
static CYTHON_INLINE int __Pyx_ListComp_Append(PyObject* list, PyObject* x) {
    PyListObject* L = (PyListObject*) list;
    Py_ssize_t len = Py_SIZE(list);
    if (likely(L->allocated > len)) {
        Py_INCREF(x);
        PyList_SET_ITEM(list, len, x);
        Py_SIZE(list) = len+1;
        return 0;
    }
    return PyList_Append(list, x);
}
#else
#define __Pyx_ListComp_Append(L,x) PyList_Append(L,x)
#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

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

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

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

/* 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

/* PyFloatBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyFloat_AddObjC(PyObject *op1, PyObject *op2, double floatval, int inplace);
#else
#define __Pyx_PyFloat_AddObjC(op1, op2, floatval, inplace)\
    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
#endif

/* PyObjectCallMethod0.proto */
static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name);

/* RaiseNoneIterError.proto */
static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void);

/* UnpackTupleError.proto */
static void __Pyx_UnpackTupleError(PyObject *, Py_ssize_t index);

/* UnpackTuple2.proto */
static CYTHON_INLINE int __Pyx_unpack_tuple2(PyObject* tuple, PyObject** value1, PyObject** value2,
                                             int is_tuple, int has_known_size, int decref_tuple);

/* dict_iter.proto */
static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* dict, int is_dict, PyObject* method_name,
                                                   Py_ssize_t* p_orig_length, int* p_is_dict);
static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* dict_or_iter, Py_ssize_t orig_length, Py_ssize_t* ppos,
                                              PyObject** pkey, PyObject** pvalue, PyObject** pitem, int is_dict);

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

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

/* 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

/* SetItemInt.proto */
#define __Pyx_SetItemInt(o, i, v, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\
    (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\
    __Pyx_SetItemInt_Fast(o, (Py_ssize_t)i, v, is_list, wraparound, boundscheck) :\
    (is_list ? (PyErr_SetString(PyExc_IndexError, "list assignment index out of range"), -1) :\
               __Pyx_SetItemInt_Generic(o, to_py_func(i), v)))
static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v);
static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v,
                                               int is_list, int wraparound, int boundscheck);

/* WriteUnraisableException.proto */
static void __Pyx_WriteUnraisable(const char *name, int clineno,
                                  int lineno, const char *filename,
                                  int full_traceback, int nogil);

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

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

/* 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

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

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

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

/* tp_new.proto */
#define __Pyx_tp_new(type_obj, args) __Pyx_tp_new_kwargs(type_obj, args, NULL)
static CYTHON_INLINE PyObject* __Pyx_tp_new_kwargs(PyObject* type_obj, PyObject* args, PyObject* kwargs) {
    return (PyObject*) (((PyTypeObject*)type_obj)->tp_new((PyTypeObject*)type_obj, args, kwargs));
}

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

/* PyFloatBinop.proto */
#if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyFloat_AddCObj(PyObject *op1, PyObject *op2, double floatval, int inplace);
#else
#define __Pyx_PyFloat_AddCObj(op1, op2, floatval, inplace)\
    (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2))
#endif

/* GetVTable.proto */
static void* __Pyx_GetVtable(PyObject *dict);

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

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value);

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

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_short(short value);

/* CIntToPy.proto */
static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value);

/* ArrayAPI.proto */
#ifndef _ARRAYARRAY_H
#define _ARRAYARRAY_H
typedef struct arraydescr {
    int typecode;
    int itemsize;
    PyObject * (*getitem)(struct arrayobject *, Py_ssize_t);
    int (*setitem)(struct arrayobject *, Py_ssize_t, PyObject *);
#if PY_MAJOR_VERSION >= 3
    char *formats;
#endif
} arraydescr;
struct arrayobject {
    PyObject_HEAD
    Py_ssize_t ob_size;
    union {
        char *ob_item;
        float *as_floats;
        double *as_doubles;
        int *as_ints;
        unsigned int *as_uints;
        unsigned char *as_uchars;
        signed char *as_schars;
        char *as_chars;
        unsigned long *as_ulongs;
        long *as_longs;
        short *as_shorts;
        unsigned short *as_ushorts;
        Py_UNICODE *as_pyunicodes;
        void *as_voidptr;
    } data;
    Py_ssize_t allocated;
    struct arraydescr *ob_descr;
    PyObject *weakreflist;
#if PY_MAJOR_VERSION >= 3
        int ob_exports;
#endif
};
#ifndef NO_NEWARRAY_INLINE
static CYTHON_INLINE PyObject * newarrayobject(PyTypeObject *type, Py_ssize_t size,
    struct arraydescr *descr) {
    arrayobject *op;
    size_t nbytes;
    if (size < 0) {
        PyErr_BadInternalCall();
        return NULL;
    }
    nbytes = size * descr->itemsize;
    if (nbytes / descr->itemsize != (size_t)size) {
        return PyErr_NoMemory();
    }
    op = (arrayobject *) type->tp_alloc(type, 0);
    if (op == NULL) {
        return NULL;
    }
    op->ob_descr = descr;
    op->allocated = size;
    op->weakreflist = NULL;
    op->ob_size = size;
    if (size <= 0) {
        op->data.ob_item = NULL;
    }
    else {
        op->data.ob_item = PyMem_NEW(char, nbytes);
        if (op->data.ob_item == NULL) {
            Py_DECREF(op);
            return PyErr_NoMemory();
        }
    }
    return (PyObject *) op;
}
#else
PyObject* newarrayobject(PyTypeObject *type, Py_ssize_t size,
    struct arraydescr *descr);
#endif
static CYTHON_INLINE int resize(arrayobject *self, Py_ssize_t n) {
    void *items = (void*) self->data.ob_item;
    PyMem_Resize(items, char, (size_t)(n * self->ob_descr->itemsize));
    if (items == NULL) {
        PyErr_NoMemory();
        return -1;
    }
    self->data.ob_item = (char*) items;
    self->ob_size = n;
    self->allocated = n;
    return 0;
}
static CYTHON_INLINE int resize_smart(arrayobject *self, Py_ssize_t n) {
    void *items = (void*) self->data.ob_item;
    Py_ssize_t newsize;
    if (n < self->allocated && n*4 > self->allocated) {
        self->ob_size = n;
        return 0;
    }
    newsize = n + (n / 2) + 1;
    if (newsize <= n) {
        PyErr_NoMemory();
        return -1;
    }
    PyMem_Resize(items, char, (size_t)(newsize * self->ob_descr->itemsize));
    if (items == NULL) {
        PyErr_NoMemory();
        return -1;
    }
    self->data.ob_item = (char*) items;
    self->ob_size = n;
    self->allocated = newsize;
    return 0;
}
#endif

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

/* CIntFromPy.proto */
static CYTHON_INLINE short __Pyx_PyInt_As_short(PyObject *);

/* CIntFromPy.proto */
static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *);

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

/* SwapException.proto */
#if CYTHON_FAST_THREAD_STATE
#define __Pyx_ExceptionSwap(type, value, tb)  __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb)
static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb);
#else
static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb);
#endif

/* CoroutineBase.proto */
typedef PyObject *(*__pyx_coroutine_body_t)(PyObject *, PyObject *);
typedef struct {
    PyObject_HEAD
    __pyx_coroutine_body_t body;
    PyObject *closure;
    PyObject *exc_type;
    PyObject *exc_value;
    PyObject *exc_traceback;
    PyObject *gi_weakreflist;
    PyObject *classobj;
    PyObject *yieldfrom;
    PyObject *gi_name;
    PyObject *gi_qualname;
    PyObject *gi_modulename;
    int resume_label;
    char is_running;
} __pyx_CoroutineObject;
static __pyx_CoroutineObject *__Pyx__Coroutine_New(
    PyTypeObject *type, __pyx_coroutine_body_t body, PyObject *closure,
    PyObject *name, PyObject *qualname, PyObject *module_name);
static int __Pyx_Coroutine_clear(PyObject *self);
#if 1 || PY_VERSION_HEX < 0x030300B0
static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue);
#else
#define __Pyx_PyGen_FetchStopIterationValue(pvalue) PyGen_FetchStopIterationValue(pvalue)
#endif

/* PatchModuleWithCoroutine.proto */
static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code);

/* PatchGeneratorABC.proto */
static int __Pyx_patch_abc(void);

/* Generator.proto */
#define __Pyx_Generator_USED
static PyTypeObject *__pyx_GeneratorType = 0;
#define __Pyx_Generator_CheckExact(obj) (Py_TYPE(obj) == __pyx_GeneratorType)
#define __Pyx_Generator_New(body, closure, name, qualname, module_name)\
    __Pyx__Coroutine_New(__pyx_GeneratorType, body, closure, name, qualname, module_name)
static PyObject *__Pyx_Generator_Next(PyObject *self);
static int __pyx_Generator_init(void);

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

/* PyIdentifierFromString.proto */
#if !defined(__Pyx_PyIdentifier_FromString)
#if PY_MAJOR_VERSION < 3
  #define __Pyx_PyIdentifier_FromString(s) PyString_FromString(s)
#else
  #define __Pyx_PyIdentifier_FromString(s) PyUnicode_FromString(s)
#endif
#endif

/* ModuleImport.proto */
static PyObject *__Pyx_ImportModule(const char *name);

/* TypeImport.proto */
static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name, size_t size, int strict);

/* VoidPtrImport.proto */
static int __Pyx_ImportVoidPtr(PyObject *module, const char *name, void **p, const char *sig);

/* FunctionImport.proto */
static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig);

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


/* Module declarations from 'libc.stdint' */

/* Module declarations from 'discodop.bit' */
static int (*__pyx_f_8discodop_3bit_bitcount)(uint64_t, int __pyx_skip_dispatch); /*proto*/
static CYTHON_INLINE int __pyx_f_8discodop_3bit_nextset(uint64_t, uint32_t); /*proto*/
static CYTHON_INLINE int __pyx_f_8discodop_3bit_nextunset(uint64_t, uint32_t); /*proto*/
static CYTHON_INLINE int __pyx_f_8discodop_3bit_bitlength(uint64_t); /*proto*/
static CYTHON_INLINE int __pyx_f_8discodop_3bit_abitcount(uint64_t *, int); /*proto*/
static CYTHON_INLINE int __pyx_f_8discodop_3bit_abitlength(uint64_t *, int); /*proto*/
static CYTHON_INLINE int __pyx_f_8discodop_3bit_anextset(uint64_t *, uint32_t, int); /*proto*/
static CYTHON_INLINE int __pyx_f_8discodop_3bit_anextunset(uint64_t *, uint32_t, int); /*proto*/
static CYTHON_INLINE void __pyx_f_8discodop_3bit_setunion(uint64_t *, uint64_t *, uint64_t *, int); /*proto*/

/* Module declarations from 'cython' */

/* Module declarations from 'libc.string' */

/* Module declarations from 'libc.stdlib' */

/* Module declarations from 'libc.stdio' */

/* Module declarations from '__builtin__' */

/* Module declarations from 'cpython.type' */
static PyTypeObject *__pyx_ptype_7cpython_4type_type = 0;

/* Module declarations from 'cpython' */

/* Module declarations from 'cpython.object' */

/* Module declarations from 'cpython.list' */

/* Module declarations from 'cpython.set' */

/* Module declarations from 'cpython.float' */

/* Module declarations from 'cpython.ref' */

/* Module declarations from 'cpython.exc' */

/* Module declarations from 'cpython.mem' */

/* Module declarations from 'array' */

/* Module declarations from 'cpython.array' */
static PyTypeObject *__pyx_ptype_7cpython_5array_array = 0;
static CYTHON_INLINE int __pyx_f_7cpython_5array_extend_buffer(arrayobject *, char *, Py_ssize_t); /*proto*/

/* Module declarations from 'discodop.containers' */
static PyTypeObject *__pyx_ptype_8discodop_10containers_Grammar = 0;
static PyTypeObject *__pyx_ptype_8discodop_10containers_Chart = 0;
static PyTypeObject *__pyx_ptype_8discodop_10containers_LexicalRule = 0;
static PyTypeObject *__pyx_ptype_8discodop_10containers_ChartItem = 0;
static PyTypeObject *__pyx_ptype_8discodop_10containers_SmallChartItem = 0;
static PyTypeObject *__pyx_ptype_8discodop_10containers_FatChartItem = 0;
static PyTypeObject *__pyx_ptype_8discodop_10containers_Edges = 0;
static PyTypeObject *__pyx_ptype_8discodop_10containers_RankedEdge = 0;
static PyTypeObject *__pyx_ptype_8discodop_10containers_Ctrees = 0;
static PyTypeObject *__pyx_ptype_8discodop_10containers_Vocabulary = 0;
static PyTypeObject *__pyx_ptype_8discodop_10containers_FixedVocabulary = 0;
static PyObject **__pyx_vp_8discodop_10containers_log1e200 = 0;
#define __pyx_v_8discodop_10containers_log1e200 (*__pyx_vp_8discodop_10containers_log1e200)
static struct __pyx_obj_8discodop_10containers_FatChartItem *(*__pyx_f_8discodop_10containers_CFGtoFatChartItem)(uint32_t, __pyx_t_8discodop_10containers_Idx, __pyx_t_8discodop_10containers_Idx); /*proto*/
static CYTHON_INLINE struct __pyx_obj_8discodop_10containers_FatChartItem *__pyx_f_8discodop_10containers_new_FatChartItem(uint32_t); /*proto*/
static CYTHON_INLINE struct __pyx_obj_8discodop_10containers_SmallChartItem *__pyx_f_8discodop_10containers_new_SmallChartItem(uint32_t, uint64_t); /*proto*/
static CYTHON_INLINE struct __pyx_obj_8discodop_10containers_RankedEdge *__pyx_f_8discodop_10containers_new_RankedEdge(PyObject *, struct __pyx_t_8discodop_10containers_Edge *, int, int); /*proto*/
static CYTHON_INLINE PyObject *__pyx_f_8discodop_10containers_logprobadd(PyObject *, PyObject *); /*proto*/
static CYTHON_INLINE double __pyx_f_8discodop_10containers_logprobsum(PyObject *); /*proto*/
static CYTHON_INLINE PyObject *__pyx_f_8discodop_10containers_yieldranges(PyObject *); /*proto*/

/* Module declarations from 'discodop.plcfrs' */
static PyTypeObject *__pyx_ptype_8discodop_6plcfrs_LCFRSChart = 0;
static PyTypeObject *__pyx_ptype_8discodop_6plcfrs_SmallLCFRSChart = 0;
static PyTypeObject *__pyx_ptype_8discodop_6plcfrs_FatLCFRSChart = 0;
static PyTypeObject *__pyx_ptype_8discodop_6plcfrs_Entry = 0;
static PyTypeObject *__pyx_ptype_8discodop_6plcfrs_DoubleEntry = 0;
static PyTypeObject *__pyx_ptype_8discodop_6plcfrs_Agenda = 0;
static PyTypeObject *__pyx_ptype_8discodop_6plcfrs_DoubleAgenda = 0;
static CYTHON_INLINE struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *__pyx_f_8discodop_6plcfrs_new_DoubleEntry(PyObject *, double, uint64_t); /*proto*/

/* Module declarations from 'discodop.disambiguation' */
static PyTypeObject *__pyx_ptype_8discodop_14disambiguation___pyx_scope_struct__doprerank = 0;
static PyTypeObject *__pyx_ptype_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank = 0;
static PyTypeObject *__pyx_ptype_8discodop_14disambiguation___pyx_scope_struct_2_genexpr = 0;
static PyObject *__pyx_v_8discodop_14disambiguation_NONCONSTLABEL = 0;
static PyObject *__pyx_v_8discodop_14disambiguation_NEGATIVECONSTLABEL = 0;
static PyObject *__pyx_f_8discodop_14disambiguation_getderivations(struct __pyx_obj_8discodop_10containers_Chart *, int, int __pyx_skip_dispatch, struct __pyx_opt_args_8discodop_14disambiguation_getderivations *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_8discodop_14disambiguation_marginalize(PyObject *, PyObject *, PyObject *, struct __pyx_obj_8discodop_10containers_Chart *, int __pyx_skip_dispatch, struct __pyx_opt_args_8discodop_14disambiguation_marginalize *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_8discodop_14disambiguation_maxconstituentscorrect(PyObject *, struct __pyx_obj_8discodop_10containers_Chart *, PyObject *, double, struct __pyx_opt_args_8discodop_14disambiguation_maxconstituentscorrect *__pyx_optional_args); /*proto*/
static PyObject *__pyx_f_8discodop_14disambiguation_sldop(PyObject *, struct __pyx_obj_8discodop_10containers_Chart *, PyObject *, PyObject *, int, int, PyObject *, PyObject *, int); /*proto*/
static PyObject *__pyx_f_8discodop_14disambiguation_sldop_simple(PyObject *, PyObject *, int, struct __pyx_obj_8discodop_10containers_Chart *, PyObject *, int); /*proto*/
static PyObject *__pyx_f_8discodop_14disambiguation_recoverfragments(PyObject *, struct __pyx_obj_8discodop_10containers_Chart *, PyObject *, int __pyx_skip_dispatch); /*proto*/
static PyObject *__pyx_f_8discodop_14disambiguation_recoverfragments_(struct __pyx_obj_8discodop_10containers_RankedEdge *, struct __pyx_obj_8discodop_10containers_Chart *, PyObject *); /*proto*/
static PyObject *__pyx_f_8discodop_14disambiguation_recoverfragments_str(PyObject *, struct __pyx_obj_8discodop_10containers_Chart *, PyObject *); /*proto*/
static PyObject *__pyx_f_8discodop_14disambiguation_fragmentsinderiv_(struct __pyx_obj_8discodop_10containers_RankedEdge *, struct __pyx_obj_8discodop_10containers_Chart *, PyObject *, PyObject *); /*proto*/
static PyObject *__pyx_f_8discodop_14disambiguation_fragmentsinderiv_str(PyObject *, struct __pyx_obj_8discodop_10containers_Chart *, PyObject *, PyObject *); /*proto*/
static double __pyx_f_8discodop_14disambiguation_getderivprob(struct __pyx_obj_8discodop_10containers_RankedEdge *, struct __pyx_obj_8discodop_10containers_Chart *, PyObject *); /*proto*/
static PyObject *__pyx_f_8discodop_14disambiguation_viterbiderivation(struct __pyx_obj_8discodop_10containers_Chart *, int __pyx_skip_dispatch); /*proto*/
static PyObject *__pyx_f_8discodop_14disambiguation_samplechart(PyObject *, struct __pyx_obj_8discodop_10containers_Chart *, PyObject *, PyObject *, PyObject *); /*proto*/
static PyObject *__pyx_f_8discodop_14disambiguation_prodrepr(PyObject *, PyObject *); /*proto*/
static PyObject *__pyx_f_8discodop_14disambiguation_nodeprod(PyObject *); /*proto*/
#define __Pyx_MODULE_NAME "discodop.disambiguation"
int __pyx_module_is_main_discodop__disambiguation = 0;

/* Implementation of 'discodop.disambiguation' */
static PyObject *__pyx_builtin_ValueError;
static PyObject *__pyx_builtin_zip;
static PyObject *__pyx_builtin_min;
static PyObject *__pyx_builtin_KeyError;
static PyObject *__pyx_builtin_range;
static PyObject *__pyx_builtin_enumerate;
static PyObject *__pyx_builtin_max;
static PyObject *__pyx_builtin_AttributeError;
static PyObject *__pyx_builtin_bin;
static PyObject *__pyx_builtin_reversed;
static PyObject *__pyx_builtin_sum;
static PyObject *__pyx_builtin_map;
static PyObject *__pyx_builtin_print;
static PyObject *__pyx_builtin_MemoryError;
static const char __pyx_k_1[] = "@1";
static const char __pyx_k_a[] = "a";
static const char __pyx_k_b[] = "b";
static const char __pyx_k_e[] = "e";
static const char __pyx_k_i[] = "i";
static const char __pyx_k_k[] = "k";
static const char __pyx_k_m[] = "m";
static const char __pyx_k_n[] = "n";
static const char __pyx_k_r[] = "r";
static const char __pyx_k_x[] = "x";
static const char __pyx_k__4[] = "";
static const char __pyx_k__7[] = ":";
static const char __pyx_k__8[] = "++";
static const char __pyx_k__9[] = "|<";
static const char __pyx_k_re[] = "re";
static const char __pyx_k_yf[] = "yf";
static const char __pyx_k_0_9[] = "@[-0-9]+";
static const char __pyx_k__13[] = "}<";
static const char __pyx_k__14[] = "(";
static const char __pyx_k__16[] = "@";
static const char __pyx_k__25[] = " ";
static const char __pyx_k__34[] = ",";
static const char __pyx_k__36[] = "_";
static const char __pyx_k__39[] = "\n";
static const char __pyx_k__41[] = "@[^ )]+";
static const char __pyx_k__43[] = "-#-";
static const char __pyx_k_add[] = "add";
static const char __pyx_k_all[] = "__all__";
static const char __pyx_k_bin[] = "bin";
static const char __pyx_k_bit[] = "bit";
static const char __pyx_k_d_d[] = "%d:%d";
static const char __pyx_k_d_s[] = "%d=%s";
static const char __pyx_k_exp[] = "exp";
static const char __pyx_k_get[] = "get";
static const char __pyx_k_idx[] = "idx";
static const char __pyx_k_inf[] = "-inf";
static const char __pyx_k_key[] = "key";
static const char __pyx_k_log[] = "log";
static const char __pyx_k_map[] = "map";
static const char __pyx_k_max[] = "max";
static const char __pyx_k_mcc[] = "mcc";
static const char __pyx_k_min[] = "min";
static const char __pyx_k_mpd[] = "mpd";
static const char __pyx_k_mpp[] = "mpp";
static const char __pyx_k_msg[] = "msg";
static const char __pyx_k_pos[] = "pos";
static const char __pyx_k_rev[] = "rev";
static const char __pyx_k_s_d[] = "(%s %d)";
static const char __pyx_k_s_s[] = "%s %s";
static const char __pyx_k_sep[] = "sep";
static const char __pyx_k_sub[] = "sub";
static const char __pyx_k_sum[] = "sum";
static const char __pyx_k_tmp[] = "tmp";
static const char __pyx_k_zip[] = "zip";
static const char __pyx_k_NONE[] = "NONE";
static const char __pyx_k_Tree[] = "Tree";
static const char __pyx_k_args[] = "args";
static const char __pyx_k_cell[] = "cell";
static const char __pyx_k_disc[] = "disc";
static const char __pyx_k_edge[] = "edge";
static const char __pyx_k_fine[] = "fine";
static const char __pyx_k_frag[] = "frag";
static const char __pyx_k_fsum[] = "fsum";
static const char __pyx_k_item[] = "item";
static const char __pyx_k_keys[] = "keys";
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_math[] = "math";
static const char __pyx_k_node[] = "node";
static const char __pyx_k_prev[] = "prev";
static const char __pyx_k_prob[] = "prob";
static const char __pyx_k_prod[] = "prod";
static const char __pyx_k_root[] = "root";
static const char __pyx_k_rule[] = "rule";
static const char __pyx_k_send[] = "send";
static const char __pyx_k_sent[] = "sent";
static const char __pyx_k_sort[] = "sort";
static const char __pyx_k_span[] = "span";
static const char __pyx_k_tags[] = "tags";
static const char __pyx_k_test[] = "test";
static const char __pyx_k_tree[] = "tree";
static const char __pyx_k_word[] = "word";
static const char __pyx_k_a_b_c[] = "a b c";
static const char __pyx_k_cells[] = "cells";
static const char __pyx_k_chart[] = "chart";
static const char __pyx_k_child[] = "child";
static const char __pyx_k_close[] = "close";
static const char __pyx_k_count[] = "count";
static const char __pyx_k_debin[] = "debin";
static const char __pyx_k_deriv[] = "deriv";
static const char __pyx_k_edges[] = "edges";
static const char __pyx_k_fitem[] = "fitem";
static const char __pyx_k_frags[] = "frags";
static const char __pyx_k_heapq[] = "heapq";
static const char __pyx_k_isinf[] = "isinf";
static const char __pyx_k_items[] = "items";
static const char __pyx_k_kbest[] = "kbest";
static const char __pyx_k_label[] = "label";
static const char __pyx_k_parse[] = "parse";
static const char __pyx_k_print[] = "print";
static const char __pyx_k_range[] = "range";
static const char __pyx_k_s_d_s[] = "(%s %d=%s)";
static const char __pyx_k_s_s_2[] = "(%s %s)";
static const char __pyx_k_s_s_s[] = "(%s %s %s)";
static const char __pyx_k_score[] = "score";
static const char __pyx_k_sents[] = "sents";
static const char __pyx_k_short[] = "short";
static const char __pyx_k_sldop[] = "sldop_";
static const char __pyx_k_split[] = "split";
static const char __pyx_k_throw[] = "throw";
static const char __pyx_k_trees[] = "trees";
static const char __pyx_k_vocab[] = "vocab";
static const char __pyx_k_append[] = "append";
static const char __pyx_k_approx[] = "approx";
static const char __pyx_k_bisect[] = "bisect";
static const char __pyx_k_bitpar[] = "bitpar";
static const char __pyx_k_bitset[] = "bitset";
static const char __pyx_k_coarse[] = "coarse";
static const char __pyx_k_derivs[] = "derivs";
static const char __pyx_k_format[] = "format";
static const char __pyx_k_import[] = "__import__";
static const char __pyx_k_leaves[] = "leaves";
static const char __pyx_k_method[] = "method";
static const char __pyx_k_plcfrs[] = "plcfrs";
static const char __pyx_k_random[] = "random";
static const char __pyx_k_result[] = "result";
static const char __pyx_k_rstrip[] = "rstrip";
static const char __pyx_k_ruleno[] = "ruleno";
static const char __pyx_k_sample[] = "sample";
static const char __pyx_k_sl_dop[] = "sl-dop";
static const char __pyx_k_switch[] = "switch";
static const char __pyx_k_tables[] = "tables";
static const char __pyx_k_test_2[] = "__test__";
static const char __pyx_k_trees1[] = "trees1";
static const char __pyx_k_values[] = "values";
static const char __pyx_k_Grammar[] = "Grammar";
static const char __pyx_k_MCC_s_r[] = "MCC:\t\t%s %r";
static const char __pyx_k_MPD_s_r[] = "MPD:\t\t%s %r";
static const char __pyx_k_MPP_s_r[] = "MPP:\t\t%s %r";
static const char __pyx_k_compile[] = "compile";
static const char __pyx_k_entries[] = "entries";
static const char __pyx_k_genexpr[] = "genexpr";
static const char __pyx_k_gettree[] = "gettree";
static const char __pyx_k_grammar[] = "grammar";
static const char __pyx_k_indices[] = "indices";
static const char __pyx_k_lensent[] = "lensent";
static const char __pyx_k_lexrule[] = "lexrule";
static const char __pyx_k_logprob[] = "logprob";
static const char __pyx_k_newprob[] = "newprob";
static const char __pyx_k_partial[] = "partial";
static const char __pyx_k_results[] = "results";
static const char __pyx_k_s_s_s_2[] = "%s %s %s";
static const char __pyx_k_setmask[] = "setmask";
static const char __pyx_k_sldop_n[] = "sldop_n";
static const char __pyx_k_treestr[] = "treestr";
static const char __pyx_k_vit_s_r[] = "\nvit:\t\t%s %r";
static const char __pyx_k_vitprob[] = "vitprob";
static const char __pyx_k_KeyError[] = "KeyError";
static const char __pyx_k_binarize[] = "binarize";
static const char __pyx_k_chartidx[] = "chartidx";
static const char __pyx_k_children[] = "children";
static const char __pyx_k_derivstr[] = "derivstr";
static const char __pyx_k_edgelist[] = "edgelist";
static const char __pyx_k_getderiv[] = "getderiv";
static const char __pyx_k_getitems[] = "getitems";
static const char __pyx_k_joinchar[] = "joinchar";
static const char __pyx_k_leftcell[] = "leftcell";
static const char __pyx_k_leftspan[] = "leftspan";
static const char __pyx_k_mcrerank[] = "mcrerank";
static const char __pyx_k_nlargest[] = "nlargest";
static const char __pyx_k_operator[] = "operator";
static const char __pyx_k_register[] = "register";
static const char __pyx_k_reversed[] = "reversed";
static const char __pyx_k_shortest[] = "shortest";
static const char __pyx_k_subtrees[] = "subtrees";
static const char __pyx_k_vitderiv[] = "vitderiv";
static const char __pyx_k_xgrammar[] = "xgrammar";
static const char __pyx_k_REMOVEIDS[] = "REMOVEIDS";
static const char __pyx_k_childchar[] = "childchar";
static const char __pyx_k_doprerank[] = "doprerank";
static const char __pyx_k_enumerate[] = "enumerate";
static const char __pyx_k_fragments[] = "_fragments";
static const char __pyx_k_functools[] = "functools";
static const char __pyx_k_getctrees[] = "getctrees";
static const char __pyx_k_itertools[] = "itertools";
static const char __pyx_k_lazykbest[] = "lazykbest";
static const char __pyx_k_maskrules[] = "maskrules";
static const char __pyx_k_mcc_labda[] = "mcc_labda";
static const char __pyx_k_pygetsent[] = "pygetsent";
static const char __pyx_k_rightcell[] = "rightcell";
static const char __pyx_k_rightspan[] = "rightspan";
static const char __pyx_k_splitfrag[] = "splitfrag";
static const char __pyx_k_unarychar[] = "unarychar";
static const char __pyx_k_whitelist[] = "whitelist";
static const char __pyx_k_ValueError[] = "ValueError";
static const char __pyx_k_addbitsets[] = "addbitsets";
static const char __pyx_k_altweights[] = "altweights";
static const char __pyx_k_attrgetter[] = "attrgetter";
static const char __pyx_k_containers[] = "containers";
static const char __pyx_k_frontiernt[] = "frontiernt";
static const char __pyx_k_getsamples[] = "getsamples";
static const char __pyx_k_itemgetter[] = "itemgetter";
static const char __pyx_k_mcc_labels[] = "mcc_labels";
static const char __pyx_k_mppsampled[] = "mppsampled";
static const char __pyx_k_parsetrees[] = "parsetrees";
static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__";
static const char __pyx_k_sentprob_g[] = "sentprob: %g";
static const char __pyx_k_setdefault[] = "setdefault";
static const char __pyx_k_startswith[] = "startswith";
static const char __pyx_k_unbinarize[] = "unbinarize";
static const char __pyx_k_MemoryError[] = "MemoryError";
static const char __pyx_k_collections[] = "collections";
static const char __pyx_k_defaultdict[] = "defaultdict";
static const char __pyx_k_derivations[] = "derivations";
static const char __pyx_k_exactcounts[] = "exactcounts";
static const char __pyx_k_expandunary[] = "expandunary";
static const char __pyx_k_marginalize[] = "marginalize";
static const char __pyx_k_rankededges[] = "rankededges";
static const char __pyx_k_sldopsimple[] = "sldopsimple";
static const char __pyx_k_treeparsing[] = "treeparsing";
static const char __pyx_k_MCC_failed_s[] = "MCC failed. %s";
static const char __pyx_k_bisect_right[] = "bisect_right";
static const char __pyx_k_canonicalize[] = "canonicalize";
static const char __pyx_k_derivstrings[] = "derivstrings";
static const char __pyx_k_dopparseprob[] = "dopparseprob";
static const char __pyx_k_dopreduction[] = "dopreduction";
static const char __pyx_k_pyintnextset[] = "pyintnextset";
static const char __pyx_k_shortest_s_r[] = "shortest:\t%s %r";
static const char __pyx_k_unused_score[] = "unused_score";
static const char __pyx_k_backtransform[] = "backtransform";
static const char __pyx_k_collapseunary[] = "collapseunary";
static const char __pyx_k_leftmostunary[] = "leftmostunary";
static const char __pyx_k_pyintbitcount[] = "pyintbitcount";
static const char __pyx_k_sl_dop_simple[] = "sl-dop-simple";
static const char __pyx_k_test_locals_e[] = "test.<locals>.e";
static const char __pyx_k_AttributeError[] = "AttributeError";
static const char __pyx_k_REMOVEWORDTAGS[] = "REMOVEWORDTAGS";
static const char __pyx_k_SL_DOP_n_7_s_r[] = "SL-DOP n=7:\t%s %r";
static const char __pyx_k_getderivations[] = "getderivations";
static const char __pyx_k_mergediscnodes[] = "mergediscnodes";
static const char __pyx_k_treetransforms[] = "treetransforms";
static const char __pyx_k_MPP_sampled_s_r[] = "MPP sampled:\t%s %r";
static const char __pyx_k_extractfragments[] = "extractfragments";
static const char __pyx_k_fragmentsinderiv[] = "fragmentsinderiv";
static const char __pyx_k_lcfrsproductions[] = "lcfrsproductions";
static const char __pyx_k_recoverfragments[] = "recoverfragments";
static const char __pyx_k_s_not_in_grammar[] = "'%s' not in grammar";
static const char __pyx_k_simple_SL_DOP_s_r[] = "simple SL-DOP:\t%s %r";
static const char __pyx_k_viterbiderivation[] = "viterbiderivation";
static const char __pyx_k_ROOT_B_A_0_B_1_C_2[] = "(ROOT (B (A 0) (B 1)) (C 2))";
static const char __pyx_k_tree_parsing_failed[] = "tree parsing failed";
static const char __pyx_k_writediscbrackettree[] = "writediscbrackettree";
static const char __pyx_k_MCC_span_not_in_cell_r[] = "MCC: span not in cell: %r";
static const char __pyx_k_mcrerank_locals_lambda[] = "mcrerank.<locals>.<lambda>";
static const char __pyx_k_discodop_disambiguation[] = "discodop.disambiguation";
static const char __pyx_k_doprerank_locals_lambda[] = "doprerank.<locals>.<lambda>";
static const char __pyx_k_expected_binarized_tree[] = "expected binarized tree.";
static const char __pyx_k_mcrerank_locals_genexpr[] = "mcrerank.<locals>.genexpr";
static const char __pyx_k_d_derivations_d_parsetrees[] = "%d derivations, %d parsetrees";
static const char __pyx_k_no_matching_derivation_found[] = "no matching derivation found";
static const char __pyx_k_Disambiguate_parse_forests_with[] = "Disambiguate parse forests with various methods for parse selection.\n\nUse as follows:\n\n>>> derivs, entries = getderivations(chart, 1000)  # doctest: +SKIP\n>>> parses, msg = marginalize('mpp', derivs, entries, chart)  # doctest: +SKIP\n";
static const char __pyx_k_ROOT_A_A_0_B_1_C_2_ROOT_C_0_A_A[] = "(ROOT (A (A 0) (B 1)) (C 2))\n\t\t(ROOT (C 0) (A (A 1) (B 2)))\n\t\t(ROOT (A 0) (C (B 1) (C 2)))\n\t\t(ROOT (A 0) (C (B 1) (C 2)))";
static const char __pyx_k_at_least_one_of_kbest_or_sample[] = "at least one of kbest or sample needs to be True.";
static const char __pyx_k_d_b_c_c_a_b_a_e_f_a_e_f_a_e_f_a[] = "d b c\n c a b\n a e f\n a e f\n a e f\n a e f\n d b f\n d b f\n\t\td b f\n d b g\n e f c\n e f c\n e f c\n e f c\n e f c\n e f c\n f b c\n\t\ta d e";
static const char __pyx_k_d_derivations_d_of_d_parsetrees[] = "(%d derivations, %d of %d parsetrees)";
static const char __pyx_k_datastore_avcrane1_disco_dop_di[] = "/datastore/avcrane1/disco-dop/discodop/disambiguation.pyx";
static const char __pyx_k_deriv_should_be_a_RankedEdge_or[] = "deriv should be a RankedEdge or a string.";
static const char __pyx_k_Grammar_should_have_log_probabil[] = "Grammar should have log probabilities.";
static const char __pyx_k_SL_DOP_couldn_t_find_parse_for_t[] = "SL-DOP couldn't find parse for tree";
static const char __pyx_k_derivation_has_unexpected_type_r[] = "derivation has unexpected type %r.";
static const char __pyx_k_expected_binary_tree_without_emp[] = "expected binary tree without empty nodes.";
static const char __pyx_k_re_ranked_d_parse_trees_best_tre[] = "re-ranked %d parse trees; best tree at %d. ";
static PyObject *__pyx_kp_u_0_9;
static PyObject *__pyx_kp_u_1;
static PyObject *__pyx_n_s_AttributeError;
static PyObject *__pyx_n_s_Grammar;
static PyObject *__pyx_kp_u_Grammar_should_have_log_probabil;
static PyObject *__pyx_n_s_KeyError;
static PyObject *__pyx_kp_u_MCC_failed_s;
static PyObject *__pyx_kp_u_MCC_s_r;
static PyObject *__pyx_kp_u_MCC_span_not_in_cell_r;
static PyObject *__pyx_kp_u_MPD_s_r;
static PyObject *__pyx_kp_u_MPP_s_r;
static PyObject *__pyx_kp_u_MPP_sampled_s_r;
static PyObject *__pyx_n_s_MemoryError;
static PyObject *__pyx_n_u_NONE;
static PyObject *__pyx_n_s_REMOVEIDS;
static PyObject *__pyx_n_s_REMOVEWORDTAGS;
static PyObject *__pyx_kp_u_ROOT_A_A_0_B_1_C_2_ROOT_C_0_A_A;
static PyObject *__pyx_kp_u_ROOT_B_A_0_B_1_C_2;
static PyObject *__pyx_kp_u_SL_DOP_couldn_t_find_parse_for_t;
static PyObject *__pyx_kp_u_SL_DOP_n_7_s_r;
static PyObject *__pyx_n_s_Tree;
static PyObject *__pyx_n_s_ValueError;
static PyObject *__pyx_kp_u__13;
static PyObject *__pyx_kp_u__14;
static PyObject *__pyx_kp_u__16;
static PyObject *__pyx_kp_u__25;
static PyObject *__pyx_kp_u__34;
static PyObject *__pyx_n_s__36;
static PyObject *__pyx_kp_u__39;
static PyObject *__pyx_n_s__4;
static PyObject *__pyx_kp_u__4;
static PyObject *__pyx_kp_u__41;
static PyObject *__pyx_kp_u__43;
static PyObject *__pyx_kp_u__7;
static PyObject *__pyx_kp_u__8;
static PyObject *__pyx_kp_u__9;
static PyObject *__pyx_n_s_a;
static PyObject *__pyx_kp_u_a_b_c;
static PyObject *__pyx_n_s_add;
static PyObject *__pyx_n_s_addbitsets;
static PyObject *__pyx_n_s_all;
static PyObject *__pyx_n_s_altweights;
static PyObject *__pyx_n_s_append;
static PyObject *__pyx_n_s_approx;
static PyObject *__pyx_n_s_args;
static PyObject *__pyx_kp_u_at_least_one_of_kbest_or_sample;
static PyObject *__pyx_n_s_attrgetter;
static PyObject *__pyx_n_s_b;
static PyObject *__pyx_n_s_backtransform;
static PyObject *__pyx_n_s_bin;
static PyObject *__pyx_n_s_binarize;
static PyObject *__pyx_n_s_bisect;
static PyObject *__pyx_n_s_bisect_right;
static PyObject *__pyx_n_s_bit;
static PyObject *__pyx_n_s_bitpar;
static PyObject *__pyx_n_s_bitset;
static PyObject *__pyx_n_s_canonicalize;
static PyObject *__pyx_n_s_cell;
static PyObject *__pyx_n_s_cells;
static PyObject *__pyx_n_s_chart;
static PyObject *__pyx_n_s_chartidx;
static PyObject *__pyx_n_s_child;
static PyObject *__pyx_n_s_childchar;
static PyObject *__pyx_n_s_children;
static PyObject *__pyx_n_s_close;
static PyObject *__pyx_n_s_coarse;
static PyObject *__pyx_n_s_collapseunary;
static PyObject *__pyx_n_s_collections;
static PyObject *__pyx_n_s_compile;
static PyObject *__pyx_n_s_containers;
static PyObject *__pyx_n_s_count;
static PyObject *__pyx_kp_u_d_b_c_c_a_b_a_e_f_a_e_f_a_e_f_a;
static PyObject *__pyx_kp_u_d_d;
static PyObject *__pyx_kp_u_d_derivations_d_of_d_parsetrees;
static PyObject *__pyx_kp_u_d_derivations_d_parsetrees;
static PyObject *__pyx_kp_u_d_s;
static PyObject *__pyx_kp_s_datastore_avcrane1_disco_dop_di;
static PyObject *__pyx_n_s_debin;
static PyObject *__pyx_n_s_defaultdict;
static PyObject *__pyx_n_s_deriv;
static PyObject *__pyx_kp_u_deriv_should_be_a_RankedEdge_or;
static PyObject *__pyx_kp_u_derivation_has_unexpected_type_r;
static PyObject *__pyx_n_s_derivations;
static PyObject *__pyx_n_s_derivs;
static PyObject *__pyx_n_s_derivstr;
static PyObject *__pyx_n_s_derivstrings;
static PyObject *__pyx_n_s_disc;
static PyObject *__pyx_n_s_discodop_disambiguation;
static PyObject *__pyx_n_s_dopparseprob;
static PyObject *__pyx_n_u_dopparseprob;
static PyObject *__pyx_n_s_dopreduction;
static PyObject *__pyx_n_s_doprerank;
static PyObject *__pyx_n_u_doprerank;
static PyObject *__pyx_n_s_doprerank_locals_lambda;
static PyObject *__pyx_n_s_e;
static PyObject *__pyx_n_s_edge;
static PyObject *__pyx_n_s_edgelist;
static PyObject *__pyx_n_s_edges;
static PyObject *__pyx_n_s_entries;
static PyObject *__pyx_n_s_enumerate;
static PyObject *__pyx_n_s_exactcounts;
static PyObject *__pyx_n_s_exp;
static PyObject *__pyx_n_s_expandunary;
static PyObject *__pyx_kp_u_expected_binarized_tree;
static PyObject *__pyx_kp_u_expected_binary_tree_without_emp;
static PyObject *__pyx_n_s_extractfragments;
static PyObject *__pyx_n_s_fine;
static PyObject *__pyx_n_s_fitem;
static PyObject *__pyx_n_s_format;
static PyObject *__pyx_n_s_frag;
static PyObject *__pyx_n_s_fragments;
static PyObject *__pyx_n_s_fragmentsinderiv;
static PyObject *__pyx_n_u_fragmentsinderiv;
static PyObject *__pyx_n_s_frags;
static PyObject *__pyx_n_s_frontiernt;
static PyObject *__pyx_n_u_frontiernt;
static PyObject *__pyx_n_s_fsum;
static PyObject *__pyx_n_s_functools;
static PyObject *__pyx_n_s_genexpr;
static PyObject *__pyx_n_s_get;
static PyObject *__pyx_n_s_getctrees;
static PyObject *__pyx_n_s_getderiv;
static PyObject *__pyx_n_u_getderivations;
static PyObject *__pyx_n_s_getitems;
static PyObject *__pyx_n_s_getsamples;
static PyObject *__pyx_n_u_getsamples;
static PyObject *__pyx_n_s_gettree;
static PyObject *__pyx_n_u_gettree;
static PyObject *__pyx_n_s_grammar;
static PyObject *__pyx_n_s_heapq;
static PyObject *__pyx_n_s_i;
static PyObject *__pyx_n_s_idx;
static PyObject *__pyx_n_s_import;
static PyObject *__pyx_n_s_indices;
static PyObject *__pyx_kp_u_inf;
static PyObject *__pyx_n_s_isinf;
static PyObject *__pyx_n_s_item;
static PyObject *__pyx_n_s_itemgetter;
static PyObject *__pyx_n_s_items;
static PyObject *__pyx_n_s_itertools;
static PyObject *__pyx_n_s_joinchar;
static PyObject *__pyx_n_s_k;
static PyObject *__pyx_n_s_kbest;
static PyObject *__pyx_n_s_key;
static PyObject *__pyx_n_s_keys;
static PyObject *__pyx_n_s_label;
static PyObject *__pyx_n_s_lazykbest;
static PyObject *__pyx_n_s_lcfrsproductions;
static PyObject *__pyx_n_s_leaves;
static PyObject *__pyx_n_s_leftcell;
static PyObject *__pyx_n_s_leftmostunary;
static PyObject *__pyx_n_s_leftspan;
static PyObject *__pyx_n_s_lensent;
static PyObject *__pyx_n_s_lexrule;
static PyObject *__pyx_n_s_log;
static PyObject *__pyx_n_s_logprob;
static PyObject *__pyx_n_s_m;
static PyObject *__pyx_n_s_main;
static PyObject *__pyx_n_s_map;
static PyObject *__pyx_n_s_marginalize;
static PyObject *__pyx_n_u_marginalize;
static PyObject *__pyx_n_s_maskrules;
static PyObject *__pyx_n_s_math;
static PyObject *__pyx_n_s_max;
static PyObject *__pyx_n_s_mcc;
static PyObject *__pyx_n_u_mcc;
static PyObject *__pyx_n_s_mcc_labda;
static PyObject *__pyx_n_s_mcc_labels;
static PyObject *__pyx_n_s_mcrerank;
static PyObject *__pyx_n_s_mcrerank_locals_genexpr;
static PyObject *__pyx_n_s_mcrerank_locals_lambda;
static PyObject *__pyx_n_s_mergediscnodes;
static PyObject *__pyx_n_s_method;
static PyObject *__pyx_n_s_min;
static PyObject *__pyx_n_s_mpd;
static PyObject *__pyx_n_u_mpd;
static PyObject *__pyx_n_s_mpp;
static PyObject *__pyx_n_u_mpp;
static PyObject *__pyx_n_s_mppsampled;
static PyObject *__pyx_n_s_msg;
static PyObject *__pyx_n_s_n;
static PyObject *__pyx_n_s_newprob;
static PyObject *__pyx_n_s_nlargest;
static PyObject *__pyx_kp_u_no_matching_derivation_found;
static PyObject *__pyx_n_s_node;
static PyObject *__pyx_n_s_operator;
static PyObject *__pyx_n_s_parse;
static PyObject *__pyx_n_s_parsetrees;
static PyObject *__pyx_n_s_partial;
static PyObject *__pyx_n_s_plcfrs;
static PyObject *__pyx_n_s_pos;
static PyObject *__pyx_n_s_prev;
static PyObject *__pyx_n_s_print;
static PyObject *__pyx_n_s_prob;
static PyObject *__pyx_n_s_prod;
static PyObject *__pyx_n_s_pygetsent;
static PyObject *__pyx_n_s_pyintbitcount;
static PyObject *__pyx_n_s_pyintnextset;
static PyObject *__pyx_n_s_pyx_vtable;
static PyObject *__pyx_n_s_r;
static PyObject *__pyx_n_s_random;
static PyObject *__pyx_n_s_range;
static PyObject *__pyx_n_s_rankededges;
static PyObject *__pyx_n_s_re;
static PyObject *__pyx_kp_u_re_ranked_d_parse_trees_best_tre;
static PyObject *__pyx_n_u_recoverfragments;
static PyObject *__pyx_n_s_register;
static PyObject *__pyx_n_s_result;
static PyObject *__pyx_n_s_results;
static PyObject *__pyx_n_s_rev;
static PyObject *__pyx_n_s_reversed;
static PyObject *__pyx_n_s_rightcell;
static PyObject *__pyx_n_s_rightspan;
static PyObject *__pyx_n_s_root;
static PyObject *__pyx_n_s_rstrip;
static PyObject *__pyx_n_s_rule;
static PyObject *__pyx_n_s_ruleno;
static PyObject *__pyx_kp_u_s_d;
static PyObject *__pyx_kp_u_s_d_s;
static PyObject *__pyx_kp_u_s_not_in_grammar;
static PyObject *__pyx_kp_u_s_s;
static PyObject *__pyx_kp_u_s_s_2;
static PyObject *__pyx_kp_u_s_s_s;
static PyObject *__pyx_kp_u_s_s_s_2;
static PyObject *__pyx_n_s_sample;
static PyObject *__pyx_n_s_score;
static PyObject *__pyx_n_s_send;
static PyObject *__pyx_n_s_sent;
static PyObject *__pyx_kp_u_sentprob_g;
static PyObject *__pyx_n_s_sents;
static PyObject *__pyx_n_s_sep;
static PyObject *__pyx_n_s_setdefault;
static PyObject *__pyx_n_s_setmask;
static PyObject *__pyx_n_s_short;
static PyObject *__pyx_n_u_shortest;
static PyObject *__pyx_kp_u_shortest_s_r;
static PyObject *__pyx_kp_u_simple_SL_DOP_s_r;
static PyObject *__pyx_kp_u_sl_dop;
static PyObject *__pyx_kp_u_sl_dop_simple;
static PyObject *__pyx_n_s_sldop;
static PyObject *__pyx_n_s_sldop_n;
static PyObject *__pyx_n_s_sldopsimple;
static PyObject *__pyx_n_s_sort;
static PyObject *__pyx_n_s_span;
static PyObject *__pyx_n_s_split;
static PyObject *__pyx_n_s_splitfrag;
static PyObject *__pyx_n_u_splitfrag;
static PyObject *__pyx_n_s_startswith;
static PyObject *__pyx_n_s_sub;
static PyObject *__pyx_n_s_subtrees;
static PyObject *__pyx_n_s_sum;
static PyObject *__pyx_n_s_switch;
static PyObject *__pyx_n_s_tables;
static PyObject *__pyx_n_s_tags;
static PyObject *__pyx_n_s_test;
static PyObject *__pyx_n_s_test_2;
static PyObject *__pyx_n_s_test_locals_e;
static PyObject *__pyx_n_s_throw;
static PyObject *__pyx_n_s_tmp;
static PyObject *__pyx_n_s_tree;
static PyObject *__pyx_kp_u_tree_parsing_failed;
static PyObject *__pyx_n_s_treeparsing;
static PyObject *__pyx_n_u_treeparsing;
static PyObject *__pyx_n_s_trees;
static PyObject *__pyx_n_u_trees1;
static PyObject *__pyx_n_s_treestr;
static PyObject *__pyx_n_s_treetransforms;
static PyObject *__pyx_n_s_unarychar;
static PyObject *__pyx_n_s_unbinarize;
static PyObject *__pyx_n_s_unused_score;
static PyObject *__pyx_n_s_values;
static PyObject *__pyx_kp_u_vit_s_r;
static PyObject *__pyx_n_s_vitderiv;
static PyObject *__pyx_n_u_viterbiderivation;
static PyObject *__pyx_n_s_vitprob;
static PyObject *__pyx_n_s_vocab;
static PyObject *__pyx_n_s_whitelist;
static PyObject *__pyx_n_s_word;
static PyObject *__pyx_n_s_writediscbrackettree;
static PyObject *__pyx_n_s_x;
static PyObject *__pyx_n_s_xgrammar;
static PyObject *__pyx_n_s_yf;
static PyObject *__pyx_n_s_zip;
static PyObject *__pyx_pf_8discodop_14disambiguation_getderivations(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, int __pyx_v_k, int __pyx_v_kbest, int __pyx_v_sample, PyObject *__pyx_v_derivstrings); /* proto */
static PyObject *__pyx_pf_8discodop_14disambiguation_2marginalize(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_method, PyObject *__pyx_v_derivations, PyObject *__pyx_v_entries, struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, PyObject *__pyx_v_backtransform, PyObject *__pyx_v_sent, PyObject *__pyx_v_tags, int __pyx_v_k, int __pyx_v_sldop_n, double __pyx_v_mcc_labda, PyObject *__pyx_v_mcc_labels, int __pyx_v_bitpar); /* proto */
static PyObject *__pyx_pf_8discodop_14disambiguation_4gettree(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_cells, PyObject *__pyx_v_span); /* proto */
static PyObject *__pyx_pf_8discodop_14disambiguation_6recoverfragments(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_deriv, struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, PyObject *__pyx_v_backtransform); /* proto */
static PyObject *__pyx_pf_8discodop_14disambiguation_8fragmentsinderiv(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_deriv, PyObject *__pyx_v_chart, PyObject *__pyx_v_backtransform); /* proto */
static PyObject *__pyx_pf_8discodop_14disambiguation_10frontiernt(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_node); /* proto */
static PyObject *__pyx_pf_8discodop_14disambiguation_12splitfrag(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_node); /* proto */
static PyObject *__pyx_pf_8discodop_14disambiguation_14treeparsing(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_trees, PyObject *__pyx_v_sent, struct __pyx_obj_8discodop_10containers_Grammar *__pyx_v_grammar, int __pyx_v_m, PyObject *__pyx_v_backtransform, PyObject *__pyx_v_tags, PyObject *__pyx_v_maskrules); /* proto */
static PyObject *__pyx_pf_8discodop_14disambiguation_16viterbiderivation(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart); /* proto */
static PyObject *__pyx_pf_8discodop_14disambiguation_18getsamples(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, PyObject *__pyx_v_k, PyObject *__pyx_v_debin); /* proto */
static PyObject *__pyx_lambda_funcdef_lambda(PyObject *__pyx_self, PyObject *__pyx_v_x); /* proto */
static PyObject *__pyx_pf_8discodop_14disambiguation_20doprerank(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_parsetrees, PyObject *__pyx_v_sent, PyObject *__pyx_v_k, struct __pyx_obj_8discodop_10containers_Grammar *__pyx_v_coarse, struct __pyx_obj_8discodop_10containers_Grammar *__pyx_v_fine); /* proto */
static PyObject *__pyx_pf_8discodop_14disambiguation_22dopparseprob(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_tree, PyObject *__pyx_v_sent, struct __pyx_obj_8discodop_10containers_Grammar *__pyx_v_coarse, struct __pyx_obj_8discodop_10containers_Grammar *__pyx_v_fine); /* proto */
static PyObject *__pyx_pf_8discodop_14disambiguation_8mcrerank_genexpr(PyObject *__pyx_self); /* proto */
static PyObject *__pyx_lambda_funcdef_lambda2(PyObject *__pyx_self, PyObject *__pyx_v_x); /* proto */
static PyObject *__pyx_pf_8discodop_14disambiguation_24mcrerank(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_parsetrees, PyObject *__pyx_v_sent, PyObject *__pyx_v_k, PyObject *__pyx_v_trees, PyObject *__pyx_v_vocab); /* proto */
static PyObject *__pyx_pf_8discodop_14disambiguation_4test_e(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_x); /* proto */
static PyObject *__pyx_pf_8discodop_14disambiguation_26test(CYTHON_UNUSED PyObject *__pyx_self); /* proto */
static int __pyx_pf_7cpython_5array_5array___getbuffer__(arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info, CYTHON_UNUSED int __pyx_v_flags); /* proto */
static void __pyx_pf_7cpython_5array_5array_2__releasebuffer__(CYTHON_UNUSED arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info); /* proto */
static PyObject *__pyx_tp_new_8discodop_14disambiguation___pyx_scope_struct__doprerank(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
static PyObject *__pyx_tp_new_8discodop_14disambiguation___pyx_scope_struct_2_genexpr(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/
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_0;
static PyObject *__pyx_float_0_5;
static PyObject *__pyx_float_1_0;
static PyObject *__pyx_float_30_0;
static PyObject *__pyx_float_neg_0_0;
static PyObject *__pyx_int_0;
static PyObject *__pyx_int_1;
static PyObject *__pyx_int_3;
static PyObject *__pyx_int_7;
static PyObject *__pyx_int_10;
static PyObject *__pyx_int_460;
static PyObject *__pyx_int_1000;
static PyObject *__pyx_int_neg_1;
static PyObject *__pyx_tuple_;
static PyObject *__pyx_tuple__2;
static PyObject *__pyx_tuple__3;
static PyObject *__pyx_tuple__5;
static PyObject *__pyx_tuple__6;
static PyObject *__pyx_slice__17;
static PyObject *__pyx_slice__18;
static PyObject *__pyx_slice__21;
static PyObject *__pyx_slice__22;
static PyObject *__pyx_slice__28;
static PyObject *__pyx_tuple__10;
static PyObject *__pyx_tuple__11;
static PyObject *__pyx_tuple__12;
static PyObject *__pyx_tuple__15;
static PyObject *__pyx_tuple__19;
static PyObject *__pyx_tuple__20;
static PyObject *__pyx_tuple__23;
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__35;
static PyObject *__pyx_tuple__37;
static PyObject *__pyx_tuple__40;
static PyObject *__pyx_tuple__42;
static PyObject *__pyx_tuple__44;
static PyObject *__pyx_tuple__46;
static PyObject *__pyx_tuple__48;
static PyObject *__pyx_tuple__50;
static PyObject *__pyx_tuple__52;
static PyObject *__pyx_tuple__54;
static PyObject *__pyx_tuple__56;
static PyObject *__pyx_tuple__58;
static PyObject *__pyx_tuple__60;
static PyObject *__pyx_tuple__62;
static PyObject *__pyx_codeobj__38;
static PyObject *__pyx_codeobj__45;
static PyObject *__pyx_codeobj__47;
static PyObject *__pyx_codeobj__49;
static PyObject *__pyx_codeobj__51;
static PyObject *__pyx_codeobj__53;
static PyObject *__pyx_codeobj__55;
static PyObject *__pyx_codeobj__57;
static PyObject *__pyx_codeobj__59;
static PyObject *__pyx_codeobj__61;
static PyObject *__pyx_codeobj__63;

/* "discodop/disambiguation.pyx":48
 * cdef str NEGATIVECONSTLABEL = '-#-'
 * 
 * cpdef getderivations(Chart chart, int k, bint kbest=True, bint sample=False,             # <<<<<<<<<<<<<<
 * 		derivstrings=True):
 * 	"""Get *k*-best and/or sampled derivations from chart.
 */

static PyObject *__pyx_pw_8discodop_14disambiguation_1getderivations(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_8discodop_14disambiguation_getderivations(struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, int __pyx_v_k, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_8discodop_14disambiguation_getderivations *__pyx_optional_args) {
  int __pyx_v_kbest = ((int)1);
  int __pyx_v_sample = ((int)0);

  /* "discodop/disambiguation.pyx":49
 * 
 * cpdef getderivations(Chart chart, int k, bint kbest=True, bint sample=False,
 * 		derivstrings=True):             # <<<<<<<<<<<<<<
 * 	"""Get *k*-best and/or sampled derivations from chart.
 * 
 */
  PyObject *__pyx_v_derivstrings = ((PyObject *)Py_True);
  PyObject *__pyx_v_derivations = 0;
  PyObject *__pyx_v_entries = 0;
  CYTHON_UNUSED PyObject *__pyx_v_unused_explored = NULL;
  PyObject *__pyx_v_filteredderivations = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  int __pyx_t_3;
  PyObject *__pyx_t_4 = NULL;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *(*__pyx_t_7)(PyObject *);
  int __pyx_t_8;
  PyObject *__pyx_t_9 = NULL;
  int __pyx_t_10;
  __Pyx_RefNannySetupContext("getderivations", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_kbest = __pyx_optional_args->kbest;
      if (__pyx_optional_args->__pyx_n > 1) {
        __pyx_v_sample = __pyx_optional_args->sample;
        if (__pyx_optional_args->__pyx_n > 2) {
          __pyx_v_derivstrings = __pyx_optional_args->derivstrings;
        }
      }
    }
  }

  /* "discodop/disambiguation.pyx":62
 * 		:entries: list of RankedEdge objects.
 * 	"""
 * 	cdef list derivations = [], entries = []             # <<<<<<<<<<<<<<
 * 	if not (kbest or sample):
 * 		raise ValueError('at least one of kbest or sample needs to be True.')
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 62, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_derivations = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 62, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_entries = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":63
 * 	"""
 * 	cdef list derivations = [], entries = []
 * 	if not (kbest or sample):             # <<<<<<<<<<<<<<
 * 		raise ValueError('at least one of kbest or sample needs to be True.')
 * 	chart.rankededges = {}
 */
  __pyx_t_3 = (__pyx_v_kbest != 0);
  if (!__pyx_t_3) {
  } else {
    __pyx_t_2 = __pyx_t_3;
    goto __pyx_L4_bool_binop_done;
  }
  __pyx_t_3 = (__pyx_v_sample != 0);
  __pyx_t_2 = __pyx_t_3;
  __pyx_L4_bool_binop_done:;
  __pyx_t_3 = ((!__pyx_t_2) != 0);
  if (__pyx_t_3) {

    /* "discodop/disambiguation.pyx":64
 * 	cdef list derivations = [], entries = []
 * 	if not (kbest or sample):
 * 		raise ValueError('at least one of kbest or sample needs to be True.')             # <<<<<<<<<<<<<<
 * 	chart.rankededges = {}
 * 	if kbest:
 */
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 64, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_Raise(__pyx_t_1, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __PYX_ERR(0, 64, __pyx_L1_error)

    /* "discodop/disambiguation.pyx":63
 * 	"""
 * 	cdef list derivations = [], entries = []
 * 	if not (kbest or sample):             # <<<<<<<<<<<<<<
 * 		raise ValueError('at least one of kbest or sample needs to be True.')
 * 	chart.rankededges = {}
 */
  }

  /* "discodop/disambiguation.pyx":65
 * 	if not (kbest or sample):
 * 		raise ValueError('at least one of kbest or sample needs to be True.')
 * 	chart.rankededges = {}             # <<<<<<<<<<<<<<
 * 	if kbest:
 * 		derivations, unused_explored = lazykbest(chart, k, derivs=derivstrings)
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 65, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __Pyx_GOTREF(__pyx_v_chart->rankededges);
  __Pyx_DECREF(__pyx_v_chart->rankededges);
  __pyx_v_chart->rankededges = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":66
 * 		raise ValueError('at least one of kbest or sample needs to be True.')
 * 	chart.rankededges = {}
 * 	if kbest:             # <<<<<<<<<<<<<<
 * 		derivations, unused_explored = lazykbest(chart, k, derivs=derivstrings)
 * 		entries = chart.rankededges[chart.root()]
 */
  __pyx_t_3 = (__pyx_v_kbest != 0);
  if (__pyx_t_3) {

    /* "discodop/disambiguation.pyx":67
 * 	chart.rankededges = {}
 * 	if kbest:
 * 		derivations, unused_explored = lazykbest(chart, k, derivs=derivstrings)             # <<<<<<<<<<<<<<
 * 		entries = chart.rankededges[chart.root()]
 * 	if sample:
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_lazykbest); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 67, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_k); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 67, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 67, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(((PyObject *)__pyx_v_chart));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_chart));
    PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_chart));
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 67, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_derivs, __pyx_v_derivstrings) < 0) __PYX_ERR(0, 67, __pyx_L1_error)
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 67, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) {
      PyObject* sequence = __pyx_t_6;
      #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, 67, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_4 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_5 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_t_5);
      #else
      __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 67, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 67, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      #endif
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_1 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 67, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_7 = Py_TYPE(__pyx_t_1)->tp_iternext;
      index = 0; __pyx_t_4 = __pyx_t_7(__pyx_t_1); if (unlikely(!__pyx_t_4)) goto __pyx_L7_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_4);
      index = 1; __pyx_t_5 = __pyx_t_7(__pyx_t_1); if (unlikely(!__pyx_t_5)) goto __pyx_L7_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_5);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_1), 2) < 0) __PYX_ERR(0, 67, __pyx_L1_error)
      __pyx_t_7 = NULL;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      goto __pyx_L8_unpacking_done;
      __pyx_L7_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_7 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 67, __pyx_L1_error)
      __pyx_L8_unpacking_done:;
    }
    if (!(likely(PyList_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(0, 67, __pyx_L1_error)
    __Pyx_DECREF_SET(__pyx_v_derivations, ((PyObject*)__pyx_t_4));
    __pyx_t_4 = 0;
    __pyx_v_unused_explored = __pyx_t_5;
    __pyx_t_5 = 0;

    /* "discodop/disambiguation.pyx":68
 * 	if kbest:
 * 		derivations, unused_explored = lazykbest(chart, k, derivs=derivstrings)
 * 		entries = chart.rankededges[chart.root()]             # <<<<<<<<<<<<<<
 * 	if sample:
 * 		derivations.extend(
 */
    if (unlikely(__pyx_v_chart->rankededges == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 68, __pyx_L1_error)
    }
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_chart), __pyx_n_s_root); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 68, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __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_6 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 68, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else {
      __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 68, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = __Pyx_PyDict_GetItem(__pyx_v_chart->rankededges, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 68, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (!(likely(PyList_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_5)->tp_name), 0))) __PYX_ERR(0, 68, __pyx_L1_error)
    __Pyx_DECREF_SET(__pyx_v_entries, ((PyObject*)__pyx_t_5));
    __pyx_t_5 = 0;

    /* "discodop/disambiguation.pyx":66
 * 		raise ValueError('at least one of kbest or sample needs to be True.')
 * 	chart.rankededges = {}
 * 	if kbest:             # <<<<<<<<<<<<<<
 * 		derivations, unused_explored = lazykbest(chart, k, derivs=derivstrings)
 * 		entries = chart.rankededges[chart.root()]
 */
  }

  /* "discodop/disambiguation.pyx":69
 * 		derivations, unused_explored = lazykbest(chart, k, derivs=derivstrings)
 * 		entries = chart.rankededges[chart.root()]
 * 	if sample:             # <<<<<<<<<<<<<<
 * 		derivations.extend(
 * 				getsamples(chart, k, None))
 */
  __pyx_t_3 = (__pyx_v_sample != 0);
  if (__pyx_t_3) {

    /* "discodop/disambiguation.pyx":70
 * 		entries = chart.rankededges[chart.root()]
 * 	if sample:
 * 		derivations.extend(             # <<<<<<<<<<<<<<
 * 				getsamples(chart, k, None))
 * 		# filter out duplicate derivations
 */
    if (unlikely(__pyx_v_derivations == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "extend");
      __PYX_ERR(0, 70, __pyx_L1_error)
    }

    /* "discodop/disambiguation.pyx":71
 * 	if sample:
 * 		derivations.extend(
 * 				getsamples(chart, k, None))             # <<<<<<<<<<<<<<
 * 		# filter out duplicate derivations
 * 		entries = chart.rankededges[chart.root()]
 */
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_getsamples); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 71, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_k); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 71, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_1 = NULL;
    __pyx_t_8 = 0;
    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);
        __pyx_t_8 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_6)) {
      PyObject *__pyx_temp[4] = {__pyx_t_1, ((PyObject *)__pyx_v_chart), __pyx_t_4, Py_None};
      __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 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_6)) {
      PyObject *__pyx_temp[4] = {__pyx_t_1, ((PyObject *)__pyx_v_chart), __pyx_t_4, Py_None};
      __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_8, 3+__pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    {
      __pyx_t_9 = PyTuple_New(3+__pyx_t_8); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      if (__pyx_t_1) {
        __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1); __pyx_t_1 = NULL;
      }
      __Pyx_INCREF(((PyObject *)__pyx_v_chart));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_chart));
      PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_8, ((PyObject *)__pyx_v_chart));
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_8, __pyx_t_4);
      __Pyx_INCREF(Py_None);
      __Pyx_GIVEREF(Py_None);
      PyTuple_SET_ITEM(__pyx_t_9, 2+__pyx_t_8, Py_None);
      __pyx_t_4 = 0;
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_9, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 71, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "discodop/disambiguation.pyx":70
 * 		entries = chart.rankededges[chart.root()]
 * 	if sample:
 * 		derivations.extend(             # <<<<<<<<<<<<<<
 * 				getsamples(chart, k, None))
 * 		# filter out duplicate derivations
 */
    __pyx_t_10 = __Pyx_PyList_Extend(__pyx_v_derivations, __pyx_t_5); if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 70, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "discodop/disambiguation.pyx":73
 * 				getsamples(chart, k, None))
 * 		# filter out duplicate derivations
 * 		entries = chart.rankededges[chart.root()]             # <<<<<<<<<<<<<<
 * 		filteredderivations = dict(zip(derivations, entries))
 * 		entries[:] = filteredderivations.values()
 */
    if (unlikely(__pyx_v_chart->rankededges == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 73, __pyx_L1_error)
    }
    __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_chart), __pyx_n_s_root); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 73, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_9 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
      __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_6);
      if (likely(__pyx_t_9)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_9);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_6, function);
      }
    }
    if (__pyx_t_9) {
      __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_9); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 73, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    } else {
      __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 73, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = __Pyx_PyDict_GetItem(__pyx_v_chart->rankededges, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 73, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (!(likely(PyList_CheckExact(__pyx_t_6))||((__pyx_t_6) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_6)->tp_name), 0))) __PYX_ERR(0, 73, __pyx_L1_error)
    __Pyx_DECREF_SET(__pyx_v_entries, ((PyObject*)__pyx_t_6));
    __pyx_t_6 = 0;

    /* "discodop/disambiguation.pyx":74
 * 		# filter out duplicate derivations
 * 		entries = chart.rankededges[chart.root()]
 * 		filteredderivations = dict(zip(derivations, entries))             # <<<<<<<<<<<<<<
 * 		entries[:] = filteredderivations.values()
 * 		derivations[:] = filteredderivations.keys()
 */
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 74, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_v_derivations);
    __Pyx_GIVEREF(__pyx_v_derivations);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_derivations);
    __Pyx_INCREF(__pyx_v_entries);
    __Pyx_GIVEREF(__pyx_v_entries);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_entries);
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_6, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 74, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 74, __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 = 0;
    __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)(&PyDict_Type)), __pyx_t_6, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 74, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_v_filteredderivations = ((PyObject*)__pyx_t_5);
    __pyx_t_5 = 0;

    /* "discodop/disambiguation.pyx":75
 * 		entries = chart.rankededges[chart.root()]
 * 		filteredderivations = dict(zip(derivations, entries))
 * 		entries[:] = filteredderivations.values()             # <<<<<<<<<<<<<<
 * 		derivations[:] = filteredderivations.keys()
 * 	return derivations, entries
 */
    __pyx_t_5 = __Pyx_PyDict_Values(__pyx_v_filteredderivations); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 75, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (unlikely(__pyx_v_entries == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 75, __pyx_L1_error)
    }
    if (__Pyx_PyObject_SetSlice(__pyx_v_entries, __pyx_t_5, 0, 0, NULL, NULL, NULL, 0, 0, 0) < 0) __PYX_ERR(0, 75, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "discodop/disambiguation.pyx":76
 * 		filteredderivations = dict(zip(derivations, entries))
 * 		entries[:] = filteredderivations.values()
 * 		derivations[:] = filteredderivations.keys()             # <<<<<<<<<<<<<<
 * 	return derivations, entries
 * 
 */
    __pyx_t_5 = __Pyx_PyDict_Keys(__pyx_v_filteredderivations); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 76, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (unlikely(__pyx_v_derivations == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 76, __pyx_L1_error)
    }
    if (__Pyx_PyObject_SetSlice(__pyx_v_derivations, __pyx_t_5, 0, 0, NULL, NULL, NULL, 0, 0, 0) < 0) __PYX_ERR(0, 76, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "discodop/disambiguation.pyx":69
 * 		derivations, unused_explored = lazykbest(chart, k, derivs=derivstrings)
 * 		entries = chart.rankededges[chart.root()]
 * 	if sample:             # <<<<<<<<<<<<<<
 * 		derivations.extend(
 * 				getsamples(chart, k, None))
 */
  }

  /* "discodop/disambiguation.pyx":77
 * 		entries[:] = filteredderivations.values()
 * 		derivations[:] = filteredderivations.keys()
 * 	return derivations, entries             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 77, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_v_derivations);
  __Pyx_GIVEREF(__pyx_v_derivations);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_derivations);
  __Pyx_INCREF(__pyx_v_entries);
  __Pyx_GIVEREF(__pyx_v_entries);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_entries);
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "discodop/disambiguation.pyx":48
 * cdef str NEGATIVECONSTLABEL = '-#-'
 * 
 * cpdef getderivations(Chart chart, int k, bint kbest=True, bint sample=False,             # <<<<<<<<<<<<<<
 * 		derivstrings=True):
 * 	"""Get *k*-best and/or sampled derivations from chart.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_AddTraceback("discodop.disambiguation.getderivations", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_derivations);
  __Pyx_XDECREF(__pyx_v_entries);
  __Pyx_XDECREF(__pyx_v_unused_explored);
  __Pyx_XDECREF(__pyx_v_filteredderivations);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_8discodop_14disambiguation_1getderivations(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8discodop_14disambiguation_getderivations[] = "getderivations(Chart chart, int k, bool kbest=True, bool sample=False, derivstrings=True)\nGet *k*-best and/or sampled derivations from chart.\n\n\t:param k: number of derivations to extract from chart\n\t:param sample: whether to *k* derivations sample from chart\n\t:param kbest: whether to extract *k*-best derivations from chart\n\t:param derivstrings: whether to create derivations as strings\n\t:returns: tuple ``(derivations, entries)``; two lists of equal length:\n\n\t\t:derivations: list of tuples ``(deriv, logprob)`` where deriv is a\n\t\t\tstring; or list of None if ``derivstrings==False``\n\t\t:entries: list of RankedEdge objects.\n\t";
static PyObject *__pyx_pw_8discodop_14disambiguation_1getderivations(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart = 0;
  int __pyx_v_k;
  int __pyx_v_kbest;
  int __pyx_v_sample;
  PyObject *__pyx_v_derivstrings = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("getderivations (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_chart,&__pyx_n_s_k,&__pyx_n_s_kbest,&__pyx_n_s_sample,&__pyx_n_s_derivstrings,0};
    PyObject* values[5] = {0,0,0,0,0};

    /* "discodop/disambiguation.pyx":49
 * 
 * cpdef getderivations(Chart chart, int k, bint kbest=True, bint sample=False,
 * 		derivstrings=True):             # <<<<<<<<<<<<<<
 * 	"""Get *k*-best and/or sampled derivations from chart.
 * 
 */
    values[4] = ((PyObject *)Py_True);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chart)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_k)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("getderivations", 0, 2, 5, 1); __PYX_ERR(0, 48, __pyx_L3_error)
        }
        case  2:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_kbest);
          if (value) { values[2] = value; kw_args--; }
        }
        case  3:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sample);
          if (value) { values[3] = value; kw_args--; }
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_derivstrings);
          if (value) { values[4] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "getderivations") < 0)) __PYX_ERR(0, 48, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        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_chart = ((struct __pyx_obj_8discodop_10containers_Chart *)values[0]);
    __pyx_v_k = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_k == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 48, __pyx_L3_error)
    if (values[2]) {
      __pyx_v_kbest = __Pyx_PyObject_IsTrue(values[2]); if (unlikely((__pyx_v_kbest == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 48, __pyx_L3_error)
    } else {

      /* "discodop/disambiguation.pyx":48
 * cdef str NEGATIVECONSTLABEL = '-#-'
 * 
 * cpdef getderivations(Chart chart, int k, bint kbest=True, bint sample=False,             # <<<<<<<<<<<<<<
 * 		derivstrings=True):
 * 	"""Get *k*-best and/or sampled derivations from chart.
 */
      __pyx_v_kbest = ((int)1);
    }
    if (values[3]) {
      __pyx_v_sample = __Pyx_PyObject_IsTrue(values[3]); if (unlikely((__pyx_v_sample == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 48, __pyx_L3_error)
    } else {
      __pyx_v_sample = ((int)0);
    }
    __pyx_v_derivstrings = values[4];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("getderivations", 0, 2, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 48, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discodop.disambiguation.getderivations", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_chart), __pyx_ptype_8discodop_10containers_Chart, 1, "chart", 0))) __PYX_ERR(0, 48, __pyx_L1_error)
  __pyx_r = __pyx_pf_8discodop_14disambiguation_getderivations(__pyx_self, __pyx_v_chart, __pyx_v_k, __pyx_v_kbest, __pyx_v_sample, __pyx_v_derivstrings);

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8discodop_14disambiguation_getderivations(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, int __pyx_v_k, int __pyx_v_kbest, int __pyx_v_sample, PyObject *__pyx_v_derivstrings) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_8discodop_14disambiguation_getderivations __pyx_t_2;
  __Pyx_RefNannySetupContext("getderivations", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 3;
  __pyx_t_2.kbest = __pyx_v_kbest;
  __pyx_t_2.sample = __pyx_v_sample;
  __pyx_t_2.derivstrings = __pyx_v_derivstrings;
  __pyx_t_1 = __pyx_f_8discodop_14disambiguation_getderivations(__pyx_v_chart, __pyx_v_k, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 48, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discodop.disambiguation.getderivations", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discodop/disambiguation.pyx":80
 * 
 * 
 * cpdef marginalize(method, list derivations, list entries, Chart chart,             # <<<<<<<<<<<<<<
 * 		list backtransform=None, list sent=None, list tags=None,
 * 		int k=1000, int sldop_n=7, double mcc_labda=1.0, set mcc_labels=None,
 */

static PyObject *__pyx_pw_8discodop_14disambiguation_3marginalize(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_8discodop_14disambiguation_marginalize(PyObject *__pyx_v_method, PyObject *__pyx_v_derivations, PyObject *__pyx_v_entries, struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, CYTHON_UNUSED int __pyx_skip_dispatch, struct __pyx_opt_args_8discodop_14disambiguation_marginalize *__pyx_optional_args) {

  /* "discodop/disambiguation.pyx":81
 * 
 * cpdef marginalize(method, list derivations, list entries, Chart chart,
 * 		list backtransform=None, list sent=None, list tags=None,             # <<<<<<<<<<<<<<
 * 		int k=1000, int sldop_n=7, double mcc_labda=1.0, set mcc_labels=None,
 * 		bint bitpar=False):
 */
  PyObject *__pyx_v_backtransform = ((PyObject*)Py_None);
  PyObject *__pyx_v_sent = ((PyObject*)Py_None);
  PyObject *__pyx_v_tags = ((PyObject*)Py_None);
  int __pyx_v_k = ((int)0x3E8);
  int __pyx_v_sldop_n = ((int)7);
  double __pyx_v_mcc_labda = ((double)1.0);

  /* "discodop/disambiguation.pyx":82
 * cpdef marginalize(method, list derivations, list entries, Chart chart,
 * 		list backtransform=None, list sent=None, list tags=None,
 * 		int k=1000, int sldop_n=7, double mcc_labda=1.0, set mcc_labels=None,             # <<<<<<<<<<<<<<
 * 		bint bitpar=False):
 * 	"""Take a list of derivations and optimize a given objective function.
 */
  PyObject *__pyx_v_mcc_labels = ((PyObject*)Py_None);

  /* "discodop/disambiguation.pyx":83
 * 		list backtransform=None, list sent=None, list tags=None,
 * 		int k=1000, int sldop_n=7, double mcc_labda=1.0, set mcc_labels=None,
 * 		bint bitpar=False):             # <<<<<<<<<<<<<<
 * 	"""Take a list of derivations and optimize a given objective function.
 * 
 */
  int __pyx_v_bitpar = ((int)0);
  int __pyx_v_mpd;
  int __pyx_v_shortest;
  int __pyx_v_dopreduction;
  struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *__pyx_v_entry = 0;
  struct __pyx_obj_8discodop_10containers_LexicalRule *__pyx_v_lexrule = 0;
  PyObject *__pyx_v_parsetrees = 0;
  PyObject *__pyx_v_derivs = 0;
  PyObject *__pyx_v_treestr = 0;
  PyObject *__pyx_v_deriv = 0;
  double __pyx_v_prob;
  double __pyx_v_maxprob;
  int __pyx_v_m;
  CYTHON_UNUSED PyObject *__pyx_v__ = NULL;
  PyObject *__pyx_v_newprob = NULL;
  PyObject *__pyx_v_score = NULL;
  PyObject *__pyx_v_tree = NULL;
  PyObject *__pyx_v_t = NULL;
  PyObject *__pyx_v_oldscore = NULL;
  PyObject *__pyx_v_results = NULL;
  PyObject *__pyx_v_msg = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  int __pyx_t_2;
  PyObject *__pyx_t_3 = NULL;
  int __pyx_t_4;
  Py_ssize_t __pyx_t_5;
  PyObject *__pyx_t_6 = NULL;
  double __pyx_t_7;
  PyObject *__pyx_t_8 = NULL;
  PyObject *(*__pyx_t_9)(PyObject *);
  PyObject *__pyx_t_10 = NULL;
  PyObject *__pyx_t_11 = NULL;
  struct __pyx_opt_args_8discodop_14disambiguation_maxconstituentscorrect __pyx_t_12;
  PyObject *__pyx_t_13 = NULL;
  PyObject *__pyx_t_14 = NULL;
  PyObject *__pyx_t_15 = NULL;
  int __pyx_t_16;
  int __pyx_t_17;
  PyObject *(*__pyx_t_18)(PyObject *);
  PyObject *__pyx_t_19 = NULL;
  int __pyx_t_20;
  Py_ssize_t __pyx_t_21;
  PyObject *(*__pyx_t_22)(PyObject *);
  Py_ssize_t __pyx_t_23;
  int __pyx_t_24;
  PyObject *__pyx_t_25 = NULL;
  PyObject *__pyx_t_26 = NULL;
  __Pyx_RefNannySetupContext("marginalize", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_backtransform = __pyx_optional_args->backtransform;
      if (__pyx_optional_args->__pyx_n > 1) {
        __pyx_v_sent = __pyx_optional_args->sent;
        if (__pyx_optional_args->__pyx_n > 2) {
          __pyx_v_tags = __pyx_optional_args->tags;
          if (__pyx_optional_args->__pyx_n > 3) {
            __pyx_v_k = __pyx_optional_args->k;
            if (__pyx_optional_args->__pyx_n > 4) {
              __pyx_v_sldop_n = __pyx_optional_args->sldop_n;
              if (__pyx_optional_args->__pyx_n > 5) {
                __pyx_v_mcc_labda = __pyx_optional_args->mcc_labda;
                if (__pyx_optional_args->__pyx_n > 6) {
                  __pyx_v_mcc_labels = __pyx_optional_args->mcc_labels;
                  if (__pyx_optional_args->__pyx_n > 7) {
                    __pyx_v_bitpar = __pyx_optional_args->bitpar;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  __Pyx_INCREF(__pyx_v_derivations);
  __Pyx_INCREF(__pyx_v_entries);

  /* "discodop/disambiguation.pyx":122
 * 		:msg: a message reporting the number of derivations / parses.
 * 	"""
 * 	cdef bint mpd = method == 'mpd'             # <<<<<<<<<<<<<<
 * 	cdef bint shortest = method == 'shortest'
 * 	cdef bint dopreduction = backtransform is None
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_method, __pyx_n_u_mpd, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 122, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 122, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_mpd = __pyx_t_2;

  /* "discodop/disambiguation.pyx":123
 * 	"""
 * 	cdef bint mpd = method == 'mpd'
 * 	cdef bint shortest = method == 'shortest'             # <<<<<<<<<<<<<<
 * 	cdef bint dopreduction = backtransform is None
 * 	cdef DoubleEntry entry
 */
  __pyx_t_1 = PyObject_RichCompare(__pyx_v_method, __pyx_n_u_shortest, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 123, __pyx_L1_error)
  __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 123, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_shortest = __pyx_t_2;

  /* "discodop/disambiguation.pyx":124
 * 	cdef bint mpd = method == 'mpd'
 * 	cdef bint shortest = method == 'shortest'
 * 	cdef bint dopreduction = backtransform is None             # <<<<<<<<<<<<<<
 * 	cdef DoubleEntry entry
 * 	cdef LexicalRule lexrule
 */
  __pyx_t_2 = (__pyx_v_backtransform == ((PyObject*)Py_None));
  __pyx_v_dopreduction = __pyx_t_2;

  /* "discodop/disambiguation.pyx":127
 * 	cdef DoubleEntry entry
 * 	cdef LexicalRule lexrule
 * 	cdef dict parsetrees = {}, derivs = {}             # <<<<<<<<<<<<<<
 * 	cdef str treestr, deriv
 * 	cdef double prob, maxprob
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 127, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_parsetrees = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 127, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_derivs = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":132
 * 	cdef int m
 * 
 * 	if method == 'sl-dop':             # <<<<<<<<<<<<<<
 * 		return sldop(dict(derivations), chart, sent, tags, k, sldop_n,
 * 				backtransform, entries, bitpar)
 */
  __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_method, __pyx_kp_u_sl_dop, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 132, __pyx_L1_error)
  if (__pyx_t_2) {

    /* "discodop/disambiguation.pyx":133
 * 
 * 	if method == 'sl-dop':
 * 		return sldop(dict(derivations), chart, sent, tags, k, sldop_n,             # <<<<<<<<<<<<<<
 * 				backtransform, entries, bitpar)
 * 	elif method == 'sl-dop-simple':
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_derivations);
    __Pyx_GIVEREF(__pyx_v_derivations);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_derivations);
    __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)(&PyDict_Type)), __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "discodop/disambiguation.pyx":134
 * 	if method == 'sl-dop':
 * 		return sldop(dict(derivations), chart, sent, tags, k, sldop_n,
 * 				backtransform, entries, bitpar)             # <<<<<<<<<<<<<<
 * 	elif method == 'sl-dop-simple':
 * 		return sldop_simple(dict(derivations), entries, sldop_n, chart,
 */
    __pyx_t_1 = __pyx_f_8discodop_14disambiguation_sldop(((PyObject*)__pyx_t_3), __pyx_v_chart, __pyx_v_sent, __pyx_v_tags, __pyx_v_k, __pyx_v_sldop_n, __pyx_v_backtransform, __pyx_v_entries, __pyx_v_bitpar); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "discodop/disambiguation.pyx":132
 * 	cdef int m
 * 
 * 	if method == 'sl-dop':             # <<<<<<<<<<<<<<
 * 		return sldop(dict(derivations), chart, sent, tags, k, sldop_n,
 * 				backtransform, entries, bitpar)
 */
  }

  /* "discodop/disambiguation.pyx":135
 * 		return sldop(dict(derivations), chart, sent, tags, k, sldop_n,
 * 				backtransform, entries, bitpar)
 * 	elif method == 'sl-dop-simple':             # <<<<<<<<<<<<<<
 * 		return sldop_simple(dict(derivations), entries, sldop_n, chart,
 * 				backtransform, bitpar)
 */
  __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_method, __pyx_kp_u_sl_dop_simple, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 135, __pyx_L1_error)
  if (__pyx_t_2) {

    /* "discodop/disambiguation.pyx":136
 * 				backtransform, entries, bitpar)
 * 	elif method == 'sl-dop-simple':
 * 		return sldop_simple(dict(derivations), entries, sldop_n, chart,             # <<<<<<<<<<<<<<
 * 				backtransform, bitpar)
 * 	elif method == 'shortest':
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 136, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_v_derivations);
    __Pyx_GIVEREF(__pyx_v_derivations);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_derivations);
    __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)(&PyDict_Type)), __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 136, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "discodop/disambiguation.pyx":137
 * 	elif method == 'sl-dop-simple':
 * 		return sldop_simple(dict(derivations), entries, sldop_n, chart,
 * 				backtransform, bitpar)             # <<<<<<<<<<<<<<
 * 	elif method == 'shortest':
 * 		# filter out all derivations which are not shortest
 */
    __pyx_t_1 = __pyx_f_8discodop_14disambiguation_sldop_simple(((PyObject*)__pyx_t_3), __pyx_v_entries, __pyx_v_sldop_n, __pyx_v_chart, __pyx_v_backtransform, __pyx_v_bitpar); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 136, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_r = __pyx_t_1;
    __pyx_t_1 = 0;
    goto __pyx_L0;

    /* "discodop/disambiguation.pyx":135
 * 		return sldop(dict(derivations), chart, sent, tags, k, sldop_n,
 * 				backtransform, entries, bitpar)
 * 	elif method == 'sl-dop-simple':             # <<<<<<<<<<<<<<
 * 		return sldop_simple(dict(derivations), entries, sldop_n, chart,
 * 				backtransform, bitpar)
 */
  }

  /* "discodop/disambiguation.pyx":138
 * 		return sldop_simple(dict(derivations), entries, sldop_n, chart,
 * 				backtransform, bitpar)
 * 	elif method == 'shortest':             # <<<<<<<<<<<<<<
 * 		# filter out all derivations which are not shortest
 * 		if not dopreduction and not bitpar:
 */
  __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_method, __pyx_n_u_shortest, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 138, __pyx_L1_error)
  if (__pyx_t_2) {

    /* "discodop/disambiguation.pyx":140
 * 	elif method == 'shortest':
 * 		# filter out all derivations which are not shortest
 * 		if not dopreduction and not bitpar:             # <<<<<<<<<<<<<<
 * 			maxprob = min([entry.value for entry in entries])
 * 			entries = [entry for entry in entries if entry.value == maxprob]
 */
    __pyx_t_4 = ((!(__pyx_v_dopreduction != 0)) != 0);
    if (__pyx_t_4) {
    } else {
      __pyx_t_2 = __pyx_t_4;
      goto __pyx_L5_bool_binop_done;
    }
    __pyx_t_4 = ((!(__pyx_v_bitpar != 0)) != 0);
    __pyx_t_2 = __pyx_t_4;
    __pyx_L5_bool_binop_done:;
    if (__pyx_t_2) {

      /* "discodop/disambiguation.pyx":141
 * 		# filter out all derivations which are not shortest
 * 		if not dopreduction and not bitpar:
 * 			maxprob = min([entry.value for entry in entries])             # <<<<<<<<<<<<<<
 * 			entries = [entry for entry in entries if entry.value == maxprob]
 * 		elif derivations:
 */
      { /* enter inner scope */
        struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *__pyx_7genexpr__pyx_v_entry = NULL;
        __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 141, __pyx_L9_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (unlikely(__pyx_v_entries == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
          __PYX_ERR(0, 141, __pyx_L9_error)
        }
        __pyx_t_3 = __pyx_v_entries; __Pyx_INCREF(__pyx_t_3); __pyx_t_5 = 0;
        for (;;) {
          if (__pyx_t_5 >= 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_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 141, __pyx_L9_error)
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 141, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
          if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_8discodop_6plcfrs_DoubleEntry))))) __PYX_ERR(0, 141, __pyx_L9_error)
          __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v_entry, ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_6));
          __pyx_t_6 = 0;
          __pyx_t_6 = PyFloat_FromDouble(__pyx_7genexpr__pyx_v_entry->value); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 141, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_6);
          if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 141, __pyx_L9_error)
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        }
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF((PyObject *)__pyx_7genexpr__pyx_v_entry);
        goto __pyx_L12_exit_scope;
        __pyx_L9_error:;
        __Pyx_XDECREF((PyObject *)__pyx_7genexpr__pyx_v_entry);
        goto __pyx_L1_error;
        __pyx_L12_exit_scope:;
      } /* exit inner scope */
      __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 141, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_min, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 141, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_7 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 141, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_v_maxprob = __pyx_t_7;

      /* "discodop/disambiguation.pyx":142
 * 		if not dopreduction and not bitpar:
 * 			maxprob = min([entry.value for entry in entries])
 * 			entries = [entry for entry in entries if entry.value == maxprob]             # <<<<<<<<<<<<<<
 * 		elif derivations:
 * 			_, maxprob = min(derivations, key=itemgetter(1))
 */
      { /* enter inner scope */
        struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *__pyx_8genexpr1__pyx_v_entry = NULL;
        __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 142, __pyx_L15_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (unlikely(__pyx_v_entries == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
          __PYX_ERR(0, 142, __pyx_L15_error)
        }
        __pyx_t_3 = __pyx_v_entries; __Pyx_INCREF(__pyx_t_3); __pyx_t_5 = 0;
        for (;;) {
          if (__pyx_t_5 >= 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_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 142, __pyx_L15_error)
          #else
          __pyx_t_6 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 142, __pyx_L15_error)
          __Pyx_GOTREF(__pyx_t_6);
          #endif
          if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_8discodop_6plcfrs_DoubleEntry))))) __PYX_ERR(0, 142, __pyx_L15_error)
          __Pyx_XDECREF_SET(__pyx_8genexpr1__pyx_v_entry, ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_6));
          __pyx_t_6 = 0;
          __pyx_t_2 = ((__pyx_8genexpr1__pyx_v_entry->value == __pyx_v_maxprob) != 0);
          if (__pyx_t_2) {
            if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_8genexpr1__pyx_v_entry))) __PYX_ERR(0, 142, __pyx_L15_error)
          }
        }
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF((PyObject *)__pyx_8genexpr1__pyx_v_entry);
        goto __pyx_L19_exit_scope;
        __pyx_L15_error:;
        __Pyx_XDECREF((PyObject *)__pyx_8genexpr1__pyx_v_entry);
        goto __pyx_L1_error;
        __pyx_L19_exit_scope:;
      } /* exit inner scope */
      __Pyx_DECREF_SET(__pyx_v_entries, ((PyObject*)__pyx_t_1));
      __pyx_t_1 = 0;

      /* "discodop/disambiguation.pyx":140
 * 	elif method == 'shortest':
 * 		# filter out all derivations which are not shortest
 * 		if not dopreduction and not bitpar:             # <<<<<<<<<<<<<<
 * 			maxprob = min([entry.value for entry in entries])
 * 			entries = [entry for entry in entries if entry.value == maxprob]
 */
      goto __pyx_L4;
    }

    /* "discodop/disambiguation.pyx":143
 * 			maxprob = min([entry.value for entry in entries])
 * 			entries = [entry for entry in entries if entry.value == maxprob]
 * 		elif derivations:             # <<<<<<<<<<<<<<
 * 			_, maxprob = min(derivations, key=itemgetter(1))
 * 			derivations = [(deriv, prob) for deriv, prob in derivations
 */
    __pyx_t_2 = (__pyx_v_derivations != Py_None) && (PyList_GET_SIZE(__pyx_v_derivations) != 0);
    if (__pyx_t_2) {

      /* "discodop/disambiguation.pyx":144
 * 			entries = [entry for entry in entries if entry.value == maxprob]
 * 		elif derivations:
 * 			_, maxprob = min(derivations, key=itemgetter(1))             # <<<<<<<<<<<<<<
 * 			derivations = [(deriv, prob) for deriv, prob in derivations
 * 					if prob == maxprob]
 */
      __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 144, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_v_derivations);
      __Pyx_GIVEREF(__pyx_v_derivations);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_derivations);
      __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 144, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_itemgetter); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 144, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 144, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_key, __pyx_t_8) < 0) __PYX_ERR(0, 144, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_min, __pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 144, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if ((likely(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) {
        PyObject* sequence = __pyx_t_8;
        #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, 144, __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_1 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_1);
        #else
        __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 144, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 144, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_6 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 144, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __pyx_t_9 = Py_TYPE(__pyx_t_6)->tp_iternext;
        index = 0; __pyx_t_3 = __pyx_t_9(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L20_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_3);
        index = 1; __pyx_t_1 = __pyx_t_9(__pyx_t_6); if (unlikely(!__pyx_t_1)) goto __pyx_L20_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_1);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_6), 2) < 0) __PYX_ERR(0, 144, __pyx_L1_error)
        __pyx_t_9 = NULL;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        goto __pyx_L21_unpacking_done;
        __pyx_L20_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_9 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 144, __pyx_L1_error)
        __pyx_L21_unpacking_done:;
      }
      __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_7 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 144, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_v__ = __pyx_t_3;
      __pyx_t_3 = 0;
      __pyx_v_maxprob = __pyx_t_7;

      /* "discodop/disambiguation.pyx":145
 * 		elif derivations:
 * 			_, maxprob = min(derivations, key=itemgetter(1))
 * 			derivations = [(deriv, prob) for deriv, prob in derivations             # <<<<<<<<<<<<<<
 * 					if prob == maxprob]
 * 	elif method == 'mcc':
 */
      { /* enter inner scope */
        PyObject *__pyx_8genexpr2__pyx_v_deriv = NULL;
        double __pyx_8genexpr2__pyx_v_prob;
        __pyx_t_8 = PyList_New(0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 145, __pyx_L24_error)
        __Pyx_GOTREF(__pyx_t_8);

        /* "discodop/disambiguation.pyx":146
 * 			_, maxprob = min(derivations, key=itemgetter(1))
 * 			derivations = [(deriv, prob) for deriv, prob in derivations
 * 					if prob == maxprob]             # <<<<<<<<<<<<<<
 * 	elif method == 'mcc':
 * 		return maxconstituentscorrect(derivations, chart,
 */
        if (unlikely(__pyx_v_derivations == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
          __PYX_ERR(0, 146, __pyx_L24_error)
        }

        /* "discodop/disambiguation.pyx":145
 * 		elif derivations:
 * 			_, maxprob = min(derivations, key=itemgetter(1))
 * 			derivations = [(deriv, prob) for deriv, prob in derivations             # <<<<<<<<<<<<<<
 * 					if prob == maxprob]
 * 	elif method == 'mcc':
 */
        __pyx_t_1 = __pyx_v_derivations; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
        for (;;) {
          if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 145, __pyx_L24_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 145, __pyx_L24_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
          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, 145, __pyx_L24_error)
            }
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            if (likely(PyTuple_CheckExact(sequence))) {
              __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); 
              __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); 
            } else {
              __pyx_t_6 = PyList_GET_ITEM(sequence, 0); 
              __pyx_t_10 = PyList_GET_ITEM(sequence, 1); 
            }
            __Pyx_INCREF(__pyx_t_6);
            __Pyx_INCREF(__pyx_t_10);
            #else
            __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 145, __pyx_L24_error)
            __Pyx_GOTREF(__pyx_t_6);
            __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 145, __pyx_L24_error)
            __Pyx_GOTREF(__pyx_t_10);
            #endif
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          } else {
            Py_ssize_t index = -1;
            __pyx_t_11 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 145, __pyx_L24_error)
            __Pyx_GOTREF(__pyx_t_11);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __pyx_t_9 = Py_TYPE(__pyx_t_11)->tp_iternext;
            index = 0; __pyx_t_6 = __pyx_t_9(__pyx_t_11); if (unlikely(!__pyx_t_6)) goto __pyx_L27_unpacking_failed;
            __Pyx_GOTREF(__pyx_t_6);
            index = 1; __pyx_t_10 = __pyx_t_9(__pyx_t_11); if (unlikely(!__pyx_t_10)) goto __pyx_L27_unpacking_failed;
            __Pyx_GOTREF(__pyx_t_10);
            if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_11), 2) < 0) __PYX_ERR(0, 145, __pyx_L24_error)
            __pyx_t_9 = NULL;
            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
            goto __pyx_L28_unpacking_done;
            __pyx_L27_unpacking_failed:;
            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
            __pyx_t_9 = NULL;
            if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
            __PYX_ERR(0, 145, __pyx_L24_error)
            __pyx_L28_unpacking_done:;
          }
          if (!(likely(PyUnicode_CheckExact(__pyx_t_6))||((__pyx_t_6) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_6)->tp_name), 0))) __PYX_ERR(0, 145, __pyx_L24_error)
          __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_t_10); if (unlikely((__pyx_t_7 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 145, __pyx_L24_error)
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_XDECREF_SET(__pyx_8genexpr2__pyx_v_deriv, ((PyObject*)__pyx_t_6));
          __pyx_t_6 = 0;
          __pyx_8genexpr2__pyx_v_prob = __pyx_t_7;

          /* "discodop/disambiguation.pyx":146
 * 			_, maxprob = min(derivations, key=itemgetter(1))
 * 			derivations = [(deriv, prob) for deriv, prob in derivations
 * 					if prob == maxprob]             # <<<<<<<<<<<<<<
 * 	elif method == 'mcc':
 * 		return maxconstituentscorrect(derivations, chart,
 */
          __pyx_t_2 = ((__pyx_8genexpr2__pyx_v_prob == __pyx_v_maxprob) != 0);
          if (__pyx_t_2) {

            /* "discodop/disambiguation.pyx":145
 * 		elif derivations:
 * 			_, maxprob = min(derivations, key=itemgetter(1))
 * 			derivations = [(deriv, prob) for deriv, prob in derivations             # <<<<<<<<<<<<<<
 * 					if prob == maxprob]
 * 	elif method == 'mcc':
 */
            __pyx_t_3 = PyFloat_FromDouble(__pyx_8genexpr2__pyx_v_prob); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 145, __pyx_L24_error)
            __Pyx_GOTREF(__pyx_t_3);
            __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 145, __pyx_L24_error)
            __Pyx_GOTREF(__pyx_t_10);
            __Pyx_INCREF(__pyx_8genexpr2__pyx_v_deriv);
            __Pyx_GIVEREF(__pyx_8genexpr2__pyx_v_deriv);
            PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_8genexpr2__pyx_v_deriv);
            __Pyx_GIVEREF(__pyx_t_3);
            PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_3);
            __pyx_t_3 = 0;
            if (unlikely(__Pyx_ListComp_Append(__pyx_t_8, (PyObject*)__pyx_t_10))) __PYX_ERR(0, 145, __pyx_L24_error)
            __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

            /* "discodop/disambiguation.pyx":146
 * 			_, maxprob = min(derivations, key=itemgetter(1))
 * 			derivations = [(deriv, prob) for deriv, prob in derivations
 * 					if prob == maxprob]             # <<<<<<<<<<<<<<
 * 	elif method == 'mcc':
 * 		return maxconstituentscorrect(derivations, chart,
 */
          }

          /* "discodop/disambiguation.pyx":145
 * 		elif derivations:
 * 			_, maxprob = min(derivations, key=itemgetter(1))
 * 			derivations = [(deriv, prob) for deriv, prob in derivations             # <<<<<<<<<<<<<<
 * 					if prob == maxprob]
 * 	elif method == 'mcc':
 */
        }
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_deriv);
        goto __pyx_L30_exit_scope;
        __pyx_L24_error:;
        __Pyx_XDECREF(__pyx_8genexpr2__pyx_v_deriv);
        goto __pyx_L1_error;
        __pyx_L30_exit_scope:;
      } /* exit inner scope */
      __Pyx_DECREF_SET(__pyx_v_derivations, ((PyObject*)__pyx_t_8));
      __pyx_t_8 = 0;

      /* "discodop/disambiguation.pyx":143
 * 			maxprob = min([entry.value for entry in entries])
 * 			entries = [entry for entry in entries if entry.value == maxprob]
 * 		elif derivations:             # <<<<<<<<<<<<<<
 * 			_, maxprob = min(derivations, key=itemgetter(1))
 * 			derivations = [(deriv, prob) for deriv, prob in derivations
 */
    }
    __pyx_L4:;

    /* "discodop/disambiguation.pyx":138
 * 		return sldop_simple(dict(derivations), entries, sldop_n, chart,
 * 				backtransform, bitpar)
 * 	elif method == 'shortest':             # <<<<<<<<<<<<<<
 * 		# filter out all derivations which are not shortest
 * 		if not dopreduction and not bitpar:
 */
    goto __pyx_L3;
  }

  /* "discodop/disambiguation.pyx":147
 * 			derivations = [(deriv, prob) for deriv, prob in derivations
 * 					if prob == maxprob]
 * 	elif method == 'mcc':             # <<<<<<<<<<<<<<
 * 		return maxconstituentscorrect(derivations, chart,
 * 				backtransform, mcc_labda, mcc_labels)
 */
  __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_method, __pyx_n_u_mcc, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 147, __pyx_L1_error)
  if (__pyx_t_2) {

    /* "discodop/disambiguation.pyx":148
 * 					if prob == maxprob]
 * 	elif method == 'mcc':
 * 		return maxconstituentscorrect(derivations, chart,             # <<<<<<<<<<<<<<
 * 				backtransform, mcc_labda, mcc_labels)
 * 
 */
    __Pyx_XDECREF(__pyx_r);

    /* "discodop/disambiguation.pyx":149
 * 	elif method == 'mcc':
 * 		return maxconstituentscorrect(derivations, chart,
 * 				backtransform, mcc_labda, mcc_labels)             # <<<<<<<<<<<<<<
 * 
 * 	if not dopreduction and not bitpar:  # Double-DOP
 */
    __pyx_t_12.__pyx_n = 1;
    __pyx_t_12.labels = __pyx_v_mcc_labels;
    __pyx_t_8 = __pyx_f_8discodop_14disambiguation_maxconstituentscorrect(__pyx_v_derivations, __pyx_v_chart, __pyx_v_backtransform, __pyx_v_mcc_labda, &__pyx_t_12); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 148, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_r = __pyx_t_8;
    __pyx_t_8 = 0;
    goto __pyx_L0;

    /* "discodop/disambiguation.pyx":147
 * 			derivations = [(deriv, prob) for deriv, prob in derivations
 * 					if prob == maxprob]
 * 	elif method == 'mcc':             # <<<<<<<<<<<<<<
 * 		return maxconstituentscorrect(derivations, chart,
 * 				backtransform, mcc_labda, mcc_labels)
 */
  }
  __pyx_L3:;

  /* "discodop/disambiguation.pyx":151
 * 				backtransform, mcc_labda, mcc_labels)
 * 
 * 	if not dopreduction and not bitpar:  # Double-DOP             # <<<<<<<<<<<<<<
 * 		for entry in entries:
 * 			prob = entry.value
 */
  __pyx_t_4 = ((!(__pyx_v_dopreduction != 0)) != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L32_bool_binop_done;
  }
  __pyx_t_4 = ((!(__pyx_v_bitpar != 0)) != 0);
  __pyx_t_2 = __pyx_t_4;
  __pyx_L32_bool_binop_done:;
  if (__pyx_t_2) {

    /* "discodop/disambiguation.pyx":152
 * 
 * 	if not dopreduction and not bitpar:  # Double-DOP
 * 		for entry in entries:             # <<<<<<<<<<<<<<
 * 			prob = entry.value
 * 			try:
 */
    if (unlikely(__pyx_v_entries == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 152, __pyx_L1_error)
    }
    __pyx_t_8 = __pyx_v_entries; __Pyx_INCREF(__pyx_t_8); __pyx_t_5 = 0;
    for (;;) {
      if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_8)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_1 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 152, __pyx_L1_error)
      #else
      __pyx_t_1 = PySequence_ITEM(__pyx_t_8, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 152, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      #endif
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8discodop_6plcfrs_DoubleEntry))))) __PYX_ERR(0, 152, __pyx_L1_error)
      __Pyx_XDECREF_SET(__pyx_v_entry, ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_1));
      __pyx_t_1 = 0;

      /* "discodop/disambiguation.pyx":153
 * 	if not dopreduction and not bitpar:  # Double-DOP
 * 		for entry in entries:
 * 			prob = entry.value             # <<<<<<<<<<<<<<
 * 			try:
 * 				treestr = recoverfragments(entry.key, chart, backtransform)
 */
      __pyx_t_7 = __pyx_v_entry->value;
      __pyx_v_prob = __pyx_t_7;

      /* "discodop/disambiguation.pyx":154
 * 		for entry in entries:
 * 			prob = entry.value
 * 			try:             # <<<<<<<<<<<<<<
 * 				treestr = recoverfragments(entry.key, chart, backtransform)
 * 			except:
 */
      {
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        __Pyx_ExceptionSave(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15);
        __Pyx_XGOTREF(__pyx_t_13);
        __Pyx_XGOTREF(__pyx_t_14);
        __Pyx_XGOTREF(__pyx_t_15);
        /*try:*/ {

          /* "discodop/disambiguation.pyx":155
 * 			prob = entry.value
 * 			try:
 * 				treestr = recoverfragments(entry.key, chart, backtransform)             # <<<<<<<<<<<<<<
 * 			except:
 * 				continue
 */
          __pyx_t_1 = __pyx_v_entry->key;
          __Pyx_INCREF(__pyx_t_1);
          __pyx_t_10 = __pyx_f_8discodop_14disambiguation_recoverfragments(__pyx_t_1, __pyx_v_chart, __pyx_v_backtransform, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 155, __pyx_L36_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_XDECREF_SET(__pyx_v_treestr, ((PyObject*)__pyx_t_10));
          __pyx_t_10 = 0;

          /* "discodop/disambiguation.pyx":154
 * 		for entry in entries:
 * 			prob = entry.value
 * 			try:             # <<<<<<<<<<<<<<
 * 				treestr = recoverfragments(entry.key, chart, backtransform)
 * 			except:
 */
        }
        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
        __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
        __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
        goto __pyx_L43_try_end;
        __pyx_L36_error:;
        __Pyx_PyThreadState_assign
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;

        /* "discodop/disambiguation.pyx":156
 * 			try:
 * 				treestr = recoverfragments(entry.key, chart, backtransform)
 * 			except:             # <<<<<<<<<<<<<<
 * 				continue
 * 			if shortest:
 */
        /*except:*/ {
          __Pyx_AddTraceback("discodop.disambiguation.marginalize", __pyx_clineno, __pyx_lineno, __pyx_filename);
          if (__Pyx_GetException(&__pyx_t_10, &__pyx_t_1, &__pyx_t_3) < 0) __PYX_ERR(0, 156, __pyx_L38_except_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_GOTREF(__pyx_t_1);
          __Pyx_GOTREF(__pyx_t_3);

          /* "discodop/disambiguation.pyx":157
 * 				treestr = recoverfragments(entry.key, chart, backtransform)
 * 			except:
 * 				continue             # <<<<<<<<<<<<<<
 * 			if shortest:
 * 				# for purposes of tie breaking, calculate the derivation
 */
          goto __pyx_L45_except_continue;
          __pyx_L45_except_continue:;
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          goto __pyx_L42_try_continue;
        }
        __pyx_L38_except_error:;

        /* "discodop/disambiguation.pyx":154
 * 		for entry in entries:
 * 			prob = entry.value
 * 			try:             # <<<<<<<<<<<<<<
 * 				treestr = recoverfragments(entry.key, chart, backtransform)
 * 			except:
 */
        __Pyx_PyThreadState_assign
        __Pyx_XGIVEREF(__pyx_t_13);
        __Pyx_XGIVEREF(__pyx_t_14);
        __Pyx_XGIVEREF(__pyx_t_15);
        __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15);
        goto __pyx_L1_error;
        __pyx_L42_try_continue:;
        __Pyx_PyThreadState_assign
        __Pyx_XGIVEREF(__pyx_t_13);
        __Pyx_XGIVEREF(__pyx_t_14);
        __Pyx_XGIVEREF(__pyx_t_15);
        __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15);
        goto __pyx_L34_continue;
        __pyx_L43_try_end:;
      }

      /* "discodop/disambiguation.pyx":158
 * 			except:
 * 				continue
 * 			if shortest:             # <<<<<<<<<<<<<<
 * 				# for purposes of tie breaking, calculate the derivation
 * 				# probability in a different model.
 */
      __pyx_t_2 = (__pyx_v_shortest != 0);
      if (__pyx_t_2) {

        /* "discodop/disambiguation.pyx":161
 * 				# for purposes of tie breaking, calculate the derivation
 * 				# probability in a different model.
 * 				newprob = exp(-getderivprob(entry.key, chart, sent))             # <<<<<<<<<<<<<<
 * 				score = (int(prob / log(0.5)), newprob)
 * 				if treestr not in parsetrees or score > parsetrees[treestr]:
 */
        __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_exp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 161, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        if (!(likely(((__pyx_v_entry->key) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_entry->key, __pyx_ptype_8discodop_10containers_RankedEdge))))) __PYX_ERR(0, 161, __pyx_L1_error)
        __pyx_t_10 = __pyx_v_entry->key;
        __Pyx_INCREF(__pyx_t_10);
        __pyx_t_6 = PyFloat_FromDouble((-__pyx_f_8discodop_14disambiguation_getderivprob(((struct __pyx_obj_8discodop_10containers_RankedEdge *)__pyx_t_10), __pyx_v_chart, __pyx_v_sent))); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 161, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_10 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
          __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_1);
          if (likely(__pyx_t_10)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
            __Pyx_INCREF(__pyx_t_10);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_1, function);
          }
        }
        if (!__pyx_t_10) {
          __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 161, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_GOTREF(__pyx_t_3);
        } else {
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_1)) {
            PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_6};
            __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 161, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
            PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_6};
            __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 161, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          } else
          #endif
          {
            __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 161, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_11);
            __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10); __pyx_t_10 = NULL;
            __Pyx_GIVEREF(__pyx_t_6);
            PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_t_6);
            __pyx_t_6 = 0;
            __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_11, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 161, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          }
        }
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_XDECREF_SET(__pyx_v_newprob, __pyx_t_3);
        __pyx_t_3 = 0;

        /* "discodop/disambiguation.pyx":162
 * 				# probability in a different model.
 * 				newprob = exp(-getderivprob(entry.key, chart, sent))
 * 				score = (int(prob / log(0.5)), newprob)             # <<<<<<<<<<<<<<
 * 				if treestr not in parsetrees or score > parsetrees[treestr]:
 * 					parsetrees[treestr] = score
 */
        __pyx_t_3 = PyFloat_FromDouble(__pyx_v_prob); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 162, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_log); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 162, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 162, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_t_3, __pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 162, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __pyx_t_11 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 162, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 162, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_11);
        PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_11);
        __Pyx_INCREF(__pyx_v_newprob);
        __Pyx_GIVEREF(__pyx_v_newprob);
        PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_newprob);
        __pyx_t_11 = 0;
        __Pyx_XDECREF_SET(__pyx_v_score, ((PyObject*)__pyx_t_1));
        __pyx_t_1 = 0;

        /* "discodop/disambiguation.pyx":163
 * 				newprob = exp(-getderivprob(entry.key, chart, sent))
 * 				score = (int(prob / log(0.5)), newprob)
 * 				if treestr not in parsetrees or score > parsetrees[treestr]:             # <<<<<<<<<<<<<<
 * 					parsetrees[treestr] = score
 * 					derivs[treestr] = entry.key
 */
        __pyx_t_4 = (__Pyx_PyDict_ContainsTF(__pyx_v_treestr, __pyx_v_parsetrees, Py_NE)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 163, __pyx_L1_error)
        __pyx_t_16 = (__pyx_t_4 != 0);
        if (!__pyx_t_16) {
        } else {
          __pyx_t_2 = __pyx_t_16;
          goto __pyx_L48_bool_binop_done;
        }
        __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_parsetrees, __pyx_v_treestr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 163, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_11 = PyObject_RichCompare(__pyx_v_score, __pyx_t_1, Py_GT); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 163, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 163, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __pyx_t_2 = __pyx_t_16;
        __pyx_L48_bool_binop_done:;
        if (__pyx_t_2) {

          /* "discodop/disambiguation.pyx":164
 * 				score = (int(prob / log(0.5)), newprob)
 * 				if treestr not in parsetrees or score > parsetrees[treestr]:
 * 					parsetrees[treestr] = score             # <<<<<<<<<<<<<<
 * 					derivs[treestr] = entry.key
 * 			elif not mpd and treestr in parsetrees:
 */
          if (unlikely(PyDict_SetItem(__pyx_v_parsetrees, __pyx_v_treestr, __pyx_v_score) < 0)) __PYX_ERR(0, 164, __pyx_L1_error)

          /* "discodop/disambiguation.pyx":165
 * 				if treestr not in parsetrees or score > parsetrees[treestr]:
 * 					parsetrees[treestr] = score
 * 					derivs[treestr] = entry.key             # <<<<<<<<<<<<<<
 * 			elif not mpd and treestr in parsetrees:
 * 				parsetrees[treestr].append(-prob)
 */
          __pyx_t_11 = __pyx_v_entry->key;
          __Pyx_INCREF(__pyx_t_11);
          if (unlikely(PyDict_SetItem(__pyx_v_derivs, __pyx_v_treestr, __pyx_t_11) < 0)) __PYX_ERR(0, 165, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

          /* "discodop/disambiguation.pyx":163
 * 				newprob = exp(-getderivprob(entry.key, chart, sent))
 * 				score = (int(prob / log(0.5)), newprob)
 * 				if treestr not in parsetrees or score > parsetrees[treestr]:             # <<<<<<<<<<<<<<
 * 					parsetrees[treestr] = score
 * 					derivs[treestr] = entry.key
 */
        }

        /* "discodop/disambiguation.pyx":158
 * 			except:
 * 				continue
 * 			if shortest:             # <<<<<<<<<<<<<<
 * 				# for purposes of tie breaking, calculate the derivation
 * 				# probability in a different model.
 */
        goto __pyx_L46;
      }

      /* "discodop/disambiguation.pyx":166
 * 					parsetrees[treestr] = score
 * 					derivs[treestr] = entry.key
 * 			elif not mpd and treestr in parsetrees:             # <<<<<<<<<<<<<<
 * 				parsetrees[treestr].append(-prob)
 * 			elif not mpd or (treestr not in parsetrees
 */
      __pyx_t_16 = ((!(__pyx_v_mpd != 0)) != 0);
      if (__pyx_t_16) {
      } else {
        __pyx_t_2 = __pyx_t_16;
        goto __pyx_L50_bool_binop_done;
      }
      __pyx_t_16 = (__Pyx_PyDict_ContainsTF(__pyx_v_treestr, __pyx_v_parsetrees, Py_EQ)); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 166, __pyx_L1_error)
      __pyx_t_4 = (__pyx_t_16 != 0);
      __pyx_t_2 = __pyx_t_4;
      __pyx_L50_bool_binop_done:;
      if (__pyx_t_2) {

        /* "discodop/disambiguation.pyx":167
 * 					derivs[treestr] = entry.key
 * 			elif not mpd and treestr in parsetrees:
 * 				parsetrees[treestr].append(-prob)             # <<<<<<<<<<<<<<
 * 			elif not mpd or (treestr not in parsetrees
 * 						or -prob > parsetrees[treestr][0]):
 */
        __pyx_t_11 = __Pyx_PyDict_GetItem(__pyx_v_parsetrees, __pyx_v_treestr); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 167, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_1 = PyFloat_FromDouble((-__pyx_v_prob)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 167, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_17 = __Pyx_PyObject_Append(__pyx_t_11, __pyx_t_1); if (unlikely(__pyx_t_17 == -1)) __PYX_ERR(0, 167, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

        /* "discodop/disambiguation.pyx":166
 * 					parsetrees[treestr] = score
 * 					derivs[treestr] = entry.key
 * 			elif not mpd and treestr in parsetrees:             # <<<<<<<<<<<<<<
 * 				parsetrees[treestr].append(-prob)
 * 			elif not mpd or (treestr not in parsetrees
 */
        goto __pyx_L46;
      }

      /* "discodop/disambiguation.pyx":168
 * 			elif not mpd and treestr in parsetrees:
 * 				parsetrees[treestr].append(-prob)
 * 			elif not mpd or (treestr not in parsetrees             # <<<<<<<<<<<<<<
 * 						or -prob > parsetrees[treestr][0]):
 * 				parsetrees[treestr] = [-prob]
 */
      __pyx_t_4 = ((!(__pyx_v_mpd != 0)) != 0);
      if (!__pyx_t_4) {
      } else {
        __pyx_t_2 = __pyx_t_4;
        goto __pyx_L52_bool_binop_done;
      }

      /* "discodop/disambiguation.pyx":169
 * 				parsetrees[treestr].append(-prob)
 * 			elif not mpd or (treestr not in parsetrees
 * 						or -prob > parsetrees[treestr][0]):             # <<<<<<<<<<<<<<
 * 				parsetrees[treestr] = [-prob]
 * 				derivs[treestr] = entry.key
 */
      __pyx_t_4 = (__Pyx_PyDict_ContainsTF(__pyx_v_treestr, __pyx_v_parsetrees, Py_NE)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 168, __pyx_L1_error)

      /* "discodop/disambiguation.pyx":168
 * 			elif not mpd and treestr in parsetrees:
 * 				parsetrees[treestr].append(-prob)
 * 			elif not mpd or (treestr not in parsetrees             # <<<<<<<<<<<<<<
 * 						or -prob > parsetrees[treestr][0]):
 * 				parsetrees[treestr] = [-prob]
 */
      __pyx_t_16 = (__pyx_t_4 != 0);
      if (!__pyx_t_16) {
      } else {
        __pyx_t_2 = __pyx_t_16;
        goto __pyx_L52_bool_binop_done;
      }

      /* "discodop/disambiguation.pyx":169
 * 				parsetrees[treestr].append(-prob)
 * 			elif not mpd or (treestr not in parsetrees
 * 						or -prob > parsetrees[treestr][0]):             # <<<<<<<<<<<<<<
 * 				parsetrees[treestr] = [-prob]
 * 				derivs[treestr] = entry.key
 */
      __pyx_t_1 = PyFloat_FromDouble((-__pyx_v_prob)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 169, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_11 = __Pyx_PyDict_GetItem(__pyx_v_parsetrees, __pyx_v_treestr); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 169, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_11, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 169, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_11 = PyObject_RichCompare(__pyx_t_1, __pyx_t_3, Py_GT); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 169, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 169, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_2 = __pyx_t_16;
      __pyx_L52_bool_binop_done:;

      /* "discodop/disambiguation.pyx":168
 * 			elif not mpd and treestr in parsetrees:
 * 				parsetrees[treestr].append(-prob)
 * 			elif not mpd or (treestr not in parsetrees             # <<<<<<<<<<<<<<
 * 						or -prob > parsetrees[treestr][0]):
 * 				parsetrees[treestr] = [-prob]
 */
      if (__pyx_t_2) {

        /* "discodop/disambiguation.pyx":170
 * 			elif not mpd or (treestr not in parsetrees
 * 						or -prob > parsetrees[treestr][0]):
 * 				parsetrees[treestr] = [-prob]             # <<<<<<<<<<<<<<
 * 				derivs[treestr] = entry.key
 * 	else:  # DOP reduction / bitpar
 */
        __pyx_t_11 = PyFloat_FromDouble((-__pyx_v_prob)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 170, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 170, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_11);
        PyList_SET_ITEM(__pyx_t_3, 0, __pyx_t_11);
        __pyx_t_11 = 0;
        if (unlikely(PyDict_SetItem(__pyx_v_parsetrees, __pyx_v_treestr, __pyx_t_3) < 0)) __PYX_ERR(0, 170, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "discodop/disambiguation.pyx":171
 * 						or -prob > parsetrees[treestr][0]):
 * 				parsetrees[treestr] = [-prob]
 * 				derivs[treestr] = entry.key             # <<<<<<<<<<<<<<
 * 	else:  # DOP reduction / bitpar
 * 		for (deriv, prob), entry in zip(derivations, entries):
 */
        __pyx_t_3 = __pyx_v_entry->key;
        __Pyx_INCREF(__pyx_t_3);
        if (unlikely(PyDict_SetItem(__pyx_v_derivs, __pyx_v_treestr, __pyx_t_3) < 0)) __PYX_ERR(0, 171, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

        /* "discodop/disambiguation.pyx":168
 * 			elif not mpd and treestr in parsetrees:
 * 				parsetrees[treestr].append(-prob)
 * 			elif not mpd or (treestr not in parsetrees             # <<<<<<<<<<<<<<
 * 						or -prob > parsetrees[treestr][0]):
 * 				parsetrees[treestr] = [-prob]
 */
      }
      __pyx_L46:;

      /* "discodop/disambiguation.pyx":152
 * 
 * 	if not dopreduction and not bitpar:  # Double-DOP
 * 		for entry in entries:             # <<<<<<<<<<<<<<
 * 			prob = entry.value
 * 			try:
 */
      __pyx_L34_continue:;
    }
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "discodop/disambiguation.pyx":151
 * 				backtransform, mcc_labda, mcc_labels)
 * 
 * 	if not dopreduction and not bitpar:  # Double-DOP             # <<<<<<<<<<<<<<
 * 		for entry in entries:
 * 			prob = entry.value
 */
    goto __pyx_L31;
  }

  /* "discodop/disambiguation.pyx":173
 * 				derivs[treestr] = entry.key
 * 	else:  # DOP reduction / bitpar
 * 		for (deriv, prob), entry in zip(derivations, entries):             # <<<<<<<<<<<<<<
 * 			if dopreduction:
 * 				treestr = REMOVEIDS.sub('@1' if mpd or shortest else '', deriv)
 */
  /*else*/ {
    __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 173, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_INCREF(__pyx_v_derivations);
    __Pyx_GIVEREF(__pyx_v_derivations);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_derivations);
    __Pyx_INCREF(__pyx_v_entries);
    __Pyx_GIVEREF(__pyx_v_entries);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_entries);
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_8, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 173, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (likely(PyList_CheckExact(__pyx_t_3)) || PyTuple_CheckExact(__pyx_t_3)) {
      __pyx_t_8 = __pyx_t_3; __Pyx_INCREF(__pyx_t_8); __pyx_t_5 = 0;
      __pyx_t_18 = NULL;
    } else {
      __pyx_t_5 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 173, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_18 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 173, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    for (;;) {
      if (likely(!__pyx_t_18)) {
        if (likely(PyList_CheckExact(__pyx_t_8))) {
          if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_8)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_3 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 173, __pyx_L1_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_8, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 173, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
        } else {
          if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 173, __pyx_L1_error)
          #else
          __pyx_t_3 = PySequence_ITEM(__pyx_t_8, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 173, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          #endif
        }
      } else {
        __pyx_t_3 = __pyx_t_18(__pyx_t_8);
        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, 173, __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, 173, __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_1 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_11 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_11);
        __Pyx_INCREF(__pyx_t_1);
        #else
        __pyx_t_11 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 173, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 173, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #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, 173, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_9 = Py_TYPE(__pyx_t_6)->tp_iternext;
        index = 0; __pyx_t_11 = __pyx_t_9(__pyx_t_6); if (unlikely(!__pyx_t_11)) goto __pyx_L57_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_11);
        index = 1; __pyx_t_1 = __pyx_t_9(__pyx_t_6); if (unlikely(!__pyx_t_1)) goto __pyx_L57_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_1);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_6), 2) < 0) __PYX_ERR(0, 173, __pyx_L1_error)
        __pyx_t_9 = NULL;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        goto __pyx_L58_unpacking_done;
        __pyx_L57_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_9 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 173, __pyx_L1_error)
        __pyx_L58_unpacking_done:;
      }
      if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8discodop_6plcfrs_DoubleEntry))))) __PYX_ERR(0, 173, __pyx_L1_error)
      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, 173, __pyx_L1_error)
        }
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        if (likely(PyTuple_CheckExact(sequence))) {
          __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); 
          __pyx_t_10 = PyTuple_GET_ITEM(sequence, 1); 
        } else {
          __pyx_t_6 = PyList_GET_ITEM(sequence, 0); 
          __pyx_t_10 = PyList_GET_ITEM(sequence, 1); 
        }
        __Pyx_INCREF(__pyx_t_6);
        __Pyx_INCREF(__pyx_t_10);
        #else
        __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 173, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 173, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        #endif
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      } else {
        Py_ssize_t index = -1;
        __pyx_t_19 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 173, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_19);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __pyx_t_9 = Py_TYPE(__pyx_t_19)->tp_iternext;
        index = 0; __pyx_t_6 = __pyx_t_9(__pyx_t_19); if (unlikely(!__pyx_t_6)) goto __pyx_L59_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_6);
        index = 1; __pyx_t_10 = __pyx_t_9(__pyx_t_19); if (unlikely(!__pyx_t_10)) goto __pyx_L59_unpacking_failed;
        __Pyx_GOTREF(__pyx_t_10);
        if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_19), 2) < 0) __PYX_ERR(0, 173, __pyx_L1_error)
        __pyx_t_9 = NULL;
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
        goto __pyx_L60_unpacking_done;
        __pyx_L59_unpacking_failed:;
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
        __pyx_t_9 = NULL;
        if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
        __PYX_ERR(0, 173, __pyx_L1_error)
        __pyx_L60_unpacking_done:;
      }
      if (!(likely(PyUnicode_CheckExact(__pyx_t_6))||((__pyx_t_6) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_6)->tp_name), 0))) __PYX_ERR(0, 173, __pyx_L1_error)
      __pyx_t_7 = __pyx_PyFloat_AsDouble(__pyx_t_10); if (unlikely((__pyx_t_7 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 173, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_XDECREF_SET(__pyx_v_deriv, ((PyObject*)__pyx_t_6));
      __pyx_t_6 = 0;
      __pyx_v_prob = __pyx_t_7;
      __Pyx_XDECREF_SET(__pyx_v_entry, ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_1));
      __pyx_t_1 = 0;

      /* "discodop/disambiguation.pyx":174
 * 	else:  # DOP reduction / bitpar
 * 		for (deriv, prob), entry in zip(derivations, entries):
 * 			if dopreduction:             # <<<<<<<<<<<<<<
 * 				treestr = REMOVEIDS.sub('@1' if mpd or shortest else '', deriv)
 * 			else:
 */
      __pyx_t_2 = (__pyx_v_dopreduction != 0);
      if (__pyx_t_2) {

        /* "discodop/disambiguation.pyx":175
 * 		for (deriv, prob), entry in zip(derivations, entries):
 * 			if dopreduction:
 * 				treestr = REMOVEIDS.sub('@1' if mpd or shortest else '', deriv)             # <<<<<<<<<<<<<<
 * 			else:
 * 				try:
 */
        __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_REMOVEIDS); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 175, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_sub); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 175, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __pyx_t_16 = (__pyx_v_mpd != 0);
        if (!__pyx_t_16) {
        } else {
          __pyx_t_2 = __pyx_t_16;
          goto __pyx_L62_bool_binop_done;
        }
        __pyx_t_16 = (__pyx_v_shortest != 0);
        __pyx_t_2 = __pyx_t_16;
        __pyx_L62_bool_binop_done:;
        if (__pyx_t_2) {
          __Pyx_INCREF(__pyx_kp_u_1);
          __pyx_t_1 = __pyx_kp_u_1;
        } else {
          __Pyx_INCREF(__pyx_kp_u__4);
          __pyx_t_1 = __pyx_kp_u__4;
        }
        __pyx_t_10 = NULL;
        __pyx_t_20 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
          __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_11);
          if (likely(__pyx_t_10)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
            __Pyx_INCREF(__pyx_t_10);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_11, function);
            __pyx_t_20 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_11)) {
          PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_t_1, __pyx_v_deriv};
          __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_20, 2+__pyx_t_20); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 175, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) {
          PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_t_1, __pyx_v_deriv};
          __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_20, 2+__pyx_t_20); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 175, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        } else
        #endif
        {
          __pyx_t_6 = PyTuple_New(2+__pyx_t_20); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 175, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          if (__pyx_t_10) {
            __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_10); __pyx_t_10 = NULL;
          }
          __Pyx_GIVEREF(__pyx_t_1);
          PyTuple_SET_ITEM(__pyx_t_6, 0+__pyx_t_20, __pyx_t_1);
          __Pyx_INCREF(__pyx_v_deriv);
          __Pyx_GIVEREF(__pyx_v_deriv);
          PyTuple_SET_ITEM(__pyx_t_6, 1+__pyx_t_20, __pyx_v_deriv);
          __pyx_t_1 = 0;
          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 175, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        }
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        if (!(likely(PyUnicode_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 175, __pyx_L1_error)
        __Pyx_XDECREF_SET(__pyx_v_treestr, ((PyObject*)__pyx_t_3));
        __pyx_t_3 = 0;

        /* "discodop/disambiguation.pyx":174
 * 	else:  # DOP reduction / bitpar
 * 		for (deriv, prob), entry in zip(derivations, entries):
 * 			if dopreduction:             # <<<<<<<<<<<<<<
 * 				treestr = REMOVEIDS.sub('@1' if mpd or shortest else '', deriv)
 * 			else:
 */
        goto __pyx_L61;
      }

      /* "discodop/disambiguation.pyx":177
 * 				treestr = REMOVEIDS.sub('@1' if mpd or shortest else '', deriv)
 * 			else:
 * 				try:             # <<<<<<<<<<<<<<
 * 					treestr = recoverfragments(deriv, chart, backtransform)
 * 				except:
 */
      /*else*/ {
        {
          __Pyx_PyThreadState_declare
          __Pyx_PyThreadState_assign
          __Pyx_ExceptionSave(&__pyx_t_15, &__pyx_t_14, &__pyx_t_13);
          __Pyx_XGOTREF(__pyx_t_15);
          __Pyx_XGOTREF(__pyx_t_14);
          __Pyx_XGOTREF(__pyx_t_13);
          /*try:*/ {

            /* "discodop/disambiguation.pyx":178
 * 			else:
 * 				try:
 * 					treestr = recoverfragments(deriv, chart, backtransform)             # <<<<<<<<<<<<<<
 * 				except:
 * 					continue
 */
            __pyx_t_3 = __pyx_f_8discodop_14disambiguation_recoverfragments(__pyx_v_deriv, __pyx_v_chart, __pyx_v_backtransform, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 178, __pyx_L64_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_XDECREF_SET(__pyx_v_treestr, ((PyObject*)__pyx_t_3));
            __pyx_t_3 = 0;

            /* "discodop/disambiguation.pyx":177
 * 				treestr = REMOVEIDS.sub('@1' if mpd or shortest else '', deriv)
 * 			else:
 * 				try:             # <<<<<<<<<<<<<<
 * 					treestr = recoverfragments(deriv, chart, backtransform)
 * 				except:
 */
          }
          __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
          __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
          goto __pyx_L71_try_end;
          __pyx_L64_error:;
          __Pyx_PyThreadState_assign
          __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
          __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;

          /* "discodop/disambiguation.pyx":179
 * 				try:
 * 					treestr = recoverfragments(deriv, chart, backtransform)
 * 				except:             # <<<<<<<<<<<<<<
 * 					continue
 * 			if shortest:
 */
          /*except:*/ {
            __Pyx_AddTraceback("discodop.disambiguation.marginalize", __pyx_clineno, __pyx_lineno, __pyx_filename);
            if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_11, &__pyx_t_6) < 0) __PYX_ERR(0, 179, __pyx_L66_except_error)
            __Pyx_GOTREF(__pyx_t_3);
            __Pyx_GOTREF(__pyx_t_11);
            __Pyx_GOTREF(__pyx_t_6);

            /* "discodop/disambiguation.pyx":180
 * 					treestr = recoverfragments(deriv, chart, backtransform)
 * 				except:
 * 					continue             # <<<<<<<<<<<<<<
 * 			if shortest:
 * 				if bitpar:
 */
            goto __pyx_L73_except_continue;
            __pyx_L73_except_continue:;
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            goto __pyx_L70_try_continue;
          }
          __pyx_L66_except_error:;

          /* "discodop/disambiguation.pyx":177
 * 				treestr = REMOVEIDS.sub('@1' if mpd or shortest else '', deriv)
 * 			else:
 * 				try:             # <<<<<<<<<<<<<<
 * 					treestr = recoverfragments(deriv, chart, backtransform)
 * 				except:
 */
          __Pyx_PyThreadState_assign
          __Pyx_XGIVEREF(__pyx_t_15);
          __Pyx_XGIVEREF(__pyx_t_14);
          __Pyx_XGIVEREF(__pyx_t_13);
          __Pyx_ExceptionReset(__pyx_t_15, __pyx_t_14, __pyx_t_13);
          goto __pyx_L1_error;
          __pyx_L70_try_continue:;
          __Pyx_PyThreadState_assign
          __Pyx_XGIVEREF(__pyx_t_15);
          __Pyx_XGIVEREF(__pyx_t_14);
          __Pyx_XGIVEREF(__pyx_t_13);
          __Pyx_ExceptionReset(__pyx_t_15, __pyx_t_14, __pyx_t_13);
          goto __pyx_L55_continue;
          __pyx_L71_try_end:;
        }
      }
      __pyx_L61:;

      /* "discodop/disambiguation.pyx":181
 * 				except:
 * 					continue
 * 			if shortest:             # <<<<<<<<<<<<<<
 * 				if bitpar:
 * 					# because with bitpar we don't know which rules have been
 */
      __pyx_t_2 = (__pyx_v_shortest != 0);
      if (__pyx_t_2) {

        /* "discodop/disambiguation.pyx":182
 * 					continue
 * 			if shortest:
 * 				if bitpar:             # <<<<<<<<<<<<<<
 * 					# because with bitpar we don't know which rules have been
 * 					# used, read off the rules from the derivation ...
 */
        __pyx_t_2 = (__pyx_v_bitpar != 0);
        if (__pyx_t_2) {

          /* "discodop/disambiguation.pyx":185
 * 					# because with bitpar we don't know which rules have been
 * 					# used, read off the rules from the derivation ...
 * 					tree = canonicalize(Tree(deriv))             # <<<<<<<<<<<<<<
 * 					newprob = 0.0
 * 					for t in tree.subtrees():
 */
          __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_canonicalize); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 185, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_Tree); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 185, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_1);
          __pyx_t_10 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
            __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_1);
            if (likely(__pyx_t_10)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
              __Pyx_INCREF(__pyx_t_10);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_1, function);
            }
          }
          if (!__pyx_t_10) {
            __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_deriv); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 185, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_3);
          } else {
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_1)) {
              PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_deriv};
              __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 185, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
              __Pyx_GOTREF(__pyx_t_3);
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
              PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_deriv};
              __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 185, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
              __Pyx_GOTREF(__pyx_t_3);
            } else
            #endif
            {
              __pyx_t_19 = PyTuple_New(1+1); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 185, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_19);
              __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_10); __pyx_t_10 = NULL;
              __Pyx_INCREF(__pyx_v_deriv);
              __Pyx_GIVEREF(__pyx_v_deriv);
              PyTuple_SET_ITEM(__pyx_t_19, 0+1, __pyx_v_deriv);
              __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_19, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 185, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_3);
              __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
            }
          }
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
          __pyx_t_1 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
            __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_11);
            if (likely(__pyx_t_1)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
              __Pyx_INCREF(__pyx_t_1);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_11, function);
            }
          }
          if (!__pyx_t_1) {
            __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 185, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            __Pyx_GOTREF(__pyx_t_6);
          } else {
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_11)) {
              PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_3};
              __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 185, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) {
              PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_3};
              __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 185, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
            } else
            #endif
            {
              __pyx_t_19 = PyTuple_New(1+1); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 185, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_19);
              __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_1); __pyx_t_1 = NULL;
              __Pyx_GIVEREF(__pyx_t_3);
              PyTuple_SET_ITEM(__pyx_t_19, 0+1, __pyx_t_3);
              __pyx_t_3 = 0;
              __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_19, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 185, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
            }
          }
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_XDECREF_SET(__pyx_v_tree, __pyx_t_6);
          __pyx_t_6 = 0;

          /* "discodop/disambiguation.pyx":186
 * 					# used, read off the rules from the derivation ...
 * 					tree = canonicalize(Tree(deriv))
 * 					newprob = 0.0             # <<<<<<<<<<<<<<
 * 					for t in tree.subtrees():
 * 						if isinstance(t[0], Tree):
 */
          __Pyx_INCREF(__pyx_float_0_0);
          __Pyx_XDECREF_SET(__pyx_v_newprob, __pyx_float_0_0);

          /* "discodop/disambiguation.pyx":187
 * 					tree = canonicalize(Tree(deriv))
 * 					newprob = 0.0
 * 					for t in tree.subtrees():             # <<<<<<<<<<<<<<
 * 						if isinstance(t[0], Tree):
 * 							if not 1 <= len(t) <= 2:
 */
          __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_subtrees); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 187, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          __pyx_t_19 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
            __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_11);
            if (likely(__pyx_t_19)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
              __Pyx_INCREF(__pyx_t_19);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_11, function);
            }
          }
          if (__pyx_t_19) {
            __pyx_t_6 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_19); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 187, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
          } else {
            __pyx_t_6 = __Pyx_PyObject_CallNoArg(__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 187, __pyx_L1_error)
          }
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          if (likely(PyList_CheckExact(__pyx_t_6)) || PyTuple_CheckExact(__pyx_t_6)) {
            __pyx_t_11 = __pyx_t_6; __Pyx_INCREF(__pyx_t_11); __pyx_t_21 = 0;
            __pyx_t_22 = NULL;
          } else {
            __pyx_t_21 = -1; __pyx_t_11 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 187, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_11);
            __pyx_t_22 = Py_TYPE(__pyx_t_11)->tp_iternext; if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 187, __pyx_L1_error)
          }
          __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
          for (;;) {
            if (likely(!__pyx_t_22)) {
              if (likely(PyList_CheckExact(__pyx_t_11))) {
                if (__pyx_t_21 >= PyList_GET_SIZE(__pyx_t_11)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_6 = PyList_GET_ITEM(__pyx_t_11, __pyx_t_21); __Pyx_INCREF(__pyx_t_6); __pyx_t_21++; if (unlikely(0 < 0)) __PYX_ERR(0, 187, __pyx_L1_error)
                #else
                __pyx_t_6 = PySequence_ITEM(__pyx_t_11, __pyx_t_21); __pyx_t_21++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 187, __pyx_L1_error)
                __Pyx_GOTREF(__pyx_t_6);
                #endif
              } else {
                if (__pyx_t_21 >= PyTuple_GET_SIZE(__pyx_t_11)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_11, __pyx_t_21); __Pyx_INCREF(__pyx_t_6); __pyx_t_21++; if (unlikely(0 < 0)) __PYX_ERR(0, 187, __pyx_L1_error)
                #else
                __pyx_t_6 = PySequence_ITEM(__pyx_t_11, __pyx_t_21); __pyx_t_21++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 187, __pyx_L1_error)
                __Pyx_GOTREF(__pyx_t_6);
                #endif
              }
            } else {
              __pyx_t_6 = __pyx_t_22(__pyx_t_11);
              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, 187, __pyx_L1_error)
                }
                break;
              }
              __Pyx_GOTREF(__pyx_t_6);
            }
            __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_6);
            __pyx_t_6 = 0;

            /* "discodop/disambiguation.pyx":188
 * 					newprob = 0.0
 * 					for t in tree.subtrees():
 * 						if isinstance(t[0], Tree):             # <<<<<<<<<<<<<<
 * 							if not 1 <= len(t) <= 2:
 * 								raise ValueError('expected binarized tree.')
 */
            __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_t, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 188, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_6);
            __pyx_t_19 = __Pyx_GetModuleGlobalName(__pyx_n_s_Tree); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 188, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_19);
            __pyx_t_2 = PyObject_IsInstance(__pyx_t_6, __pyx_t_19); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(0, 188, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
            __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
            __pyx_t_16 = (__pyx_t_2 != 0);
            if (__pyx_t_16) {

              /* "discodop/disambiguation.pyx":189
 * 					for t in tree.subtrees():
 * 						if isinstance(t[0], Tree):
 * 							if not 1 <= len(t) <= 2:             # <<<<<<<<<<<<<<
 * 								raise ValueError('expected binarized tree.')
 * 							m = chart.grammar.rulenos[nodeprod(t)]
 */
              __pyx_t_23 = PyObject_Length(__pyx_v_t); if (unlikely(__pyx_t_23 == -1)) __PYX_ERR(0, 189, __pyx_L1_error)
              __pyx_t_16 = (1 <= __pyx_t_23);
              if (__pyx_t_16) {
                __pyx_t_16 = (__pyx_t_23 <= 2);
              }
              __pyx_t_2 = ((!(__pyx_t_16 != 0)) != 0);
              if (__pyx_t_2) {

                /* "discodop/disambiguation.pyx":190
 * 						if isinstance(t[0], Tree):
 * 							if not 1 <= len(t) <= 2:
 * 								raise ValueError('expected binarized tree.')             # <<<<<<<<<<<<<<
 * 							m = chart.grammar.rulenos[nodeprod(t)]
 * 							newprob += chart.grammar.bylhs[0][
 */
                __pyx_t_19 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__5, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 190, __pyx_L1_error)
                __Pyx_GOTREF(__pyx_t_19);
                __Pyx_Raise(__pyx_t_19, 0, 0, 0);
                __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
                __PYX_ERR(0, 190, __pyx_L1_error)

                /* "discodop/disambiguation.pyx":189
 * 					for t in tree.subtrees():
 * 						if isinstance(t[0], Tree):
 * 							if not 1 <= len(t) <= 2:             # <<<<<<<<<<<<<<
 * 								raise ValueError('expected binarized tree.')
 * 							m = chart.grammar.rulenos[nodeprod(t)]
 */
              }

              /* "discodop/disambiguation.pyx":191
 * 							if not 1 <= len(t) <= 2:
 * 								raise ValueError('expected binarized tree.')
 * 							m = chart.grammar.rulenos[nodeprod(t)]             # <<<<<<<<<<<<<<
 * 							newprob += chart.grammar.bylhs[0][
 * 									chart.grammar.revmap[m]].prob
 */
              if (unlikely(__pyx_v_chart->grammar->rulenos == Py_None)) {
                PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
                __PYX_ERR(0, 191, __pyx_L1_error)
              }
              __pyx_t_19 = __pyx_f_8discodop_14disambiguation_nodeprod(__pyx_v_t); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 191, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_19);
              __pyx_t_6 = __Pyx_PyDict_GetItem(__pyx_v_chart->grammar->rulenos, __pyx_t_19); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 191, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
              __pyx_t_20 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_20 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 191, __pyx_L1_error)
              __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
              __pyx_v_m = __pyx_t_20;

              /* "discodop/disambiguation.pyx":193
 * 							m = chart.grammar.rulenos[nodeprod(t)]
 * 							newprob += chart.grammar.bylhs[0][
 * 									chart.grammar.revmap[m]].prob             # <<<<<<<<<<<<<<
 * 						else:
 * 							m = chart.grammar.toid[t.label]
 */
              __pyx_t_6 = PyFloat_FromDouble(((__pyx_v_chart->grammar->bylhs[0])[(__pyx_v_chart->grammar->revmap[__pyx_v_m])]).prob); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 193, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_6);

              /* "discodop/disambiguation.pyx":192
 * 								raise ValueError('expected binarized tree.')
 * 							m = chart.grammar.rulenos[nodeprod(t)]
 * 							newprob += chart.grammar.bylhs[0][             # <<<<<<<<<<<<<<
 * 									chart.grammar.revmap[m]].prob
 * 						else:
 */
              __pyx_t_19 = PyNumber_InPlaceAdd(__pyx_v_newprob, __pyx_t_6); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 192, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_19);
              __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
              __Pyx_DECREF_SET(__pyx_v_newprob, __pyx_t_19);
              __pyx_t_19 = 0;

              /* "discodop/disambiguation.pyx":188
 * 					newprob = 0.0
 * 					for t in tree.subtrees():
 * 						if isinstance(t[0], Tree):             # <<<<<<<<<<<<<<
 * 							if not 1 <= len(t) <= 2:
 * 								raise ValueError('expected binarized tree.')
 */
              goto __pyx_L78;
            }

            /* "discodop/disambiguation.pyx":195
 * 									chart.grammar.revmap[m]].prob
 * 						else:
 * 							m = chart.grammar.toid[t.label]             # <<<<<<<<<<<<<<
 * 							try:
 * 								lexrule = chart.grammar.lexicalbylhs[
 */
            /*else*/ {
              if (unlikely(__pyx_v_chart->grammar->toid == Py_None)) {
                PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
                __PYX_ERR(0, 195, __pyx_L1_error)
              }
              __pyx_t_19 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_label); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 195, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_19);
              __pyx_t_6 = __Pyx_PyDict_GetItem(__pyx_v_chart->grammar->toid, __pyx_t_19); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 195, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_6);
              __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
              __pyx_t_20 = __Pyx_PyInt_As_int(__pyx_t_6); if (unlikely((__pyx_t_20 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 195, __pyx_L1_error)
              __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
              __pyx_v_m = __pyx_t_20;

              /* "discodop/disambiguation.pyx":196
 * 						else:
 * 							m = chart.grammar.toid[t.label]
 * 							try:             # <<<<<<<<<<<<<<
 * 								lexrule = chart.grammar.lexicalbylhs[
 * 										m][sent[t[0]]]
 */
              {
                __Pyx_PyThreadState_declare
                __Pyx_PyThreadState_assign
                __Pyx_ExceptionSave(&__pyx_t_13, &__pyx_t_14, &__pyx_t_15);
                __Pyx_XGOTREF(__pyx_t_13);
                __Pyx_XGOTREF(__pyx_t_14);
                __Pyx_XGOTREF(__pyx_t_15);
                /*try:*/ {

                  /* "discodop/disambiguation.pyx":197
 * 							m = chart.grammar.toid[t.label]
 * 							try:
 * 								lexrule = chart.grammar.lexicalbylhs[             # <<<<<<<<<<<<<<
 * 										m][sent[t[0]]]
 * 							except KeyError:
 */
                  if (unlikely(__pyx_v_chart->grammar->lexicalbylhs == Py_None)) {
                    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
                    __PYX_ERR(0, 197, __pyx_L80_error)
                  }

                  /* "discodop/disambiguation.pyx":198
 * 							try:
 * 								lexrule = chart.grammar.lexicalbylhs[
 * 										m][sent[t[0]]]             # <<<<<<<<<<<<<<
 * 							except KeyError:
 * 								newprob += 30.0
 */
                  __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_m); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 198, __pyx_L80_error)
                  __Pyx_GOTREF(__pyx_t_6);

                  /* "discodop/disambiguation.pyx":197
 * 							m = chart.grammar.toid[t.label]
 * 							try:
 * 								lexrule = chart.grammar.lexicalbylhs[             # <<<<<<<<<<<<<<
 * 										m][sent[t[0]]]
 * 							except KeyError:
 */
                  __pyx_t_19 = __Pyx_PyDict_GetItem(__pyx_v_chart->grammar->lexicalbylhs, __pyx_t_6); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 197, __pyx_L80_error)
                  __Pyx_GOTREF(__pyx_t_19);
                  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

                  /* "discodop/disambiguation.pyx":198
 * 							try:
 * 								lexrule = chart.grammar.lexicalbylhs[
 * 										m][sent[t[0]]]             # <<<<<<<<<<<<<<
 * 							except KeyError:
 * 								newprob += 30.0
 */
                  if (unlikely(__pyx_v_sent == Py_None)) {
                    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
                    __PYX_ERR(0, 198, __pyx_L80_error)
                  }
                  __pyx_t_6 = __Pyx_GetItemInt(__pyx_v_t, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 198, __pyx_L80_error)
                  __Pyx_GOTREF(__pyx_t_6);
                  __pyx_t_3 = PyObject_GetItem(__pyx_v_sent, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 198, __pyx_L80_error)
                  __Pyx_GOTREF(__pyx_t_3);
                  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
                  __pyx_t_6 = PyObject_GetItem(__pyx_t_19, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 198, __pyx_L80_error)
                  __Pyx_GOTREF(__pyx_t_6);
                  __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
                  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
                  if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_8discodop_10containers_LexicalRule))))) __PYX_ERR(0, 198, __pyx_L80_error)
                  __Pyx_XDECREF_SET(__pyx_v_lexrule, ((struct __pyx_obj_8discodop_10containers_LexicalRule *)__pyx_t_6));
                  __pyx_t_6 = 0;

                  /* "discodop/disambiguation.pyx":196
 * 						else:
 * 							m = chart.grammar.toid[t.label]
 * 							try:             # <<<<<<<<<<<<<<
 * 								lexrule = chart.grammar.lexicalbylhs[
 * 										m][sent[t[0]]]
 */
                }

                /* "discodop/disambiguation.pyx":202
 * 								newprob += 30.0
 * 							else:
 * 								newprob += lexrule.prob             # <<<<<<<<<<<<<<
 * 				else:
 * 					newprob = getderivprob(entry.key, chart, sent)
 */
                /*else:*/ {
                  __pyx_t_6 = PyFloat_FromDouble(__pyx_v_lexrule->prob); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 202, __pyx_L82_except_error)
                  __Pyx_GOTREF(__pyx_t_6);
                  __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_v_newprob, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 202, __pyx_L82_except_error)
                  __Pyx_GOTREF(__pyx_t_3);
                  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
                  __Pyx_DECREF_SET(__pyx_v_newprob, __pyx_t_3);
                  __pyx_t_3 = 0;
                }
                __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
                __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
                __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
                goto __pyx_L87_try_end;
                __pyx_L80_error:;
                __Pyx_PyThreadState_assign
                __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
                __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
                __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
                __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
                __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;

                /* "discodop/disambiguation.pyx":199
 * 								lexrule = chart.grammar.lexicalbylhs[
 * 										m][sent[t[0]]]
 * 							except KeyError:             # <<<<<<<<<<<<<<
 * 								newprob += 30.0
 * 							else:
 */
                __pyx_t_20 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
                if (__pyx_t_20) {
                  __Pyx_AddTraceback("discodop.disambiguation.marginalize", __pyx_clineno, __pyx_lineno, __pyx_filename);
                  if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_6, &__pyx_t_19) < 0) __PYX_ERR(0, 199, __pyx_L82_except_error)
                  __Pyx_GOTREF(__pyx_t_3);
                  __Pyx_GOTREF(__pyx_t_6);
                  __Pyx_GOTREF(__pyx_t_19);

                  /* "discodop/disambiguation.pyx":200
 * 										m][sent[t[0]]]
 * 							except KeyError:
 * 								newprob += 30.0             # <<<<<<<<<<<<<<
 * 							else:
 * 								newprob += lexrule.prob
 */
                  __pyx_t_1 = __Pyx_PyFloat_AddObjC(__pyx_v_newprob, __pyx_float_30_0, 30.0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 200, __pyx_L82_except_error)
                  __Pyx_GOTREF(__pyx_t_1);
                  __Pyx_DECREF_SET(__pyx_v_newprob, __pyx_t_1);
                  __pyx_t_1 = 0;
                  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
                  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
                  __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
                  goto __pyx_L81_exception_handled;
                }
                goto __pyx_L82_except_error;
                __pyx_L82_except_error:;

                /* "discodop/disambiguation.pyx":196
 * 						else:
 * 							m = chart.grammar.toid[t.label]
 * 							try:             # <<<<<<<<<<<<<<
 * 								lexrule = chart.grammar.lexicalbylhs[
 * 										m][sent[t[0]]]
 */
                __Pyx_PyThreadState_assign
                __Pyx_XGIVEREF(__pyx_t_13);
                __Pyx_XGIVEREF(__pyx_t_14);
                __Pyx_XGIVEREF(__pyx_t_15);
                __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15);
                goto __pyx_L1_error;
                __pyx_L81_exception_handled:;
                __Pyx_PyThreadState_assign
                __Pyx_XGIVEREF(__pyx_t_13);
                __Pyx_XGIVEREF(__pyx_t_14);
                __Pyx_XGIVEREF(__pyx_t_15);
                __Pyx_ExceptionReset(__pyx_t_13, __pyx_t_14, __pyx_t_15);
                __pyx_L87_try_end:;
              }
            }
            __pyx_L78:;

            /* "discodop/disambiguation.pyx":187
 * 					tree = canonicalize(Tree(deriv))
 * 					newprob = 0.0
 * 					for t in tree.subtrees():             # <<<<<<<<<<<<<<
 * 						if isinstance(t[0], Tree):
 * 							if not 1 <= len(t) <= 2:
 */
          }
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

          /* "discodop/disambiguation.pyx":182
 * 					continue
 * 			if shortest:
 * 				if bitpar:             # <<<<<<<<<<<<<<
 * 					# because with bitpar we don't know which rules have been
 * 					# used, read off the rules from the derivation ...
 */
          goto __pyx_L75;
        }

        /* "discodop/disambiguation.pyx":204
 * 								newprob += lexrule.prob
 * 				else:
 * 					newprob = getderivprob(entry.key, chart, sent)             # <<<<<<<<<<<<<<
 * 				score = (int(prob / log(0.5)), exp(-newprob))
 * 				if treestr not in parsetrees or (not dopreduction
 */
        /*else*/ {
          if (!(likely(((__pyx_v_entry->key) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_entry->key, __pyx_ptype_8discodop_10containers_RankedEdge))))) __PYX_ERR(0, 204, __pyx_L1_error)
          __pyx_t_11 = __pyx_v_entry->key;
          __Pyx_INCREF(__pyx_t_11);
          __pyx_t_19 = PyFloat_FromDouble(__pyx_f_8discodop_14disambiguation_getderivprob(((struct __pyx_obj_8discodop_10containers_RankedEdge *)__pyx_t_11), __pyx_v_chart, __pyx_v_sent)); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 204, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_19);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_XDECREF_SET(__pyx_v_newprob, __pyx_t_19);
          __pyx_t_19 = 0;
        }
        __pyx_L75:;

        /* "discodop/disambiguation.pyx":205
 * 				else:
 * 					newprob = getderivprob(entry.key, chart, sent)
 * 				score = (int(prob / log(0.5)), exp(-newprob))             # <<<<<<<<<<<<<<
 * 				if treestr not in parsetrees or (not dopreduction
 * 						and score > parsetrees[treestr]):
 */
        __pyx_t_19 = PyFloat_FromDouble(__pyx_v_prob); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 205, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_19);
        __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_log); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 205, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 205, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __pyx_t_11 = __Pyx_PyNumber_Divide(__pyx_t_19, __pyx_t_6); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 205, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_6 = __Pyx_PyNumber_Int(__pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 205, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __pyx_t_19 = __Pyx_GetModuleGlobalName(__pyx_n_s_exp); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 205, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_19);
        __pyx_t_3 = PyNumber_Negative(__pyx_v_newprob); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 205, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_1 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_19))) {
          __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_19);
          if (likely(__pyx_t_1)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19);
            __Pyx_INCREF(__pyx_t_1);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_19, function);
          }
        }
        if (!__pyx_t_1) {
          __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_t_19, __pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 205, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_GOTREF(__pyx_t_11);
        } else {
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_19)) {
            PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_3};
            __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_19, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 205, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_GOTREF(__pyx_t_11);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_19)) {
            PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_3};
            __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_19, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 205, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
            __Pyx_GOTREF(__pyx_t_11);
            __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          } else
          #endif
          {
            __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 205, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_10);
            __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_1); __pyx_t_1 = NULL;
            __Pyx_GIVEREF(__pyx_t_3);
            PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_3);
            __pyx_t_3 = 0;
            __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_19, __pyx_t_10, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 205, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_11);
            __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          }
        }
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
        __pyx_t_19 = PyTuple_New(2); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 205, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_19);
        __Pyx_GIVEREF(__pyx_t_6);
        PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_6);
        __Pyx_GIVEREF(__pyx_t_11);
        PyTuple_SET_ITEM(__pyx_t_19, 1, __pyx_t_11);
        __pyx_t_6 = 0;
        __pyx_t_11 = 0;
        __Pyx_XDECREF_SET(__pyx_v_score, ((PyObject*)__pyx_t_19));
        __pyx_t_19 = 0;

        /* "discodop/disambiguation.pyx":206
 * 					newprob = getderivprob(entry.key, chart, sent)
 * 				score = (int(prob / log(0.5)), exp(-newprob))
 * 				if treestr not in parsetrees or (not dopreduction             # <<<<<<<<<<<<<<
 * 						and score > parsetrees[treestr]):
 * 					parsetrees[treestr] = score
 */
        __pyx_t_16 = (__Pyx_PyDict_ContainsTF(__pyx_v_treestr, __pyx_v_parsetrees, Py_NE)); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 206, __pyx_L1_error)
        __pyx_t_4 = (__pyx_t_16 != 0);
        if (!__pyx_t_4) {
        } else {
          __pyx_t_2 = __pyx_t_4;
          goto __pyx_L91_bool_binop_done;
        }

        /* "discodop/disambiguation.pyx":207
 * 				score = (int(prob / log(0.5)), exp(-newprob))
 * 				if treestr not in parsetrees or (not dopreduction
 * 						and score > parsetrees[treestr]):             # <<<<<<<<<<<<<<
 * 					parsetrees[treestr] = score
 * 					derivs[treestr] = deriv
 */
        __pyx_t_4 = ((!(__pyx_v_dopreduction != 0)) != 0);
        if (__pyx_t_4) {
        } else {
          __pyx_t_2 = __pyx_t_4;
          goto __pyx_L91_bool_binop_done;
        }
        __pyx_t_19 = __Pyx_PyDict_GetItem(__pyx_v_parsetrees, __pyx_v_treestr); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 207, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_19);
        __pyx_t_11 = PyObject_RichCompare(__pyx_v_score, __pyx_t_19, Py_GT); __Pyx_XGOTREF(__pyx_t_11); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 207, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
        __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_11); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 207, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __pyx_t_2 = __pyx_t_4;
        __pyx_L91_bool_binop_done:;

        /* "discodop/disambiguation.pyx":206
 * 					newprob = getderivprob(entry.key, chart, sent)
 * 				score = (int(prob / log(0.5)), exp(-newprob))
 * 				if treestr not in parsetrees or (not dopreduction             # <<<<<<<<<<<<<<
 * 						and score > parsetrees[treestr]):
 * 					parsetrees[treestr] = score
 */
        if (__pyx_t_2) {

          /* "discodop/disambiguation.pyx":208
 * 				if treestr not in parsetrees or (not dopreduction
 * 						and score > parsetrees[treestr]):
 * 					parsetrees[treestr] = score             # <<<<<<<<<<<<<<
 * 					derivs[treestr] = deriv
 * 				elif dopreduction:
 */
          if (unlikely(PyDict_SetItem(__pyx_v_parsetrees, __pyx_v_treestr, __pyx_v_score) < 0)) __PYX_ERR(0, 208, __pyx_L1_error)

          /* "discodop/disambiguation.pyx":209
 * 						and score > parsetrees[treestr]):
 * 					parsetrees[treestr] = score
 * 					derivs[treestr] = deriv             # <<<<<<<<<<<<<<
 * 				elif dopreduction:
 * 					oldscore = parsetrees[treestr]
 */
          if (unlikely(PyDict_SetItem(__pyx_v_derivs, __pyx_v_treestr, __pyx_v_deriv) < 0)) __PYX_ERR(0, 209, __pyx_L1_error)

          /* "discodop/disambiguation.pyx":206
 * 					newprob = getderivprob(entry.key, chart, sent)
 * 				score = (int(prob / log(0.5)), exp(-newprob))
 * 				if treestr not in parsetrees or (not dopreduction             # <<<<<<<<<<<<<<
 * 						and score > parsetrees[treestr]):
 * 					parsetrees[treestr] = score
 */
          goto __pyx_L90;
        }

        /* "discodop/disambiguation.pyx":210
 * 					parsetrees[treestr] = score
 * 					derivs[treestr] = deriv
 * 				elif dopreduction:             # <<<<<<<<<<<<<<
 * 					oldscore = parsetrees[treestr]
 * 					parsetrees[treestr] = oldscore[0], oldscore[1] + score[1]
 */
        __pyx_t_2 = (__pyx_v_dopreduction != 0);
        if (__pyx_t_2) {

          /* "discodop/disambiguation.pyx":211
 * 					derivs[treestr] = deriv
 * 				elif dopreduction:
 * 					oldscore = parsetrees[treestr]             # <<<<<<<<<<<<<<
 * 					parsetrees[treestr] = oldscore[0], oldscore[1] + score[1]
 * 			elif treestr not in parsetrees or (not dopreduction and mpd
 */
          __pyx_t_11 = __Pyx_PyDict_GetItem(__pyx_v_parsetrees, __pyx_v_treestr); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 211, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_XDECREF_SET(__pyx_v_oldscore, __pyx_t_11);
          __pyx_t_11 = 0;

          /* "discodop/disambiguation.pyx":212
 * 				elif dopreduction:
 * 					oldscore = parsetrees[treestr]
 * 					parsetrees[treestr] = oldscore[0], oldscore[1] + score[1]             # <<<<<<<<<<<<<<
 * 			elif treestr not in parsetrees or (not dopreduction and mpd
 * 					and -prob > parsetrees[treestr][0]):
 */
          __pyx_t_11 = __Pyx_GetItemInt(__pyx_v_oldscore, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 212, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          __pyx_t_19 = __Pyx_GetItemInt(__pyx_v_oldscore, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 212, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_19);
          __pyx_t_6 = PyNumber_Add(__pyx_t_19, PyTuple_GET_ITEM(__pyx_v_score, 1)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 212, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_6);
          __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
          __pyx_t_19 = PyTuple_New(2); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 212, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_19);
          __Pyx_GIVEREF(__pyx_t_11);
          PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_11);
          __Pyx_GIVEREF(__pyx_t_6);
          PyTuple_SET_ITEM(__pyx_t_19, 1, __pyx_t_6);
          __pyx_t_11 = 0;
          __pyx_t_6 = 0;
          if (unlikely(PyDict_SetItem(__pyx_v_parsetrees, __pyx_v_treestr, __pyx_t_19) < 0)) __PYX_ERR(0, 212, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;

          /* "discodop/disambiguation.pyx":210
 * 					parsetrees[treestr] = score
 * 					derivs[treestr] = deriv
 * 				elif dopreduction:             # <<<<<<<<<<<<<<
 * 					oldscore = parsetrees[treestr]
 * 					parsetrees[treestr] = oldscore[0], oldscore[1] + score[1]
 */
        }
        __pyx_L90:;

        /* "discodop/disambiguation.pyx":181
 * 				except:
 * 					continue
 * 			if shortest:             # <<<<<<<<<<<<<<
 * 				if bitpar:
 * 					# because with bitpar we don't know which rules have been
 */
        goto __pyx_L74;
      }

      /* "discodop/disambiguation.pyx":213
 * 					oldscore = parsetrees[treestr]
 * 					parsetrees[treestr] = oldscore[0], oldscore[1] + score[1]
 * 			elif treestr not in parsetrees or (not dopreduction and mpd             # <<<<<<<<<<<<<<
 * 					and -prob > parsetrees[treestr][0]):
 * 				parsetrees[treestr] = [-prob]
 */
      __pyx_t_4 = (__Pyx_PyDict_ContainsTF(__pyx_v_treestr, __pyx_v_parsetrees, Py_NE)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 213, __pyx_L1_error)
      __pyx_t_16 = (__pyx_t_4 != 0);
      if (!__pyx_t_16) {
      } else {
        __pyx_t_2 = __pyx_t_16;
        goto __pyx_L94_bool_binop_done;
      }
      __pyx_t_16 = ((!(__pyx_v_dopreduction != 0)) != 0);
      if (__pyx_t_16) {
      } else {
        __pyx_t_2 = __pyx_t_16;
        goto __pyx_L94_bool_binop_done;
      }

      /* "discodop/disambiguation.pyx":214
 * 					parsetrees[treestr] = oldscore[0], oldscore[1] + score[1]
 * 			elif treestr not in parsetrees or (not dopreduction and mpd
 * 					and -prob > parsetrees[treestr][0]):             # <<<<<<<<<<<<<<
 * 				parsetrees[treestr] = [-prob]
 * 				derivs[treestr] = deriv
 */
      __pyx_t_16 = (__pyx_v_mpd != 0);
      if (__pyx_t_16) {
      } else {
        __pyx_t_2 = __pyx_t_16;
        goto __pyx_L94_bool_binop_done;
      }
      __pyx_t_19 = PyFloat_FromDouble((-__pyx_v_prob)); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 214, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_19);
      __pyx_t_6 = __Pyx_PyDict_GetItem(__pyx_v_parsetrees, __pyx_v_treestr); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 214, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_11 = __Pyx_GetItemInt(__pyx_t_6, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 214, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = PyObject_RichCompare(__pyx_t_19, __pyx_t_11, Py_GT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 214, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_16 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 214, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_2 = __pyx_t_16;
      __pyx_L94_bool_binop_done:;

      /* "discodop/disambiguation.pyx":213
 * 					oldscore = parsetrees[treestr]
 * 					parsetrees[treestr] = oldscore[0], oldscore[1] + score[1]
 * 			elif treestr not in parsetrees or (not dopreduction and mpd             # <<<<<<<<<<<<<<
 * 					and -prob > parsetrees[treestr][0]):
 * 				parsetrees[treestr] = [-prob]
 */
      if (__pyx_t_2) {

        /* "discodop/disambiguation.pyx":215
 * 			elif treestr not in parsetrees or (not dopreduction and mpd
 * 					and -prob > parsetrees[treestr][0]):
 * 				parsetrees[treestr] = [-prob]             # <<<<<<<<<<<<<<
 * 				derivs[treestr] = deriv
 * 			elif treestr in parsetrees and (dopreduction or not mpd):
 */
        __pyx_t_6 = PyFloat_FromDouble((-__pyx_v_prob)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 215, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_11 = PyList_New(1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 215, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_GIVEREF(__pyx_t_6);
        PyList_SET_ITEM(__pyx_t_11, 0, __pyx_t_6);
        __pyx_t_6 = 0;
        if (unlikely(PyDict_SetItem(__pyx_v_parsetrees, __pyx_v_treestr, __pyx_t_11) < 0)) __PYX_ERR(0, 215, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

        /* "discodop/disambiguation.pyx":216
 * 					and -prob > parsetrees[treestr][0]):
 * 				parsetrees[treestr] = [-prob]
 * 				derivs[treestr] = deriv             # <<<<<<<<<<<<<<
 * 			elif treestr in parsetrees and (dopreduction or not mpd):
 * 				parsetrees[treestr].append(-prob)
 */
        if (unlikely(PyDict_SetItem(__pyx_v_derivs, __pyx_v_treestr, __pyx_v_deriv) < 0)) __PYX_ERR(0, 216, __pyx_L1_error)

        /* "discodop/disambiguation.pyx":213
 * 					oldscore = parsetrees[treestr]
 * 					parsetrees[treestr] = oldscore[0], oldscore[1] + score[1]
 * 			elif treestr not in parsetrees or (not dopreduction and mpd             # <<<<<<<<<<<<<<
 * 					and -prob > parsetrees[treestr][0]):
 * 				parsetrees[treestr] = [-prob]
 */
        goto __pyx_L74;
      }

      /* "discodop/disambiguation.pyx":217
 * 				parsetrees[treestr] = [-prob]
 * 				derivs[treestr] = deriv
 * 			elif treestr in parsetrees and (dopreduction or not mpd):             # <<<<<<<<<<<<<<
 * 				parsetrees[treestr].append(-prob)
 * 
 */
      __pyx_t_16 = (__Pyx_PyDict_ContainsTF(__pyx_v_treestr, __pyx_v_parsetrees, Py_EQ)); if (unlikely(__pyx_t_16 < 0)) __PYX_ERR(0, 217, __pyx_L1_error)
      __pyx_t_4 = (__pyx_t_16 != 0);
      if (__pyx_t_4) {
      } else {
        __pyx_t_2 = __pyx_t_4;
        goto __pyx_L98_bool_binop_done;
      }
      __pyx_t_4 = (__pyx_v_dopreduction != 0);
      if (!__pyx_t_4) {
      } else {
        __pyx_t_2 = __pyx_t_4;
        goto __pyx_L98_bool_binop_done;
      }
      __pyx_t_4 = ((!(__pyx_v_mpd != 0)) != 0);
      __pyx_t_2 = __pyx_t_4;
      __pyx_L98_bool_binop_done:;
      if (__pyx_t_2) {

        /* "discodop/disambiguation.pyx":218
 * 				derivs[treestr] = deriv
 * 			elif treestr in parsetrees and (dopreduction or not mpd):
 * 				parsetrees[treestr].append(-prob)             # <<<<<<<<<<<<<<
 * 
 * 	if mpd and dopreduction:
 */
        __pyx_t_11 = __Pyx_PyDict_GetItem(__pyx_v_parsetrees, __pyx_v_treestr); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 218, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_6 = PyFloat_FromDouble((-__pyx_v_prob)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 218, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_17 = __Pyx_PyObject_Append(__pyx_t_11, __pyx_t_6); if (unlikely(__pyx_t_17 == -1)) __PYX_ERR(0, 218, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

        /* "discodop/disambiguation.pyx":217
 * 				parsetrees[treestr] = [-prob]
 * 				derivs[treestr] = deriv
 * 			elif treestr in parsetrees and (dopreduction or not mpd):             # <<<<<<<<<<<<<<
 * 				parsetrees[treestr].append(-prob)
 * 
 */
      }
      __pyx_L74:;

      /* "discodop/disambiguation.pyx":173
 * 				derivs[treestr] = entry.key
 * 	else:  # DOP reduction / bitpar
 * 		for (deriv, prob), entry in zip(derivations, entries):             # <<<<<<<<<<<<<<
 * 			if dopreduction:
 * 				treestr = REMOVEIDS.sub('@1' if mpd or shortest else '', deriv)
 */
      __pyx_L55_continue:;
    }
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  }
  __pyx_L31:;

  /* "discodop/disambiguation.pyx":220
 * 				parsetrees[treestr].append(-prob)
 * 
 * 	if mpd and dopreduction:             # <<<<<<<<<<<<<<
 * 		results = [(REMOVEIDS.sub('', treestr), logprobsum(probs),
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 */
  __pyx_t_4 = (__pyx_v_mpd != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L102_bool_binop_done;
  }
  __pyx_t_4 = (__pyx_v_dopreduction != 0);
  __pyx_t_2 = __pyx_t_4;
  __pyx_L102_bool_binop_done:;
  if (__pyx_t_2) {

    /* "discodop/disambiguation.pyx":221
 * 
 * 	if mpd and dopreduction:
 * 		results = [(REMOVEIDS.sub('', treestr), logprobsum(probs),             # <<<<<<<<<<<<<<
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 * 				for treestr, probs in parsetrees.items()]
 */
    { /* enter inner scope */
      PyObject *__pyx_8genexpr3__pyx_v_treestr = NULL;
      PyObject *__pyx_8genexpr3__pyx_v_probs = NULL;
      __pyx_t_8 = PyList_New(0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 221, __pyx_L106_error)
      __Pyx_GOTREF(__pyx_t_8);

      /* "discodop/disambiguation.pyx":223
 * 		results = [(REMOVEIDS.sub('', treestr), logprobsum(probs),
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 * 				for treestr, probs in parsetrees.items()]             # <<<<<<<<<<<<<<
 * 	elif shortest and dopreduction:
 * 		results = [(REMOVEIDS.sub('', treestr), (-a, b),
 */
      __pyx_t_5 = 0;
      __pyx_t_11 = __Pyx_dict_iterator(__pyx_v_parsetrees, 1, __pyx_n_s_items, (&__pyx_t_21), (&__pyx_t_20)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 223, __pyx_L106_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_XDECREF(__pyx_t_6);
      __pyx_t_6 = __pyx_t_11;
      __pyx_t_11 = 0;
      while (1) {
        __pyx_t_24 = __Pyx_dict_iter_next(__pyx_t_6, __pyx_t_21, &__pyx_t_5, &__pyx_t_11, &__pyx_t_19, NULL, __pyx_t_20);
        if (unlikely(__pyx_t_24 == 0)) break;
        if (unlikely(__pyx_t_24 == -1)) __PYX_ERR(0, 223, __pyx_L106_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_GOTREF(__pyx_t_19);
        if (!(likely(PyUnicode_CheckExact(__pyx_t_11))||((__pyx_t_11) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_11)->tp_name), 0))) __PYX_ERR(0, 223, __pyx_L106_error)
        __Pyx_XDECREF_SET(__pyx_8genexpr3__pyx_v_treestr, ((PyObject*)__pyx_t_11));
        __pyx_t_11 = 0;
        __Pyx_XDECREF_SET(__pyx_8genexpr3__pyx_v_probs, __pyx_t_19);
        __pyx_t_19 = 0;

        /* "discodop/disambiguation.pyx":221
 * 
 * 	if mpd and dopreduction:
 * 		results = [(REMOVEIDS.sub('', treestr), logprobsum(probs),             # <<<<<<<<<<<<<<
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 * 				for treestr, probs in parsetrees.items()]
 */
        __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_REMOVEIDS); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 221, __pyx_L106_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_sub); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 221, __pyx_L106_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __pyx_t_11 = NULL;
        __pyx_t_24 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(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_24 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_10)) {
          PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_kp_u__4, __pyx_8genexpr3__pyx_v_treestr};
          __pyx_t_19 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_24, 2+__pyx_t_24); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 221, __pyx_L106_error)
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_GOTREF(__pyx_t_19);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) {
          PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_kp_u__4, __pyx_8genexpr3__pyx_v_treestr};
          __pyx_t_19 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_24, 2+__pyx_t_24); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 221, __pyx_L106_error)
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_GOTREF(__pyx_t_19);
        } else
        #endif
        {
          __pyx_t_3 = PyTuple_New(2+__pyx_t_24); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 221, __pyx_L106_error)
          __Pyx_GOTREF(__pyx_t_3);
          if (__pyx_t_11) {
            __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_11); __pyx_t_11 = NULL;
          }
          __Pyx_INCREF(__pyx_kp_u__4);
          __Pyx_GIVEREF(__pyx_kp_u__4);
          PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_24, __pyx_kp_u__4);
          __Pyx_INCREF(__pyx_8genexpr3__pyx_v_treestr);
          __Pyx_GIVEREF(__pyx_8genexpr3__pyx_v_treestr);
          PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_24, __pyx_8genexpr3__pyx_v_treestr);
          __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_3, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 221, __pyx_L106_error)
          __Pyx_GOTREF(__pyx_t_19);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        }
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        if (!(likely(PyList_CheckExact(__pyx_8genexpr3__pyx_v_probs))||((__pyx_8genexpr3__pyx_v_probs) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_8genexpr3__pyx_v_probs)->tp_name), 0))) __PYX_ERR(0, 221, __pyx_L106_error)
        __pyx_t_10 = PyFloat_FromDouble(__pyx_f_8discodop_10containers_logprobsum(((PyObject*)__pyx_8genexpr3__pyx_v_probs))); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 221, __pyx_L106_error)
        __Pyx_GOTREF(__pyx_t_10);

        /* "discodop/disambiguation.pyx":222
 * 	if mpd and dopreduction:
 * 		results = [(REMOVEIDS.sub('', treestr), logprobsum(probs),
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))             # <<<<<<<<<<<<<<
 * 				for treestr, probs in parsetrees.items()]
 * 	elif shortest and dopreduction:
 */
        __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_fragmentsinderiv); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 222, __pyx_L106_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_derivs, __pyx_8genexpr3__pyx_v_treestr); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 222, __pyx_L106_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_25 = NULL;
        __pyx_t_24 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
          __pyx_t_25 = PyMethod_GET_SELF(__pyx_t_11);
          if (likely(__pyx_t_25)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
            __Pyx_INCREF(__pyx_t_25);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_11, function);
            __pyx_t_24 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_11)) {
          PyObject *__pyx_temp[4] = {__pyx_t_25, __pyx_t_1, ((PyObject *)__pyx_v_chart), __pyx_v_backtransform};
          __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_24, 3+__pyx_t_24); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 222, __pyx_L106_error)
          __Pyx_XDECREF(__pyx_t_25); __pyx_t_25 = 0;
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) {
          PyObject *__pyx_temp[4] = {__pyx_t_25, __pyx_t_1, ((PyObject *)__pyx_v_chart), __pyx_v_backtransform};
          __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_24, 3+__pyx_t_24); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 222, __pyx_L106_error)
          __Pyx_XDECREF(__pyx_t_25); __pyx_t_25 = 0;
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        } else
        #endif
        {
          __pyx_t_26 = PyTuple_New(3+__pyx_t_24); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 222, __pyx_L106_error)
          __Pyx_GOTREF(__pyx_t_26);
          if (__pyx_t_25) {
            __Pyx_GIVEREF(__pyx_t_25); PyTuple_SET_ITEM(__pyx_t_26, 0, __pyx_t_25); __pyx_t_25 = NULL;
          }
          __Pyx_GIVEREF(__pyx_t_1);
          PyTuple_SET_ITEM(__pyx_t_26, 0+__pyx_t_24, __pyx_t_1);
          __Pyx_INCREF(((PyObject *)__pyx_v_chart));
          __Pyx_GIVEREF(((PyObject *)__pyx_v_chart));
          PyTuple_SET_ITEM(__pyx_t_26, 1+__pyx_t_24, ((PyObject *)__pyx_v_chart));
          __Pyx_INCREF(__pyx_v_backtransform);
          __Pyx_GIVEREF(__pyx_v_backtransform);
          PyTuple_SET_ITEM(__pyx_t_26, 2+__pyx_t_24, __pyx_v_backtransform);
          __pyx_t_1 = 0;
          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_26, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 222, __pyx_L106_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
        }
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

        /* "discodop/disambiguation.pyx":221
 * 
 * 	if mpd and dopreduction:
 * 		results = [(REMOVEIDS.sub('', treestr), logprobsum(probs),             # <<<<<<<<<<<<<<
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 * 				for treestr, probs in parsetrees.items()]
 */
        __pyx_t_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 221, __pyx_L106_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_GIVEREF(__pyx_t_19);
        PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_19);
        __Pyx_GIVEREF(__pyx_t_10);
        PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_10);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_t_3);
        __pyx_t_19 = 0;
        __pyx_t_10 = 0;
        __pyx_t_3 = 0;
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_8, (PyObject*)__pyx_t_11))) __PYX_ERR(0, 221, __pyx_L106_error)
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_8genexpr3__pyx_v_treestr);
      __Pyx_XDECREF(__pyx_8genexpr3__pyx_v_probs);
      goto __pyx_L109_exit_scope;
      __pyx_L106_error:;
      __Pyx_XDECREF(__pyx_8genexpr3__pyx_v_treestr);
      __Pyx_XDECREF(__pyx_8genexpr3__pyx_v_probs);
      goto __pyx_L1_error;
      __pyx_L109_exit_scope:;
    } /* exit inner scope */
    __pyx_v_results = ((PyObject*)__pyx_t_8);
    __pyx_t_8 = 0;

    /* "discodop/disambiguation.pyx":220
 * 				parsetrees[treestr].append(-prob)
 * 
 * 	if mpd and dopreduction:             # <<<<<<<<<<<<<<
 * 		results = [(REMOVEIDS.sub('', treestr), logprobsum(probs),
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 */
    goto __pyx_L101;
  }

  /* "discodop/disambiguation.pyx":224
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 * 				for treestr, probs in parsetrees.items()]
 * 	elif shortest and dopreduction:             # <<<<<<<<<<<<<<
 * 		results = [(REMOVEIDS.sub('', treestr), (-a, b),
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 */
  __pyx_t_4 = (__pyx_v_shortest != 0);
  if (__pyx_t_4) {
  } else {
    __pyx_t_2 = __pyx_t_4;
    goto __pyx_L110_bool_binop_done;
  }
  __pyx_t_4 = (__pyx_v_dopreduction != 0);
  __pyx_t_2 = __pyx_t_4;
  __pyx_L110_bool_binop_done:;
  if (__pyx_t_2) {

    /* "discodop/disambiguation.pyx":225
 * 				for treestr, probs in parsetrees.items()]
 * 	elif shortest and dopreduction:
 * 		results = [(REMOVEIDS.sub('', treestr), (-a, b),             # <<<<<<<<<<<<<<
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 * 				for treestr, (a, b) in parsetrees.items()]
 */
    { /* enter inner scope */
      PyObject *__pyx_8genexpr4__pyx_v_treestr = NULL;
      PyObject *__pyx_8genexpr4__pyx_v_a = NULL;
      PyObject *__pyx_8genexpr4__pyx_v_b = NULL;
      __pyx_t_8 = PyList_New(0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 225, __pyx_L114_error)
      __Pyx_GOTREF(__pyx_t_8);

      /* "discodop/disambiguation.pyx":227
 * 		results = [(REMOVEIDS.sub('', treestr), (-a, b),
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 * 				for treestr, (a, b) in parsetrees.items()]             # <<<<<<<<<<<<<<
 * 	elif shortest:
 * 		results = [(treestr, (-a, b),
 */
      __pyx_t_21 = 0;
      __pyx_t_11 = __Pyx_dict_iterator(__pyx_v_parsetrees, 1, __pyx_n_s_items, (&__pyx_t_5), (&__pyx_t_20)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 227, __pyx_L114_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_XDECREF(__pyx_t_6);
      __pyx_t_6 = __pyx_t_11;
      __pyx_t_11 = 0;
      while (1) {
        __pyx_t_24 = __Pyx_dict_iter_next(__pyx_t_6, __pyx_t_5, &__pyx_t_21, &__pyx_t_11, &__pyx_t_3, NULL, __pyx_t_20);
        if (unlikely(__pyx_t_24 == 0)) break;
        if (unlikely(__pyx_t_24 == -1)) __PYX_ERR(0, 227, __pyx_L114_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_GOTREF(__pyx_t_3);
        if (!(likely(PyUnicode_CheckExact(__pyx_t_11))||((__pyx_t_11) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_11)->tp_name), 0))) __PYX_ERR(0, 227, __pyx_L114_error)
        __Pyx_XDECREF_SET(__pyx_8genexpr4__pyx_v_treestr, ((PyObject*)__pyx_t_11));
        __pyx_t_11 = 0;
        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, 227, __pyx_L114_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_10 = PyTuple_GET_ITEM(sequence, 1); 
          } else {
            __pyx_t_11 = PyList_GET_ITEM(sequence, 0); 
            __pyx_t_10 = PyList_GET_ITEM(sequence, 1); 
          }
          __Pyx_INCREF(__pyx_t_11);
          __Pyx_INCREF(__pyx_t_10);
          #else
          __pyx_t_11 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 227, __pyx_L114_error)
          __Pyx_GOTREF(__pyx_t_11);
          __pyx_t_10 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 227, __pyx_L114_error)
          __Pyx_GOTREF(__pyx_t_10);
          #endif
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else {
          Py_ssize_t index = -1;
          __pyx_t_19 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 227, __pyx_L114_error)
          __Pyx_GOTREF(__pyx_t_19);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_9 = Py_TYPE(__pyx_t_19)->tp_iternext;
          index = 0; __pyx_t_11 = __pyx_t_9(__pyx_t_19); if (unlikely(!__pyx_t_11)) goto __pyx_L117_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_11);
          index = 1; __pyx_t_10 = __pyx_t_9(__pyx_t_19); if (unlikely(!__pyx_t_10)) goto __pyx_L117_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_10);
          if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_19), 2) < 0) __PYX_ERR(0, 227, __pyx_L114_error)
          __pyx_t_9 = NULL;
          __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
          goto __pyx_L118_unpacking_done;
          __pyx_L117_unpacking_failed:;
          __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
          __pyx_t_9 = NULL;
          if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
          __PYX_ERR(0, 227, __pyx_L114_error)
          __pyx_L118_unpacking_done:;
        }
        __Pyx_XDECREF_SET(__pyx_8genexpr4__pyx_v_a, __pyx_t_11);
        __pyx_t_11 = 0;
        __Pyx_XDECREF_SET(__pyx_8genexpr4__pyx_v_b, __pyx_t_10);
        __pyx_t_10 = 0;

        /* "discodop/disambiguation.pyx":225
 * 				for treestr, probs in parsetrees.items()]
 * 	elif shortest and dopreduction:
 * 		results = [(REMOVEIDS.sub('', treestr), (-a, b),             # <<<<<<<<<<<<<<
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 * 				for treestr, (a, b) in parsetrees.items()]
 */
        __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_REMOVEIDS); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 225, __pyx_L114_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_10, __pyx_n_s_sub); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 225, __pyx_L114_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_10 = NULL;
        __pyx_t_24 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
          __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_11);
          if (likely(__pyx_t_10)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
            __Pyx_INCREF(__pyx_t_10);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_11, function);
            __pyx_t_24 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_11)) {
          PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_kp_u__4, __pyx_8genexpr4__pyx_v_treestr};
          __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_24, 2+__pyx_t_24); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 225, __pyx_L114_error)
          __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_GOTREF(__pyx_t_3);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) {
          PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_kp_u__4, __pyx_8genexpr4__pyx_v_treestr};
          __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_24, 2+__pyx_t_24); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 225, __pyx_L114_error)
          __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_GOTREF(__pyx_t_3);
        } else
        #endif
        {
          __pyx_t_19 = PyTuple_New(2+__pyx_t_24); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 225, __pyx_L114_error)
          __Pyx_GOTREF(__pyx_t_19);
          if (__pyx_t_10) {
            __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_10); __pyx_t_10 = NULL;
          }
          __Pyx_INCREF(__pyx_kp_u__4);
          __Pyx_GIVEREF(__pyx_kp_u__4);
          PyTuple_SET_ITEM(__pyx_t_19, 0+__pyx_t_24, __pyx_kp_u__4);
          __Pyx_INCREF(__pyx_8genexpr4__pyx_v_treestr);
          __Pyx_GIVEREF(__pyx_8genexpr4__pyx_v_treestr);
          PyTuple_SET_ITEM(__pyx_t_19, 1+__pyx_t_24, __pyx_8genexpr4__pyx_v_treestr);
          __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_19, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 225, __pyx_L114_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
        }
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __pyx_t_11 = PyNumber_Negative(__pyx_8genexpr4__pyx_v_a); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 225, __pyx_L114_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_19 = PyTuple_New(2); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 225, __pyx_L114_error)
        __Pyx_GOTREF(__pyx_t_19);
        __Pyx_GIVEREF(__pyx_t_11);
        PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_11);
        __Pyx_INCREF(__pyx_8genexpr4__pyx_v_b);
        __Pyx_GIVEREF(__pyx_8genexpr4__pyx_v_b);
        PyTuple_SET_ITEM(__pyx_t_19, 1, __pyx_8genexpr4__pyx_v_b);
        __pyx_t_11 = 0;

        /* "discodop/disambiguation.pyx":226
 * 	elif shortest and dopreduction:
 * 		results = [(REMOVEIDS.sub('', treestr), (-a, b),
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))             # <<<<<<<<<<<<<<
 * 				for treestr, (a, b) in parsetrees.items()]
 * 	elif shortest:
 */
        __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_fragmentsinderiv); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 226, __pyx_L114_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_26 = __Pyx_PyDict_GetItem(__pyx_v_derivs, __pyx_8genexpr4__pyx_v_treestr); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 226, __pyx_L114_error)
        __Pyx_GOTREF(__pyx_t_26);
        __pyx_t_1 = NULL;
        __pyx_t_24 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) {
          __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_10);
          if (likely(__pyx_t_1)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
            __Pyx_INCREF(__pyx_t_1);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_10, function);
            __pyx_t_24 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_10)) {
          PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_t_26, ((PyObject *)__pyx_v_chart), __pyx_v_backtransform};
          __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_24, 3+__pyx_t_24); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 226, __pyx_L114_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) {
          PyObject *__pyx_temp[4] = {__pyx_t_1, __pyx_t_26, ((PyObject *)__pyx_v_chart), __pyx_v_backtransform};
          __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_24, 3+__pyx_t_24); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 226, __pyx_L114_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
        } else
        #endif
        {
          __pyx_t_25 = PyTuple_New(3+__pyx_t_24); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 226, __pyx_L114_error)
          __Pyx_GOTREF(__pyx_t_25);
          if (__pyx_t_1) {
            __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_25, 0, __pyx_t_1); __pyx_t_1 = NULL;
          }
          __Pyx_GIVEREF(__pyx_t_26);
          PyTuple_SET_ITEM(__pyx_t_25, 0+__pyx_t_24, __pyx_t_26);
          __Pyx_INCREF(((PyObject *)__pyx_v_chart));
          __Pyx_GIVEREF(((PyObject *)__pyx_v_chart));
          PyTuple_SET_ITEM(__pyx_t_25, 1+__pyx_t_24, ((PyObject *)__pyx_v_chart));
          __Pyx_INCREF(__pyx_v_backtransform);
          __Pyx_GIVEREF(__pyx_v_backtransform);
          PyTuple_SET_ITEM(__pyx_t_25, 2+__pyx_t_24, __pyx_v_backtransform);
          __pyx_t_26 = 0;
          __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_25, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 226, __pyx_L114_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0;
        }
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

        /* "discodop/disambiguation.pyx":225
 * 				for treestr, probs in parsetrees.items()]
 * 	elif shortest and dopreduction:
 * 		results = [(REMOVEIDS.sub('', treestr), (-a, b),             # <<<<<<<<<<<<<<
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 * 				for treestr, (a, b) in parsetrees.items()]
 */
        __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 225, __pyx_L114_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_19);
        PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_19);
        __Pyx_GIVEREF(__pyx_t_11);
        PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_11);
        __pyx_t_3 = 0;
        __pyx_t_19 = 0;
        __pyx_t_11 = 0;
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_8, (PyObject*)__pyx_t_10))) __PYX_ERR(0, 225, __pyx_L114_error)
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_8genexpr4__pyx_v_treestr);
      __Pyx_XDECREF(__pyx_8genexpr4__pyx_v_a);
      __Pyx_XDECREF(__pyx_8genexpr4__pyx_v_b);
      goto __pyx_L119_exit_scope;
      __pyx_L114_error:;
      __Pyx_XDECREF(__pyx_8genexpr4__pyx_v_treestr);
      __Pyx_XDECREF(__pyx_8genexpr4__pyx_v_a);
      __Pyx_XDECREF(__pyx_8genexpr4__pyx_v_b);
      goto __pyx_L1_error;
      __pyx_L119_exit_scope:;
    } /* exit inner scope */
    __pyx_v_results = ((PyObject*)__pyx_t_8);
    __pyx_t_8 = 0;

    /* "discodop/disambiguation.pyx":224
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 * 				for treestr, probs in parsetrees.items()]
 * 	elif shortest and dopreduction:             # <<<<<<<<<<<<<<
 * 		results = [(REMOVEIDS.sub('', treestr), (-a, b),
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 */
    goto __pyx_L101;
  }

  /* "discodop/disambiguation.pyx":228
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 * 				for treestr, (a, b) in parsetrees.items()]
 * 	elif shortest:             # <<<<<<<<<<<<<<
 * 		results = [(treestr, (-a, b),
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 */
  __pyx_t_2 = (__pyx_v_shortest != 0);
  if (__pyx_t_2) {

    /* "discodop/disambiguation.pyx":229
 * 				for treestr, (a, b) in parsetrees.items()]
 * 	elif shortest:
 * 		results = [(treestr, (-a, b),             # <<<<<<<<<<<<<<
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 * 				for treestr, (a, b) in parsetrees.items()]
 */
    { /* enter inner scope */
      PyObject *__pyx_8genexpr5__pyx_v_treestr = NULL;
      PyObject *__pyx_8genexpr5__pyx_v_a = NULL;
      PyObject *__pyx_8genexpr5__pyx_v_b = NULL;
      __pyx_t_8 = PyList_New(0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 229, __pyx_L122_error)
      __Pyx_GOTREF(__pyx_t_8);

      /* "discodop/disambiguation.pyx":231
 * 		results = [(treestr, (-a, b),
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 * 				for treestr, (a, b) in parsetrees.items()]             # <<<<<<<<<<<<<<
 * 	else:
 * 		results = [(treestr, logprobsum(probs),
 */
      __pyx_t_5 = 0;
      __pyx_t_10 = __Pyx_dict_iterator(__pyx_v_parsetrees, 1, __pyx_n_s_items, (&__pyx_t_21), (&__pyx_t_20)); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 231, __pyx_L122_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_XDECREF(__pyx_t_6);
      __pyx_t_6 = __pyx_t_10;
      __pyx_t_10 = 0;
      while (1) {
        __pyx_t_24 = __Pyx_dict_iter_next(__pyx_t_6, __pyx_t_21, &__pyx_t_5, &__pyx_t_10, &__pyx_t_11, NULL, __pyx_t_20);
        if (unlikely(__pyx_t_24 == 0)) break;
        if (unlikely(__pyx_t_24 == -1)) __PYX_ERR(0, 231, __pyx_L122_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_GOTREF(__pyx_t_11);
        if (!(likely(PyUnicode_CheckExact(__pyx_t_10))||((__pyx_t_10) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_10)->tp_name), 0))) __PYX_ERR(0, 231, __pyx_L122_error)
        __Pyx_XDECREF_SET(__pyx_8genexpr5__pyx_v_treestr, ((PyObject*)__pyx_t_10));
        __pyx_t_10 = 0;
        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, 231, __pyx_L122_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_19 = PyTuple_GET_ITEM(sequence, 1); 
          } else {
            __pyx_t_10 = PyList_GET_ITEM(sequence, 0); 
            __pyx_t_19 = PyList_GET_ITEM(sequence, 1); 
          }
          __Pyx_INCREF(__pyx_t_10);
          __Pyx_INCREF(__pyx_t_19);
          #else
          __pyx_t_10 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 231, __pyx_L122_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_19 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 231, __pyx_L122_error)
          __Pyx_GOTREF(__pyx_t_19);
          #endif
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        } else {
          Py_ssize_t index = -1;
          __pyx_t_3 = PyObject_GetIter(__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 231, __pyx_L122_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
          __pyx_t_9 = Py_TYPE(__pyx_t_3)->tp_iternext;
          index = 0; __pyx_t_10 = __pyx_t_9(__pyx_t_3); if (unlikely(!__pyx_t_10)) goto __pyx_L125_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_10);
          index = 1; __pyx_t_19 = __pyx_t_9(__pyx_t_3); if (unlikely(!__pyx_t_19)) goto __pyx_L125_unpacking_failed;
          __Pyx_GOTREF(__pyx_t_19);
          if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_3), 2) < 0) __PYX_ERR(0, 231, __pyx_L122_error)
          __pyx_t_9 = NULL;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          goto __pyx_L126_unpacking_done;
          __pyx_L125_unpacking_failed:;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_t_9 = NULL;
          if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
          __PYX_ERR(0, 231, __pyx_L122_error)
          __pyx_L126_unpacking_done:;
        }
        __Pyx_XDECREF_SET(__pyx_8genexpr5__pyx_v_a, __pyx_t_10);
        __pyx_t_10 = 0;
        __Pyx_XDECREF_SET(__pyx_8genexpr5__pyx_v_b, __pyx_t_19);
        __pyx_t_19 = 0;

        /* "discodop/disambiguation.pyx":229
 * 				for treestr, (a, b) in parsetrees.items()]
 * 	elif shortest:
 * 		results = [(treestr, (-a, b),             # <<<<<<<<<<<<<<
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 * 				for treestr, (a, b) in parsetrees.items()]
 */
        __pyx_t_11 = PyNumber_Negative(__pyx_8genexpr5__pyx_v_a); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 229, __pyx_L122_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_19 = PyTuple_New(2); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 229, __pyx_L122_error)
        __Pyx_GOTREF(__pyx_t_19);
        __Pyx_GIVEREF(__pyx_t_11);
        PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_11);
        __Pyx_INCREF(__pyx_8genexpr5__pyx_v_b);
        __Pyx_GIVEREF(__pyx_8genexpr5__pyx_v_b);
        PyTuple_SET_ITEM(__pyx_t_19, 1, __pyx_8genexpr5__pyx_v_b);
        __pyx_t_11 = 0;

        /* "discodop/disambiguation.pyx":230
 * 	elif shortest:
 * 		results = [(treestr, (-a, b),
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))             # <<<<<<<<<<<<<<
 * 				for treestr, (a, b) in parsetrees.items()]
 * 	else:
 */
        __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_fragmentsinderiv); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 230, __pyx_L122_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_derivs, __pyx_8genexpr5__pyx_v_treestr); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 230, __pyx_L122_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_25 = NULL;
        __pyx_t_24 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) {
          __pyx_t_25 = PyMethod_GET_SELF(__pyx_t_10);
          if (likely(__pyx_t_25)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
            __Pyx_INCREF(__pyx_t_25);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_10, function);
            __pyx_t_24 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_10)) {
          PyObject *__pyx_temp[4] = {__pyx_t_25, __pyx_t_3, ((PyObject *)__pyx_v_chart), __pyx_v_backtransform};
          __pyx_t_11 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_24, 3+__pyx_t_24); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 230, __pyx_L122_error)
          __Pyx_XDECREF(__pyx_t_25); __pyx_t_25 = 0;
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) {
          PyObject *__pyx_temp[4] = {__pyx_t_25, __pyx_t_3, ((PyObject *)__pyx_v_chart), __pyx_v_backtransform};
          __pyx_t_11 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_24, 3+__pyx_t_24); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 230, __pyx_L122_error)
          __Pyx_XDECREF(__pyx_t_25); __pyx_t_25 = 0;
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        } else
        #endif
        {
          __pyx_t_26 = PyTuple_New(3+__pyx_t_24); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 230, __pyx_L122_error)
          __Pyx_GOTREF(__pyx_t_26);
          if (__pyx_t_25) {
            __Pyx_GIVEREF(__pyx_t_25); PyTuple_SET_ITEM(__pyx_t_26, 0, __pyx_t_25); __pyx_t_25 = NULL;
          }
          __Pyx_GIVEREF(__pyx_t_3);
          PyTuple_SET_ITEM(__pyx_t_26, 0+__pyx_t_24, __pyx_t_3);
          __Pyx_INCREF(((PyObject *)__pyx_v_chart));
          __Pyx_GIVEREF(((PyObject *)__pyx_v_chart));
          PyTuple_SET_ITEM(__pyx_t_26, 1+__pyx_t_24, ((PyObject *)__pyx_v_chart));
          __Pyx_INCREF(__pyx_v_backtransform);
          __Pyx_GIVEREF(__pyx_v_backtransform);
          PyTuple_SET_ITEM(__pyx_t_26, 2+__pyx_t_24, __pyx_v_backtransform);
          __pyx_t_3 = 0;
          __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_26, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 230, __pyx_L122_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
        }
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

        /* "discodop/disambiguation.pyx":229
 * 				for treestr, (a, b) in parsetrees.items()]
 * 	elif shortest:
 * 		results = [(treestr, (-a, b),             # <<<<<<<<<<<<<<
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 * 				for treestr, (a, b) in parsetrees.items()]
 */
        __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 229, __pyx_L122_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_INCREF(__pyx_8genexpr5__pyx_v_treestr);
        __Pyx_GIVEREF(__pyx_8genexpr5__pyx_v_treestr);
        PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_8genexpr5__pyx_v_treestr);
        __Pyx_GIVEREF(__pyx_t_19);
        PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_19);
        __Pyx_GIVEREF(__pyx_t_11);
        PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_t_11);
        __pyx_t_19 = 0;
        __pyx_t_11 = 0;
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_8, (PyObject*)__pyx_t_10))) __PYX_ERR(0, 229, __pyx_L122_error)
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_8genexpr5__pyx_v_treestr);
      __Pyx_XDECREF(__pyx_8genexpr5__pyx_v_a);
      __Pyx_XDECREF(__pyx_8genexpr5__pyx_v_b);
      goto __pyx_L127_exit_scope;
      __pyx_L122_error:;
      __Pyx_XDECREF(__pyx_8genexpr5__pyx_v_treestr);
      __Pyx_XDECREF(__pyx_8genexpr5__pyx_v_a);
      __Pyx_XDECREF(__pyx_8genexpr5__pyx_v_b);
      goto __pyx_L1_error;
      __pyx_L127_exit_scope:;
    } /* exit inner scope */
    __pyx_v_results = ((PyObject*)__pyx_t_8);
    __pyx_t_8 = 0;

    /* "discodop/disambiguation.pyx":228
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 * 				for treestr, (a, b) in parsetrees.items()]
 * 	elif shortest:             # <<<<<<<<<<<<<<
 * 		results = [(treestr, (-a, b),
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 */
    goto __pyx_L101;
  }

  /* "discodop/disambiguation.pyx":233
 * 				for treestr, (a, b) in parsetrees.items()]
 * 	else:
 * 		results = [(treestr, logprobsum(probs),             # <<<<<<<<<<<<<<
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 * 				for treestr, probs in parsetrees.items()]
 */
  /*else*/ {
    { /* enter inner scope */
      PyObject *__pyx_8genexpr6__pyx_v_treestr = NULL;
      PyObject *__pyx_8genexpr6__pyx_v_probs = NULL;
      __pyx_t_8 = PyList_New(0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 233, __pyx_L130_error)
      __Pyx_GOTREF(__pyx_t_8);

      /* "discodop/disambiguation.pyx":235
 * 		results = [(treestr, logprobsum(probs),
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 * 				for treestr, probs in parsetrees.items()]             # <<<<<<<<<<<<<<
 * 
 * 	msg = '%d derivations, %d parsetrees' % (
 */
      __pyx_t_21 = 0;
      __pyx_t_10 = __Pyx_dict_iterator(__pyx_v_parsetrees, 1, __pyx_n_s_items, (&__pyx_t_5), (&__pyx_t_20)); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 235, __pyx_L130_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_XDECREF(__pyx_t_6);
      __pyx_t_6 = __pyx_t_10;
      __pyx_t_10 = 0;
      while (1) {
        __pyx_t_24 = __Pyx_dict_iter_next(__pyx_t_6, __pyx_t_5, &__pyx_t_21, &__pyx_t_10, &__pyx_t_11, NULL, __pyx_t_20);
        if (unlikely(__pyx_t_24 == 0)) break;
        if (unlikely(__pyx_t_24 == -1)) __PYX_ERR(0, 235, __pyx_L130_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_GOTREF(__pyx_t_11);
        if (!(likely(PyUnicode_CheckExact(__pyx_t_10))||((__pyx_t_10) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_10)->tp_name), 0))) __PYX_ERR(0, 235, __pyx_L130_error)
        __Pyx_XDECREF_SET(__pyx_8genexpr6__pyx_v_treestr, ((PyObject*)__pyx_t_10));
        __pyx_t_10 = 0;
        __Pyx_XDECREF_SET(__pyx_8genexpr6__pyx_v_probs, __pyx_t_11);
        __pyx_t_11 = 0;

        /* "discodop/disambiguation.pyx":233
 * 				for treestr, (a, b) in parsetrees.items()]
 * 	else:
 * 		results = [(treestr, logprobsum(probs),             # <<<<<<<<<<<<<<
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 * 				for treestr, probs in parsetrees.items()]
 */
        if (!(likely(PyList_CheckExact(__pyx_8genexpr6__pyx_v_probs))||((__pyx_8genexpr6__pyx_v_probs) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_8genexpr6__pyx_v_probs)->tp_name), 0))) __PYX_ERR(0, 233, __pyx_L130_error)
        __pyx_t_11 = PyFloat_FromDouble(__pyx_f_8discodop_10containers_logprobsum(((PyObject*)__pyx_8genexpr6__pyx_v_probs))); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 233, __pyx_L130_error)
        __Pyx_GOTREF(__pyx_t_11);

        /* "discodop/disambiguation.pyx":234
 * 	else:
 * 		results = [(treestr, logprobsum(probs),
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))             # <<<<<<<<<<<<<<
 * 				for treestr, probs in parsetrees.items()]
 * 
 */
        __pyx_t_19 = __Pyx_GetModuleGlobalName(__pyx_n_s_fragmentsinderiv); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 234, __pyx_L130_error)
        __Pyx_GOTREF(__pyx_t_19);
        __pyx_t_26 = __Pyx_PyDict_GetItem(__pyx_v_derivs, __pyx_8genexpr6__pyx_v_treestr); if (unlikely(!__pyx_t_26)) __PYX_ERR(0, 234, __pyx_L130_error)
        __Pyx_GOTREF(__pyx_t_26);
        __pyx_t_3 = NULL;
        __pyx_t_24 = 0;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_19))) {
          __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_19);
          if (likely(__pyx_t_3)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19);
            __Pyx_INCREF(__pyx_t_3);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_19, function);
            __pyx_t_24 = 1;
          }
        }
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_19)) {
          PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_t_26, ((PyObject *)__pyx_v_chart), __pyx_v_backtransform};
          __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_19, __pyx_temp+1-__pyx_t_24, 3+__pyx_t_24); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 234, __pyx_L130_error)
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_19)) {
          PyObject *__pyx_temp[4] = {__pyx_t_3, __pyx_t_26, ((PyObject *)__pyx_v_chart), __pyx_v_backtransform};
          __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_19, __pyx_temp+1-__pyx_t_24, 3+__pyx_t_24); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 234, __pyx_L130_error)
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_26); __pyx_t_26 = 0;
        } else
        #endif
        {
          __pyx_t_25 = PyTuple_New(3+__pyx_t_24); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 234, __pyx_L130_error)
          __Pyx_GOTREF(__pyx_t_25);
          if (__pyx_t_3) {
            __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_25, 0, __pyx_t_3); __pyx_t_3 = NULL;
          }
          __Pyx_GIVEREF(__pyx_t_26);
          PyTuple_SET_ITEM(__pyx_t_25, 0+__pyx_t_24, __pyx_t_26);
          __Pyx_INCREF(((PyObject *)__pyx_v_chart));
          __Pyx_GIVEREF(((PyObject *)__pyx_v_chart));
          PyTuple_SET_ITEM(__pyx_t_25, 1+__pyx_t_24, ((PyObject *)__pyx_v_chart));
          __Pyx_INCREF(__pyx_v_backtransform);
          __Pyx_GIVEREF(__pyx_v_backtransform);
          PyTuple_SET_ITEM(__pyx_t_25, 2+__pyx_t_24, __pyx_v_backtransform);
          __pyx_t_26 = 0;
          __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_19, __pyx_t_25, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 234, __pyx_L130_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_25); __pyx_t_25 = 0;
        }
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;

        /* "discodop/disambiguation.pyx":233
 * 				for treestr, (a, b) in parsetrees.items()]
 * 	else:
 * 		results = [(treestr, logprobsum(probs),             # <<<<<<<<<<<<<<
 * 				fragmentsinderiv(derivs[treestr], chart, backtransform))
 * 				for treestr, probs in parsetrees.items()]
 */
        __pyx_t_19 = PyTuple_New(3); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 233, __pyx_L130_error)
        __Pyx_GOTREF(__pyx_t_19);
        __Pyx_INCREF(__pyx_8genexpr6__pyx_v_treestr);
        __Pyx_GIVEREF(__pyx_8genexpr6__pyx_v_treestr);
        PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_8genexpr6__pyx_v_treestr);
        __Pyx_GIVEREF(__pyx_t_11);
        PyTuple_SET_ITEM(__pyx_t_19, 1, __pyx_t_11);
        __Pyx_GIVEREF(__pyx_t_10);
        PyTuple_SET_ITEM(__pyx_t_19, 2, __pyx_t_10);
        __pyx_t_11 = 0;
        __pyx_t_10 = 0;
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_8, (PyObject*)__pyx_t_19))) __PYX_ERR(0, 233, __pyx_L130_error)
        __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_8genexpr6__pyx_v_treestr);
      __Pyx_XDECREF(__pyx_8genexpr6__pyx_v_probs);
      goto __pyx_L133_exit_scope;
      __pyx_L130_error:;
      __Pyx_XDECREF(__pyx_8genexpr6__pyx_v_treestr);
      __Pyx_XDECREF(__pyx_8genexpr6__pyx_v_probs);
      goto __pyx_L1_error;
      __pyx_L133_exit_scope:;
    } /* exit inner scope */
    __pyx_v_results = ((PyObject*)__pyx_t_8);
    __pyx_t_8 = 0;
  }
  __pyx_L101:;

  /* "discodop/disambiguation.pyx":238
 * 
 * 	msg = '%d derivations, %d parsetrees' % (
 * 			len(derivations if dopreduction else entries),             # <<<<<<<<<<<<<<
 * 			len(parsetrees))
 * 	return results, msg
 */
  if ((__pyx_v_dopreduction != 0)) {
    __Pyx_INCREF(__pyx_v_derivations);
    __pyx_t_8 = __pyx_v_derivations;
  } else {
    __Pyx_INCREF(__pyx_v_entries);
    __pyx_t_8 = __pyx_v_entries;
  }
  if (unlikely(__pyx_t_8 == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 238, __pyx_L1_error)
  }
  __pyx_t_5 = PyList_GET_SIZE(__pyx_t_8); if (unlikely(__pyx_t_5 == -1)) __PYX_ERR(0, 238, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 238, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);

  /* "discodop/disambiguation.pyx":239
 * 	msg = '%d derivations, %d parsetrees' % (
 * 			len(derivations if dopreduction else entries),
 * 			len(parsetrees))             # <<<<<<<<<<<<<<
 * 	return results, msg
 * 
 */
  __pyx_t_5 = PyDict_Size(__pyx_v_parsetrees); if (unlikely(__pyx_t_5 == -1)) __PYX_ERR(0, 239, __pyx_L1_error)
  __pyx_t_6 = PyInt_FromSsize_t(__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 239, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);

  /* "discodop/disambiguation.pyx":238
 * 
 * 	msg = '%d derivations, %d parsetrees' % (
 * 			len(derivations if dopreduction else entries),             # <<<<<<<<<<<<<<
 * 			len(parsetrees))
 * 	return results, msg
 */
  __pyx_t_19 = PyTuple_New(2); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 238, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_19);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_19, 0, __pyx_t_8);
  __Pyx_GIVEREF(__pyx_t_6);
  PyTuple_SET_ITEM(__pyx_t_19, 1, __pyx_t_6);
  __pyx_t_8 = 0;
  __pyx_t_6 = 0;

  /* "discodop/disambiguation.pyx":237
 * 				for treestr, probs in parsetrees.items()]
 * 
 * 	msg = '%d derivations, %d parsetrees' % (             # <<<<<<<<<<<<<<
 * 			len(derivations if dopreduction else entries),
 * 			len(parsetrees))
 */
  __pyx_t_6 = PyUnicode_Format(__pyx_kp_u_d_derivations_d_parsetrees, __pyx_t_19); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 237, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
  __pyx_v_msg = ((PyObject*)__pyx_t_6);
  __pyx_t_6 = 0;

  /* "discodop/disambiguation.pyx":240
 * 			len(derivations if dopreduction else entries),
 * 			len(parsetrees))
 * 	return results, msg             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 240, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_INCREF(__pyx_v_results);
  __Pyx_GIVEREF(__pyx_v_results);
  PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_results);
  __Pyx_INCREF(__pyx_v_msg);
  __Pyx_GIVEREF(__pyx_v_msg);
  PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_msg);
  __pyx_r = __pyx_t_6;
  __pyx_t_6 = 0;
  goto __pyx_L0;

  /* "discodop/disambiguation.pyx":80
 * 
 * 
 * cpdef marginalize(method, list derivations, list entries, Chart chart,             # <<<<<<<<<<<<<<
 * 		list backtransform=None, list sent=None, list tags=None,
 * 		int k=1000, int sldop_n=7, double mcc_labda=1.0, set mcc_labels=None,
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_11);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_XDECREF(__pyx_t_25);
  __Pyx_XDECREF(__pyx_t_26);
  __Pyx_AddTraceback("discodop.disambiguation.marginalize", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_entry);
  __Pyx_XDECREF((PyObject *)__pyx_v_lexrule);
  __Pyx_XDECREF(__pyx_v_parsetrees);
  __Pyx_XDECREF(__pyx_v_derivs);
  __Pyx_XDECREF(__pyx_v_treestr);
  __Pyx_XDECREF(__pyx_v_deriv);
  __Pyx_XDECREF(__pyx_v__);
  __Pyx_XDECREF(__pyx_v_newprob);
  __Pyx_XDECREF(__pyx_v_score);
  __Pyx_XDECREF(__pyx_v_tree);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XDECREF(__pyx_v_oldscore);
  __Pyx_XDECREF(__pyx_v_results);
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XDECREF(__pyx_v_derivations);
  __Pyx_XDECREF(__pyx_v_entries);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_8discodop_14disambiguation_3marginalize(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8discodop_14disambiguation_2marginalize[] = "marginalize(method, list derivations, list entries, Chart chart, list backtransform=None, list sent=None, list tags=None, int k=1000, int sldop_n=7, double mcc_labda=1.0, set mcc_labels=None, bool bitpar=False)\nTake a list of derivations and optimize a given objective function.\n\n\t1. Rewrites derivations into the intended parse trees.\n\t2. Marginalizes (sum / combine) weights of derivations for same parse tree.\n\t3. Applies objective function (scoring criterion) for ranking parse trees.\n\n\t:param method:\n\t\tAvailable objective functions:\n\n\t\t:'mpp': Most Probable Parse\n\t\t:'mpd': Most Probable Derivation\n\t\t:'shortest': Most Probable Shortest Derivation\n\t\t:'sl-dop': Simplicity-Likelihood DOP; select most likely parse from the\n\t\t\t``sldop_n`` parse trees with the shortest derivations.\n\t\t:'sl-dop-simple': Approximation of Simplicity-Likelihood DOP\n\t:param backtransform:\n\t\tDependending on the value of this parameter, one of two ways is\n\t\temployed to turn derivations into parse trees:\n\n\t\t:``None``: assume derivations are from DOP reduction and strip\n\t\t\tannotations of the form ``@123`` from labels. This option is also\n\t\t\tapplicable when the grammar is not a TSG and derivations already\n\t\t\tcoincide with parse trees.\n\t\t:list of strings: assume Double-DOP and recover derivations by\n\t\t\tsubstituting fragments in this list for flattened rules in\n\t\t\tderivations.\n\t:param k: when ``method='sl-dop``, number of derivations to consider.\n\t:param bitpar: whether bitpar was used in nbest mode.\n\t:returns:\n\t\t``(parses, msg)``.\n\n\t\t:parses: a list of tuples ``(parsetree, probability, fragments)``\n\t\t\twhere ``parsetree`` is a string, ``probability`` is a float\n\t\t\t(0 < p <= 1), or a tuple ``(numfrags, p)`` for shortest derivation\n\t\t\tparsing, and ``fragments`` is a list of fragments in the most\n\t\t\tprobable derivation for this parse.\n\t\t:msg: a message reporting the number of derivations / parses.\n\t";
static PyObject *__pyx_pw_8discodop_14disambiguation_3marginalize(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_method = 0;
  PyObject *__pyx_v_derivations = 0;
  PyObject *__pyx_v_entries = 0;
  struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart = 0;
  PyObject *__pyx_v_backtransform = 0;
  PyObject *__pyx_v_sent = 0;
  PyObject *__pyx_v_tags = 0;
  int __pyx_v_k;
  int __pyx_v_sldop_n;
  double __pyx_v_mcc_labda;
  PyObject *__pyx_v_mcc_labels = 0;
  int __pyx_v_bitpar;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("marginalize (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_method,&__pyx_n_s_derivations,&__pyx_n_s_entries,&__pyx_n_s_chart,&__pyx_n_s_backtransform,&__pyx_n_s_sent,&__pyx_n_s_tags,&__pyx_n_s_k,&__pyx_n_s_sldop_n,&__pyx_n_s_mcc_labda,&__pyx_n_s_mcc_labels,&__pyx_n_s_bitpar,0};
    PyObject* values[12] = {0,0,0,0,0,0,0,0,0,0,0,0};

    /* "discodop/disambiguation.pyx":81
 * 
 * cpdef marginalize(method, list derivations, list entries, Chart chart,
 * 		list backtransform=None, list sent=None, list tags=None,             # <<<<<<<<<<<<<<
 * 		int k=1000, int sldop_n=7, double mcc_labda=1.0, set mcc_labels=None,
 * 		bint bitpar=False):
 */
    values[4] = ((PyObject*)Py_None);
    values[5] = ((PyObject*)Py_None);
    values[6] = ((PyObject*)Py_None);

    /* "discodop/disambiguation.pyx":82
 * cpdef marginalize(method, list derivations, list entries, Chart chart,
 * 		list backtransform=None, list sent=None, list tags=None,
 * 		int k=1000, int sldop_n=7, double mcc_labda=1.0, set mcc_labels=None,             # <<<<<<<<<<<<<<
 * 		bint bitpar=False):
 * 	"""Take a list of derivations and optimize a given objective function.
 */
    values[10] = ((PyObject*)Py_None);
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11);
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_method)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_derivations)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("marginalize", 0, 4, 12, 1); __PYX_ERR(0, 80, __pyx_L3_error)
        }
        case  2:
        if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_entries)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("marginalize", 0, 4, 12, 2); __PYX_ERR(0, 80, __pyx_L3_error)
        }
        case  3:
        if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chart)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("marginalize", 0, 4, 12, 3); __PYX_ERR(0, 80, __pyx_L3_error)
        }
        case  4:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_backtransform);
          if (value) { values[4] = value; kw_args--; }
        }
        case  5:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sent);
          if (value) { values[5] = value; kw_args--; }
        }
        case  6:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tags);
          if (value) { values[6] = value; kw_args--; }
        }
        case  7:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_k);
          if (value) { values[7] = value; kw_args--; }
        }
        case  8:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sldop_n);
          if (value) { values[8] = value; kw_args--; }
        }
        case  9:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_mcc_labda);
          if (value) { values[9] = value; kw_args--; }
        }
        case 10:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_mcc_labels);
          if (value) { values[10] = value; kw_args--; }
        }
        case 11:
        if (kw_args > 0) {
          PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_bitpar);
          if (value) { values[11] = value; kw_args--; }
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "marginalize") < 0)) __PYX_ERR(0, 80, __pyx_L3_error)
      }
    } else {
      switch (PyTuple_GET_SIZE(__pyx_args)) {
        case 12: values[11] = PyTuple_GET_ITEM(__pyx_args, 11);
        case 11: values[10] = PyTuple_GET_ITEM(__pyx_args, 10);
        case 10: values[9] = PyTuple_GET_ITEM(__pyx_args, 9);
        case  9: values[8] = PyTuple_GET_ITEM(__pyx_args, 8);
        case  8: values[7] = PyTuple_GET_ITEM(__pyx_args, 7);
        case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
        case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
        case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
        case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
        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_method = values[0];
    __pyx_v_derivations = ((PyObject*)values[1]);
    __pyx_v_entries = ((PyObject*)values[2]);
    __pyx_v_chart = ((struct __pyx_obj_8discodop_10containers_Chart *)values[3]);
    __pyx_v_backtransform = ((PyObject*)values[4]);
    __pyx_v_sent = ((PyObject*)values[5]);
    __pyx_v_tags = ((PyObject*)values[6]);
    if (values[7]) {
      __pyx_v_k = __Pyx_PyInt_As_int(values[7]); if (unlikely((__pyx_v_k == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 82, __pyx_L3_error)
    } else {
      __pyx_v_k = ((int)0x3E8);
    }
    if (values[8]) {
      __pyx_v_sldop_n = __Pyx_PyInt_As_int(values[8]); if (unlikely((__pyx_v_sldop_n == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 82, __pyx_L3_error)
    } else {
      __pyx_v_sldop_n = ((int)7);
    }
    if (values[9]) {
      __pyx_v_mcc_labda = __pyx_PyFloat_AsDouble(values[9]); if (unlikely((__pyx_v_mcc_labda == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 82, __pyx_L3_error)
    } else {
      __pyx_v_mcc_labda = ((double)1.0);
    }
    __pyx_v_mcc_labels = ((PyObject*)values[10]);
    if (values[11]) {
      __pyx_v_bitpar = __Pyx_PyObject_IsTrue(values[11]); if (unlikely((__pyx_v_bitpar == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 83, __pyx_L3_error)
    } else {

      /* "discodop/disambiguation.pyx":83
 * 		list backtransform=None, list sent=None, list tags=None,
 * 		int k=1000, int sldop_n=7, double mcc_labda=1.0, set mcc_labels=None,
 * 		bint bitpar=False):             # <<<<<<<<<<<<<<
 * 	"""Take a list of derivations and optimize a given objective function.
 * 
 */
      __pyx_v_bitpar = ((int)0);
    }
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("marginalize", 0, 4, 12, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 80, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discodop.disambiguation.marginalize", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_derivations), (&PyList_Type), 1, "derivations", 1))) __PYX_ERR(0, 80, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_entries), (&PyList_Type), 1, "entries", 1))) __PYX_ERR(0, 80, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_chart), __pyx_ptype_8discodop_10containers_Chart, 1, "chart", 0))) __PYX_ERR(0, 80, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_backtransform), (&PyList_Type), 1, "backtransform", 1))) __PYX_ERR(0, 81, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_sent), (&PyList_Type), 1, "sent", 1))) __PYX_ERR(0, 81, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_tags), (&PyList_Type), 1, "tags", 1))) __PYX_ERR(0, 81, __pyx_L1_error)
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_mcc_labels), (&PySet_Type), 1, "mcc_labels", 1))) __PYX_ERR(0, 82, __pyx_L1_error)
  __pyx_r = __pyx_pf_8discodop_14disambiguation_2marginalize(__pyx_self, __pyx_v_method, __pyx_v_derivations, __pyx_v_entries, __pyx_v_chart, __pyx_v_backtransform, __pyx_v_sent, __pyx_v_tags, __pyx_v_k, __pyx_v_sldop_n, __pyx_v_mcc_labda, __pyx_v_mcc_labels, __pyx_v_bitpar);

  /* "discodop/disambiguation.pyx":80
 * 
 * 
 * cpdef marginalize(method, list derivations, list entries, Chart chart,             # <<<<<<<<<<<<<<
 * 		list backtransform=None, list sent=None, list tags=None,
 * 		int k=1000, int sldop_n=7, double mcc_labda=1.0, set mcc_labels=None,
 */

  /* function exit code */
  goto __pyx_L0;
  __pyx_L1_error:;
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

static PyObject *__pyx_pf_8discodop_14disambiguation_2marginalize(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_method, PyObject *__pyx_v_derivations, PyObject *__pyx_v_entries, struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, PyObject *__pyx_v_backtransform, PyObject *__pyx_v_sent, PyObject *__pyx_v_tags, int __pyx_v_k, int __pyx_v_sldop_n, double __pyx_v_mcc_labda, PyObject *__pyx_v_mcc_labels, int __pyx_v_bitpar) {
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  struct __pyx_opt_args_8discodop_14disambiguation_marginalize __pyx_t_2;
  __Pyx_RefNannySetupContext("marginalize", 0);
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2.__pyx_n = 8;
  __pyx_t_2.backtransform = __pyx_v_backtransform;
  __pyx_t_2.sent = __pyx_v_sent;
  __pyx_t_2.tags = __pyx_v_tags;
  __pyx_t_2.k = __pyx_v_k;
  __pyx_t_2.sldop_n = __pyx_v_sldop_n;
  __pyx_t_2.mcc_labda = __pyx_v_mcc_labda;
  __pyx_t_2.mcc_labels = __pyx_v_mcc_labels;
  __pyx_t_2.bitpar = __pyx_v_bitpar;
  __pyx_t_1 = __pyx_f_8discodop_14disambiguation_marginalize(__pyx_v_method, __pyx_v_derivations, __pyx_v_entries, __pyx_v_chart, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_AddTraceback("discodop.disambiguation.marginalize", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discodop/disambiguation.pyx":243
 * 
 * 
 * cdef maxconstituentscorrect(list derivations, Chart chart,             # <<<<<<<<<<<<<<
 * 		list backtransform, double labda, set labels=None):
 * 	"""Approximate the Most Constituents Correct (MCC) parse from n-best list.
 */

static PyObject *__pyx_f_8discodop_14disambiguation_maxconstituentscorrect(PyObject *__pyx_v_derivations, struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, PyObject *__pyx_v_backtransform, double __pyx_v_labda, struct __pyx_opt_args_8discodop_14disambiguation_maxconstituentscorrect *__pyx_optional_args) {

  /* "discodop/disambiguation.pyx":244
 * 
 * cdef maxconstituentscorrect(list derivations, Chart chart,
 * 		list backtransform, double labda, set labels=None):             # <<<<<<<<<<<<<<
 * 	"""Approximate the Most Constituents Correct (MCC) parse from n-best list.
 * 
 */
  PyObject *__pyx_v_labels = ((PyObject*)Py_None);
  double __pyx_v_sentprob;
  double __pyx_v_maxscore;
  double __pyx_v_prob;
  double __pyx_v_score;
  double __pyx_v_maxcombscore;
  double __pyx_v_contribution;
  short __pyx_v_start;
  short __pyx_v_spanlen;
  PyObject *__pyx_v_span = 0;
  PyObject *__pyx_v_leftspan = 0;
  PyObject *__pyx_v_rightspan = 0;
  PyObject *__pyx_v_maxleft = 0;
  PyObject *__pyx_v_table = NULL;
  PyObject *__pyx_v_tree = NULL;
  PyObject *__pyx_v_deriv = NULL;
  PyObject *__pyx_v_treestr = NULL;
  PyObject *__pyx_v_t = NULL;
  PyObject *__pyx_v_tablecell = NULL;
  PyObject *__pyx_v_cells = NULL;
  CYTHON_UNUSED PyObject *__pyx_v__ = NULL;
  PyObject *__pyx_v_maxlabel = NULL;
  PyObject *__pyx_v_spans = NULL;
  PyObject *__pyx_v_tmp = NULL;
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_r = NULL;
  __Pyx_RefNannyDeclarations
  PyObject *__pyx_t_1 = NULL;
  PyObject *__pyx_t_2 = NULL;
  Py_ssize_t __pyx_t_3;
  Py_ssize_t __pyx_t_4;
  PyObject *__pyx_t_5 = NULL;
  Py_ssize_t __pyx_t_6;
  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)(PyObject *);
  double __pyx_t_12;
  int __pyx_t_13;
  int __pyx_t_14;
  int __pyx_t_15;
  PyObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  PyObject *__pyx_t_18 = NULL;
  PyObject *__pyx_t_19 = NULL;
  PyObject *__pyx_t_20 = NULL;
  PyObject *__pyx_t_21 = NULL;
  PyObject *__pyx_t_22 = NULL;
  PyObject *(*__pyx_t_23)(PyObject *);
  short __pyx_t_24;
  int __pyx_t_25;
  short __pyx_t_26;
  int __pyx_t_27;
  Py_ssize_t __pyx_t_28;
  Py_ssize_t __pyx_t_29;
  PyObject *(*__pyx_t_30)(PyObject *);
  PyObject *__pyx_t_31 = NULL;
  PyObject *__pyx_t_32 = NULL;
  PyObject *__pyx_t_33 = NULL;
  __Pyx_RefNannySetupContext("maxconstituentscorrect", 0);
  if (__pyx_optional_args) {
    if (__pyx_optional_args->__pyx_n > 0) {
      __pyx_v_labels = __pyx_optional_args->labels;
    }
  }

  /* "discodop/disambiguation.pyx":258
 * 	"""
 * 	# NB: this requires derivations not entries.
 * 	cdef double sentprob = 0.0, maxscore = 0.0             # <<<<<<<<<<<<<<
 * 	cdef double prob, score, maxcombscore, contribution
 * 	cdef short start, spanlen
 */
  __pyx_v_sentprob = 0.0;
  __pyx_v_maxscore = 0.0;

  /* "discodop/disambiguation.pyx":263
 * 	cdef object span, leftspan, rightspan, maxleft  # bitsets as Python ints
 * 	# table[start][spanlen][span][label] = prob
 * 	table = [[defaultdict(dict)             # <<<<<<<<<<<<<<
 * 				for _ in range(len(chart.sent) - n + 1)]
 * 			for n in range(len(chart.sent))]
 */
  { /* enter inner scope */
    Py_ssize_t __pyx_8genexpr7__pyx_v_n;
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 263, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "discodop/disambiguation.pyx":265
 * 	table = [[defaultdict(dict)
 * 				for _ in range(len(chart.sent) - n + 1)]
 * 			for n in range(len(chart.sent))]             # <<<<<<<<<<<<<<
 * 	tree = None
 * 	# get marginal probabilities
 */
    __pyx_t_2 = __pyx_v_chart->sent;
    __Pyx_INCREF(__pyx_t_2);
    if (unlikely(__pyx_t_2 == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
      __PYX_ERR(0, 265, __pyx_L1_error)
    }
    __pyx_t_3 = PyList_GET_SIZE(__pyx_t_2); if (unlikely(__pyx_t_3 == -1)) __PYX_ERR(0, 265, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    for (__pyx_t_4 = 0; __pyx_t_4 < __pyx_t_3; __pyx_t_4+=1) {
      __pyx_8genexpr7__pyx_v_n = __pyx_t_4;
      { /* enter inner scope */
        CYTHON_UNUSED Py_ssize_t __pyx_8genexpr8__pyx_8genexpr7__pyx_v__;

        /* "discodop/disambiguation.pyx":263
 * 	cdef object span, leftspan, rightspan, maxleft  # bitsets as Python ints
 * 	# table[start][spanlen][span][label] = prob
 * 	table = [[defaultdict(dict)             # <<<<<<<<<<<<<<
 * 				for _ in range(len(chart.sent) - n + 1)]
 * 			for n in range(len(chart.sent))]
 */
        __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 263, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);

        /* "discodop/disambiguation.pyx":264
 * 	# table[start][spanlen][span][label] = prob
 * 	table = [[defaultdict(dict)
 * 				for _ in range(len(chart.sent) - n + 1)]             # <<<<<<<<<<<<<<
 * 			for n in range(len(chart.sent))]
 * 	tree = None
 */
        __pyx_t_5 = __pyx_v_chart->sent;
        __Pyx_INCREF(__pyx_t_5);
        if (unlikely(__pyx_t_5 == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
          __PYX_ERR(0, 264, __pyx_L1_error)
        }
        __pyx_t_6 = PyList_GET_SIZE(__pyx_t_5); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 264, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        __pyx_t_7 = ((__pyx_t_6 - __pyx_8genexpr7__pyx_v_n) + 1);
        for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_7; __pyx_t_6+=1) {
          __pyx_8genexpr8__pyx_8genexpr7__pyx_v__ = __pyx_t_6;

          /* "discodop/disambiguation.pyx":263
 * 	cdef object span, leftspan, rightspan, maxleft  # bitsets as Python ints
 * 	# table[start][spanlen][span][label] = prob
 * 	table = [[defaultdict(dict)             # <<<<<<<<<<<<<<
 * 				for _ in range(len(chart.sent) - n + 1)]
 * 			for n in range(len(chart.sent))]
 */
          __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_defaultdict); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 263, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_9 = NULL;
          if (CYTHON_UNPACK_METHODS && unlikely(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_5 = __Pyx_PyObject_CallOneArg(__pyx_t_8, ((PyObject *)(&PyDict_Type))); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 263, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_5);
          } else {
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_8)) {
              PyObject *__pyx_temp[2] = {__pyx_t_9, ((PyObject *)(&PyDict_Type))};
              __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 263, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
              __Pyx_GOTREF(__pyx_t_5);
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
              PyObject *__pyx_temp[2] = {__pyx_t_9, ((PyObject *)(&PyDict_Type))};
              __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 263, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
              __Pyx_GOTREF(__pyx_t_5);
            } else
            #endif
            {
              __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 263, __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(((PyObject *)(&PyDict_Type)));
              __Pyx_GIVEREF(((PyObject *)(&PyDict_Type)));
              PyTuple_SET_ITEM(__pyx_t_10, 0+1, ((PyObject *)(&PyDict_Type)));
              __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_10, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 263, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_5);
              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
            }
          }
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_5))) __PYX_ERR(0, 263, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
        }
      } /* exit inner scope */
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_2))) __PYX_ERR(0, 263, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
  } /* exit inner scope */
  __pyx_v_table = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":266
 * 				for _ in range(len(chart.sent) - n + 1)]
 * 			for n in range(len(chart.sent))]
 * 	tree = None             # <<<<<<<<<<<<<<
 * 	# get marginal probabilities
 * 	for deriv, prob in derivations:
 */
  __Pyx_INCREF(Py_None);
  __pyx_v_tree = Py_None;

  /* "discodop/disambiguation.pyx":268
 * 	tree = None
 * 	# get marginal probabilities
 * 	for deriv, prob in derivations:             # <<<<<<<<<<<<<<
 * 		if backtransform is None:
 * 			treestr = REMOVEIDS.sub('', deriv)
 */
  if (unlikely(__pyx_v_derivations == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(0, 268, __pyx_L1_error)
  }
  __pyx_t_1 = __pyx_v_derivations; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
  for (;;) {
    if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_1)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_3); __Pyx_INCREF(__pyx_t_2); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 268, __pyx_L1_error)
    #else
    __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 268, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    #endif
    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_5 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_8 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_5 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_8 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_8);
      #else
      __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 268, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 268, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      #endif
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_10 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 268, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_11 = Py_TYPE(__pyx_t_10)->tp_iternext;
      index = 0; __pyx_t_5 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_5)) goto __pyx_L9_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_5);
      index = 1; __pyx_t_8 = __pyx_t_11(__pyx_t_10); if (unlikely(!__pyx_t_8)) goto __pyx_L9_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_8);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_10), 2) < 0) __PYX_ERR(0, 268, __pyx_L1_error)
      __pyx_t_11 = NULL;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      goto __pyx_L10_unpacking_done;
      __pyx_L9_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_11 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 268, __pyx_L1_error)
      __pyx_L10_unpacking_done:;
    }
    __pyx_t_12 = __pyx_PyFloat_AsDouble(__pyx_t_8); if (unlikely((__pyx_t_12 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 268, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_XDECREF_SET(__pyx_v_deriv, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_v_prob = __pyx_t_12;

    /* "discodop/disambiguation.pyx":269
 * 	# get marginal probabilities
 * 	for deriv, prob in derivations:
 * 		if backtransform is None:             # <<<<<<<<<<<<<<
 * 			treestr = REMOVEIDS.sub('', deriv)
 * 		else:
 */
    __pyx_t_13 = (__pyx_v_backtransform == ((PyObject*)Py_None));
    __pyx_t_14 = (__pyx_t_13 != 0);
    if (__pyx_t_14) {

      /* "discodop/disambiguation.pyx":270
 * 	for deriv, prob in derivations:
 * 		if backtransform is None:
 * 			treestr = REMOVEIDS.sub('', deriv)             # <<<<<<<<<<<<<<
 * 		else:
 * 			treestr = recoverfragments(deriv, chart, backtransform)
 */
      __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_REMOVEIDS); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 270, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_sub); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 270, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = NULL;
      __pyx_t_15 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(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);
          __pyx_t_15 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_kp_u__4, __pyx_v_deriv};
        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 270, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[3] = {__pyx_t_8, __pyx_kp_u__4, __pyx_v_deriv};
        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 270, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else
      #endif
      {
        __pyx_t_10 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 270, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        if (__pyx_t_8) {
          __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_8); __pyx_t_8 = NULL;
        }
        __Pyx_INCREF(__pyx_kp_u__4);
        __Pyx_GIVEREF(__pyx_kp_u__4);
        PyTuple_SET_ITEM(__pyx_t_10, 0+__pyx_t_15, __pyx_kp_u__4);
        __Pyx_INCREF(__pyx_v_deriv);
        __Pyx_GIVEREF(__pyx_v_deriv);
        PyTuple_SET_ITEM(__pyx_t_10, 1+__pyx_t_15, __pyx_v_deriv);
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_10, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 270, __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_XDECREF_SET(__pyx_v_treestr, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "discodop/disambiguation.pyx":269
 * 	# get marginal probabilities
 * 	for deriv, prob in derivations:
 * 		if backtransform is None:             # <<<<<<<<<<<<<<
 * 			treestr = REMOVEIDS.sub('', deriv)
 * 		else:
 */
      goto __pyx_L11;
    }

    /* "discodop/disambiguation.pyx":272
 * 			treestr = REMOVEIDS.sub('', deriv)
 * 		else:
 * 			treestr = recoverfragments(deriv, chart, backtransform)             # <<<<<<<<<<<<<<
 * 		# rebinarize, collapse unaries, because we optimize only
 * 		# for constituents in the tree as it will be evaluated.
 */
    /*else*/ {
      __pyx_t_2 = __pyx_f_8discodop_14disambiguation_recoverfragments(__pyx_v_deriv, __pyx_v_chart, __pyx_v_backtransform, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 272, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_XDECREF_SET(__pyx_v_treestr, __pyx_t_2);
      __pyx_t_2 = 0;
    }
    __pyx_L11:;

    /* "discodop/disambiguation.pyx":275
 * 		# rebinarize, collapse unaries, because we optimize only
 * 		# for constituents in the tree as it will be evaluated.
 * 		tree = addbitsets(             # <<<<<<<<<<<<<<
 * 				binarize(
 * 				collapseunary(unbinarize(
 */
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_addbitsets); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 275, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);

    /* "discodop/disambiguation.pyx":276
 * 		# for constituents in the tree as it will be evaluated.
 * 		tree = addbitsets(
 * 				binarize(             # <<<<<<<<<<<<<<
 * 				collapseunary(unbinarize(
 * 					mergediscnodes(unbinarize(
 */
    __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_binarize); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 276, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);

    /* "discodop/disambiguation.pyx":277
 * 		tree = addbitsets(
 * 				binarize(
 * 				collapseunary(unbinarize(             # <<<<<<<<<<<<<<
 * 					mergediscnodes(unbinarize(
 * 						Tree(treestr),
 */
    __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_collapseunary); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 277, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_unbinarize); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 277, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);

    /* "discodop/disambiguation.pyx":278
 * 				binarize(
 * 				collapseunary(unbinarize(
 * 					mergediscnodes(unbinarize(             # <<<<<<<<<<<<<<
 * 						Tree(treestr),
 * 						childchar=':', expandunary=False)),
 */
    __pyx_t_17 = __Pyx_GetModuleGlobalName(__pyx_n_s_mergediscnodes); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 278, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_17);
    __pyx_t_18 = __Pyx_GetModuleGlobalName(__pyx_n_s_unbinarize); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 278, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_18);

    /* "discodop/disambiguation.pyx":279
 * 				collapseunary(unbinarize(
 * 					mergediscnodes(unbinarize(
 * 						Tree(treestr),             # <<<<<<<<<<<<<<
 * 						childchar=':', expandunary=False)),
 * 					expandunary=False),
 */
    __pyx_t_20 = __Pyx_GetModuleGlobalName(__pyx_n_s_Tree); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 279, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __pyx_t_21 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_20))) {
      __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_20);
      if (likely(__pyx_t_21)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_20);
        __Pyx_INCREF(__pyx_t_21);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_20, function);
      }
    }
    if (!__pyx_t_21) {
      __pyx_t_19 = __Pyx_PyObject_CallOneArg(__pyx_t_20, __pyx_v_treestr); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 279, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_19);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_20)) {
        PyObject *__pyx_temp[2] = {__pyx_t_21, __pyx_v_treestr};
        __pyx_t_19 = __Pyx_PyFunction_FastCall(__pyx_t_20, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 279, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0;
        __Pyx_GOTREF(__pyx_t_19);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_20)) {
        PyObject *__pyx_temp[2] = {__pyx_t_21, __pyx_v_treestr};
        __pyx_t_19 = __Pyx_PyCFunction_FastCall(__pyx_t_20, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 279, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0;
        __Pyx_GOTREF(__pyx_t_19);
      } else
      #endif
      {
        __pyx_t_22 = PyTuple_New(1+1); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 279, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_22);
        __Pyx_GIVEREF(__pyx_t_21); PyTuple_SET_ITEM(__pyx_t_22, 0, __pyx_t_21); __pyx_t_21 = NULL;
        __Pyx_INCREF(__pyx_v_treestr);
        __Pyx_GIVEREF(__pyx_v_treestr);
        PyTuple_SET_ITEM(__pyx_t_22, 0+1, __pyx_v_treestr);
        __pyx_t_19 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_t_22, NULL); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 279, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_19);
        __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;

    /* "discodop/disambiguation.pyx":278
 * 				binarize(
 * 				collapseunary(unbinarize(
 * 					mergediscnodes(unbinarize(             # <<<<<<<<<<<<<<
 * 						Tree(treestr),
 * 						childchar=':', expandunary=False)),
 */
    __pyx_t_20 = PyTuple_New(1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 278, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_GIVEREF(__pyx_t_19);
    PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_19);
    __pyx_t_19 = 0;

    /* "discodop/disambiguation.pyx":280
 * 					mergediscnodes(unbinarize(
 * 						Tree(treestr),
 * 						childchar=':', expandunary=False)),             # <<<<<<<<<<<<<<
 * 					expandunary=False),
 * 					joinchar='++'),
 */
    __pyx_t_19 = PyDict_New(); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 280, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_19);
    if (PyDict_SetItem(__pyx_t_19, __pyx_n_s_childchar, __pyx_kp_u__7) < 0) __PYX_ERR(0, 280, __pyx_L1_error)
    if (PyDict_SetItem(__pyx_t_19, __pyx_n_s_expandunary, Py_False) < 0) __PYX_ERR(0, 280, __pyx_L1_error)

    /* "discodop/disambiguation.pyx":278
 * 				binarize(
 * 				collapseunary(unbinarize(
 * 					mergediscnodes(unbinarize(             # <<<<<<<<<<<<<<
 * 						Tree(treestr),
 * 						childchar=':', expandunary=False)),
 */
    __pyx_t_22 = __Pyx_PyObject_Call(__pyx_t_18, __pyx_t_20, __pyx_t_19); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 278, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_22);
    __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0;
    __pyx_t_19 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_17))) {
      __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_17);
      if (likely(__pyx_t_19)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_17);
        __Pyx_INCREF(__pyx_t_19);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_17, function);
      }
    }
    if (!__pyx_t_19) {
      __pyx_t_16 = __Pyx_PyObject_CallOneArg(__pyx_t_17, __pyx_t_22); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 278, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
      __Pyx_GOTREF(__pyx_t_16);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_17)) {
        PyObject *__pyx_temp[2] = {__pyx_t_19, __pyx_t_22};
        __pyx_t_16 = __Pyx_PyFunction_FastCall(__pyx_t_17, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 278, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
        __Pyx_GOTREF(__pyx_t_16);
        __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_17)) {
        PyObject *__pyx_temp[2] = {__pyx_t_19, __pyx_t_22};
        __pyx_t_16 = __Pyx_PyCFunction_FastCall(__pyx_t_17, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 278, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
        __Pyx_GOTREF(__pyx_t_16);
        __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0;
      } else
      #endif
      {
        __pyx_t_20 = PyTuple_New(1+1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 278, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_20);
        __Pyx_GIVEREF(__pyx_t_19); PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_19); __pyx_t_19 = NULL;
        __Pyx_GIVEREF(__pyx_t_22);
        PyTuple_SET_ITEM(__pyx_t_20, 0+1, __pyx_t_22);
        __pyx_t_22 = 0;
        __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_17, __pyx_t_20, NULL); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 278, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_16);
        __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;

    /* "discodop/disambiguation.pyx":277
 * 		tree = addbitsets(
 * 				binarize(
 * 				collapseunary(unbinarize(             # <<<<<<<<<<<<<<
 * 					mergediscnodes(unbinarize(
 * 						Tree(treestr),
 */
    __pyx_t_17 = PyTuple_New(1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 277, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_17);
    __Pyx_GIVEREF(__pyx_t_16);
    PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_16);
    __pyx_t_16 = 0;

    /* "discodop/disambiguation.pyx":281
 * 						Tree(treestr),
 * 						childchar=':', expandunary=False)),
 * 					expandunary=False),             # <<<<<<<<<<<<<<
 * 					joinchar='++'),
 * 					leftmostunary=True))
 */
    __pyx_t_16 = PyDict_New(); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 281, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    if (PyDict_SetItem(__pyx_t_16, __pyx_n_s_expandunary, Py_False) < 0) __PYX_ERR(0, 281, __pyx_L1_error)

    /* "discodop/disambiguation.pyx":277
 * 		tree = addbitsets(
 * 				binarize(
 * 				collapseunary(unbinarize(             # <<<<<<<<<<<<<<
 * 					mergediscnodes(unbinarize(
 * 						Tree(treestr),
 */
    __pyx_t_20 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_17, __pyx_t_16); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 277, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    __pyx_t_16 = PyTuple_New(1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 277, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __Pyx_GIVEREF(__pyx_t_20);
    PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_20);
    __pyx_t_20 = 0;

    /* "discodop/disambiguation.pyx":282
 * 						childchar=':', expandunary=False)),
 * 					expandunary=False),
 * 					joinchar='++'),             # <<<<<<<<<<<<<<
 * 					leftmostunary=True))
 * 		sentprob += exp(-prob)
 */
    __pyx_t_20 = PyDict_New(); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 282, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    if (PyDict_SetItem(__pyx_t_20, __pyx_n_s_joinchar, __pyx_kp_u__8) < 0) __PYX_ERR(0, 282, __pyx_L1_error)

    /* "discodop/disambiguation.pyx":277
 * 		tree = addbitsets(
 * 				binarize(
 * 				collapseunary(unbinarize(             # <<<<<<<<<<<<<<
 * 					mergediscnodes(unbinarize(
 * 						Tree(treestr),
 */
    __pyx_t_17 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_16, __pyx_t_20); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 277, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_17);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;

    /* "discodop/disambiguation.pyx":276
 * 		# for constituents in the tree as it will be evaluated.
 * 		tree = addbitsets(
 * 				binarize(             # <<<<<<<<<<<<<<
 * 				collapseunary(unbinarize(
 * 					mergediscnodes(unbinarize(
 */
    __pyx_t_20 = PyTuple_New(1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 276, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_GIVEREF(__pyx_t_17);
    PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_17);
    __pyx_t_17 = 0;

    /* "discodop/disambiguation.pyx":283
 * 					expandunary=False),
 * 					joinchar='++'),
 * 					leftmostunary=True))             # <<<<<<<<<<<<<<
 * 		sentprob += exp(-prob)
 * 		for t in tree.subtrees():
 */
    __pyx_t_17 = PyDict_New(); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 283, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_17);
    if (PyDict_SetItem(__pyx_t_17, __pyx_n_s_leftmostunary, Py_True) < 0) __PYX_ERR(0, 283, __pyx_L1_error)

    /* "discodop/disambiguation.pyx":276
 * 		# for constituents in the tree as it will be evaluated.
 * 		tree = addbitsets(
 * 				binarize(             # <<<<<<<<<<<<<<
 * 				collapseunary(unbinarize(
 * 					mergediscnodes(unbinarize(
 */
    __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_20, __pyx_t_17); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 276, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
    __pyx_t_17 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(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_2 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_16); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 275, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_GOTREF(__pyx_t_2);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[2] = {__pyx_t_17, __pyx_t_16};
        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 275, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[2] = {__pyx_t_17, __pyx_t_16};
        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 275, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      } else
      #endif
      {
        __pyx_t_20 = PyTuple_New(1+1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 275, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_20);
        __Pyx_GIVEREF(__pyx_t_17); PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_17); __pyx_t_17 = NULL;
        __Pyx_GIVEREF(__pyx_t_16);
        PyTuple_SET_ITEM(__pyx_t_20, 0+1, __pyx_t_16);
        __pyx_t_16 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_20, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 275, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_DECREF_SET(__pyx_v_tree, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "discodop/disambiguation.pyx":284
 * 					joinchar='++'),
 * 					leftmostunary=True))
 * 		sentprob += exp(-prob)             # <<<<<<<<<<<<<<
 * 		for t in tree.subtrees():
 * 			span = t.bitset
 */
    __pyx_t_2 = PyFloat_FromDouble(__pyx_v_sentprob); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 284, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_20 = __Pyx_GetModuleGlobalName(__pyx_n_s_exp); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 284, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __pyx_t_16 = PyFloat_FromDouble((-__pyx_v_prob)); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 284, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_16);
    __pyx_t_17 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_20))) {
      __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_20);
      if (likely(__pyx_t_17)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_20);
        __Pyx_INCREF(__pyx_t_17);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_20, function);
      }
    }
    if (!__pyx_t_17) {
      __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_20, __pyx_t_16); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 284, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_GOTREF(__pyx_t_5);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_20)) {
        PyObject *__pyx_temp[2] = {__pyx_t_17, __pyx_t_16};
        __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_20, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 284, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_20)) {
        PyObject *__pyx_temp[2] = {__pyx_t_17, __pyx_t_16};
        __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_20, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 284, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      } else
      #endif
      {
        __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 284, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_GIVEREF(__pyx_t_17); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_17); __pyx_t_17 = NULL;
        __Pyx_GIVEREF(__pyx_t_16);
        PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_16);
        __pyx_t_16 = 0;
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_t_10, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 284, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __pyx_t_20 = PyNumber_InPlaceAdd(__pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 284, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_12 = __pyx_PyFloat_AsDouble(__pyx_t_20); if (unlikely((__pyx_t_12 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 284, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    __pyx_v_sentprob = __pyx_t_12;

    /* "discodop/disambiguation.pyx":285
 * 					leftmostunary=True))
 * 		sentprob += exp(-prob)
 * 		for t in tree.subtrees():             # <<<<<<<<<<<<<<
 * 			span = t.bitset
 * 			start = pyintnextset(span, 0)
 */
    __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_subtrees); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 285, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_2 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
      __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5);
      if (likely(__pyx_t_2)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
        __Pyx_INCREF(__pyx_t_2);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_5, function);
      }
    }
    if (__pyx_t_2) {
      __pyx_t_20 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 285, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else {
      __pyx_t_20 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 285, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_20);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    if (likely(PyList_CheckExact(__pyx_t_20)) || PyTuple_CheckExact(__pyx_t_20)) {
      __pyx_t_5 = __pyx_t_20; __Pyx_INCREF(__pyx_t_5); __pyx_t_4 = 0;
      __pyx_t_23 = NULL;
    } else {
      __pyx_t_4 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_20); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 285, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_23 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 285, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
    for (;;) {
      if (likely(!__pyx_t_23)) {
        if (likely(PyList_CheckExact(__pyx_t_5))) {
          if (__pyx_t_4 >= PyList_GET_SIZE(__pyx_t_5)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_20 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_4); __Pyx_INCREF(__pyx_t_20); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 285, __pyx_L1_error)
          #else
          __pyx_t_20 = PySequence_ITEM(__pyx_t_5, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 285, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_20);
          #endif
        } else {
          if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_20 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_4); __Pyx_INCREF(__pyx_t_20); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 285, __pyx_L1_error)
          #else
          __pyx_t_20 = PySequence_ITEM(__pyx_t_5, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 285, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_20);
          #endif
        }
      } else {
        __pyx_t_20 = __pyx_t_23(__pyx_t_5);
        if (unlikely(!__pyx_t_20)) {
          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, 285, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_20);
      }
      __Pyx_XDECREF_SET(__pyx_v_t, __pyx_t_20);
      __pyx_t_20 = 0;

      /* "discodop/disambiguation.pyx":286
 * 		sentprob += exp(-prob)
 * 		for t in tree.subtrees():
 * 			span = t.bitset             # <<<<<<<<<<<<<<
 * 			start = pyintnextset(span, 0)
 * 			spanlen = pyintbitcount(span)
 */
      __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_bitset); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 286, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_20);
      __Pyx_XDECREF_SET(__pyx_v_span, __pyx_t_20);
      __pyx_t_20 = 0;

      /* "discodop/disambiguation.pyx":287
 * 		for t in tree.subtrees():
 * 			span = t.bitset
 * 			start = pyintnextset(span, 0)             # <<<<<<<<<<<<<<
 * 			spanlen = pyintbitcount(span)
 * 			tablecell = table[start][spanlen][span]
 */
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyintnextset); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 287, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_10 = NULL;
      __pyx_t_15 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_10)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_10);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
          __pyx_t_15 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_span, __pyx_int_0};
        __pyx_t_20 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 287, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_GOTREF(__pyx_t_20);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
        PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_v_span, __pyx_int_0};
        __pyx_t_20 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 287, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_GOTREF(__pyx_t_20);
      } else
      #endif
      {
        __pyx_t_16 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 287, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_16);
        if (__pyx_t_10) {
          __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_10); __pyx_t_10 = NULL;
        }
        __Pyx_INCREF(__pyx_v_span);
        __Pyx_GIVEREF(__pyx_v_span);
        PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_15, __pyx_v_span);
        __Pyx_INCREF(__pyx_int_0);
        __Pyx_GIVEREF(__pyx_int_0);
        PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_15, __pyx_int_0);
        __pyx_t_20 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_16, NULL); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 287, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_20);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_24 = __Pyx_PyInt_As_short(__pyx_t_20); if (unlikely((__pyx_t_24 == (short)-1) && PyErr_Occurred())) __PYX_ERR(0, 287, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __pyx_v_start = __pyx_t_24;

      /* "discodop/disambiguation.pyx":288
 * 			span = t.bitset
 * 			start = pyintnextset(span, 0)
 * 			spanlen = pyintbitcount(span)             # <<<<<<<<<<<<<<
 * 			tablecell = table[start][spanlen][span]
 * 			tablecell.setdefault(t.label, 0.0)
 */
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyintbitcount); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 288, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_16 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_16)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_16);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      if (!__pyx_t_16) {
        __pyx_t_20 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_span); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 288, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_20);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_2)) {
          PyObject *__pyx_temp[2] = {__pyx_t_16, __pyx_v_span};
          __pyx_t_20 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 288, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
          __Pyx_GOTREF(__pyx_t_20);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
          PyObject *__pyx_temp[2] = {__pyx_t_16, __pyx_v_span};
          __pyx_t_20 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 288, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
          __Pyx_GOTREF(__pyx_t_20);
        } else
        #endif
        {
          __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 288, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_GIVEREF(__pyx_t_16); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_16); __pyx_t_16 = NULL;
          __Pyx_INCREF(__pyx_v_span);
          __Pyx_GIVEREF(__pyx_v_span);
          PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_v_span);
          __pyx_t_20 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_10, NULL); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 288, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_20);
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_24 = __Pyx_PyInt_As_short(__pyx_t_20); if (unlikely((__pyx_t_24 == (short)-1) && PyErr_Occurred())) __PYX_ERR(0, 288, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __pyx_v_spanlen = __pyx_t_24;

      /* "discodop/disambiguation.pyx":289
 * 			start = pyintnextset(span, 0)
 * 			spanlen = pyintbitcount(span)
 * 			tablecell = table[start][spanlen][span]             # <<<<<<<<<<<<<<
 * 			tablecell.setdefault(t.label, 0.0)
 * 			if '|<' not in t.label and (labels is None or t.label in labels):
 */
      __pyx_t_20 = __Pyx_GetItemInt(PyList_GET_ITEM(__pyx_v_table, __pyx_v_start), __pyx_v_spanlen, short, 1, __Pyx_PyInt_From_short, 0, 0, 0); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 289, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_20);
      __pyx_t_2 = PyObject_GetItem(__pyx_t_20, __pyx_v_span); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 289, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __Pyx_XDECREF_SET(__pyx_v_tablecell, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "discodop/disambiguation.pyx":290
 * 			spanlen = pyintbitcount(span)
 * 			tablecell = table[start][spanlen][span]
 * 			tablecell.setdefault(t.label, 0.0)             # <<<<<<<<<<<<<<
 * 			if '|<' not in t.label and (labels is None or t.label in labels):
 * 				tablecell[t.label] += exp(-prob)
 */
      __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_v_tablecell, __pyx_n_s_setdefault); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 290, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_20);
      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_label); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 290, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_16 = NULL;
      __pyx_t_15 = 0;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_20))) {
        __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_20);
        if (likely(__pyx_t_16)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_20);
          __Pyx_INCREF(__pyx_t_16);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_20, function);
          __pyx_t_15 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_20)) {
        PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_t_10, __pyx_float_0_0};
        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_20, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 290, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 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_20)) {
        PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_t_10, __pyx_float_0_0};
        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_20, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 290, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      } else
      #endif
      {
        __pyx_t_17 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 290, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_17);
        if (__pyx_t_16) {
          __Pyx_GIVEREF(__pyx_t_16); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_16); __pyx_t_16 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_10);
        PyTuple_SET_ITEM(__pyx_t_17, 0+__pyx_t_15, __pyx_t_10);
        __Pyx_INCREF(__pyx_float_0_0);
        __Pyx_GIVEREF(__pyx_float_0_0);
        PyTuple_SET_ITEM(__pyx_t_17, 1+__pyx_t_15, __pyx_float_0_0);
        __pyx_t_10 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_20, __pyx_t_17, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 290, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
      }
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "discodop/disambiguation.pyx":291
 * 			tablecell = table[start][spanlen][span]
 * 			tablecell.setdefault(t.label, 0.0)
 * 			if '|<' not in t.label and (labels is None or t.label in labels):             # <<<<<<<<<<<<<<
 * 				tablecell[t.label] += exp(-prob)
 * 
 */
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_label); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 291, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_13 = (__Pyx_PySequence_ContainsTF(__pyx_kp_u__9, __pyx_t_2, Py_NE)); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 291, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_25 = (__pyx_t_13 != 0);
      if (__pyx_t_25) {
      } else {
        __pyx_t_14 = __pyx_t_25;
        goto __pyx_L15_bool_binop_done;
      }
      __pyx_t_25 = (__pyx_v_labels == ((PyObject*)Py_None));
      __pyx_t_13 = (__pyx_t_25 != 0);
      if (!__pyx_t_13) {
      } else {
        __pyx_t_14 = __pyx_t_13;
        goto __pyx_L15_bool_binop_done;
      }
      __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_label); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 291, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_13 = (__Pyx_PySequence_ContainsTF(__pyx_t_2, __pyx_v_labels, Py_EQ)); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 291, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_25 = (__pyx_t_13 != 0);
      __pyx_t_14 = __pyx_t_25;
      __pyx_L15_bool_binop_done:;
      if (__pyx_t_14) {

        /* "discodop/disambiguation.pyx":292
 * 			tablecell.setdefault(t.label, 0.0)
 * 			if '|<' not in t.label and (labels is None or t.label in labels):
 * 				tablecell[t.label] += exp(-prob)             # <<<<<<<<<<<<<<
 * 
 * 	cells = defaultdict(dict)  # cells[span] = (label, score, leftspan)
 */
        __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_t, __pyx_n_s_label); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 292, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __pyx_t_20 = PyObject_GetItem(__pyx_v_tablecell, __pyx_t_2); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 292, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_20);
        __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_exp); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 292, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_16 = PyFloat_FromDouble((-__pyx_v_prob)); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 292, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_16);
        __pyx_t_8 = NULL;
        if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_10))) {
          __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_10);
          if (likely(__pyx_t_8)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
            __Pyx_INCREF(__pyx_t_8);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_10, function);
          }
        }
        if (!__pyx_t_8) {
          __pyx_t_17 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_16); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 292, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          __Pyx_GOTREF(__pyx_t_17);
        } else {
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_10)) {
            PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_16};
            __pyx_t_17 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 292, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
            __Pyx_GOTREF(__pyx_t_17);
            __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) {
            PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_16};
            __pyx_t_17 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 292, __pyx_L1_error)
            __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
            __Pyx_GOTREF(__pyx_t_17);
            __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          } else
          #endif
          {
            __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 292, __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_16);
            PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_16);
            __pyx_t_16 = 0;
            __pyx_t_17 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_9, NULL); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 292, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_17);
            __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          }
        }
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_t_10 = PyNumber_InPlaceAdd(__pyx_t_20, __pyx_t_17); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 292, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
        __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
        if (unlikely(PyObject_SetItem(__pyx_v_tablecell, __pyx_t_2, __pyx_t_10) < 0)) __PYX_ERR(0, 292, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "discodop/disambiguation.pyx":291
 * 			tablecell = table[start][spanlen][span]
 * 			tablecell.setdefault(t.label, 0.0)
 * 			if '|<' not in t.label and (labels is None or t.label in labels):             # <<<<<<<<<<<<<<
 * 				tablecell[t.label] += exp(-prob)
 * 
 */
      }

      /* "discodop/disambiguation.pyx":285
 * 					leftmostunary=True))
 * 		sentprob += exp(-prob)
 * 		for t in tree.subtrees():             # <<<<<<<<<<<<<<
 * 			span = t.bitset
 * 			start = pyintnextset(span, 0)
 */
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "discodop/disambiguation.pyx":268
 * 	tree = None
 * 	# get marginal probabilities
 * 	for deriv, prob in derivations:             # <<<<<<<<<<<<<<
 * 		if backtransform is None:
 * 			treestr = REMOVEIDS.sub('', deriv)
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":294
 * 				tablecell[t.label] += exp(-prob)
 * 
 * 	cells = defaultdict(dict)  # cells[span] = (label, score, leftspan)             # <<<<<<<<<<<<<<
 * 	# select best derivation
 * 	for spanlen in range(1, len(chart.sent) + 1):
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_defaultdict); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 294, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  if (!__pyx_t_2) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, ((PyObject *)(&PyDict_Type))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 294, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[2] = {__pyx_t_2, ((PyObject *)(&PyDict_Type))};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 294, __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_5)) {
      PyObject *__pyx_temp[2] = {__pyx_t_2, ((PyObject *)(&PyDict_Type))};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 294, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 294, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_2); __pyx_t_2 = NULL;
      __Pyx_INCREF(((PyObject *)(&PyDict_Type)));
      __Pyx_GIVEREF(((PyObject *)(&PyDict_Type)));
      PyTuple_SET_ITEM(__pyx_t_10, 0+1, ((PyObject *)(&PyDict_Type)));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_10, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 294, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_v_cells = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":296
 * 	cells = defaultdict(dict)  # cells[span] = (label, score, leftspan)
 * 	# select best derivation
 * 	for spanlen in range(1, len(chart.sent) + 1):             # <<<<<<<<<<<<<<
 * 		for start, _ in enumerate(table):
 * 			if len(table[start]) <= spanlen:
 */
  __pyx_t_1 = __pyx_v_chart->sent;
  __Pyx_INCREF(__pyx_t_1);
  if (unlikely(__pyx_t_1 == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 296, __pyx_L1_error)
  }
  __pyx_t_3 = PyList_GET_SIZE(__pyx_t_1); if (unlikely(__pyx_t_3 == -1)) __PYX_ERR(0, 296, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_4 = (__pyx_t_3 + 1);
  for (__pyx_t_24 = 1; __pyx_t_24 < __pyx_t_4; __pyx_t_24+=1) {
    __pyx_v_spanlen = __pyx_t_24;

    /* "discodop/disambiguation.pyx":297
 * 	# select best derivation
 * 	for spanlen in range(1, len(chart.sent) + 1):
 * 		for start, _ in enumerate(table):             # <<<<<<<<<<<<<<
 * 			if len(table[start]) <= spanlen:
 * 				continue
 */
    __pyx_t_26 = 0;
    __pyx_t_1 = __pyx_v_table; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = 0;
    for (;;) {
      if (__pyx_t_3 >= 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_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 297, __pyx_L1_error)
      #else
      __pyx_t_5 = PySequence_ITEM(__pyx_t_1, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 297, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      #endif
      __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_v_start = __pyx_t_26;
      __pyx_t_26 = (__pyx_t_26 + 1);

      /* "discodop/disambiguation.pyx":298
 * 	for spanlen in range(1, len(chart.sent) + 1):
 * 		for start, _ in enumerate(table):
 * 			if len(table[start]) <= spanlen:             # <<<<<<<<<<<<<<
 * 				continue
 * 			for span, tablecell in table[start][spanlen].items():
 */
      __pyx_t_5 = PyList_GET_ITEM(__pyx_v_table, __pyx_v_start);
      __Pyx_INCREF(__pyx_t_5);
      __pyx_t_7 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_7 == -1)) __PYX_ERR(0, 298, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_14 = ((__pyx_t_7 <= __pyx_v_spanlen) != 0);
      if (__pyx_t_14) {

        /* "discodop/disambiguation.pyx":299
 * 		for start, _ in enumerate(table):
 * 			if len(table[start]) <= spanlen:
 * 				continue             # <<<<<<<<<<<<<<
 * 			for span, tablecell in table[start][spanlen].items():
 * 				maxlabel, maxscore = NONCONSTLABEL, 0.0
 */
        goto __pyx_L20_continue;

        /* "discodop/disambiguation.pyx":298
 * 	for spanlen in range(1, len(chart.sent) + 1):
 * 		for start, _ in enumerate(table):
 * 			if len(table[start]) <= spanlen:             # <<<<<<<<<<<<<<
 * 				continue
 * 			for span, tablecell in table[start][spanlen].items():
 */
      }

      /* "discodop/disambiguation.pyx":300
 * 			if len(table[start]) <= spanlen:
 * 				continue
 * 			for span, tablecell in table[start][spanlen].items():             # <<<<<<<<<<<<<<
 * 				maxlabel, maxscore = NONCONSTLABEL, 0.0
 * 				if tablecell:
 */
      __pyx_t_7 = 0;
      __pyx_t_10 = __Pyx_GetItemInt(PyList_GET_ITEM(__pyx_v_table, __pyx_v_start), __pyx_v_spanlen, short, 1, __Pyx_PyInt_From_short, 0, 0, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 300, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      if (unlikely(__pyx_t_10 == Py_None)) {
        PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "items");
        __PYX_ERR(0, 300, __pyx_L1_error)
      }
      __pyx_t_2 = __Pyx_dict_iterator(__pyx_t_10, 0, __pyx_n_s_items, (&__pyx_t_6), (&__pyx_t_15)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 300, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_XDECREF(__pyx_t_5);
      __pyx_t_5 = __pyx_t_2;
      __pyx_t_2 = 0;
      while (1) {
        __pyx_t_27 = __Pyx_dict_iter_next(__pyx_t_5, __pyx_t_6, &__pyx_t_7, &__pyx_t_2, &__pyx_t_10, NULL, __pyx_t_15);
        if (unlikely(__pyx_t_27 == 0)) break;
        if (unlikely(__pyx_t_27 == -1)) __PYX_ERR(0, 300, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_XDECREF_SET(__pyx_v_span, __pyx_t_2);
        __pyx_t_2 = 0;
        __Pyx_XDECREF_SET(__pyx_v_tablecell, __pyx_t_10);
        __pyx_t_10 = 0;

        /* "discodop/disambiguation.pyx":301
 * 				continue
 * 			for span, tablecell in table[start][spanlen].items():
 * 				maxlabel, maxscore = NONCONSTLABEL, 0.0             # <<<<<<<<<<<<<<
 * 				if tablecell:
 * 					maxlabel, maxscore = max(tablecell.items(),
 */
        __pyx_t_10 = __pyx_v_8discodop_14disambiguation_NONCONSTLABEL;
        __Pyx_INCREF(__pyx_t_10);
        __pyx_t_12 = 0.0;
        __Pyx_XDECREF_SET(__pyx_v_maxlabel, __pyx_t_10);
        __pyx_t_10 = 0;
        __pyx_v_maxscore = __pyx_t_12;

        /* "discodop/disambiguation.pyx":302
 * 			for span, tablecell in table[start][spanlen].items():
 * 				maxlabel, maxscore = NONCONSTLABEL, 0.0
 * 				if tablecell:             # <<<<<<<<<<<<<<
 * 					maxlabel, maxscore = max(tablecell.items(),
 * 							key=itemgetter(1))
 */
        __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_v_tablecell); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 302, __pyx_L1_error)
        if (__pyx_t_14) {

          /* "discodop/disambiguation.pyx":303
 * 				maxlabel, maxscore = NONCONSTLABEL, 0.0
 * 				if tablecell:
 * 					maxlabel, maxscore = max(tablecell.items(),             # <<<<<<<<<<<<<<
 * 							key=itemgetter(1))
 * 				maxcombscore = 0.0
 */
          __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_tablecell, __pyx_n_s_items); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 303, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_17 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) {
            __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_2);
            if (likely(__pyx_t_17)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
              __Pyx_INCREF(__pyx_t_17);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_2, function);
            }
          }
          if (__pyx_t_17) {
            __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_17); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 303, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
          } else {
            __pyx_t_10 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 303, __pyx_L1_error)
          }
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 303, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_10);
          PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_10);
          __pyx_t_10 = 0;

          /* "discodop/disambiguation.pyx":304
 * 				if tablecell:
 * 					maxlabel, maxscore = max(tablecell.items(),
 * 							key=itemgetter(1))             # <<<<<<<<<<<<<<
 * 				maxcombscore = 0.0
 * 				maxleft = None
 */
          __pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 304, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __pyx_t_17 = __Pyx_GetModuleGlobalName(__pyx_n_s_itemgetter); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 304, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_17);
          __pyx_t_20 = __Pyx_PyObject_Call(__pyx_t_17, __pyx_tuple__10, NULL); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 304, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_20);
          __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
          if (PyDict_SetItem(__pyx_t_10, __pyx_n_s_key, __pyx_t_20) < 0) __PYX_ERR(0, 304, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;

          /* "discodop/disambiguation.pyx":303
 * 				maxlabel, maxscore = NONCONSTLABEL, 0.0
 * 				if tablecell:
 * 					maxlabel, maxscore = max(tablecell.items(),             # <<<<<<<<<<<<<<
 * 							key=itemgetter(1))
 * 				maxcombscore = 0.0
 */
          __pyx_t_20 = __Pyx_PyObject_Call(__pyx_builtin_max, __pyx_t_2, __pyx_t_10); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 303, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_20);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          if ((likely(PyTuple_CheckExact(__pyx_t_20))) || (PyList_CheckExact(__pyx_t_20))) {
            PyObject* sequence = __pyx_t_20;
            #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, 303, __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_2 = PyTuple_GET_ITEM(sequence, 1); 
            } else {
              __pyx_t_10 = PyList_GET_ITEM(sequence, 0); 
              __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
            }
            __Pyx_INCREF(__pyx_t_10);
            __Pyx_INCREF(__pyx_t_2);
            #else
            __pyx_t_10 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 303, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_10);
            __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 303, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_2);
            #endif
            __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
          } else {
            Py_ssize_t index = -1;
            __pyx_t_17 = PyObject_GetIter(__pyx_t_20); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 303, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_17);
            __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
            __pyx_t_11 = Py_TYPE(__pyx_t_17)->tp_iternext;
            index = 0; __pyx_t_10 = __pyx_t_11(__pyx_t_17); if (unlikely(!__pyx_t_10)) goto __pyx_L26_unpacking_failed;
            __Pyx_GOTREF(__pyx_t_10);
            index = 1; __pyx_t_2 = __pyx_t_11(__pyx_t_17); if (unlikely(!__pyx_t_2)) goto __pyx_L26_unpacking_failed;
            __Pyx_GOTREF(__pyx_t_2);
            if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_17), 2) < 0) __PYX_ERR(0, 303, __pyx_L1_error)
            __pyx_t_11 = NULL;
            __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
            goto __pyx_L27_unpacking_done;
            __pyx_L26_unpacking_failed:;
            __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
            __pyx_t_11 = NULL;
            if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
            __PYX_ERR(0, 303, __pyx_L1_error)
            __pyx_L27_unpacking_done:;
          }
          __pyx_t_12 = __pyx_PyFloat_AsDouble(__pyx_t_2); if (unlikely((__pyx_t_12 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 303, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_DECREF_SET(__pyx_v_maxlabel, __pyx_t_10);
          __pyx_t_10 = 0;
          __pyx_v_maxscore = __pyx_t_12;

          /* "discodop/disambiguation.pyx":302
 * 			for span, tablecell in table[start][spanlen].items():
 * 				maxlabel, maxscore = NONCONSTLABEL, 0.0
 * 				if tablecell:             # <<<<<<<<<<<<<<
 * 					maxlabel, maxscore = max(tablecell.items(),
 * 							key=itemgetter(1))
 */
        }

        /* "discodop/disambiguation.pyx":305
 * 					maxlabel, maxscore = max(tablecell.items(),
 * 							key=itemgetter(1))
 * 				maxcombscore = 0.0             # <<<<<<<<<<<<<<
 * 				maxleft = None
 * 				for spans in table[start][1:spanlen]:
 */
        __pyx_v_maxcombscore = 0.0;

        /* "discodop/disambiguation.pyx":306
 * 							key=itemgetter(1))
 * 				maxcombscore = 0.0
 * 				maxleft = None             # <<<<<<<<<<<<<<
 * 				for spans in table[start][1:spanlen]:
 * 					for leftspan in spans:
 */
        __Pyx_INCREF(Py_None);
        __Pyx_XDECREF_SET(__pyx_v_maxleft, Py_None);

        /* "discodop/disambiguation.pyx":307
 * 				maxcombscore = 0.0
 * 				maxleft = None
 * 				for spans in table[start][1:spanlen]:             # <<<<<<<<<<<<<<
 * 					for leftspan in spans:
 * 						if (span & leftspan != leftspan
 */
        __pyx_t_20 = __Pyx_PyObject_GetSlice(PyList_GET_ITEM(__pyx_v_table, __pyx_v_start), 1, __pyx_v_spanlen, NULL, NULL, NULL, 1, 1, 0); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 307, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_20);
        if (likely(PyList_CheckExact(__pyx_t_20)) || PyTuple_CheckExact(__pyx_t_20)) {
          __pyx_t_2 = __pyx_t_20; __Pyx_INCREF(__pyx_t_2); __pyx_t_28 = 0;
          __pyx_t_23 = NULL;
        } else {
          __pyx_t_28 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_20); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 307, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_23 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 307, __pyx_L1_error)
        }
        __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
        for (;;) {
          if (likely(!__pyx_t_23)) {
            if (likely(PyList_CheckExact(__pyx_t_2))) {
              if (__pyx_t_28 >= PyList_GET_SIZE(__pyx_t_2)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_20 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_28); __Pyx_INCREF(__pyx_t_20); __pyx_t_28++; if (unlikely(0 < 0)) __PYX_ERR(0, 307, __pyx_L1_error)
              #else
              __pyx_t_20 = PySequence_ITEM(__pyx_t_2, __pyx_t_28); __pyx_t_28++; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 307, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_20);
              #endif
            } else {
              if (__pyx_t_28 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_20 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_28); __Pyx_INCREF(__pyx_t_20); __pyx_t_28++; if (unlikely(0 < 0)) __PYX_ERR(0, 307, __pyx_L1_error)
              #else
              __pyx_t_20 = PySequence_ITEM(__pyx_t_2, __pyx_t_28); __pyx_t_28++; if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 307, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_20);
              #endif
            }
          } else {
            __pyx_t_20 = __pyx_t_23(__pyx_t_2);
            if (unlikely(!__pyx_t_20)) {
              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, 307, __pyx_L1_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_20);
          }
          __Pyx_XDECREF_SET(__pyx_v_spans, __pyx_t_20);
          __pyx_t_20 = 0;

          /* "discodop/disambiguation.pyx":308
 * 				maxleft = None
 * 				for spans in table[start][1:spanlen]:
 * 					for leftspan in spans:             # <<<<<<<<<<<<<<
 * 						if (span & leftspan != leftspan
 * 								or cells[leftspan][0] == NONCONSTLABEL):
 */
          if (likely(PyList_CheckExact(__pyx_v_spans)) || PyTuple_CheckExact(__pyx_v_spans)) {
            __pyx_t_20 = __pyx_v_spans; __Pyx_INCREF(__pyx_t_20); __pyx_t_29 = 0;
            __pyx_t_30 = NULL;
          } else {
            __pyx_t_29 = -1; __pyx_t_20 = PyObject_GetIter(__pyx_v_spans); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 308, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_20);
            __pyx_t_30 = Py_TYPE(__pyx_t_20)->tp_iternext; if (unlikely(!__pyx_t_30)) __PYX_ERR(0, 308, __pyx_L1_error)
          }
          for (;;) {
            if (likely(!__pyx_t_30)) {
              if (likely(PyList_CheckExact(__pyx_t_20))) {
                if (__pyx_t_29 >= PyList_GET_SIZE(__pyx_t_20)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_10 = PyList_GET_ITEM(__pyx_t_20, __pyx_t_29); __Pyx_INCREF(__pyx_t_10); __pyx_t_29++; if (unlikely(0 < 0)) __PYX_ERR(0, 308, __pyx_L1_error)
                #else
                __pyx_t_10 = PySequence_ITEM(__pyx_t_20, __pyx_t_29); __pyx_t_29++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 308, __pyx_L1_error)
                __Pyx_GOTREF(__pyx_t_10);
                #endif
              } else {
                if (__pyx_t_29 >= PyTuple_GET_SIZE(__pyx_t_20)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_10 = PyTuple_GET_ITEM(__pyx_t_20, __pyx_t_29); __Pyx_INCREF(__pyx_t_10); __pyx_t_29++; if (unlikely(0 < 0)) __PYX_ERR(0, 308, __pyx_L1_error)
                #else
                __pyx_t_10 = PySequence_ITEM(__pyx_t_20, __pyx_t_29); __pyx_t_29++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 308, __pyx_L1_error)
                __Pyx_GOTREF(__pyx_t_10);
                #endif
              }
            } else {
              __pyx_t_10 = __pyx_t_30(__pyx_t_20);
              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, 308, __pyx_L1_error)
                }
                break;
              }
              __Pyx_GOTREF(__pyx_t_10);
            }
            __Pyx_XDECREF_SET(__pyx_v_leftspan, __pyx_t_10);
            __pyx_t_10 = 0;

            /* "discodop/disambiguation.pyx":309
 * 				for spans in table[start][1:spanlen]:
 * 					for leftspan in spans:
 * 						if (span & leftspan != leftspan             # <<<<<<<<<<<<<<
 * 								or cells[leftspan][0] == NONCONSTLABEL):
 * 							continue
 */
            __pyx_t_10 = PyNumber_And(__pyx_v_span, __pyx_v_leftspan); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 309, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_10);

            /* "discodop/disambiguation.pyx":310
 * 					for leftspan in spans:
 * 						if (span & leftspan != leftspan
 * 								or cells[leftspan][0] == NONCONSTLABEL):             # <<<<<<<<<<<<<<
 * 							continue
 * 						rightspan = span & ~leftspan
 */
            __pyx_t_17 = PyObject_RichCompare(__pyx_t_10, __pyx_v_leftspan, Py_NE); __Pyx_XGOTREF(__pyx_t_17); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 309, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

            /* "discodop/disambiguation.pyx":309
 * 				for spans in table[start][1:spanlen]:
 * 					for leftspan in spans:
 * 						if (span & leftspan != leftspan             # <<<<<<<<<<<<<<
 * 								or cells[leftspan][0] == NONCONSTLABEL):
 * 							continue
 */
            __pyx_t_25 = __Pyx_PyObject_IsTrue(__pyx_t_17); if (unlikely(__pyx_t_25 < 0)) __PYX_ERR(0, 309, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
            if (!__pyx_t_25) {
            } else {
              __pyx_t_14 = __pyx_t_25;
              goto __pyx_L33_bool_binop_done;
            }

            /* "discodop/disambiguation.pyx":310
 * 					for leftspan in spans:
 * 						if (span & leftspan != leftspan
 * 								or cells[leftspan][0] == NONCONSTLABEL):             # <<<<<<<<<<<<<<
 * 							continue
 * 						rightspan = span & ~leftspan
 */
            __pyx_t_17 = PyObject_GetItem(__pyx_v_cells, __pyx_v_leftspan); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 310, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_17);
            __pyx_t_10 = __Pyx_GetItemInt(__pyx_t_17, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 310, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_10);
            __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
            __pyx_t_25 = (__Pyx_PyUnicode_Equals(__pyx_t_10, __pyx_v_8discodop_14disambiguation_NONCONSTLABEL, Py_EQ)); if (unlikely(__pyx_t_25 < 0)) __PYX_ERR(0, 310, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
            __pyx_t_14 = __pyx_t_25;
            __pyx_L33_bool_binop_done:;

            /* "discodop/disambiguation.pyx":309
 * 				for spans in table[start][1:spanlen]:
 * 					for leftspan in spans:
 * 						if (span & leftspan != leftspan             # <<<<<<<<<<<<<<
 * 								or cells[leftspan][0] == NONCONSTLABEL):
 * 							continue
 */
            if (__pyx_t_14) {

              /* "discodop/disambiguation.pyx":311
 * 						if (span & leftspan != leftspan
 * 								or cells[leftspan][0] == NONCONSTLABEL):
 * 							continue             # <<<<<<<<<<<<<<
 * 						rightspan = span & ~leftspan
 * 						if (rightspan in cells
 */
              goto __pyx_L30_continue;

              /* "discodop/disambiguation.pyx":309
 * 				for spans in table[start][1:spanlen]:
 * 					for leftspan in spans:
 * 						if (span & leftspan != leftspan             # <<<<<<<<<<<<<<
 * 								or cells[leftspan][0] == NONCONSTLABEL):
 * 							continue
 */
            }

            /* "discodop/disambiguation.pyx":312
 * 								or cells[leftspan][0] == NONCONSTLABEL):
 * 							continue
 * 						rightspan = span & ~leftspan             # <<<<<<<<<<<<<<
 * 						if (rightspan in cells
 * 								and cells[rightspan][0] != NONCONSTLABEL):
 */
            __pyx_t_10 = PyNumber_Invert(__pyx_v_leftspan); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 312, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_10);
            __pyx_t_17 = PyNumber_And(__pyx_v_span, __pyx_t_10); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 312, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_17);
            __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
            __Pyx_XDECREF_SET(__pyx_v_rightspan, __pyx_t_17);
            __pyx_t_17 = 0;

            /* "discodop/disambiguation.pyx":314
 * 						rightspan = span & ~leftspan
 * 						if (rightspan in cells
 * 								and cells[rightspan][0] != NONCONSTLABEL):             # <<<<<<<<<<<<<<
 * 							score = cells[leftspan][1] + cells[rightspan][1]
 * 							if score > maxcombscore:
 */
            __pyx_t_25 = (__Pyx_PySequence_ContainsTF(__pyx_v_rightspan, __pyx_v_cells, Py_EQ)); if (unlikely(__pyx_t_25 < 0)) __PYX_ERR(0, 313, __pyx_L1_error)

            /* "discodop/disambiguation.pyx":313
 * 							continue
 * 						rightspan = span & ~leftspan
 * 						if (rightspan in cells             # <<<<<<<<<<<<<<
 * 								and cells[rightspan][0] != NONCONSTLABEL):
 * 							score = cells[leftspan][1] + cells[rightspan][1]
 */
            __pyx_t_13 = (__pyx_t_25 != 0);
            if (__pyx_t_13) {
            } else {
              __pyx_t_14 = __pyx_t_13;
              goto __pyx_L36_bool_binop_done;
            }

            /* "discodop/disambiguation.pyx":314
 * 						rightspan = span & ~leftspan
 * 						if (rightspan in cells
 * 								and cells[rightspan][0] != NONCONSTLABEL):             # <<<<<<<<<<<<<<
 * 							score = cells[leftspan][1] + cells[rightspan][1]
 * 							if score > maxcombscore:
 */
            __pyx_t_17 = PyObject_GetItem(__pyx_v_cells, __pyx_v_rightspan); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 314, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_17);
            __pyx_t_10 = __Pyx_GetItemInt(__pyx_t_17, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 314, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_10);
            __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
            __pyx_t_13 = (__Pyx_PyUnicode_Equals(__pyx_t_10, __pyx_v_8discodop_14disambiguation_NONCONSTLABEL, Py_NE)); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 314, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
            __pyx_t_14 = __pyx_t_13;
            __pyx_L36_bool_binop_done:;

            /* "discodop/disambiguation.pyx":313
 * 							continue
 * 						rightspan = span & ~leftspan
 * 						if (rightspan in cells             # <<<<<<<<<<<<<<
 * 								and cells[rightspan][0] != NONCONSTLABEL):
 * 							score = cells[leftspan][1] + cells[rightspan][1]
 */
            if (__pyx_t_14) {

              /* "discodop/disambiguation.pyx":315
 * 						if (rightspan in cells
 * 								and cells[rightspan][0] != NONCONSTLABEL):
 * 							score = cells[leftspan][1] + cells[rightspan][1]             # <<<<<<<<<<<<<<
 * 							if score > maxcombscore:
 * 								maxcombscore = score
 */
              __pyx_t_10 = PyObject_GetItem(__pyx_v_cells, __pyx_v_leftspan); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 315, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_10);
              __pyx_t_17 = __Pyx_GetItemInt(__pyx_t_10, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 315, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_17);
              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
              __pyx_t_10 = PyObject_GetItem(__pyx_v_cells, __pyx_v_rightspan); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 315, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_10);
              __pyx_t_9 = __Pyx_GetItemInt(__pyx_t_10, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 315, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_9);
              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
              __pyx_t_10 = PyNumber_Add(__pyx_t_17, __pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 315, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_10);
              __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
              __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
              __pyx_t_12 = __pyx_PyFloat_AsDouble(__pyx_t_10); if (unlikely((__pyx_t_12 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 315, __pyx_L1_error)
              __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
              __pyx_v_score = __pyx_t_12;

              /* "discodop/disambiguation.pyx":316
 * 								and cells[rightspan][0] != NONCONSTLABEL):
 * 							score = cells[leftspan][1] + cells[rightspan][1]
 * 							if score > maxcombscore:             # <<<<<<<<<<<<<<
 * 								maxcombscore = score
 * 								maxleft = leftspan
 */
              __pyx_t_14 = ((__pyx_v_score > __pyx_v_maxcombscore) != 0);
              if (__pyx_t_14) {

                /* "discodop/disambiguation.pyx":317
 * 							score = cells[leftspan][1] + cells[rightspan][1]
 * 							if score > maxcombscore:
 * 								maxcombscore = score             # <<<<<<<<<<<<<<
 * 								maxleft = leftspan
 * 				score = maxscore / sentprob
 */
                __pyx_v_maxcombscore = __pyx_v_score;

                /* "discodop/disambiguation.pyx":318
 * 							if score > maxcombscore:
 * 								maxcombscore = score
 * 								maxleft = leftspan             # <<<<<<<<<<<<<<
 * 				score = maxscore / sentprob
 * 				contribution = score - labda * (1 - score)
 */
                __Pyx_INCREF(__pyx_v_leftspan);
                __Pyx_DECREF_SET(__pyx_v_maxleft, __pyx_v_leftspan);

                /* "discodop/disambiguation.pyx":316
 * 								and cells[rightspan][0] != NONCONSTLABEL):
 * 							score = cells[leftspan][1] + cells[rightspan][1]
 * 							if score > maxcombscore:             # <<<<<<<<<<<<<<
 * 								maxcombscore = score
 * 								maxleft = leftspan
 */
              }

              /* "discodop/disambiguation.pyx":313
 * 							continue
 * 						rightspan = span & ~leftspan
 * 						if (rightspan in cells             # <<<<<<<<<<<<<<
 * 								and cells[rightspan][0] != NONCONSTLABEL):
 * 							score = cells[leftspan][1] + cells[rightspan][1]
 */
            }

            /* "discodop/disambiguation.pyx":308
 * 				maxleft = None
 * 				for spans in table[start][1:spanlen]:
 * 					for leftspan in spans:             # <<<<<<<<<<<<<<
 * 						if (span & leftspan != leftspan
 * 								or cells[leftspan][0] == NONCONSTLABEL):
 */
            __pyx_L30_continue:;
          }
          __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;

          /* "discodop/disambiguation.pyx":307
 * 				maxcombscore = 0.0
 * 				maxleft = None
 * 				for spans in table[start][1:spanlen]:             # <<<<<<<<<<<<<<
 * 					for leftspan in spans:
 * 						if (span & leftspan != leftspan
 */
        }
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

        /* "discodop/disambiguation.pyx":319
 * 								maxcombscore = score
 * 								maxleft = leftspan
 * 				score = maxscore / sentprob             # <<<<<<<<<<<<<<
 * 				contribution = score - labda * (1 - score)
 * 				if contribution < 0:
 */
        __pyx_v_score = (__pyx_v_maxscore / __pyx_v_sentprob);

        /* "discodop/disambiguation.pyx":320
 * 								maxleft = leftspan
 * 				score = maxscore / sentprob
 * 				contribution = score - labda * (1 - score)             # <<<<<<<<<<<<<<
 * 				if contribution < 0:
 * 					cells[span] = (NEGATIVECONSTLABEL
 */
        __pyx_v_contribution = (__pyx_v_score - (__pyx_v_labda * (1.0 - __pyx_v_score)));

        /* "discodop/disambiguation.pyx":321
 * 				score = maxscore / sentprob
 * 				contribution = score - labda * (1 - score)
 * 				if contribution < 0:             # <<<<<<<<<<<<<<
 * 					cells[span] = (NEGATIVECONSTLABEL
 * 							if 1 < pyintbitcount(span) < len(chart.sent)
 */
        __pyx_t_14 = ((__pyx_v_contribution < 0.0) != 0);
        if (__pyx_t_14) {

          /* "discodop/disambiguation.pyx":323
 * 				if contribution < 0:
 * 					cells[span] = (NEGATIVECONSTLABEL
 * 							if 1 < pyintbitcount(span) < len(chart.sent)             # <<<<<<<<<<<<<<
 * 							else maxlabel,
 * 							maxcombscore, maxleft)
 */
          __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyintbitcount); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 323, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __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_20 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_v_span); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 323, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_20);
          } else {
            #if CYTHON_FAST_PYCALL
            if (PyFunction_Check(__pyx_t_10)) {
              PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_v_span};
              __pyx_t_20 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 323, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
              __Pyx_GOTREF(__pyx_t_20);
            } else
            #endif
            #if CYTHON_FAST_PYCCALL
            if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) {
              PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_v_span};
              __pyx_t_20 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 323, __pyx_L1_error)
              __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
              __Pyx_GOTREF(__pyx_t_20);
            } else
            #endif
            {
              __pyx_t_17 = PyTuple_New(1+1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 323, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_17);
              __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_9); __pyx_t_9 = NULL;
              __Pyx_INCREF(__pyx_v_span);
              __Pyx_GIVEREF(__pyx_v_span);
              PyTuple_SET_ITEM(__pyx_t_17, 0+1, __pyx_v_span);
              __pyx_t_20 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_17, NULL); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 323, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_20);
              __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
            }
          }
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __pyx_t_10 = PyObject_RichCompare(__pyx_int_1, __pyx_t_20, Py_LT); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 323, __pyx_L1_error)
          if (__Pyx_PyObject_IsTrue(__pyx_t_10)) {
            __Pyx_DECREF(__pyx_t_10);
            __pyx_t_17 = __pyx_v_chart->sent;
            __Pyx_INCREF(__pyx_t_17);
            if (unlikely(__pyx_t_17 == Py_None)) {
              PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
              __PYX_ERR(0, 323, __pyx_L1_error)
            }
            __pyx_t_28 = PyList_GET_SIZE(__pyx_t_17); if (unlikely(__pyx_t_28 == -1)) __PYX_ERR(0, 323, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
            __pyx_t_17 = PyInt_FromSsize_t(__pyx_t_28); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 323, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_17);
            __pyx_t_10 = PyObject_RichCompare(__pyx_t_20, __pyx_t_17, Py_LT); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 323, __pyx_L1_error)
            __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
          }
          __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
          __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 323, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          if (__pyx_t_14) {
            __Pyx_INCREF(__pyx_v_8discodop_14disambiguation_NEGATIVECONSTLABEL);
            __pyx_t_2 = __pyx_v_8discodop_14disambiguation_NEGATIVECONSTLABEL;
          } else {

            /* "discodop/disambiguation.pyx":324
 * 					cells[span] = (NEGATIVECONSTLABEL
 * 							if 1 < pyintbitcount(span) < len(chart.sent)
 * 							else maxlabel,             # <<<<<<<<<<<<<<
 * 							maxcombscore, maxleft)
 * 				else:
 */
            __Pyx_INCREF(__pyx_v_maxlabel);
            __pyx_t_2 = __pyx_v_maxlabel;
          }

          /* "discodop/disambiguation.pyx":325
 * 							if 1 < pyintbitcount(span) < len(chart.sent)
 * 							else maxlabel,
 * 							maxcombscore, maxleft)             # <<<<<<<<<<<<<<
 * 				else:
 * 					maxcombscore += contribution
 */
          __pyx_t_10 = PyFloat_FromDouble(__pyx_v_maxcombscore); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 325, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);

          /* "discodop/disambiguation.pyx":322
 * 				contribution = score - labda * (1 - score)
 * 				if contribution < 0:
 * 					cells[span] = (NEGATIVECONSTLABEL             # <<<<<<<<<<<<<<
 * 							if 1 < pyintbitcount(span) < len(chart.sent)
 * 							else maxlabel,
 */
          __pyx_t_20 = PyTuple_New(3); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 322, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_20);
          __Pyx_GIVEREF(__pyx_t_2);
          PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_2);
          __Pyx_GIVEREF(__pyx_t_10);
          PyTuple_SET_ITEM(__pyx_t_20, 1, __pyx_t_10);
          __Pyx_INCREF(__pyx_v_maxleft);
          __Pyx_GIVEREF(__pyx_v_maxleft);
          PyTuple_SET_ITEM(__pyx_t_20, 2, __pyx_v_maxleft);
          __pyx_t_2 = 0;
          __pyx_t_10 = 0;
          if (unlikely(PyObject_SetItem(__pyx_v_cells, __pyx_v_span, __pyx_t_20) < 0)) __PYX_ERR(0, 322, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;

          /* "discodop/disambiguation.pyx":321
 * 				score = maxscore / sentprob
 * 				contribution = score - labda * (1 - score)
 * 				if contribution < 0:             # <<<<<<<<<<<<<<
 * 					cells[span] = (NEGATIVECONSTLABEL
 * 							if 1 < pyintbitcount(span) < len(chart.sent)
 */
          goto __pyx_L39;
        }

        /* "discodop/disambiguation.pyx":327
 * 							maxcombscore, maxleft)
 * 				else:
 * 					maxcombscore += contribution             # <<<<<<<<<<<<<<
 * 					cells[span] = (maxlabel, maxcombscore, maxleft)
 * 
 */
        /*else*/ {
          __pyx_v_maxcombscore = (__pyx_v_maxcombscore + __pyx_v_contribution);

          /* "discodop/disambiguation.pyx":328
 * 				else:
 * 					maxcombscore += contribution
 * 					cells[span] = (maxlabel, maxcombscore, maxleft)             # <<<<<<<<<<<<<<
 * 
 * 	# reconstruct tree
 */
          __pyx_t_20 = PyFloat_FromDouble(__pyx_v_maxcombscore); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 328, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_20);
          __pyx_t_10 = PyTuple_New(3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 328, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_INCREF(__pyx_v_maxlabel);
          __Pyx_GIVEREF(__pyx_v_maxlabel);
          PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_v_maxlabel);
          __Pyx_GIVEREF(__pyx_t_20);
          PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_20);
          __Pyx_INCREF(__pyx_v_maxleft);
          __Pyx_GIVEREF(__pyx_v_maxleft);
          PyTuple_SET_ITEM(__pyx_t_10, 2, __pyx_v_maxleft);
          __pyx_t_20 = 0;
          if (unlikely(PyObject_SetItem(__pyx_v_cells, __pyx_v_span, __pyx_t_10) < 0)) __PYX_ERR(0, 328, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        }
        __pyx_L39:;
      }
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "discodop/disambiguation.pyx":297
 * 	# select best derivation
 * 	for spanlen in range(1, len(chart.sent) + 1):
 * 		for start, _ in enumerate(table):             # <<<<<<<<<<<<<<
 * 			if len(table[start]) <= spanlen:
 * 				continue
 */
      __pyx_L20_continue:;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }

  /* "discodop/disambiguation.pyx":331
 * 
 * 	# reconstruct tree
 * 	tmp = ''             # <<<<<<<<<<<<<<
 * 	try:
 * 		tmp = gettree(cells, tree.bitset)
 */
  __Pyx_INCREF(__pyx_kp_u__4);
  __pyx_v_tmp = __pyx_kp_u__4;

  /* "discodop/disambiguation.pyx":332
 * 	# reconstruct tree
 * 	tmp = ''
 * 	try:             # <<<<<<<<<<<<<<
 * 		tmp = gettree(cells, tree.bitset)
 * 		result = unbinarize(Tree(tmp),
 */
  {
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ExceptionSave(&__pyx_t_31, &__pyx_t_32, &__pyx_t_33);
    __Pyx_XGOTREF(__pyx_t_31);
    __Pyx_XGOTREF(__pyx_t_32);
    __Pyx_XGOTREF(__pyx_t_33);
    /*try:*/ {

      /* "discodop/disambiguation.pyx":333
 * 	tmp = ''
 * 	try:
 * 		tmp = gettree(cells, tree.bitset)             # <<<<<<<<<<<<<<
 * 		result = unbinarize(Tree(tmp),
 * 				childchar='NONE', unarychar='++')
 */
      __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_gettree); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 333, __pyx_L40_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_bitset); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 333, __pyx_L40_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_20 = NULL;
      __pyx_t_15 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
        __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_5);
        if (likely(__pyx_t_20)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
          __Pyx_INCREF(__pyx_t_20);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_5, function);
          __pyx_t_15 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_5)) {
        PyObject *__pyx_temp[3] = {__pyx_t_20, __pyx_v_cells, __pyx_t_10};
        __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 333, __pyx_L40_error)
        __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __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[3] = {__pyx_t_20, __pyx_v_cells, __pyx_t_10};
        __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 333, __pyx_L40_error)
        __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      } else
      #endif
      {
        __pyx_t_2 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 333, __pyx_L40_error)
        __Pyx_GOTREF(__pyx_t_2);
        if (__pyx_t_20) {
          __Pyx_GIVEREF(__pyx_t_20); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_20); __pyx_t_20 = NULL;
        }
        __Pyx_INCREF(__pyx_v_cells);
        __Pyx_GIVEREF(__pyx_v_cells);
        PyTuple_SET_ITEM(__pyx_t_2, 0+__pyx_t_15, __pyx_v_cells);
        __Pyx_GIVEREF(__pyx_t_10);
        PyTuple_SET_ITEM(__pyx_t_2, 1+__pyx_t_15, __pyx_t_10);
        __pyx_t_10 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 333, __pyx_L40_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_DECREF_SET(__pyx_v_tmp, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "discodop/disambiguation.pyx":334
 * 	try:
 * 		tmp = gettree(cells, tree.bitset)
 * 		result = unbinarize(Tree(tmp),             # <<<<<<<<<<<<<<
 * 				childchar='NONE', unarychar='++')
 * 	except (ValueError, AttributeError):
 */
      __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_unbinarize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 334, __pyx_L40_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_Tree); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 334, __pyx_L40_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_10 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
        __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_2);
        if (likely(__pyx_t_10)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
          __Pyx_INCREF(__pyx_t_10);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_2, function);
        }
      }
      if (!__pyx_t_10) {
        __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_v_tmp); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 334, __pyx_L40_error)
        __Pyx_GOTREF(__pyx_t_5);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_2)) {
          PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_tmp};
          __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 334, __pyx_L40_error)
          __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 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_10, __pyx_v_tmp};
          __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 334, __pyx_L40_error)
          __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_GOTREF(__pyx_t_5);
        } else
        #endif
        {
          __pyx_t_20 = PyTuple_New(1+1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 334, __pyx_L40_error)
          __Pyx_GOTREF(__pyx_t_20);
          __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_t_10); __pyx_t_10 = NULL;
          __Pyx_INCREF(__pyx_v_tmp);
          __Pyx_GIVEREF(__pyx_v_tmp);
          PyTuple_SET_ITEM(__pyx_t_20, 0+1, __pyx_v_tmp);
          __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_20, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 334, __pyx_L40_error)
          __Pyx_GOTREF(__pyx_t_5);
          __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 334, __pyx_L40_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
      __pyx_t_5 = 0;

      /* "discodop/disambiguation.pyx":335
 * 		tmp = gettree(cells, tree.bitset)
 * 		result = unbinarize(Tree(tmp),
 * 				childchar='NONE', unarychar='++')             # <<<<<<<<<<<<<<
 * 	except (ValueError, AttributeError):
 * 		return [], 'MCC failed. %s' % tmp
 */
      __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 335, __pyx_L40_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_childchar, __pyx_n_u_NONE) < 0) __PYX_ERR(0, 335, __pyx_L40_error)
      if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_unarychar, __pyx_kp_u__8) < 0) __PYX_ERR(0, 335, __pyx_L40_error)

      /* "discodop/disambiguation.pyx":334
 * 	try:
 * 		tmp = gettree(cells, tree.bitset)
 * 		result = unbinarize(Tree(tmp),             # <<<<<<<<<<<<<<
 * 				childchar='NONE', unarychar='++')
 * 	except (ValueError, AttributeError):
 */
      __pyx_t_20 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 334, __pyx_L40_error)
      __Pyx_GOTREF(__pyx_t_20);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_v_result = __pyx_t_20;
      __pyx_t_20 = 0;

      /* "discodop/disambiguation.pyx":332
 * 	# reconstruct tree
 * 	tmp = ''
 * 	try:             # <<<<<<<<<<<<<<
 * 		tmp = gettree(cells, tree.bitset)
 * 		result = unbinarize(Tree(tmp),
 */
    }

    /* "discodop/disambiguation.pyx":339
 * 		return [], 'MCC failed. %s' % tmp
 * 	else:
 * 		result.label = tree.label  # fix root label             # <<<<<<<<<<<<<<
 * 		return [(str(result), maxscore,
 * 				None)], 'sentprob: %g' % sentprob
 */
    /*else:*/ {
      __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_label); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 339, __pyx_L42_except_error)
      __Pyx_GOTREF(__pyx_t_20);
      if (__Pyx_PyObject_SetAttrStr(__pyx_v_result, __pyx_n_s_label, __pyx_t_20) < 0) __PYX_ERR(0, 339, __pyx_L42_except_error)
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;

      /* "discodop/disambiguation.pyx":340
 * 	else:
 * 		result.label = tree.label  # fix root label
 * 		return [(str(result), maxscore,             # <<<<<<<<<<<<<<
 * 				None)], 'sentprob: %g' % sentprob
 * 
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_20 = PyTuple_New(1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 340, __pyx_L42_except_error)
      __Pyx_GOTREF(__pyx_t_20);
      __Pyx_INCREF(__pyx_v_result);
      __Pyx_GIVEREF(__pyx_v_result);
      PyTuple_SET_ITEM(__pyx_t_20, 0, __pyx_v_result);
      __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)(&PyUnicode_Type)), __pyx_t_20, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 340, __pyx_L42_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      __pyx_t_20 = PyFloat_FromDouble(__pyx_v_maxscore); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 340, __pyx_L42_except_error)
      __Pyx_GOTREF(__pyx_t_20);

      /* "discodop/disambiguation.pyx":341
 * 		result.label = tree.label  # fix root label
 * 		return [(str(result), maxscore,
 * 				None)], 'sentprob: %g' % sentprob             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 340, __pyx_L42_except_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5);
      __Pyx_GIVEREF(__pyx_t_20);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_20);
      __Pyx_INCREF(Py_None);
      __Pyx_GIVEREF(Py_None);
      PyTuple_SET_ITEM(__pyx_t_2, 2, Py_None);
      __pyx_t_5 = 0;
      __pyx_t_20 = 0;

      /* "discodop/disambiguation.pyx":340
 * 	else:
 * 		result.label = tree.label  # fix root label
 * 		return [(str(result), maxscore,             # <<<<<<<<<<<<<<
 * 				None)], 'sentprob: %g' % sentprob
 * 
 */
      __pyx_t_20 = PyList_New(1); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 340, __pyx_L42_except_error)
      __Pyx_GOTREF(__pyx_t_20);
      __Pyx_GIVEREF(__pyx_t_2);
      PyList_SET_ITEM(__pyx_t_20, 0, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "discodop/disambiguation.pyx":341
 * 		result.label = tree.label  # fix root label
 * 		return [(str(result), maxscore,
 * 				None)], 'sentprob: %g' % sentprob             # <<<<<<<<<<<<<<
 * 
 * 
 */
      __pyx_t_2 = PyFloat_FromDouble(__pyx_v_sentprob); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 341, __pyx_L42_except_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_5 = PyUnicode_Format(__pyx_kp_u_sentprob_g, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 341, __pyx_L42_except_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "discodop/disambiguation.pyx":340
 * 	else:
 * 		result.label = tree.label  # fix root label
 * 		return [(str(result), maxscore,             # <<<<<<<<<<<<<<
 * 				None)], 'sentprob: %g' % sentprob
 * 
 */
      __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 340, __pyx_L42_except_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_20);
      PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_20);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5);
      __pyx_t_20 = 0;
      __pyx_t_5 = 0;
      __pyx_r = __pyx_t_2;
      __pyx_t_2 = 0;
      goto __pyx_L43_except_return;
    }
    __pyx_L40_error:;
    __Pyx_PyThreadState_assign
    __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0;
    __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0;
    __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
    __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0;
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
    __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
    __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0;
    __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;

    /* "discodop/disambiguation.pyx":336
 * 		result = unbinarize(Tree(tmp),
 * 				childchar='NONE', unarychar='++')
 * 	except (ValueError, AttributeError):             # <<<<<<<<<<<<<<
 * 		return [], 'MCC failed. %s' % tmp
 * 	else:
 */
    __pyx_t_15 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError) || __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError);
    if (__pyx_t_15) {
      __Pyx_AddTraceback("discodop.disambiguation.maxconstituentscorrect", __pyx_clineno, __pyx_lineno, __pyx_filename);
      if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_5, &__pyx_t_20) < 0) __PYX_ERR(0, 336, __pyx_L42_except_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_GOTREF(__pyx_t_20);

      /* "discodop/disambiguation.pyx":337
 * 				childchar='NONE', unarychar='++')
 * 	except (ValueError, AttributeError):
 * 		return [], 'MCC failed. %s' % tmp             # <<<<<<<<<<<<<<
 * 	else:
 * 		result.label = tree.label  # fix root label
 */
      __Pyx_XDECREF(__pyx_r);
      __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 337, __pyx_L42_except_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_10 = PyUnicode_Format(__pyx_kp_u_MCC_failed_s, __pyx_v_tmp); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 337, __pyx_L42_except_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_17 = PyTuple_New(2); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 337, __pyx_L42_except_error)
      __Pyx_GOTREF(__pyx_t_17);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_10);
      PyTuple_SET_ITEM(__pyx_t_17, 1, __pyx_t_10);
      __pyx_t_1 = 0;
      __pyx_t_10 = 0;
      __pyx_r = __pyx_t_17;
      __pyx_t_17 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0;
      goto __pyx_L43_except_return;
    }
    goto __pyx_L42_except_error;
    __pyx_L42_except_error:;

    /* "discodop/disambiguation.pyx":332
 * 	# reconstruct tree
 * 	tmp = ''
 * 	try:             # <<<<<<<<<<<<<<
 * 		tmp = gettree(cells, tree.bitset)
 * 		result = unbinarize(Tree(tmp),
 */
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_31);
    __Pyx_XGIVEREF(__pyx_t_32);
    __Pyx_XGIVEREF(__pyx_t_33);
    __Pyx_ExceptionReset(__pyx_t_31, __pyx_t_32, __pyx_t_33);
    goto __pyx_L1_error;
    __pyx_L43_except_return:;
    __Pyx_PyThreadState_assign
    __Pyx_XGIVEREF(__pyx_t_31);
    __Pyx_XGIVEREF(__pyx_t_32);
    __Pyx_XGIVEREF(__pyx_t_33);
    __Pyx_ExceptionReset(__pyx_t_31, __pyx_t_32, __pyx_t_33);
    goto __pyx_L0;
  }

  /* "discodop/disambiguation.pyx":243
 * 
 * 
 * cdef maxconstituentscorrect(list derivations, Chart chart,             # <<<<<<<<<<<<<<
 * 		list backtransform, double labda, set labels=None):
 * 	"""Approximate the Most Constituents Correct (MCC) parse from n-best list.
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_8);
  __Pyx_XDECREF(__pyx_t_9);
  __Pyx_XDECREF(__pyx_t_10);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_XDECREF(__pyx_t_18);
  __Pyx_XDECREF(__pyx_t_19);
  __Pyx_XDECREF(__pyx_t_20);
  __Pyx_XDECREF(__pyx_t_21);
  __Pyx_XDECREF(__pyx_t_22);
  __Pyx_AddTraceback("discodop.disambiguation.maxconstituentscorrect", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_span);
  __Pyx_XDECREF(__pyx_v_leftspan);
  __Pyx_XDECREF(__pyx_v_rightspan);
  __Pyx_XDECREF(__pyx_v_maxleft);
  __Pyx_XDECREF(__pyx_v_table);
  __Pyx_XDECREF(__pyx_v_tree);
  __Pyx_XDECREF(__pyx_v_deriv);
  __Pyx_XDECREF(__pyx_v_treestr);
  __Pyx_XDECREF(__pyx_v_t);
  __Pyx_XDECREF(__pyx_v_tablecell);
  __Pyx_XDECREF(__pyx_v_cells);
  __Pyx_XDECREF(__pyx_v__);
  __Pyx_XDECREF(__pyx_v_maxlabel);
  __Pyx_XDECREF(__pyx_v_spans);
  __Pyx_XDECREF(__pyx_v_tmp);
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discodop/disambiguation.pyx":344
 * 
 * 
 * def gettree(cells, span):             # <<<<<<<<<<<<<<
 * 	"""Extract parse tree from most constituents correct table."""
 * 	if span not in cells:
 */

/* Python wrapper */
static PyObject *__pyx_pw_8discodop_14disambiguation_5gettree(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8discodop_14disambiguation_4gettree[] = "gettree(cells, span)\nExtract parse tree from most constituents correct table.";
static PyMethodDef __pyx_mdef_8discodop_14disambiguation_5gettree = {"gettree", (PyCFunction)__pyx_pw_8discodop_14disambiguation_5gettree, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8discodop_14disambiguation_4gettree};
static PyObject *__pyx_pw_8discodop_14disambiguation_5gettree(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_cells = 0;
  PyObject *__pyx_v_span = 0;
  PyObject *__pyx_r = 0;
  __Pyx_RefNannyDeclarations
  __Pyx_RefNannySetupContext("gettree (wrapper)", 0);
  {
    static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_cells,&__pyx_n_s_span,0};
    PyObject* values[2] = {0,0};
    if (unlikely(__pyx_kwds)) {
      Py_ssize_t kw_args;
      const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
      switch (pos_args) {
        case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
        case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
        case  0: break;
        default: goto __pyx_L5_argtuple_error;
      }
      kw_args = PyDict_Size(__pyx_kwds);
      switch (pos_args) {
        case  0:
        if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_cells)) != 0)) kw_args--;
        else goto __pyx_L5_argtuple_error;
        case  1:
        if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_span)) != 0)) kw_args--;
        else {
          __Pyx_RaiseArgtupleInvalid("gettree", 1, 2, 2, 1); __PYX_ERR(0, 344, __pyx_L3_error)
        }
      }
      if (unlikely(kw_args > 0)) {
        if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "gettree") < 0)) __PYX_ERR(0, 344, __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_cells = values[0];
    __pyx_v_span = values[1];
  }
  goto __pyx_L4_argument_unpacking_done;
  __pyx_L5_argtuple_error:;
  __Pyx_RaiseArgtupleInvalid("gettree", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 344, __pyx_L3_error)
  __pyx_L3_error:;
  __Pyx_AddTraceback("discodop.disambiguation.gettree", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __Pyx_RefNannyFinishContext();
  return NULL;
  __pyx_L4_argument_unpacking_done:;
  __pyx_r = __pyx_pf_8discodop_14disambiguation_4gettree(__pyx_self, __pyx_v_cells, __pyx_v_span);

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

static PyObject *__pyx_pf_8discodop_14disambiguation_4gettree(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_cells, PyObject *__pyx_v_span) {
  PyObject *__pyx_v_label = NULL;
  CYTHON_UNUSED PyObject *__pyx_v_unused_score = NULL;
  PyObject *__pyx_v_leftspan = NULL;
  PyObject *__pyx_v_rightspan = 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;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  PyObject *__pyx_t_7 = NULL;
  PyObject *(*__pyx_t_8)(PyObject *);
  int __pyx_t_9;
  __Pyx_RefNannySetupContext("gettree", 0);

  /* "discodop/disambiguation.pyx":346
 * def gettree(cells, span):
 * 	"""Extract parse tree from most constituents correct table."""
 * 	if span not in cells:             # <<<<<<<<<<<<<<
 * 		raise ValueError('MCC: span not in cell: %r' % bin(span))
 * 	label, unused_score, leftspan = cells[span]
 */
  __pyx_t_1 = (__Pyx_PySequence_ContainsTF(__pyx_v_span, __pyx_v_cells, Py_NE)); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 346, __pyx_L1_error)
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discodop/disambiguation.pyx":347
 * 	"""Extract parse tree from most constituents correct table."""
 * 	if span not in cells:
 * 		raise ValueError('MCC: span not in cell: %r' % bin(span))             # <<<<<<<<<<<<<<
 * 	label, unused_score, leftspan = cells[span]
 * 	if leftspan not in cells:
 */
    __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 347, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_v_span);
    __Pyx_GIVEREF(__pyx_v_span);
    PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_span);
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_bin, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 347, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyUnicode_Format(__pyx_kp_u_MCC_span_not_in_cell_r, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 347, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 347, __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 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 347, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 347, __pyx_L1_error)

    /* "discodop/disambiguation.pyx":346
 * def gettree(cells, span):
 * 	"""Extract parse tree from most constituents correct table."""
 * 	if span not in cells:             # <<<<<<<<<<<<<<
 * 		raise ValueError('MCC: span not in cell: %r' % bin(span))
 * 	label, unused_score, leftspan = cells[span]
 */
  }

  /* "discodop/disambiguation.pyx":348
 * 	if span not in cells:
 * 		raise ValueError('MCC: span not in cell: %r' % bin(span))
 * 	label, unused_score, leftspan = cells[span]             # <<<<<<<<<<<<<<
 * 	if leftspan not in cells:
 * 		return '(%s %d)' % (label, pyintnextset(span, 0))
 */
  __pyx_t_3 = PyObject_GetItem(__pyx_v_cells, __pyx_v_span); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 348, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) {
    PyObject* sequence = __pyx_t_3;
    #if !CYTHON_COMPILING_IN_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, 348, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_6 = PyTuple_GET_ITEM(sequence, 2); 
    } else {
      __pyx_t_4 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_5 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_6 = PyList_GET_ITEM(sequence, 2); 
    }
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_5);
    __Pyx_INCREF(__pyx_t_6);
    #else
    __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 348, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 348, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 348, __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_7 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 348, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_8 = Py_TYPE(__pyx_t_7)->tp_iternext;
    index = 0; __pyx_t_4 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_4)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_4);
    index = 1; __pyx_t_5 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_5)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_5);
    index = 2; __pyx_t_6 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_6)) goto __pyx_L4_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_6);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 3) < 0) __PYX_ERR(0, 348, __pyx_L1_error)
    __pyx_t_8 = NULL;
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    goto __pyx_L5_unpacking_done;
    __pyx_L4_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, 348, __pyx_L1_error)
    __pyx_L5_unpacking_done:;
  }
  __pyx_v_label = __pyx_t_4;
  __pyx_t_4 = 0;
  __pyx_v_unused_score = __pyx_t_5;
  __pyx_t_5 = 0;
  __pyx_v_leftspan = __pyx_t_6;
  __pyx_t_6 = 0;

  /* "discodop/disambiguation.pyx":349
 * 		raise ValueError('MCC: span not in cell: %r' % bin(span))
 * 	label, unused_score, leftspan = cells[span]
 * 	if leftspan not in cells:             # <<<<<<<<<<<<<<
 * 		return '(%s %d)' % (label, pyintnextset(span, 0))
 * 	rightspan = span & ~leftspan
 */
  __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_v_leftspan, __pyx_v_cells, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 349, __pyx_L1_error)
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (__pyx_t_1) {

    /* "discodop/disambiguation.pyx":350
 * 	label, unused_score, leftspan = cells[span]
 * 	if leftspan not in cells:
 * 		return '(%s %d)' % (label, pyintnextset(span, 0))             # <<<<<<<<<<<<<<
 * 	rightspan = span & ~leftspan
 * 	if label == NONCONSTLABEL or label == NEGATIVECONSTLABEL:
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_pyintnextset); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 350, __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[3] = {__pyx_t_5, __pyx_v_span, __pyx_int_0};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 350, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
      PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_span, __pyx_int_0};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 350, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else
    #endif
    {
      __pyx_t_4 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 350, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (__pyx_t_5) {
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_5); __pyx_t_5 = NULL;
      }
      __Pyx_INCREF(__pyx_v_span);
      __Pyx_GIVEREF(__pyx_v_span);
      PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_9, __pyx_v_span);
      __Pyx_INCREF(__pyx_int_0);
      __Pyx_GIVEREF(__pyx_int_0);
      PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_9, __pyx_int_0);
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 350, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 350, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_INCREF(__pyx_v_label);
    __Pyx_GIVEREF(__pyx_v_label);
    PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_label);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_3 = PyUnicode_Format(__pyx_kp_u_s_d, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 350, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "discodop/disambiguation.pyx":349
 * 		raise ValueError('MCC: span not in cell: %r' % bin(span))
 * 	label, unused_score, leftspan = cells[span]
 * 	if leftspan not in cells:             # <<<<<<<<<<<<<<
 * 		return '(%s %d)' % (label, pyintnextset(span, 0))
 * 	rightspan = span & ~leftspan
 */
  }

  /* "discodop/disambiguation.pyx":351
 * 	if leftspan not in cells:
 * 		return '(%s %d)' % (label, pyintnextset(span, 0))
 * 	rightspan = span & ~leftspan             # <<<<<<<<<<<<<<
 * 	if label == NONCONSTLABEL or label == NEGATIVECONSTLABEL:
 * 		return '%s %s' % (gettree(cells, leftspan), gettree(cells, rightspan))
 */
  __pyx_t_3 = PyNumber_Invert(__pyx_v_leftspan); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 351, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = PyNumber_And(__pyx_v_span, __pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 351, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_rightspan = __pyx_t_6;
  __pyx_t_6 = 0;

  /* "discodop/disambiguation.pyx":352
 * 		return '(%s %d)' % (label, pyintnextset(span, 0))
 * 	rightspan = span & ~leftspan
 * 	if label == NONCONSTLABEL or label == NEGATIVECONSTLABEL:             # <<<<<<<<<<<<<<
 * 		return '%s %s' % (gettree(cells, leftspan), gettree(cells, rightspan))
 * 	return '(%s %s %s)' % (label,
 */
  __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_label, __pyx_v_8discodop_14disambiguation_NONCONSTLABEL, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 352, __pyx_L1_error)
  if (!__pyx_t_2) {
  } else {
    __pyx_t_1 = __pyx_t_2;
    goto __pyx_L8_bool_binop_done;
  }
  __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_v_label, __pyx_v_8discodop_14disambiguation_NEGATIVECONSTLABEL, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 352, __pyx_L1_error)
  __pyx_t_1 = __pyx_t_2;
  __pyx_L8_bool_binop_done:;
  if (__pyx_t_1) {

    /* "discodop/disambiguation.pyx":353
 * 	rightspan = span & ~leftspan
 * 	if label == NONCONSTLABEL or label == NEGATIVECONSTLABEL:
 * 		return '%s %s' % (gettree(cells, leftspan), gettree(cells, rightspan))             # <<<<<<<<<<<<<<
 * 	return '(%s %s %s)' % (label,
 * 			gettree(cells, leftspan), gettree(cells, rightspan))
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_gettree); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 353, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = NULL;
    __pyx_t_9 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
      __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
      if (likely(__pyx_t_4)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
        __Pyx_INCREF(__pyx_t_4);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_3, function);
        __pyx_t_9 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_cells, __pyx_v_leftspan};
      __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 353, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_6);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_cells, __pyx_v_leftspan};
      __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 353, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_6);
    } else
    #endif
    {
      __pyx_t_5 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 353, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      if (__pyx_t_4) {
        __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
      }
      __Pyx_INCREF(__pyx_v_cells);
      __Pyx_GIVEREF(__pyx_v_cells);
      PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_9, __pyx_v_cells);
      __Pyx_INCREF(__pyx_v_leftspan);
      __Pyx_GIVEREF(__pyx_v_leftspan);
      PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_9, __pyx_v_leftspan);
      __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 353, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_gettree); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 353, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_4 = NULL;
    __pyx_t_9 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(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);
        __pyx_t_9 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_cells, __pyx_v_rightspan};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 353, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_cells, __pyx_v_rightspan};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 353, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else
    #endif
    {
      __pyx_t_7 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 353, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      if (__pyx_t_4) {
        __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4); __pyx_t_4 = NULL;
      }
      __Pyx_INCREF(__pyx_v_cells);
      __Pyx_GIVEREF(__pyx_v_cells);
      PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_9, __pyx_v_cells);
      __Pyx_INCREF(__pyx_v_rightspan);
      __Pyx_GIVEREF(__pyx_v_rightspan);
      PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_9, __pyx_v_rightspan);
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 353, __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 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 353, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_6);
    PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_3);
    __pyx_t_6 = 0;
    __pyx_t_3 = 0;
    __pyx_t_3 = PyUnicode_Format(__pyx_kp_u_s_s, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 353, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_r = __pyx_t_3;
    __pyx_t_3 = 0;
    goto __pyx_L0;

    /* "discodop/disambiguation.pyx":352
 * 		return '(%s %d)' % (label, pyintnextset(span, 0))
 * 	rightspan = span & ~leftspan
 * 	if label == NONCONSTLABEL or label == NEGATIVECONSTLABEL:             # <<<<<<<<<<<<<<
 * 		return '%s %s' % (gettree(cells, leftspan), gettree(cells, rightspan))
 * 	return '(%s %s %s)' % (label,
 */
  }

  /* "discodop/disambiguation.pyx":354
 * 	if label == NONCONSTLABEL or label == NEGATIVECONSTLABEL:
 * 		return '%s %s' % (gettree(cells, leftspan), gettree(cells, rightspan))
 * 	return '(%s %s %s)' % (label,             # <<<<<<<<<<<<<<
 * 			gettree(cells, leftspan), gettree(cells, rightspan))
 * 
 */
  __Pyx_XDECREF(__pyx_r);

  /* "discodop/disambiguation.pyx":355
 * 		return '%s %s' % (gettree(cells, leftspan), gettree(cells, rightspan))
 * 	return '(%s %s %s)' % (label,
 * 			gettree(cells, leftspan), gettree(cells, rightspan))             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_gettree); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 355, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = NULL;
  __pyx_t_9 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(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);
      __pyx_t_9 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_5)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_v_cells, __pyx_v_leftspan};
    __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 355, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_v_cells, __pyx_v_leftspan};
    __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 355, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else
  #endif
  {
    __pyx_t_7 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 355, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (__pyx_t_6) {
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL;
    }
    __Pyx_INCREF(__pyx_v_cells);
    __Pyx_GIVEREF(__pyx_v_cells);
    PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_9, __pyx_v_cells);
    __Pyx_INCREF(__pyx_v_leftspan);
    __Pyx_GIVEREF(__pyx_v_leftspan);
    PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_9, __pyx_v_leftspan);
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 355, __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_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_gettree); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 355, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_6 = NULL;
  __pyx_t_9 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(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);
      __pyx_t_9 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_7)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_v_cells, __pyx_v_rightspan};
    __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 355, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_5);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_v_cells, __pyx_v_rightspan};
    __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 355, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_5);
  } else
  #endif
  {
    __pyx_t_4 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 355, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    if (__pyx_t_6) {
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_6); __pyx_t_6 = NULL;
    }
    __Pyx_INCREF(__pyx_v_cells);
    __Pyx_GIVEREF(__pyx_v_cells);
    PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_9, __pyx_v_cells);
    __Pyx_INCREF(__pyx_v_rightspan);
    __Pyx_GIVEREF(__pyx_v_rightspan);
    PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_9, __pyx_v_rightspan);
    __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 355, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "discodop/disambiguation.pyx":354
 * 	if label == NONCONSTLABEL or label == NEGATIVECONSTLABEL:
 * 		return '%s %s' % (gettree(cells, leftspan), gettree(cells, rightspan))
 * 	return '(%s %s %s)' % (label,             # <<<<<<<<<<<<<<
 * 			gettree(cells, leftspan), gettree(cells, rightspan))
 * 
 */
  __pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 354, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_v_label);
  __Pyx_GIVEREF(__pyx_v_label);
  PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_label);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_t_5);
  __pyx_t_3 = 0;
  __pyx_t_5 = 0;
  __pyx_t_5 = PyUnicode_Format(__pyx_kp_u_s_s_s, __pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 354, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_r = __pyx_t_5;
  __pyx_t_5 = 0;
  goto __pyx_L0;

  /* "discodop/disambiguation.pyx":344
 * 
 * 
 * def gettree(cells, span):             # <<<<<<<<<<<<<<
 * 	"""Extract parse tree from most constituents correct table."""
 * 	if span not in cells:
 */

  /* function exit code */
  __pyx_L1_error:;
  __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("discodop.disambiguation.gettree", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = NULL;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_label);
  __Pyx_XDECREF(__pyx_v_unused_score);
  __Pyx_XDECREF(__pyx_v_leftspan);
  __Pyx_XDECREF(__pyx_v_rightspan);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discodop/disambiguation.pyx":358
 * 
 * 
 * cdef sldop(dict derivations, Chart chart, list sent, list tags,             # <<<<<<<<<<<<<<
 * 		int m, int sldop_n, list backtransform, entries, bint bitpar):
 * 	"""'Proper' method for sl-dop.
 */

static PyObject *__pyx_f_8discodop_14disambiguation_sldop(PyObject *__pyx_v_derivations, struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, PyObject *__pyx_v_sent, PyObject *__pyx_v_tags, int __pyx_v_m, int __pyx_v_sldop_n, PyObject *__pyx_v_backtransform, PyObject *__pyx_v_entries, int __pyx_v_bitpar) {
  PyObject *__pyx_v_derivs = 0;
  PyObject *__pyx_v_derivsfortree = NULL;
  PyObject *__pyx_v_deriv = NULL;
  PyObject *__pyx_v_entry = NULL;
  PyObject *__pyx_v_parsetreeprob = NULL;
  PyObject *__pyx_v_nmostlikelytrees = NULL;
  PyObject *__pyx_v_model = NULL;
  PyObject *__pyx_v_shortestderivations = NULL;
  CYTHON_UNUSED PyObject *__pyx_v_unused_explored = NULL;
  PyObject *__pyx_v_chart2 = NULL;
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_v_s = NULL;
  PyObject *__pyx_v_treestr = NULL;
  PyObject *__pyx_v_msg = 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;
  int __pyx_t_5;
  int __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  Py_ssize_t __pyx_t_8;
  int __pyx_t_9;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  PyObject *(*__pyx_t_13)(PyObject *);
  Py_ssize_t __pyx_t_14;
  PyObject *(*__pyx_t_15)(PyObject *);
  PyObject *__pyx_t_16 = NULL;
  int __pyx_t_17;
  __Pyx_RefNannySetupContext("sldop", 0);

  /* "discodop/disambiguation.pyx":372
 * 	NB: doesn't seem to work so well, so may contain a subtle bug.
 * 		Does not support PCFG charts."""
 * 	cdef dict derivs = {}             # <<<<<<<<<<<<<<
 * 	# collect derivations for each parse tree
 * 	derivsfortree = defaultdict(set)
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 372, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_derivs = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":374
 * 	cdef dict derivs = {}
 * 	# collect derivations for each parse tree
 * 	derivsfortree = defaultdict(set)             # <<<<<<<<<<<<<<
 * 	if backtransform is None:
 * 		for deriv in derivations:
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_defaultdict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 374, __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, ((PyObject *)(&PySet_Type))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 374, __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, ((PyObject *)(&PySet_Type))};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 374, __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, ((PyObject *)(&PySet_Type))};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 374, __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, 374, __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(((PyObject *)(&PySet_Type)));
      __Pyx_GIVEREF(((PyObject *)(&PySet_Type)));
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)(&PySet_Type)));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 374, __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_derivsfortree = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":375
 * 	# collect derivations for each parse tree
 * 	derivsfortree = defaultdict(set)
 * 	if backtransform is None:             # <<<<<<<<<<<<<<
 * 		for deriv in derivations:
 * 			derivsfortree[REMOVEIDS.sub('', deriv)].add(deriv)
 */
  __pyx_t_5 = (__pyx_v_backtransform == ((PyObject*)Py_None));
  __pyx_t_6 = (__pyx_t_5 != 0);
  if (__pyx_t_6) {

    /* "discodop/disambiguation.pyx":376
 * 	derivsfortree = defaultdict(set)
 * 	if backtransform is None:
 * 		for deriv in derivations:             # <<<<<<<<<<<<<<
 * 			derivsfortree[REMOVEIDS.sub('', deriv)].add(deriv)
 * 	elif bitpar:
 */
    __pyx_t_7 = 0;
    if (unlikely(__pyx_v_derivations == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 376, __pyx_L1_error)
    }
    __pyx_t_2 = __Pyx_dict_iterator(__pyx_v_derivations, 1, ((PyObject *)NULL), (&__pyx_t_8), (&__pyx_t_9)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 376, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_XDECREF(__pyx_t_1);
    __pyx_t_1 = __pyx_t_2;
    __pyx_t_2 = 0;
    while (1) {
      __pyx_t_10 = __Pyx_dict_iter_next(__pyx_t_1, __pyx_t_8, &__pyx_t_7, &__pyx_t_2, NULL, NULL, __pyx_t_9);
      if (unlikely(__pyx_t_10 == 0)) break;
      if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 376, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_XDECREF_SET(__pyx_v_deriv, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "discodop/disambiguation.pyx":377
 * 	if backtransform is None:
 * 		for deriv in derivations:
 * 			derivsfortree[REMOVEIDS.sub('', deriv)].add(deriv)             # <<<<<<<<<<<<<<
 * 	elif bitpar:
 * 		for deriv in derivations:
 */
      __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_REMOVEIDS); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 377, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_sub); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 377, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = NULL;
      __pyx_t_10 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_11);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_11, function);
          __pyx_t_10 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_11)) {
        PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_kp_u__4, __pyx_v_deriv};
        __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 377, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_4);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) {
        PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_kp_u__4, __pyx_v_deriv};
        __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 377, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_GOTREF(__pyx_t_4);
      } else
      #endif
      {
        __pyx_t_12 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 377, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        if (__pyx_t_3) {
          __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_3); __pyx_t_3 = NULL;
        }
        __Pyx_INCREF(__pyx_kp_u__4);
        __Pyx_GIVEREF(__pyx_kp_u__4);
        PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_10, __pyx_kp_u__4);
        __Pyx_INCREF(__pyx_v_deriv);
        __Pyx_GIVEREF(__pyx_v_deriv);
        PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_10, __pyx_v_deriv);
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_12, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 377, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      }
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_11 = PyObject_GetItem(__pyx_v_derivsfortree, __pyx_t_4); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 377, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_add); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 377, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_11 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_11)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_11);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
        }
      }
      if (!__pyx_t_11) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_deriv); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 377, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_4)) {
          PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_v_deriv};
          __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 377, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_GOTREF(__pyx_t_2);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
          PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_v_deriv};
          __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 377, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_GOTREF(__pyx_t_2);
        } else
        #endif
        {
          __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 377, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL;
          __Pyx_INCREF(__pyx_v_deriv);
          __Pyx_GIVEREF(__pyx_v_deriv);
          PyTuple_SET_ITEM(__pyx_t_12, 0+1, __pyx_v_deriv);
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_12, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 377, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "discodop/disambiguation.pyx":375
 * 	# collect derivations for each parse tree
 * 	derivsfortree = defaultdict(set)
 * 	if backtransform is None:             # <<<<<<<<<<<<<<
 * 		for deriv in derivations:
 * 			derivsfortree[REMOVEIDS.sub('', deriv)].add(deriv)
 */
    goto __pyx_L3;
  }

  /* "discodop/disambiguation.pyx":378
 * 		for deriv in derivations:
 * 			derivsfortree[REMOVEIDS.sub('', deriv)].add(deriv)
 * 	elif bitpar:             # <<<<<<<<<<<<<<
 * 		for deriv in derivations:
 * 			derivsfortree[recoverfragments(deriv, chart,
 */
  __pyx_t_6 = (__pyx_v_bitpar != 0);
  if (__pyx_t_6) {

    /* "discodop/disambiguation.pyx":379
 * 			derivsfortree[REMOVEIDS.sub('', deriv)].add(deriv)
 * 	elif bitpar:
 * 		for deriv in derivations:             # <<<<<<<<<<<<<<
 * 			derivsfortree[recoverfragments(deriv, chart,
 * 					backtransform)].add(deriv)
 */
    __pyx_t_8 = 0;
    if (unlikely(__pyx_v_derivations == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 379, __pyx_L1_error)
    }
    __pyx_t_2 = __Pyx_dict_iterator(__pyx_v_derivations, 1, ((PyObject *)NULL), (&__pyx_t_7), (&__pyx_t_9)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 379, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_XDECREF(__pyx_t_1);
    __pyx_t_1 = __pyx_t_2;
    __pyx_t_2 = 0;
    while (1) {
      __pyx_t_10 = __Pyx_dict_iter_next(__pyx_t_1, __pyx_t_7, &__pyx_t_8, &__pyx_t_2, NULL, NULL, __pyx_t_9);
      if (unlikely(__pyx_t_10 == 0)) break;
      if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 379, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_XDECREF_SET(__pyx_v_deriv, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "discodop/disambiguation.pyx":380
 * 	elif bitpar:
 * 		for deriv in derivations:
 * 			derivsfortree[recoverfragments(deriv, chart,             # <<<<<<<<<<<<<<
 * 					backtransform)].add(deriv)
 * 	else:
 */
      __pyx_t_4 = __pyx_f_8discodop_14disambiguation_recoverfragments(__pyx_v_deriv, __pyx_v_chart, __pyx_v_backtransform, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 380, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_12 = PyObject_GetItem(__pyx_v_derivsfortree, __pyx_t_4); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 380, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "discodop/disambiguation.pyx":381
 * 		for deriv in derivations:
 * 			derivsfortree[recoverfragments(deriv, chart,
 * 					backtransform)].add(deriv)             # <<<<<<<<<<<<<<
 * 	else:
 * 		for entry in entries:
 */
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_add); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 381, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_12 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_12)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_12);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
        }
      }
      if (!__pyx_t_12) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_deriv); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 381, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_4)) {
          PyObject *__pyx_temp[2] = {__pyx_t_12, __pyx_v_deriv};
          __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 381, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
          __Pyx_GOTREF(__pyx_t_2);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
          PyObject *__pyx_temp[2] = {__pyx_t_12, __pyx_v_deriv};
          __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 381, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
          __Pyx_GOTREF(__pyx_t_2);
        } else
        #endif
        {
          __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 381, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_12); __pyx_t_12 = NULL;
          __Pyx_INCREF(__pyx_v_deriv);
          __Pyx_GIVEREF(__pyx_v_deriv);
          PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_deriv);
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 381, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "discodop/disambiguation.pyx":378
 * 		for deriv in derivations:
 * 			derivsfortree[REMOVEIDS.sub('', deriv)].add(deriv)
 * 	elif bitpar:             # <<<<<<<<<<<<<<
 * 		for deriv in derivations:
 * 			derivsfortree[recoverfragments(deriv, chart,
 */
    goto __pyx_L3;
  }

  /* "discodop/disambiguation.pyx":383
 * 					backtransform)].add(deriv)
 * 	else:
 * 		for entry in entries:             # <<<<<<<<<<<<<<
 * 			deriv = getderiv(chart.root(), (<DoubleEntry>entry).key, chart,
 * 					None)
 */
  /*else*/ {
    if (likely(PyList_CheckExact(__pyx_v_entries)) || PyTuple_CheckExact(__pyx_v_entries)) {
      __pyx_t_1 = __pyx_v_entries; __Pyx_INCREF(__pyx_t_1); __pyx_t_7 = 0;
      __pyx_t_13 = NULL;
    } else {
      __pyx_t_7 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_entries); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 383, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_13 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 383, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_13)) {
        if (likely(PyList_CheckExact(__pyx_t_1))) {
          if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_2); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 383, __pyx_L1_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 383, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        } else {
          if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_2); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 383, __pyx_L1_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 383, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        }
      } else {
        __pyx_t_2 = __pyx_t_13(__pyx_t_1);
        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, 383, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      __Pyx_XDECREF_SET(__pyx_v_entry, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "discodop/disambiguation.pyx":384
 * 	else:
 * 		for entry in entries:
 * 			deriv = getderiv(chart.root(), (<DoubleEntry>entry).key, chart,             # <<<<<<<<<<<<<<
 * 					None)
 * 			derivations[deriv] = (<DoubleEntry>entry).value
 */
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_getderiv); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 384, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_chart), __pyx_n_s_root); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 384, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __pyx_t_3 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_12);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_12, function);
        }
      }
      if (__pyx_t_3) {
        __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 384, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      } else {
        __pyx_t_11 = __Pyx_PyObject_CallNoArg(__pyx_t_12); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 384, __pyx_L1_error)
      }
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;

      /* "discodop/disambiguation.pyx":385
 * 		for entry in entries:
 * 			deriv = getderiv(chart.root(), (<DoubleEntry>entry).key, chart,
 * 					None)             # <<<<<<<<<<<<<<
 * 			derivations[deriv] = (<DoubleEntry>entry).value
 * 			derivsfortree[recoverfragments((<DoubleEntry>entry).key, chart,
 */
      __pyx_t_12 = NULL;
      __pyx_t_9 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_12)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_12);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
          __pyx_t_9 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_4)) {
        PyObject *__pyx_temp[5] = {__pyx_t_12, __pyx_t_11, ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_v_entry)->key, ((PyObject *)__pyx_v_chart), Py_None};
        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_9, 4+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 384, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
        PyObject *__pyx_temp[5] = {__pyx_t_12, __pyx_t_11, ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_v_entry)->key, ((PyObject *)__pyx_v_chart), Py_None};
        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_9, 4+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 384, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      } else
      #endif
      {
        __pyx_t_3 = PyTuple_New(4+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 384, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        if (__pyx_t_12) {
          __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_12); __pyx_t_12 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_11);
        PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_9, __pyx_t_11);
        __Pyx_INCREF(((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_v_entry)->key);
        __Pyx_GIVEREF(((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_v_entry)->key);
        PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_9, ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_v_entry)->key);
        __Pyx_INCREF(((PyObject *)__pyx_v_chart));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_chart));
        PyTuple_SET_ITEM(__pyx_t_3, 2+__pyx_t_9, ((PyObject *)__pyx_v_chart));
        __Pyx_INCREF(Py_None);
        __Pyx_GIVEREF(Py_None);
        PyTuple_SET_ITEM(__pyx_t_3, 3+__pyx_t_9, Py_None);
        __pyx_t_11 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 384, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF_SET(__pyx_v_deriv, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "discodop/disambiguation.pyx":386
 * 			deriv = getderiv(chart.root(), (<DoubleEntry>entry).key, chart,
 * 					None)
 * 			derivations[deriv] = (<DoubleEntry>entry).value             # <<<<<<<<<<<<<<
 * 			derivsfortree[recoverfragments((<DoubleEntry>entry).key, chart,
 * 					backtransform)].add(deriv)
 */
      __pyx_t_2 = PyFloat_FromDouble(((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_v_entry)->value); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 386, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      if (unlikely(__pyx_v_derivations == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 386, __pyx_L1_error)
      }
      if (unlikely(PyDict_SetItem(__pyx_v_derivations, __pyx_v_deriv, __pyx_t_2) < 0)) __PYX_ERR(0, 386, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "discodop/disambiguation.pyx":387
 * 					None)
 * 			derivations[deriv] = (<DoubleEntry>entry).value
 * 			derivsfortree[recoverfragments((<DoubleEntry>entry).key, chart,             # <<<<<<<<<<<<<<
 * 					backtransform)].add(deriv)
 * 	# sum over probs of derivations to get probs of parse trees
 */
      __pyx_t_4 = ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_v_entry)->key;
      __Pyx_INCREF(__pyx_t_4);

      /* "discodop/disambiguation.pyx":388
 * 			derivations[deriv] = (<DoubleEntry>entry).value
 * 			derivsfortree[recoverfragments((<DoubleEntry>entry).key, chart,
 * 					backtransform)].add(deriv)             # <<<<<<<<<<<<<<
 * 	# sum over probs of derivations to get probs of parse trees
 * 	parsetreeprob = {tree: logprobsum([-derivations[d] for d in ds])
 */
      __pyx_t_3 = __pyx_f_8discodop_14disambiguation_recoverfragments(__pyx_t_4, __pyx_v_chart, __pyx_v_backtransform, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 387, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "discodop/disambiguation.pyx":387
 * 					None)
 * 			derivations[deriv] = (<DoubleEntry>entry).value
 * 			derivsfortree[recoverfragments((<DoubleEntry>entry).key, chart,             # <<<<<<<<<<<<<<
 * 					backtransform)].add(deriv)
 * 	# sum over probs of derivations to get probs of parse trees
 */
      __pyx_t_4 = PyObject_GetItem(__pyx_v_derivsfortree, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 387, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "discodop/disambiguation.pyx":388
 * 			derivations[deriv] = (<DoubleEntry>entry).value
 * 			derivsfortree[recoverfragments((<DoubleEntry>entry).key, chart,
 * 					backtransform)].add(deriv)             # <<<<<<<<<<<<<<
 * 	# sum over probs of derivations to get probs of parse trees
 * 	parsetreeprob = {tree: logprobsum([-derivations[d] for d in ds])
 */
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_add); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 388, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
        }
      }
      if (!__pyx_t_4) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_deriv); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 388, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_3)) {
          PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_deriv};
          __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 388, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_GOTREF(__pyx_t_2);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
          PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_deriv};
          __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 388, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_GOTREF(__pyx_t_2);
        } else
        #endif
        {
          __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 388, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_4); __pyx_t_4 = NULL;
          __Pyx_INCREF(__pyx_v_deriv);
          __Pyx_GIVEREF(__pyx_v_deriv);
          PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_deriv);
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 388, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "discodop/disambiguation.pyx":383
 * 					backtransform)].add(deriv)
 * 	else:
 * 		for entry in entries:             # <<<<<<<<<<<<<<
 * 			deriv = getderiv(chart.root(), (<DoubleEntry>entry).key, chart,
 * 					None)
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __pyx_L3:;

  /* "discodop/disambiguation.pyx":390
 * 					backtransform)].add(deriv)
 * 	# sum over probs of derivations to get probs of parse trees
 * 	parsetreeprob = {tree: logprobsum([-derivations[d] for d in ds])             # <<<<<<<<<<<<<<
 * 			for tree, ds in derivsfortree.items()}
 * 	nmostlikelytrees = set(nlargest(sldop_n, parsetreeprob,
 */
  { /* enter inner scope */
    PyObject *__pyx_8genexpr9__pyx_v_tree = NULL;
    PyObject *__pyx_8genexpr9__pyx_v_ds = NULL;
    __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 390, __pyx_L12_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "discodop/disambiguation.pyx":391
 * 	# sum over probs of derivations to get probs of parse trees
 * 	parsetreeprob = {tree: logprobsum([-derivations[d] for d in ds])
 * 			for tree, ds in derivsfortree.items()}             # <<<<<<<<<<<<<<
 * 	nmostlikelytrees = set(nlargest(sldop_n, parsetreeprob,
 * 			key=parsetreeprob.get))
 */
    __pyx_t_7 = 0;
    if (unlikely(__pyx_v_derivsfortree == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "items");
      __PYX_ERR(0, 391, __pyx_L12_error)
    }
    __pyx_t_3 = __Pyx_dict_iterator(__pyx_v_derivsfortree, 0, __pyx_n_s_items, (&__pyx_t_8), (&__pyx_t_9)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 391, __pyx_L12_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_XDECREF(__pyx_t_2);
    __pyx_t_2 = __pyx_t_3;
    __pyx_t_3 = 0;
    while (1) {
      __pyx_t_10 = __Pyx_dict_iter_next(__pyx_t_2, __pyx_t_8, &__pyx_t_7, &__pyx_t_3, &__pyx_t_11, NULL, __pyx_t_9);
      if (unlikely(__pyx_t_10 == 0)) break;
      if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 391, __pyx_L12_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_XDECREF_SET(__pyx_8genexpr9__pyx_v_tree, __pyx_t_3);
      __pyx_t_3 = 0;
      __Pyx_XDECREF_SET(__pyx_8genexpr9__pyx_v_ds, __pyx_t_11);
      __pyx_t_11 = 0;

      /* "discodop/disambiguation.pyx":390
 * 					backtransform)].add(deriv)
 * 	# sum over probs of derivations to get probs of parse trees
 * 	parsetreeprob = {tree: logprobsum([-derivations[d] for d in ds])             # <<<<<<<<<<<<<<
 * 			for tree, ds in derivsfortree.items()}
 * 	nmostlikelytrees = set(nlargest(sldop_n, parsetreeprob,
 */
      { /* enter inner scope */
        PyObject *__pyx_9genexpr10__pyx_8genexpr9__pyx_v_d = NULL;
        __pyx_t_11 = PyList_New(0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 390, __pyx_L17_error)
        __Pyx_GOTREF(__pyx_t_11);
        if (likely(PyList_CheckExact(__pyx_8genexpr9__pyx_v_ds)) || PyTuple_CheckExact(__pyx_8genexpr9__pyx_v_ds)) {
          __pyx_t_3 = __pyx_8genexpr9__pyx_v_ds; __Pyx_INCREF(__pyx_t_3); __pyx_t_14 = 0;
          __pyx_t_13 = NULL;
        } else {
          __pyx_t_14 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_8genexpr9__pyx_v_ds); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 390, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_13 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 390, __pyx_L17_error)
        }
        for (;;) {
          if (likely(!__pyx_t_13)) {
            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_4 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_14); __Pyx_INCREF(__pyx_t_4); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 390, __pyx_L17_error)
              #else
              __pyx_t_4 = PySequence_ITEM(__pyx_t_3, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 390, __pyx_L17_error)
              __Pyx_GOTREF(__pyx_t_4);
              #endif
            } else {
              if (__pyx_t_14 >= 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_14); __Pyx_INCREF(__pyx_t_4); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 390, __pyx_L17_error)
              #else
              __pyx_t_4 = PySequence_ITEM(__pyx_t_3, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 390, __pyx_L17_error)
              __Pyx_GOTREF(__pyx_t_4);
              #endif
            }
          } else {
            __pyx_t_4 = __pyx_t_13(__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, 390, __pyx_L17_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_4);
          }
          __Pyx_XDECREF_SET(__pyx_9genexpr10__pyx_8genexpr9__pyx_v_d, __pyx_t_4);
          __pyx_t_4 = 0;
          if (unlikely(__pyx_v_derivations == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 390, __pyx_L17_error)
          }
          __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_derivations, __pyx_9genexpr10__pyx_8genexpr9__pyx_v_d); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 390, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_4);
          __pyx_t_12 = PyNumber_Negative(__pyx_t_4); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 390, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          if (unlikely(__Pyx_ListComp_Append(__pyx_t_11, (PyObject*)__pyx_t_12))) __PYX_ERR(0, 390, __pyx_L17_error)
          __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        }
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_9genexpr10__pyx_8genexpr9__pyx_v_d);
        goto __pyx_L20_exit_scope;
        __pyx_L17_error:;
        __Pyx_XDECREF(__pyx_9genexpr10__pyx_8genexpr9__pyx_v_d);
        goto __pyx_L12_error;
        __pyx_L20_exit_scope:;
      } /* exit inner scope */
      __pyx_t_3 = PyFloat_FromDouble(__pyx_f_8discodop_10containers_logprobsum(((PyObject*)__pyx_t_11))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 390, __pyx_L12_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      if (unlikely(PyDict_SetItem(__pyx_t_1, (PyObject*)__pyx_8genexpr9__pyx_v_tree, (PyObject*)__pyx_t_3))) __PYX_ERR(0, 390, __pyx_L12_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    }
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_XDECREF(__pyx_8genexpr9__pyx_v_tree);
    __Pyx_XDECREF(__pyx_8genexpr9__pyx_v_ds);
    goto __pyx_L21_exit_scope;
    __pyx_L12_error:;
    __Pyx_XDECREF(__pyx_8genexpr9__pyx_v_tree);
    __Pyx_XDECREF(__pyx_8genexpr9__pyx_v_ds);
    goto __pyx_L1_error;
    __pyx_L21_exit_scope:;
  } /* exit inner scope */
  __pyx_v_parsetreeprob = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":392
 * 	parsetreeprob = {tree: logprobsum([-derivations[d] for d in ds])
 * 			for tree, ds in derivsfortree.items()}
 * 	nmostlikelytrees = set(nlargest(sldop_n, parsetreeprob,             # <<<<<<<<<<<<<<
 * 			key=parsetreeprob.get))
 * 
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_nlargest); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 392, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_sldop_n); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 392, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 392, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
  __Pyx_INCREF(__pyx_v_parsetreeprob);
  __Pyx_GIVEREF(__pyx_v_parsetreeprob);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_parsetreeprob);
  __pyx_t_2 = 0;

  /* "discodop/disambiguation.pyx":393
 * 			for tree, ds in derivsfortree.items()}
 * 	nmostlikelytrees = set(nlargest(sldop_n, parsetreeprob,
 * 			key=parsetreeprob.get))             # <<<<<<<<<<<<<<
 * 
 * 	model = chart.grammar.modelnames[chart.grammar.currentmodel]
 */
  __pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 393, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_parsetreeprob, __pyx_n_s_get); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 393, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_key, __pyx_t_11) < 0) __PYX_ERR(0, 393, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

  /* "discodop/disambiguation.pyx":392
 * 	parsetreeprob = {tree: logprobsum([-derivations[d] for d in ds])
 * 			for tree, ds in derivsfortree.items()}
 * 	nmostlikelytrees = set(nlargest(sldop_n, parsetreeprob,             # <<<<<<<<<<<<<<
 * 			key=parsetreeprob.get))
 * 
 */
  __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 392, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PySet_New(__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 392, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_v_nmostlikelytrees = ((PyObject*)__pyx_t_2);
  __pyx_t_2 = 0;

  /* "discodop/disambiguation.pyx":395
 * 			key=parsetreeprob.get))
 * 
 * 	model = chart.grammar.modelnames[chart.grammar.currentmodel]             # <<<<<<<<<<<<<<
 * 	chart.grammar.switch(u'shortest', logprob=True)
 * 	shortestderivations, unused_explored, chart2 = treeparsing(
 */
  if (unlikely(__pyx_v_chart->grammar->modelnames == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 395, __pyx_L1_error)
  }
  __pyx_t_2 = PyList_GET_ITEM(__pyx_v_chart->grammar->modelnames, __pyx_v_chart->grammar->currentmodel);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_v_model = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "discodop/disambiguation.pyx":396
 * 
 * 	model = chart.grammar.modelnames[chart.grammar.currentmodel]
 * 	chart.grammar.switch(u'shortest', logprob=True)             # <<<<<<<<<<<<<<
 * 	shortestderivations, unused_explored, chart2 = treeparsing(
 * 			nmostlikelytrees, sent, chart.grammar, m, backtransform, tags)
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_chart->grammar), __pyx_n_s_switch); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 396, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_11 = PyDict_New(); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 396, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  if (PyDict_SetItem(__pyx_t_11, __pyx_n_s_logprob, Py_True) < 0) __PYX_ERR(0, 396, __pyx_L1_error)
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__11, __pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 396, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "discodop/disambiguation.pyx":397
 * 	model = chart.grammar.modelnames[chart.grammar.currentmodel]
 * 	chart.grammar.switch(u'shortest', logprob=True)
 * 	shortestderivations, unused_explored, chart2 = treeparsing(             # <<<<<<<<<<<<<<
 * 			nmostlikelytrees, sent, chart.grammar, m, backtransform, tags)
 * 	if not chart2.rankededges.get(chart2.root()):
 */
  __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_treeparsing); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 397, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);

  /* "discodop/disambiguation.pyx":398
 * 	chart.grammar.switch(u'shortest', logprob=True)
 * 	shortestderivations, unused_explored, chart2 = treeparsing(
 * 			nmostlikelytrees, sent, chart.grammar, m, backtransform, tags)             # <<<<<<<<<<<<<<
 * 	if not chart2.rankededges.get(chart2.root()):
 * 		return [], 'SL-DOP couldn\'t find parse for tree'
 */
  __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_m); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 398, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = NULL;
  __pyx_t_9 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_11);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_11, function);
      __pyx_t_9 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_11)) {
    PyObject *__pyx_temp[7] = {__pyx_t_1, __pyx_v_nmostlikelytrees, __pyx_v_sent, ((PyObject *)__pyx_v_chart->grammar), __pyx_t_2, __pyx_v_backtransform, __pyx_v_tags};
    __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 6+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 397, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) {
    PyObject *__pyx_temp[7] = {__pyx_t_1, __pyx_v_nmostlikelytrees, __pyx_v_sent, ((PyObject *)__pyx_v_chart->grammar), __pyx_t_2, __pyx_v_backtransform, __pyx_v_tags};
    __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-__pyx_t_9, 6+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 397, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  {
    __pyx_t_12 = PyTuple_New(6+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 397, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    if (__pyx_t_1) {
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_1); __pyx_t_1 = NULL;
    }
    __Pyx_INCREF(__pyx_v_nmostlikelytrees);
    __Pyx_GIVEREF(__pyx_v_nmostlikelytrees);
    PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_9, __pyx_v_nmostlikelytrees);
    __Pyx_INCREF(__pyx_v_sent);
    __Pyx_GIVEREF(__pyx_v_sent);
    PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_9, __pyx_v_sent);
    __Pyx_INCREF(((PyObject *)__pyx_v_chart->grammar));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_chart->grammar));
    PyTuple_SET_ITEM(__pyx_t_12, 2+__pyx_t_9, ((PyObject *)__pyx_v_chart->grammar));
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_12, 3+__pyx_t_9, __pyx_t_2);
    __Pyx_INCREF(__pyx_v_backtransform);
    __Pyx_GIVEREF(__pyx_v_backtransform);
    PyTuple_SET_ITEM(__pyx_t_12, 4+__pyx_t_9, __pyx_v_backtransform);
    __Pyx_INCREF(__pyx_v_tags);
    __Pyx_GIVEREF(__pyx_v_tags);
    PyTuple_SET_ITEM(__pyx_t_12, 5+__pyx_t_9, __pyx_v_tags);
    __pyx_t_2 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_12, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 397, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  }
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  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 != 3)) {
      if (size > 3) __Pyx_RaiseTooManyValuesError(3);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 397, __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_12 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 2); 
    } else {
      __pyx_t_11 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_12 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_2 = PyList_GET_ITEM(sequence, 2); 
    }
    __Pyx_INCREF(__pyx_t_11);
    __Pyx_INCREF(__pyx_t_12);
    __Pyx_INCREF(__pyx_t_2);
    #else
    __pyx_t_11 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 397, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_12 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 397, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_2 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 397, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    #endif
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_1 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 397, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_15 = Py_TYPE(__pyx_t_1)->tp_iternext;
    index = 0; __pyx_t_11 = __pyx_t_15(__pyx_t_1); if (unlikely(!__pyx_t_11)) goto __pyx_L22_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_11);
    index = 1; __pyx_t_12 = __pyx_t_15(__pyx_t_1); if (unlikely(!__pyx_t_12)) goto __pyx_L22_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_12);
    index = 2; __pyx_t_2 = __pyx_t_15(__pyx_t_1); if (unlikely(!__pyx_t_2)) goto __pyx_L22_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_1), 3) < 0) __PYX_ERR(0, 397, __pyx_L1_error)
    __pyx_t_15 = NULL;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    goto __pyx_L23_unpacking_done;
    __pyx_L22_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_15 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 397, __pyx_L1_error)
    __pyx_L23_unpacking_done:;
  }

  /* "discodop/disambiguation.pyx":397
 * 	model = chart.grammar.modelnames[chart.grammar.currentmodel]
 * 	chart.grammar.switch(u'shortest', logprob=True)
 * 	shortestderivations, unused_explored, chart2 = treeparsing(             # <<<<<<<<<<<<<<
 * 			nmostlikelytrees, sent, chart.grammar, m, backtransform, tags)
 * 	if not chart2.rankededges.get(chart2.root()):
 */
  __pyx_v_shortestderivations = __pyx_t_11;
  __pyx_t_11 = 0;
  __pyx_v_unused_explored = __pyx_t_12;
  __pyx_t_12 = 0;
  __pyx_v_chart2 = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "discodop/disambiguation.pyx":399
 * 	shortestderivations, unused_explored, chart2 = treeparsing(
 * 			nmostlikelytrees, sent, chart.grammar, m, backtransform, tags)
 * 	if not chart2.rankededges.get(chart2.root()):             # <<<<<<<<<<<<<<
 * 		return [], 'SL-DOP couldn\'t find parse for tree'
 * 	result = {}
 */
  __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_chart2, __pyx_n_s_rankededges); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 399, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_get); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 399, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_v_chart2, __pyx_n_s_root); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 399, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_11);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_11, function);
    }
  }
  if (__pyx_t_1) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 399, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_11); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 399, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) {
    __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_12);
    if (likely(__pyx_t_11)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
      __Pyx_INCREF(__pyx_t_11);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_12, function);
    }
  }
  if (!__pyx_t_11) {
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 399, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_12)) {
      PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_t_2};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 399, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) {
      PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_t_2};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 399, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else
    #endif
    {
      __pyx_t_1 = PyTuple_New(1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 399, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_11); __pyx_t_11 = NULL;
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_1, 0+1, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 399, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 399, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_5 = ((!__pyx_t_6) != 0);
  if (__pyx_t_5) {

    /* "discodop/disambiguation.pyx":400
 * 			nmostlikelytrees, sent, chart.grammar, m, backtransform, tags)
 * 	if not chart2.rankededges.get(chart2.root()):
 * 		return [], 'SL-DOP couldn\'t find parse for tree'             # <<<<<<<<<<<<<<
 * 	result = {}
 * 	for (deriv, s), entry in zip(shortestderivations,
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 400, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 400, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_3);
    __Pyx_INCREF(__pyx_kp_u_SL_DOP_couldn_t_find_parse_for_t);
    __Pyx_GIVEREF(__pyx_kp_u_SL_DOP_couldn_t_find_parse_for_t);
    PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_kp_u_SL_DOP_couldn_t_find_parse_for_t);
    __pyx_t_3 = 0;
    __pyx_r = __pyx_t_12;
    __pyx_t_12 = 0;
    goto __pyx_L0;

    /* "discodop/disambiguation.pyx":399
 * 	shortestderivations, unused_explored, chart2 = treeparsing(
 * 			nmostlikelytrees, sent, chart.grammar, m, backtransform, tags)
 * 	if not chart2.rankededges.get(chart2.root()):             # <<<<<<<<<<<<<<
 * 		return [], 'SL-DOP couldn\'t find parse for tree'
 * 	result = {}
 */
  }

  /* "discodop/disambiguation.pyx":401
 * 	if not chart2.rankededges.get(chart2.root()):
 * 		return [], 'SL-DOP couldn\'t find parse for tree'
 * 	result = {}             # <<<<<<<<<<<<<<
 * 	for (deriv, s), entry in zip(shortestderivations,
 * 			chart2.rankededges[chart2.root()]):
 */
  __pyx_t_12 = PyDict_New(); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 401, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_v_result = ((PyObject*)__pyx_t_12);
  __pyx_t_12 = 0;

  /* "discodop/disambiguation.pyx":403
 * 	result = {}
 * 	for (deriv, s), entry in zip(shortestderivations,
 * 			chart2.rankededges[chart2.root()]):             # <<<<<<<<<<<<<<
 * 		if backtransform is None:
 * 			treestr = REMOVEIDS.sub('', deriv)
 */
  __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_chart2, __pyx_n_s_rankededges); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 403, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_chart2, __pyx_n_s_root); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 403, __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, 403, __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, 403, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyObject_GetItem(__pyx_t_12, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 403, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "discodop/disambiguation.pyx":402
 * 		return [], 'SL-DOP couldn\'t find parse for tree'
 * 	result = {}
 * 	for (deriv, s), entry in zip(shortestderivations,             # <<<<<<<<<<<<<<
 * 			chart2.rankededges[chart2.root()]):
 * 		if backtransform is None:
 */
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 402, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_v_shortestderivations);
  __Pyx_GIVEREF(__pyx_v_shortestderivations);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_shortestderivations);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 402, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_3 = __pyx_t_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_8 = 0;
    __pyx_t_13 = NULL;
  } else {
    __pyx_t_8 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 402, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_13 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 402, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_13)) {
      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_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 402, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 402, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_8); __Pyx_INCREF(__pyx_t_1); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 402, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 402, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_13(__pyx_t_3);
      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, 402, __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, 402, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_12 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_12 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_12);
      __Pyx_INCREF(__pyx_t_2);
      #else
      __pyx_t_12 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 402, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 402, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      #endif
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_11 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 402, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_15 = Py_TYPE(__pyx_t_11)->tp_iternext;
      index = 0; __pyx_t_12 = __pyx_t_15(__pyx_t_11); if (unlikely(!__pyx_t_12)) goto __pyx_L27_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_12);
      index = 1; __pyx_t_2 = __pyx_t_15(__pyx_t_11); if (unlikely(!__pyx_t_2)) goto __pyx_L27_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_2);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_11), 2) < 0) __PYX_ERR(0, 402, __pyx_L1_error)
      __pyx_t_15 = NULL;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      goto __pyx_L28_unpacking_done;
      __pyx_L27_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_15 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 402, __pyx_L1_error)
      __pyx_L28_unpacking_done:;
    }
    if ((likely(PyTuple_CheckExact(__pyx_t_12))) || (PyList_CheckExact(__pyx_t_12))) {
      PyObject* sequence = __pyx_t_12;
      #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, 402, __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_4 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_11 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_4 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_11);
      __Pyx_INCREF(__pyx_t_4);
      #else
      __pyx_t_11 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 402, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 402, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      #endif
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_16 = PyObject_GetIter(__pyx_t_12); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 402, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_15 = Py_TYPE(__pyx_t_16)->tp_iternext;
      index = 0; __pyx_t_11 = __pyx_t_15(__pyx_t_16); if (unlikely(!__pyx_t_11)) goto __pyx_L29_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_11);
      index = 1; __pyx_t_4 = __pyx_t_15(__pyx_t_16); if (unlikely(!__pyx_t_4)) goto __pyx_L29_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_4);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_15(__pyx_t_16), 2) < 0) __PYX_ERR(0, 402, __pyx_L1_error)
      __pyx_t_15 = NULL;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      goto __pyx_L30_unpacking_done;
      __pyx_L29_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __pyx_t_15 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 402, __pyx_L1_error)
      __pyx_L30_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_deriv, __pyx_t_11);
    __pyx_t_11 = 0;
    __Pyx_XDECREF_SET(__pyx_v_s, __pyx_t_4);
    __pyx_t_4 = 0;
    __Pyx_XDECREF_SET(__pyx_v_entry, __pyx_t_2);
    __pyx_t_2 = 0;

    /* "discodop/disambiguation.pyx":404
 * 	for (deriv, s), entry in zip(shortestderivations,
 * 			chart2.rankededges[chart2.root()]):
 * 		if backtransform is None:             # <<<<<<<<<<<<<<
 * 			treestr = REMOVEIDS.sub('', deriv)
 * 		else:
 */
    __pyx_t_5 = (__pyx_v_backtransform == ((PyObject*)Py_None));
    __pyx_t_6 = (__pyx_t_5 != 0);
    if (__pyx_t_6) {

      /* "discodop/disambiguation.pyx":405
 * 			chart2.rankededges[chart2.root()]):
 * 		if backtransform is None:
 * 			treestr = REMOVEIDS.sub('', deriv)             # <<<<<<<<<<<<<<
 * 		else:
 * 			treestr = recoverfragments(
 */
      __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_REMOVEIDS); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 405, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_sub); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 405, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = NULL;
      __pyx_t_9 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_12);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_12, function);
          __pyx_t_9 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_12)) {
        PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_kp_u__4, __pyx_v_deriv};
        __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 405, __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_12)) {
        PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_kp_u__4, __pyx_v_deriv};
        __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 405, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GOTREF(__pyx_t_1);
      } else
      #endif
      {
        __pyx_t_4 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 405, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        if (__pyx_t_2) {
          __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2); __pyx_t_2 = NULL;
        }
        __Pyx_INCREF(__pyx_kp_u__4);
        __Pyx_GIVEREF(__pyx_kp_u__4);
        PyTuple_SET_ITEM(__pyx_t_4, 0+__pyx_t_9, __pyx_kp_u__4);
        __Pyx_INCREF(__pyx_v_deriv);
        __Pyx_GIVEREF(__pyx_v_deriv);
        PyTuple_SET_ITEM(__pyx_t_4, 1+__pyx_t_9, __pyx_v_deriv);
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 405, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      }
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __Pyx_XDECREF_SET(__pyx_v_treestr, __pyx_t_1);
      __pyx_t_1 = 0;

      /* "discodop/disambiguation.pyx":404
 * 	for (deriv, s), entry in zip(shortestderivations,
 * 			chart2.rankededges[chart2.root()]):
 * 		if backtransform is None:             # <<<<<<<<<<<<<<
 * 			treestr = REMOVEIDS.sub('', deriv)
 * 		else:
 */
      goto __pyx_L31;
    }

    /* "discodop/disambiguation.pyx":407
 * 			treestr = REMOVEIDS.sub('', deriv)
 * 		else:
 * 			treestr = recoverfragments(             # <<<<<<<<<<<<<<
 * 					deriv if bitpar else (<DoubleEntry>entry).key,
 * 					chart2, backtransform)
 */
    /*else*/ {

      /* "discodop/disambiguation.pyx":408
 * 		else:
 * 			treestr = recoverfragments(
 * 					deriv if bitpar else (<DoubleEntry>entry).key,             # <<<<<<<<<<<<<<
 * 					chart2, backtransform)
 * 		if treestr in nmostlikelytrees and treestr not in result:
 */
      if ((__pyx_v_bitpar != 0)) {
        __Pyx_INCREF(__pyx_v_deriv);
        __pyx_t_1 = __pyx_v_deriv;
      } else {
        __Pyx_INCREF(((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_v_entry)->key);
        __pyx_t_1 = ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_v_entry)->key;
      }

      /* "discodop/disambiguation.pyx":409
 * 			treestr = recoverfragments(
 * 					deriv if bitpar else (<DoubleEntry>entry).key,
 * 					chart2, backtransform)             # <<<<<<<<<<<<<<
 * 		if treestr in nmostlikelytrees and treestr not in result:
 * 			result[treestr] = (-abs(int(s / log(0.5))), parsetreeprob[treestr])
 */
      if (!(likely(((__pyx_v_chart2) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_chart2, __pyx_ptype_8discodop_10containers_Chart))))) __PYX_ERR(0, 409, __pyx_L1_error)

      /* "discodop/disambiguation.pyx":407
 * 			treestr = REMOVEIDS.sub('', deriv)
 * 		else:
 * 			treestr = recoverfragments(             # <<<<<<<<<<<<<<
 * 					deriv if bitpar else (<DoubleEntry>entry).key,
 * 					chart2, backtransform)
 */
      __pyx_t_12 = __pyx_f_8discodop_14disambiguation_recoverfragments(__pyx_t_1, ((struct __pyx_obj_8discodop_10containers_Chart *)__pyx_v_chart2), __pyx_v_backtransform, 0); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 407, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF_SET(__pyx_v_treestr, __pyx_t_12);
      __pyx_t_12 = 0;
    }
    __pyx_L31:;

    /* "discodop/disambiguation.pyx":410
 * 					deriv if bitpar else (<DoubleEntry>entry).key,
 * 					chart2, backtransform)
 * 		if treestr in nmostlikelytrees and treestr not in result:             # <<<<<<<<<<<<<<
 * 			result[treestr] = (-abs(int(s / log(0.5))), parsetreeprob[treestr])
 * 			derivs[treestr] = fragmentsinderiv(
 */
    __pyx_t_5 = (__Pyx_PySequence_ContainsTF(__pyx_v_treestr, __pyx_v_nmostlikelytrees, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 410, __pyx_L1_error)
    __pyx_t_17 = (__pyx_t_5 != 0);
    if (__pyx_t_17) {
    } else {
      __pyx_t_6 = __pyx_t_17;
      goto __pyx_L33_bool_binop_done;
    }
    __pyx_t_17 = (__Pyx_PyDict_ContainsTF(__pyx_v_treestr, __pyx_v_result, Py_NE)); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 410, __pyx_L1_error)
    __pyx_t_5 = (__pyx_t_17 != 0);
    __pyx_t_6 = __pyx_t_5;
    __pyx_L33_bool_binop_done:;
    if (__pyx_t_6) {

      /* "discodop/disambiguation.pyx":411
 * 					chart2, backtransform)
 * 		if treestr in nmostlikelytrees and treestr not in result:
 * 			result[treestr] = (-abs(int(s / log(0.5))), parsetreeprob[treestr])             # <<<<<<<<<<<<<<
 * 			derivs[treestr] = fragmentsinderiv(
 * 					deriv if bitpar or backtransform is None
 */
      __pyx_t_12 = __Pyx_GetModuleGlobalName(__pyx_n_s_log); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 411, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_tuple__12, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 411, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_12 = __Pyx_PyNumber_Divide(__pyx_v_s, __pyx_t_1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 411, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_12); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 411, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_12 = PyNumber_Absolute(__pyx_t_1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 411, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyNumber_Negative(__pyx_t_12); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 411, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_12 = __Pyx_PyDict_GetItem(__pyx_v_parsetreeprob, __pyx_v_treestr); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 411, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 411, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_12);
      PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_12);
      __pyx_t_1 = 0;
      __pyx_t_12 = 0;
      if (unlikely(PyDict_SetItem(__pyx_v_result, __pyx_v_treestr, __pyx_t_4) < 0)) __PYX_ERR(0, 411, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "discodop/disambiguation.pyx":412
 * 		if treestr in nmostlikelytrees and treestr not in result:
 * 			result[treestr] = (-abs(int(s / log(0.5))), parsetreeprob[treestr])
 * 			derivs[treestr] = fragmentsinderiv(             # <<<<<<<<<<<<<<
 * 					deriv if bitpar or backtransform is None
 * 					else (<DoubleEntry>entry).key,
 */
      __pyx_t_12 = __Pyx_GetModuleGlobalName(__pyx_n_s_fragmentsinderiv); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 412, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);

      /* "discodop/disambiguation.pyx":413
 * 			result[treestr] = (-abs(int(s / log(0.5))), parsetreeprob[treestr])
 * 			derivs[treestr] = fragmentsinderiv(
 * 					deriv if bitpar or backtransform is None             # <<<<<<<<<<<<<<
 * 					else (<DoubleEntry>entry).key,
 * 					chart2, backtransform)
 */
      __pyx_t_5 = (__pyx_v_bitpar != 0);
      if (!__pyx_t_5) {
      } else {
        __pyx_t_6 = __pyx_t_5;
        goto __pyx_L35_bool_binop_done;
      }
      __pyx_t_5 = (__pyx_v_backtransform == ((PyObject*)Py_None));
      __pyx_t_17 = (__pyx_t_5 != 0);
      __pyx_t_6 = __pyx_t_17;
      __pyx_L35_bool_binop_done:;
      if (__pyx_t_6) {
        __Pyx_INCREF(__pyx_v_deriv);
        __pyx_t_1 = __pyx_v_deriv;
      } else {

        /* "discodop/disambiguation.pyx":414
 * 			derivs[treestr] = fragmentsinderiv(
 * 					deriv if bitpar or backtransform is None
 * 					else (<DoubleEntry>entry).key,             # <<<<<<<<<<<<<<
 * 					chart2, backtransform)
 * 			if len(result) > sldop_n:
 */
        __Pyx_INCREF(((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_v_entry)->key);
        __pyx_t_1 = ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_v_entry)->key;
      }

      /* "discodop/disambiguation.pyx":415
 * 					deriv if bitpar or backtransform is None
 * 					else (<DoubleEntry>entry).key,
 * 					chart2, backtransform)             # <<<<<<<<<<<<<<
 * 			if len(result) > sldop_n:
 * 				break
 */
      __pyx_t_2 = NULL;
      __pyx_t_9 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_12);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_12, function);
          __pyx_t_9 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_12)) {
        PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_t_1, __pyx_v_chart2, __pyx_v_backtransform};
        __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 412, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 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_12)) {
        PyObject *__pyx_temp[4] = {__pyx_t_2, __pyx_t_1, __pyx_v_chart2, __pyx_v_backtransform};
        __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 412, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      } else
      #endif
      {
        __pyx_t_11 = PyTuple_New(3+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 412, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        if (__pyx_t_2) {
          __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_2); __pyx_t_2 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_1);
        PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_9, __pyx_t_1);
        __Pyx_INCREF(__pyx_v_chart2);
        __Pyx_GIVEREF(__pyx_v_chart2);
        PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_9, __pyx_v_chart2);
        __Pyx_INCREF(__pyx_v_backtransform);
        __Pyx_GIVEREF(__pyx_v_backtransform);
        PyTuple_SET_ITEM(__pyx_t_11, 2+__pyx_t_9, __pyx_v_backtransform);
        __pyx_t_1 = 0;
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_11, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 412, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      }
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;

      /* "discodop/disambiguation.pyx":412
 * 		if treestr in nmostlikelytrees and treestr not in result:
 * 			result[treestr] = (-abs(int(s / log(0.5))), parsetreeprob[treestr])
 * 			derivs[treestr] = fragmentsinderiv(             # <<<<<<<<<<<<<<
 * 					deriv if bitpar or backtransform is None
 * 					else (<DoubleEntry>entry).key,
 */
      if (unlikely(PyDict_SetItem(__pyx_v_derivs, __pyx_v_treestr, __pyx_t_4) < 0)) __PYX_ERR(0, 412, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "discodop/disambiguation.pyx":416
 * 					else (<DoubleEntry>entry).key,
 * 					chart2, backtransform)
 * 			if len(result) > sldop_n:             # <<<<<<<<<<<<<<
 * 				break
 * 	chart.grammar.switch(model, logprob=True)
 */
      __pyx_t_7 = PyDict_Size(__pyx_v_result); if (unlikely(__pyx_t_7 == -1)) __PYX_ERR(0, 416, __pyx_L1_error)
      __pyx_t_6 = ((__pyx_t_7 > __pyx_v_sldop_n) != 0);
      if (__pyx_t_6) {

        /* "discodop/disambiguation.pyx":417
 * 					chart2, backtransform)
 * 			if len(result) > sldop_n:
 * 				break             # <<<<<<<<<<<<<<
 * 	chart.grammar.switch(model, logprob=True)
 * 	if not len(result):
 */
        goto __pyx_L26_break;

        /* "discodop/disambiguation.pyx":416
 * 					else (<DoubleEntry>entry).key,
 * 					chart2, backtransform)
 * 			if len(result) > sldop_n:             # <<<<<<<<<<<<<<
 * 				break
 * 	chart.grammar.switch(model, logprob=True)
 */
      }

      /* "discodop/disambiguation.pyx":410
 * 					deriv if bitpar else (<DoubleEntry>entry).key,
 * 					chart2, backtransform)
 * 		if treestr in nmostlikelytrees and treestr not in result:             # <<<<<<<<<<<<<<
 * 			result[treestr] = (-abs(int(s / log(0.5))), parsetreeprob[treestr])
 * 			derivs[treestr] = fragmentsinderiv(
 */
    }

    /* "discodop/disambiguation.pyx":402
 * 		return [], 'SL-DOP couldn\'t find parse for tree'
 * 	result = {}
 * 	for (deriv, s), entry in zip(shortestderivations,             # <<<<<<<<<<<<<<
 * 			chart2.rankededges[chart2.root()]):
 * 		if backtransform is None:
 */
  }
  __pyx_L26_break:;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "discodop/disambiguation.pyx":418
 * 			if len(result) > sldop_n:
 * 				break
 * 	chart.grammar.switch(model, logprob=True)             # <<<<<<<<<<<<<<
 * 	if not len(result):
 * 		return [], 'no matching derivation found'
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_chart->grammar), __pyx_n_s_switch); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 418, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 418, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_model);
  __Pyx_GIVEREF(__pyx_v_model);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_model);
  __pyx_t_12 = PyDict_New(); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 418, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_logprob, Py_True) < 0) __PYX_ERR(0, 418, __pyx_L1_error)
  __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_4, __pyx_t_12); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 418, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

  /* "discodop/disambiguation.pyx":419
 * 				break
 * 	chart.grammar.switch(model, logprob=True)
 * 	if not len(result):             # <<<<<<<<<<<<<<
 * 		return [], 'no matching derivation found'
 * 	msg = '(%d derivations, %d of %d parsetrees)' % (
 */
  __pyx_t_8 = PyDict_Size(__pyx_v_result); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(0, 419, __pyx_L1_error)
  __pyx_t_6 = ((!(__pyx_t_8 != 0)) != 0);
  if (__pyx_t_6) {

    /* "discodop/disambiguation.pyx":420
 * 	chart.grammar.switch(model, logprob=True)
 * 	if not len(result):
 * 		return [], 'no matching derivation found'             # <<<<<<<<<<<<<<
 * 	msg = '(%d derivations, %d of %d parsetrees)' % (
 * 		len(derivations), min(sldop_n, len(parsetreeprob)), len(parsetreeprob))
 */
    __Pyx_XDECREF(__pyx_r);
    __pyx_t_11 = PyList_New(0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 420, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 420, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_GIVEREF(__pyx_t_11);
    PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11);
    __Pyx_INCREF(__pyx_kp_u_no_matching_derivation_found);
    __Pyx_GIVEREF(__pyx_kp_u_no_matching_derivation_found);
    PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_kp_u_no_matching_derivation_found);
    __pyx_t_11 = 0;
    __pyx_r = __pyx_t_12;
    __pyx_t_12 = 0;
    goto __pyx_L0;

    /* "discodop/disambiguation.pyx":419
 * 				break
 * 	chart.grammar.switch(model, logprob=True)
 * 	if not len(result):             # <<<<<<<<<<<<<<
 * 		return [], 'no matching derivation found'
 * 	msg = '(%d derivations, %d of %d parsetrees)' % (
 */
  }

  /* "discodop/disambiguation.pyx":422
 * 		return [], 'no matching derivation found'
 * 	msg = '(%d derivations, %d of %d parsetrees)' % (
 * 		len(derivations), min(sldop_n, len(parsetreeprob)), len(parsetreeprob))             # <<<<<<<<<<<<<<
 * 	return [(tree, result[tree], derivs[tree]) for tree in result], msg
 * 
 */
  if (unlikely(__pyx_v_derivations == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 422, __pyx_L1_error)
  }
  __pyx_t_8 = PyDict_Size(__pyx_v_derivations); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(0, 422, __pyx_L1_error)
  __pyx_t_12 = PyInt_FromSsize_t(__pyx_t_8); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 422, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_t_8 = PyDict_Size(__pyx_v_parsetreeprob); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(0, 422, __pyx_L1_error)
  __pyx_t_9 = __pyx_v_sldop_n;
  if (((__pyx_t_8 < __pyx_t_9) != 0)) {
    __pyx_t_7 = __pyx_t_8;
  } else {
    __pyx_t_7 = __pyx_t_9;
  }
  __pyx_t_11 = PyInt_FromSsize_t(__pyx_t_7); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 422, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_7 = PyDict_Size(__pyx_v_parsetreeprob); if (unlikely(__pyx_t_7 == -1)) __PYX_ERR(0, 422, __pyx_L1_error)
  __pyx_t_4 = PyInt_FromSsize_t(__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 422, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 422, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_12);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_12);
  __Pyx_GIVEREF(__pyx_t_11);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_4);
  __pyx_t_12 = 0;
  __pyx_t_11 = 0;
  __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":421
 * 	if not len(result):
 * 		return [], 'no matching derivation found'
 * 	msg = '(%d derivations, %d of %d parsetrees)' % (             # <<<<<<<<<<<<<<
 * 		len(derivations), min(sldop_n, len(parsetreeprob)), len(parsetreeprob))
 * 	return [(tree, result[tree], derivs[tree]) for tree in result], msg
 */
  __pyx_t_4 = PyUnicode_Format(__pyx_kp_u_d_derivations_d_of_d_parsetrees, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 421, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_msg = ((PyObject*)__pyx_t_4);
  __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":423
 * 	msg = '(%d derivations, %d of %d parsetrees)' % (
 * 		len(derivations), min(sldop_n, len(parsetreeprob)), len(parsetreeprob))
 * 	return [(tree, result[tree], derivs[tree]) for tree in result], msg             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  { /* enter inner scope */
    PyObject *__pyx_9genexpr11__pyx_v_tree = NULL;
    __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 423, __pyx_L41_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_7 = 0;
    __pyx_t_11 = __Pyx_dict_iterator(__pyx_v_result, 1, ((PyObject *)NULL), (&__pyx_t_8), (&__pyx_t_9)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 423, __pyx_L41_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_XDECREF(__pyx_t_3);
    __pyx_t_3 = __pyx_t_11;
    __pyx_t_11 = 0;
    while (1) {
      __pyx_t_10 = __Pyx_dict_iter_next(__pyx_t_3, __pyx_t_8, &__pyx_t_7, &__pyx_t_11, NULL, NULL, __pyx_t_9);
      if (unlikely(__pyx_t_10 == 0)) break;
      if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 423, __pyx_L41_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_XDECREF_SET(__pyx_9genexpr11__pyx_v_tree, __pyx_t_11);
      __pyx_t_11 = 0;
      __pyx_t_11 = __Pyx_PyDict_GetItem(__pyx_v_result, __pyx_9genexpr11__pyx_v_tree); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 423, __pyx_L41_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_12 = __Pyx_PyDict_GetItem(__pyx_v_derivs, __pyx_9genexpr11__pyx_v_tree); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 423, __pyx_L41_error)
      __Pyx_GOTREF(__pyx_t_12);
      __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 423, __pyx_L41_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_9genexpr11__pyx_v_tree);
      __Pyx_GIVEREF(__pyx_9genexpr11__pyx_v_tree);
      PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_9genexpr11__pyx_v_tree);
      __Pyx_GIVEREF(__pyx_t_11);
      PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_11);
      __Pyx_GIVEREF(__pyx_t_12);
      PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_12);
      __pyx_t_11 = 0;
      __pyx_t_12 = 0;
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_t_1))) __PYX_ERR(0, 423, __pyx_L41_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    }
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_XDECREF(__pyx_9genexpr11__pyx_v_tree);
    goto __pyx_L44_exit_scope;
    __pyx_L41_error:;
    __Pyx_XDECREF(__pyx_9genexpr11__pyx_v_tree);
    goto __pyx_L1_error;
    __pyx_L44_exit_scope:;
  } /* exit inner scope */
  __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 423, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4);
  __Pyx_INCREF(__pyx_v_msg);
  __Pyx_GIVEREF(__pyx_v_msg);
  PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_msg);
  __pyx_t_4 = 0;
  __pyx_r = __pyx_t_3;
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "discodop/disambiguation.pyx":358
 * 
 * 
 * cdef sldop(dict derivations, Chart chart, list sent, list tags,             # <<<<<<<<<<<<<<
 * 		int m, int sldop_n, list backtransform, entries, bint bitpar):
 * 	"""'Proper' method for sl-dop.
 */

  /* 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_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_AddTraceback("discodop.disambiguation.sldop", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_derivs);
  __Pyx_XDECREF(__pyx_v_derivsfortree);
  __Pyx_XDECREF(__pyx_v_deriv);
  __Pyx_XDECREF(__pyx_v_entry);
  __Pyx_XDECREF(__pyx_v_parsetreeprob);
  __Pyx_XDECREF(__pyx_v_nmostlikelytrees);
  __Pyx_XDECREF(__pyx_v_model);
  __Pyx_XDECREF(__pyx_v_shortestderivations);
  __Pyx_XDECREF(__pyx_v_unused_explored);
  __Pyx_XDECREF(__pyx_v_chart2);
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_s);
  __Pyx_XDECREF(__pyx_v_treestr);
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discodop/disambiguation.pyx":426
 * 
 * 
 * cdef sldop_simple(dict derivations, list entries, int sldop_n,             # <<<<<<<<<<<<<<
 * 		Chart chart, list backtransform, bint bitpar):
 * 	"""Simple sl-dop method.
 */

static PyObject *__pyx_f_8discodop_14disambiguation_sldop_simple(PyObject *__pyx_v_derivations, PyObject *__pyx_v_entries, int __pyx_v_sldop_n, struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, PyObject *__pyx_v_backtransform, int __pyx_v_bitpar) {
  struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *__pyx_v_entry = 0;
  PyObject *__pyx_v_derivs = 0;
  PyObject *__pyx_v_keys = 0;
  PyObject *__pyx_v_derivsfortree = NULL;
  PyObject *__pyx_v_deriv = NULL;
  PyObject *__pyx_v_tree = NULL;
  PyObject *__pyx_v_parsetreeprob = NULL;
  PyObject *__pyx_v_selectedtrees = NULL;
  PyObject *__pyx_v_result = NULL;
  PyObject *__pyx_v_score = NULL;
  PyObject *__pyx_v_msg = 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;
  int __pyx_t_5;
  int __pyx_t_6;
  Py_ssize_t __pyx_t_7;
  Py_ssize_t __pyx_t_8;
  int __pyx_t_9;
  int __pyx_t_10;
  PyObject *__pyx_t_11 = NULL;
  PyObject *__pyx_t_12 = NULL;
  Py_ssize_t __pyx_t_13;
  PyObject *(*__pyx_t_14)(PyObject *);
  PyObject *(*__pyx_t_15)(PyObject *);
  PyObject *__pyx_t_16 = NULL;
  PyObject *__pyx_t_17 = NULL;
  PyObject *(*__pyx_t_18)(PyObject *);
  int __pyx_t_19;
  PyObject *(*__pyx_t_20)(PyObject *);
  __Pyx_RefNannySetupContext("sldop_simple", 0);

  /* "discodop/disambiguation.pyx":436
 * 	shortest among all possible derivations using Viterbi."""
 * 	cdef DoubleEntry entry
 * 	cdef dict derivs = {}, keys = {}             # <<<<<<<<<<<<<<
 * 	derivsfortree = defaultdict(set)
 * 	# collect derivations for each parse tree
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 436, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_derivs = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 436, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_keys = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":437
 * 	cdef DoubleEntry entry
 * 	cdef dict derivs = {}, keys = {}
 * 	derivsfortree = defaultdict(set)             # <<<<<<<<<<<<<<
 * 	# collect derivations for each parse tree
 * 	if backtransform is None:
 */
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_defaultdict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 437, __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, ((PyObject *)(&PySet_Type))); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 437, __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, ((PyObject *)(&PySet_Type))};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 437, __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, ((PyObject *)(&PySet_Type))};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 437, __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, 437, __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(((PyObject *)(&PySet_Type)));
      __Pyx_GIVEREF(((PyObject *)(&PySet_Type)));
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, ((PyObject *)(&PySet_Type)));
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 437, __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_derivsfortree = __pyx_t_1;
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":439
 * 	derivsfortree = defaultdict(set)
 * 	# collect derivations for each parse tree
 * 	if backtransform is None:             # <<<<<<<<<<<<<<
 * 		for deriv in derivations:
 * 			tree = REMOVEIDS.sub('', deriv)
 */
  __pyx_t_5 = (__pyx_v_backtransform == ((PyObject*)Py_None));
  __pyx_t_6 = (__pyx_t_5 != 0);
  if (__pyx_t_6) {

    /* "discodop/disambiguation.pyx":440
 * 	# collect derivations for each parse tree
 * 	if backtransform is None:
 * 		for deriv in derivations:             # <<<<<<<<<<<<<<
 * 			tree = REMOVEIDS.sub('', deriv)
 * 			derivsfortree[tree].add(deriv)
 */
    __pyx_t_7 = 0;
    if (unlikely(__pyx_v_derivations == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 440, __pyx_L1_error)
    }
    __pyx_t_2 = __Pyx_dict_iterator(__pyx_v_derivations, 1, ((PyObject *)NULL), (&__pyx_t_8), (&__pyx_t_9)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 440, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_XDECREF(__pyx_t_1);
    __pyx_t_1 = __pyx_t_2;
    __pyx_t_2 = 0;
    while (1) {
      __pyx_t_10 = __Pyx_dict_iter_next(__pyx_t_1, __pyx_t_8, &__pyx_t_7, &__pyx_t_2, NULL, NULL, __pyx_t_9);
      if (unlikely(__pyx_t_10 == 0)) break;
      if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 440, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_XDECREF_SET(__pyx_v_deriv, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "discodop/disambiguation.pyx":441
 * 	if backtransform is None:
 * 		for deriv in derivations:
 * 			tree = REMOVEIDS.sub('', deriv)             # <<<<<<<<<<<<<<
 * 			derivsfortree[tree].add(deriv)
 * 	elif bitpar:
 */
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_REMOVEIDS); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 441, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_sub); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 441, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_4 = NULL;
      __pyx_t_10 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_3))) {
        __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
        if (likely(__pyx_t_4)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
          __Pyx_INCREF(__pyx_t_4);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_3, function);
          __pyx_t_10 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_3)) {
        PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_kp_u__4, __pyx_v_deriv};
        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 441, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 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_4, __pyx_kp_u__4, __pyx_v_deriv};
        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_10, 2+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 441, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_GOTREF(__pyx_t_2);
      } else
      #endif
      {
        __pyx_t_11 = PyTuple_New(2+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 441, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        if (__pyx_t_4) {
          __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_4); __pyx_t_4 = NULL;
        }
        __Pyx_INCREF(__pyx_kp_u__4);
        __Pyx_GIVEREF(__pyx_kp_u__4);
        PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_kp_u__4);
        __Pyx_INCREF(__pyx_v_deriv);
        __Pyx_GIVEREF(__pyx_v_deriv);
        PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_v_deriv);
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 441, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF_SET(__pyx_v_tree, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "discodop/disambiguation.pyx":442
 * 		for deriv in derivations:
 * 			tree = REMOVEIDS.sub('', deriv)
 * 			derivsfortree[tree].add(deriv)             # <<<<<<<<<<<<<<
 * 	elif bitpar:
 * 		for deriv in derivations:
 */
      __pyx_t_3 = PyObject_GetItem(__pyx_v_derivsfortree, __pyx_v_tree); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 442, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_add); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 442, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_3 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
        __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_11);
        if (likely(__pyx_t_3)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
          __Pyx_INCREF(__pyx_t_3);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_11, function);
        }
      }
      if (!__pyx_t_3) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_v_deriv); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 442, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_11)) {
          PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_deriv};
          __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 442, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_GOTREF(__pyx_t_2);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) {
          PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_deriv};
          __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 442, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_GOTREF(__pyx_t_2);
        } else
        #endif
        {
          __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 442, __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_deriv);
          __Pyx_GIVEREF(__pyx_v_deriv);
          PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_deriv);
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 442, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "discodop/disambiguation.pyx":439
 * 	derivsfortree = defaultdict(set)
 * 	# collect derivations for each parse tree
 * 	if backtransform is None:             # <<<<<<<<<<<<<<
 * 		for deriv in derivations:
 * 			tree = REMOVEIDS.sub('', deriv)
 */
    goto __pyx_L3;
  }

  /* "discodop/disambiguation.pyx":443
 * 			tree = REMOVEIDS.sub('', deriv)
 * 			derivsfortree[tree].add(deriv)
 * 	elif bitpar:             # <<<<<<<<<<<<<<
 * 		for deriv in derivations:
 * 			tree = recoverfragments(deriv, chart, backtransform)
 */
  __pyx_t_6 = (__pyx_v_bitpar != 0);
  if (__pyx_t_6) {

    /* "discodop/disambiguation.pyx":444
 * 			derivsfortree[tree].add(deriv)
 * 	elif bitpar:
 * 		for deriv in derivations:             # <<<<<<<<<<<<<<
 * 			tree = recoverfragments(deriv, chart, backtransform)
 * 			derivsfortree[tree].add(deriv)
 */
    __pyx_t_8 = 0;
    if (unlikely(__pyx_v_derivations == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 444, __pyx_L1_error)
    }
    __pyx_t_2 = __Pyx_dict_iterator(__pyx_v_derivations, 1, ((PyObject *)NULL), (&__pyx_t_7), (&__pyx_t_9)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 444, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_XDECREF(__pyx_t_1);
    __pyx_t_1 = __pyx_t_2;
    __pyx_t_2 = 0;
    while (1) {
      __pyx_t_10 = __Pyx_dict_iter_next(__pyx_t_1, __pyx_t_7, &__pyx_t_8, &__pyx_t_2, NULL, NULL, __pyx_t_9);
      if (unlikely(__pyx_t_10 == 0)) break;
      if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 444, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_XDECREF_SET(__pyx_v_deriv, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "discodop/disambiguation.pyx":445
 * 	elif bitpar:
 * 		for deriv in derivations:
 * 			tree = recoverfragments(deriv, chart, backtransform)             # <<<<<<<<<<<<<<
 * 			derivsfortree[tree].add(deriv)
 * 	else:
 */
      __pyx_t_2 = __pyx_f_8discodop_14disambiguation_recoverfragments(__pyx_v_deriv, __pyx_v_chart, __pyx_v_backtransform, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 445, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_XDECREF_SET(__pyx_v_tree, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "discodop/disambiguation.pyx":446
 * 		for deriv in derivations:
 * 			tree = recoverfragments(deriv, chart, backtransform)
 * 			derivsfortree[tree].add(deriv)             # <<<<<<<<<<<<<<
 * 	else:
 * 		for entry in entries:
 */
      __pyx_t_11 = PyObject_GetItem(__pyx_v_derivsfortree, __pyx_v_tree); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 446, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_add); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 446, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_11 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_11)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_11);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
        }
      }
      if (!__pyx_t_11) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_deriv); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 446, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_4)) {
          PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_v_deriv};
          __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 446, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_GOTREF(__pyx_t_2);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
          PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_v_deriv};
          __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 446, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
          __Pyx_GOTREF(__pyx_t_2);
        } else
        #endif
        {
          __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 446, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_11); __pyx_t_11 = NULL;
          __Pyx_INCREF(__pyx_v_deriv);
          __Pyx_GIVEREF(__pyx_v_deriv);
          PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_v_deriv);
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 446, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "discodop/disambiguation.pyx":443
 * 			tree = REMOVEIDS.sub('', deriv)
 * 			derivsfortree[tree].add(deriv)
 * 	elif bitpar:             # <<<<<<<<<<<<<<
 * 		for deriv in derivations:
 * 			tree = recoverfragments(deriv, chart, backtransform)
 */
    goto __pyx_L3;
  }

  /* "discodop/disambiguation.pyx":448
 * 			derivsfortree[tree].add(deriv)
 * 	else:
 * 		for entry in entries:             # <<<<<<<<<<<<<<
 * 			deriv = getderiv(chart.root(), entry.key, chart, '}<')
 * 			tree = recoverfragments(entry.key, chart, backtransform)
 */
  /*else*/ {
    if (unlikely(__pyx_v_entries == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
      __PYX_ERR(0, 448, __pyx_L1_error)
    }
    __pyx_t_1 = __pyx_v_entries; __Pyx_INCREF(__pyx_t_1); __pyx_t_7 = 0;
    for (;;) {
      if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_2); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 448, __pyx_L1_error)
      #else
      __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 448, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      #endif
      if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_ptype_8discodop_6plcfrs_DoubleEntry))))) __PYX_ERR(0, 448, __pyx_L1_error)
      __Pyx_XDECREF_SET(__pyx_v_entry, ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_2));
      __pyx_t_2 = 0;

      /* "discodop/disambiguation.pyx":449
 * 	else:
 * 		for entry in entries:
 * 			deriv = getderiv(chart.root(), entry.key, chart, '}<')             # <<<<<<<<<<<<<<
 * 			tree = recoverfragments(entry.key, chart, backtransform)
 * 			keys[deriv] = entry.key
 */
      __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_getderiv); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 449, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_chart), __pyx_n_s_root); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 449, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_12 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_11))) {
        __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_11);
        if (likely(__pyx_t_12)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
          __Pyx_INCREF(__pyx_t_12);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_11, function);
        }
      }
      if (__pyx_t_12) {
        __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_12); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 449, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      } else {
        __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 449, __pyx_L1_error)
      }
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_11 = NULL;
      __pyx_t_9 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
        __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_4);
        if (likely(__pyx_t_11)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
          __Pyx_INCREF(__pyx_t_11);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_4, function);
          __pyx_t_9 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_4)) {
        PyObject *__pyx_temp[5] = {__pyx_t_11, __pyx_t_3, __pyx_v_entry->key, ((PyObject *)__pyx_v_chart), __pyx_kp_u__13};
        __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_9, 4+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 449, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 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[5] = {__pyx_t_11, __pyx_t_3, __pyx_v_entry->key, ((PyObject *)__pyx_v_chart), __pyx_kp_u__13};
        __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_9, 4+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 449, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      } else
      #endif
      {
        __pyx_t_12 = PyTuple_New(4+__pyx_t_9); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 449, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_12);
        if (__pyx_t_11) {
          __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_9, __pyx_t_3);
        __Pyx_INCREF(__pyx_v_entry->key);
        __Pyx_GIVEREF(__pyx_v_entry->key);
        PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_9, __pyx_v_entry->key);
        __Pyx_INCREF(((PyObject *)__pyx_v_chart));
        __Pyx_GIVEREF(((PyObject *)__pyx_v_chart));
        PyTuple_SET_ITEM(__pyx_t_12, 2+__pyx_t_9, ((PyObject *)__pyx_v_chart));
        __Pyx_INCREF(__pyx_kp_u__13);
        __Pyx_GIVEREF(__pyx_kp_u__13);
        PyTuple_SET_ITEM(__pyx_t_12, 3+__pyx_t_9, __pyx_kp_u__13);
        __pyx_t_3 = 0;
        __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_12, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 449, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      }
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_XDECREF_SET(__pyx_v_deriv, __pyx_t_2);
      __pyx_t_2 = 0;

      /* "discodop/disambiguation.pyx":450
 * 		for entry in entries:
 * 			deriv = getderiv(chart.root(), entry.key, chart, '}<')
 * 			tree = recoverfragments(entry.key, chart, backtransform)             # <<<<<<<<<<<<<<
 * 			keys[deriv] = entry.key
 * 			derivations[deriv] = entry.value
 */
      __pyx_t_2 = __pyx_v_entry->key;
      __Pyx_INCREF(__pyx_t_2);
      __pyx_t_4 = __pyx_f_8discodop_14disambiguation_recoverfragments(__pyx_t_2, __pyx_v_chart, __pyx_v_backtransform, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 450, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_XDECREF_SET(__pyx_v_tree, __pyx_t_4);
      __pyx_t_4 = 0;

      /* "discodop/disambiguation.pyx":451
 * 			deriv = getderiv(chart.root(), entry.key, chart, '}<')
 * 			tree = recoverfragments(entry.key, chart, backtransform)
 * 			keys[deriv] = entry.key             # <<<<<<<<<<<<<<
 * 			derivations[deriv] = entry.value
 * 			derivsfortree[tree].add(deriv)
 */
      __pyx_t_4 = __pyx_v_entry->key;
      __Pyx_INCREF(__pyx_t_4);
      if (unlikely(PyDict_SetItem(__pyx_v_keys, __pyx_v_deriv, __pyx_t_4) < 0)) __PYX_ERR(0, 451, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "discodop/disambiguation.pyx":452
 * 			tree = recoverfragments(entry.key, chart, backtransform)
 * 			keys[deriv] = entry.key
 * 			derivations[deriv] = entry.value             # <<<<<<<<<<<<<<
 * 			derivsfortree[tree].add(deriv)
 * 
 */
      __pyx_t_4 = PyFloat_FromDouble(__pyx_v_entry->value); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 452, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (unlikely(__pyx_v_derivations == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 452, __pyx_L1_error)
      }
      if (unlikely(PyDict_SetItem(__pyx_v_derivations, __pyx_v_deriv, __pyx_t_4) < 0)) __PYX_ERR(0, 452, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "discodop/disambiguation.pyx":453
 * 			keys[deriv] = entry.key
 * 			derivations[deriv] = entry.value
 * 			derivsfortree[tree].add(deriv)             # <<<<<<<<<<<<<<
 * 
 * 	# sum over derivations to get parse trees
 */
      __pyx_t_2 = PyObject_GetItem(__pyx_v_derivsfortree, __pyx_v_tree); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 453, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_add); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 453, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
      __pyx_t_2 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) {
        __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_12);
        if (likely(__pyx_t_2)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
          __Pyx_INCREF(__pyx_t_2);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_12, function);
        }
      }
      if (!__pyx_t_2) {
        __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_v_deriv); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 453, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_12)) {
          PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_deriv};
          __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 453, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_GOTREF(__pyx_t_4);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) {
          PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_deriv};
          __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 453, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_GOTREF(__pyx_t_4);
        } else
        #endif
        {
          __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 453, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2); __pyx_t_2 = NULL;
          __Pyx_INCREF(__pyx_v_deriv);
          __Pyx_GIVEREF(__pyx_v_deriv);
          PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_v_deriv);
          __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 453, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

      /* "discodop/disambiguation.pyx":448
 * 			derivsfortree[tree].add(deriv)
 * 	else:
 * 		for entry in entries:             # <<<<<<<<<<<<<<
 * 			deriv = getderiv(chart.root(), entry.key, chart, '}<')
 * 			tree = recoverfragments(entry.key, chart, backtransform)
 */
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  }
  __pyx_L3:;

  /* "discodop/disambiguation.pyx":456
 * 
 * 	# sum over derivations to get parse trees
 * 	parsetreeprob = {tree: logprobsum([-derivations[d] for d in ds])             # <<<<<<<<<<<<<<
 * 			for tree, ds in derivsfortree.items()}
 * 	selectedtrees = nlargest(sldop_n, parsetreeprob, key=parsetreeprob.get)
 */
  { /* enter inner scope */
    PyObject *__pyx_9genexpr12__pyx_v_tree = NULL;
    PyObject *__pyx_9genexpr12__pyx_v_ds = NULL;
    __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 456, __pyx_L12_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "discodop/disambiguation.pyx":457
 * 	# sum over derivations to get parse trees
 * 	parsetreeprob = {tree: logprobsum([-derivations[d] for d in ds])
 * 			for tree, ds in derivsfortree.items()}             # <<<<<<<<<<<<<<
 * 	selectedtrees = nlargest(sldop_n, parsetreeprob, key=parsetreeprob.get)
 * 
 */
    __pyx_t_7 = 0;
    if (unlikely(__pyx_v_derivsfortree == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "items");
      __PYX_ERR(0, 457, __pyx_L12_error)
    }
    __pyx_t_12 = __Pyx_dict_iterator(__pyx_v_derivsfortree, 0, __pyx_n_s_items, (&__pyx_t_8), (&__pyx_t_9)); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 457, __pyx_L12_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_XDECREF(__pyx_t_4);
    __pyx_t_4 = __pyx_t_12;
    __pyx_t_12 = 0;
    while (1) {
      __pyx_t_10 = __Pyx_dict_iter_next(__pyx_t_4, __pyx_t_8, &__pyx_t_7, &__pyx_t_12, &__pyx_t_3, NULL, __pyx_t_9);
      if (unlikely(__pyx_t_10 == 0)) break;
      if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 457, __pyx_L12_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_XDECREF_SET(__pyx_9genexpr12__pyx_v_tree, __pyx_t_12);
      __pyx_t_12 = 0;
      __Pyx_XDECREF_SET(__pyx_9genexpr12__pyx_v_ds, __pyx_t_3);
      __pyx_t_3 = 0;

      /* "discodop/disambiguation.pyx":456
 * 
 * 	# sum over derivations to get parse trees
 * 	parsetreeprob = {tree: logprobsum([-derivations[d] for d in ds])             # <<<<<<<<<<<<<<
 * 			for tree, ds in derivsfortree.items()}
 * 	selectedtrees = nlargest(sldop_n, parsetreeprob, key=parsetreeprob.get)
 */
      { /* enter inner scope */
        PyObject *__pyx_9genexpr13__pyx_9genexpr12__pyx_v_d = NULL;
        __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 456, __pyx_L17_error)
        __Pyx_GOTREF(__pyx_t_3);
        if (likely(PyList_CheckExact(__pyx_9genexpr12__pyx_v_ds)) || PyTuple_CheckExact(__pyx_9genexpr12__pyx_v_ds)) {
          __pyx_t_12 = __pyx_9genexpr12__pyx_v_ds; __Pyx_INCREF(__pyx_t_12); __pyx_t_13 = 0;
          __pyx_t_14 = NULL;
        } else {
          __pyx_t_13 = -1; __pyx_t_12 = PyObject_GetIter(__pyx_9genexpr12__pyx_v_ds); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 456, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_12);
          __pyx_t_14 = Py_TYPE(__pyx_t_12)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 456, __pyx_L17_error)
        }
        for (;;) {
          if (likely(!__pyx_t_14)) {
            if (likely(PyList_CheckExact(__pyx_t_12))) {
              if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_12)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_2 = PyList_GET_ITEM(__pyx_t_12, __pyx_t_13); __Pyx_INCREF(__pyx_t_2); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 456, __pyx_L17_error)
              #else
              __pyx_t_2 = PySequence_ITEM(__pyx_t_12, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 456, __pyx_L17_error)
              __Pyx_GOTREF(__pyx_t_2);
              #endif
            } else {
              if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_12)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_12, __pyx_t_13); __Pyx_INCREF(__pyx_t_2); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 456, __pyx_L17_error)
              #else
              __pyx_t_2 = PySequence_ITEM(__pyx_t_12, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 456, __pyx_L17_error)
              __Pyx_GOTREF(__pyx_t_2);
              #endif
            }
          } else {
            __pyx_t_2 = __pyx_t_14(__pyx_t_12);
            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, 456, __pyx_L17_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_2);
          }
          __Pyx_XDECREF_SET(__pyx_9genexpr13__pyx_9genexpr12__pyx_v_d, __pyx_t_2);
          __pyx_t_2 = 0;
          if (unlikely(__pyx_v_derivations == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 456, __pyx_L17_error)
          }
          __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_derivations, __pyx_9genexpr13__pyx_9genexpr12__pyx_v_d); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 456, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_2);
          __pyx_t_11 = PyNumber_Negative(__pyx_t_2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 456, __pyx_L17_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_11))) __PYX_ERR(0, 456, __pyx_L17_error)
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        }
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_XDECREF(__pyx_9genexpr13__pyx_9genexpr12__pyx_v_d);
        goto __pyx_L20_exit_scope;
        __pyx_L17_error:;
        __Pyx_XDECREF(__pyx_9genexpr13__pyx_9genexpr12__pyx_v_d);
        goto __pyx_L12_error;
        __pyx_L20_exit_scope:;
      } /* exit inner scope */
      __pyx_t_12 = PyFloat_FromDouble(__pyx_f_8discodop_10containers_logprobsum(((PyObject*)__pyx_t_3))); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 456, __pyx_L12_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      if (unlikely(PyDict_SetItem(__pyx_t_1, (PyObject*)__pyx_9genexpr12__pyx_v_tree, (PyObject*)__pyx_t_12))) __PYX_ERR(0, 456, __pyx_L12_error)
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_XDECREF(__pyx_9genexpr12__pyx_v_tree);
    __Pyx_XDECREF(__pyx_9genexpr12__pyx_v_ds);
    goto __pyx_L21_exit_scope;
    __pyx_L12_error:;
    __Pyx_XDECREF(__pyx_9genexpr12__pyx_v_tree);
    __Pyx_XDECREF(__pyx_9genexpr12__pyx_v_ds);
    goto __pyx_L1_error;
    __pyx_L21_exit_scope:;
  } /* exit inner scope */
  __pyx_v_parsetreeprob = ((PyObject*)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":458
 * 	parsetreeprob = {tree: logprobsum([-derivations[d] for d in ds])
 * 			for tree, ds in derivsfortree.items()}
 * 	selectedtrees = nlargest(sldop_n, parsetreeprob, key=parsetreeprob.get)             # <<<<<<<<<<<<<<
 * 
 * 	# the number of fragments used is the number of
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_nlargest); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 458, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_sldop_n); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 458, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 458, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_4);
  __Pyx_INCREF(__pyx_v_parsetreeprob);
  __Pyx_GIVEREF(__pyx_v_parsetreeprob);
  PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_v_parsetreeprob);
  __pyx_t_4 = 0;
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 458, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_parsetreeprob, __pyx_n_s_get); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 458, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_key, __pyx_t_3) < 0) __PYX_ERR(0, 458, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_12, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 458, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_v_selectedtrees = __pyx_t_3;
  __pyx_t_3 = 0;

  /* "discodop/disambiguation.pyx":463
 * 	# nodes (open parens), minus the number of interior
 * 	# (addressed) nodes.
 * 	result = {}             # <<<<<<<<<<<<<<
 * 	for tree in selectedtrees:
 * 		score, deriv = min([(deriv.count('(') -
 */
  __pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 463, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_v_result = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;

  /* "discodop/disambiguation.pyx":464
 * 	# (addressed) nodes.
 * 	result = {}
 * 	for tree in selectedtrees:             # <<<<<<<<<<<<<<
 * 		score, deriv = min([(deriv.count('(') -
 * 				len([a for a in deriv.split() if '@' in a or '}<' in a]),
 */
  if (likely(PyList_CheckExact(__pyx_v_selectedtrees)) || PyTuple_CheckExact(__pyx_v_selectedtrees)) {
    __pyx_t_3 = __pyx_v_selectedtrees; __Pyx_INCREF(__pyx_t_3); __pyx_t_8 = 0;
    __pyx_t_14 = NULL;
  } else {
    __pyx_t_8 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_selectedtrees); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 464, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_14 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 464, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_14)) {
      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, 464, __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, 464, __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, 464, __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, 464, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        #endif
      }
    } else {
      __pyx_t_4 = __pyx_t_14(__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, 464, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XDECREF_SET(__pyx_v_tree, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "discodop/disambiguation.pyx":465
 * 	result = {}
 * 	for tree in selectedtrees:
 * 		score, deriv = min([(deriv.count('(') -             # <<<<<<<<<<<<<<
 * 				len([a for a in deriv.split() if '@' in a or '}<' in a]),
 * 				deriv)
 */
    { /* enter inner scope */
      PyObject *__pyx_9genexpr14__pyx_v_deriv = NULL;
      __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 465, __pyx_L26_error)
      __Pyx_GOTREF(__pyx_t_4);

      /* "discodop/disambiguation.pyx":468
 * 				len([a for a in deriv.split() if '@' in a or '}<' in a]),
 * 				deriv)
 * 				for deriv in derivsfortree[tree]])             # <<<<<<<<<<<<<<
 * 		result[tree] = (-score, parsetreeprob[tree])
 * 		derivs[tree] = fragmentsinderiv(
 */
      __pyx_t_12 = PyObject_GetItem(__pyx_v_derivsfortree, __pyx_v_tree); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 468, __pyx_L26_error)
      __Pyx_GOTREF(__pyx_t_12);
      if (likely(PyList_CheckExact(__pyx_t_12)) || PyTuple_CheckExact(__pyx_t_12)) {
        __pyx_t_1 = __pyx_t_12; __Pyx_INCREF(__pyx_t_1); __pyx_t_7 = 0;
        __pyx_t_15 = NULL;
      } else {
        __pyx_t_7 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_12); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 468, __pyx_L26_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_15 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 468, __pyx_L26_error)
      }
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      for (;;) {
        if (likely(!__pyx_t_15)) {
          if (likely(PyList_CheckExact(__pyx_t_1))) {
            if (__pyx_t_7 >= PyList_GET_SIZE(__pyx_t_1)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_12 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_12); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 468, __pyx_L26_error)
            #else
            __pyx_t_12 = PySequence_ITEM(__pyx_t_1, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 468, __pyx_L26_error)
            __Pyx_GOTREF(__pyx_t_12);
            #endif
          } else {
            if (__pyx_t_7 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_12 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_7); __Pyx_INCREF(__pyx_t_12); __pyx_t_7++; if (unlikely(0 < 0)) __PYX_ERR(0, 468, __pyx_L26_error)
            #else
            __pyx_t_12 = PySequence_ITEM(__pyx_t_1, __pyx_t_7); __pyx_t_7++; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 468, __pyx_L26_error)
            __Pyx_GOTREF(__pyx_t_12);
            #endif
          }
        } else {
          __pyx_t_12 = __pyx_t_15(__pyx_t_1);
          if (unlikely(!__pyx_t_12)) {
            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_L26_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_12);
        }
        __Pyx_XDECREF_SET(__pyx_9genexpr14__pyx_v_deriv, __pyx_t_12);
        __pyx_t_12 = 0;

        /* "discodop/disambiguation.pyx":465
 * 	result = {}
 * 	for tree in selectedtrees:
 * 		score, deriv = min([(deriv.count('(') -             # <<<<<<<<<<<<<<
 * 				len([a for a in deriv.split() if '@' in a or '}<' in a]),
 * 				deriv)
 */
        __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_9genexpr14__pyx_v_deriv, __pyx_n_s_count); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 465, __pyx_L26_error)
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 465, __pyx_L26_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;

        /* "discodop/disambiguation.pyx":466
 * 	for tree in selectedtrees:
 * 		score, deriv = min([(deriv.count('(') -
 * 				len([a for a in deriv.split() if '@' in a or '}<' in a]),             # <<<<<<<<<<<<<<
 * 				deriv)
 * 				for deriv in derivsfortree[tree]])
 */
        { /* enter inner scope */
          PyObject *__pyx_9genexpr15__pyx_9genexpr14__pyx_v_a = NULL;
          __pyx_t_12 = PyList_New(0); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 466, __pyx_L31_error)
          __Pyx_GOTREF(__pyx_t_12);
          __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_9genexpr14__pyx_v_deriv, __pyx_n_s_split); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 466, __pyx_L31_error)
          __Pyx_GOTREF(__pyx_t_16);
          __pyx_t_17 = NULL;
          if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_16))) {
            __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_16);
            if (likely(__pyx_t_17)) {
              PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
              __Pyx_INCREF(__pyx_t_17);
              __Pyx_INCREF(function);
              __Pyx_DECREF_SET(__pyx_t_16, function);
            }
          }
          if (__pyx_t_17) {
            __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_t_17); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 466, __pyx_L31_error)
            __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0;
          } else {
            __pyx_t_2 = __Pyx_PyObject_CallNoArg(__pyx_t_16); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 466, __pyx_L31_error)
          }
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) {
            __pyx_t_16 = __pyx_t_2; __Pyx_INCREF(__pyx_t_16); __pyx_t_13 = 0;
            __pyx_t_18 = NULL;
          } else {
            __pyx_t_13 = -1; __pyx_t_16 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 466, __pyx_L31_error)
            __Pyx_GOTREF(__pyx_t_16);
            __pyx_t_18 = Py_TYPE(__pyx_t_16)->tp_iternext; if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 466, __pyx_L31_error)
          }
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          for (;;) {
            if (likely(!__pyx_t_18)) {
              if (likely(PyList_CheckExact(__pyx_t_16))) {
                if (__pyx_t_13 >= PyList_GET_SIZE(__pyx_t_16)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_2 = PyList_GET_ITEM(__pyx_t_16, __pyx_t_13); __Pyx_INCREF(__pyx_t_2); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 466, __pyx_L31_error)
                #else
                __pyx_t_2 = PySequence_ITEM(__pyx_t_16, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 466, __pyx_L31_error)
                __Pyx_GOTREF(__pyx_t_2);
                #endif
              } else {
                if (__pyx_t_13 >= PyTuple_GET_SIZE(__pyx_t_16)) break;
                #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_16, __pyx_t_13); __Pyx_INCREF(__pyx_t_2); __pyx_t_13++; if (unlikely(0 < 0)) __PYX_ERR(0, 466, __pyx_L31_error)
                #else
                __pyx_t_2 = PySequence_ITEM(__pyx_t_16, __pyx_t_13); __pyx_t_13++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 466, __pyx_L31_error)
                __Pyx_GOTREF(__pyx_t_2);
                #endif
              }
            } else {
              __pyx_t_2 = __pyx_t_18(__pyx_t_16);
              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, 466, __pyx_L31_error)
                }
                break;
              }
              __Pyx_GOTREF(__pyx_t_2);
            }
            __Pyx_XDECREF_SET(__pyx_9genexpr15__pyx_9genexpr14__pyx_v_a, __pyx_t_2);
            __pyx_t_2 = 0;
            __pyx_t_5 = (__Pyx_PySequence_ContainsTF(__pyx_kp_u__16, __pyx_9genexpr15__pyx_9genexpr14__pyx_v_a, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 466, __pyx_L31_error)
            __pyx_t_19 = (__pyx_t_5 != 0);
            if (!__pyx_t_19) {
            } else {
              __pyx_t_6 = __pyx_t_19;
              goto __pyx_L35_bool_binop_done;
            }
            __pyx_t_19 = (__Pyx_PySequence_ContainsTF(__pyx_kp_u__13, __pyx_9genexpr15__pyx_9genexpr14__pyx_v_a, Py_EQ)); if (unlikely(__pyx_t_19 < 0)) __PYX_ERR(0, 466, __pyx_L31_error)
            __pyx_t_5 = (__pyx_t_19 != 0);
            __pyx_t_6 = __pyx_t_5;
            __pyx_L35_bool_binop_done:;
            if (__pyx_t_6) {
              if (unlikely(__Pyx_ListComp_Append(__pyx_t_12, (PyObject*)__pyx_9genexpr15__pyx_9genexpr14__pyx_v_a))) __PYX_ERR(0, 466, __pyx_L31_error)
            }
          }
          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          __Pyx_XDECREF(__pyx_9genexpr15__pyx_9genexpr14__pyx_v_a);
          goto __pyx_L37_exit_scope;
          __pyx_L31_error:;
          __Pyx_XDECREF(__pyx_9genexpr15__pyx_9genexpr14__pyx_v_a);
          goto __pyx_L26_error;
          __pyx_L37_exit_scope:;
        } /* exit inner scope */
        __pyx_t_13 = PyList_GET_SIZE(__pyx_t_12); if (unlikely(__pyx_t_13 == -1)) __PYX_ERR(0, 466, __pyx_L26_error)
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __pyx_t_12 = PyInt_FromSsize_t(__pyx_t_13); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 466, __pyx_L26_error)
        __Pyx_GOTREF(__pyx_t_12);

        /* "discodop/disambiguation.pyx":465
 * 	result = {}
 * 	for tree in selectedtrees:
 * 		score, deriv = min([(deriv.count('(') -             # <<<<<<<<<<<<<<
 * 				len([a for a in deriv.split() if '@' in a or '}<' in a]),
 * 				deriv)
 */
        __pyx_t_16 = PyNumber_Subtract(__pyx_t_11, __pyx_t_12); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 465, __pyx_L26_error)
        __Pyx_GOTREF(__pyx_t_16);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;

        /* "discodop/disambiguation.pyx":467
 * 		score, deriv = min([(deriv.count('(') -
 * 				len([a for a in deriv.split() if '@' in a or '}<' in a]),
 * 				deriv)             # <<<<<<<<<<<<<<
 * 				for deriv in derivsfortree[tree]])
 * 		result[tree] = (-score, parsetreeprob[tree])
 */
        __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 465, __pyx_L26_error)
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_GIVEREF(__pyx_t_16);
        PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_16);
        __Pyx_INCREF(__pyx_9genexpr14__pyx_v_deriv);
        __Pyx_GIVEREF(__pyx_9genexpr14__pyx_v_deriv);
        PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_9genexpr14__pyx_v_deriv);
        __pyx_t_16 = 0;
        if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_t_12))) __PYX_ERR(0, 465, __pyx_L26_error)
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;

        /* "discodop/disambiguation.pyx":468
 * 				len([a for a in deriv.split() if '@' in a or '}<' in a]),
 * 				deriv)
 * 				for deriv in derivsfortree[tree]])             # <<<<<<<<<<<<<<
 * 		result[tree] = (-score, parsetreeprob[tree])
 * 		derivs[tree] = fragmentsinderiv(
 */
      }
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_XDECREF(__pyx_9genexpr14__pyx_v_deriv);
      goto __pyx_L38_exit_scope;
      __pyx_L26_error:;
      __Pyx_XDECREF(__pyx_9genexpr14__pyx_v_deriv);
      goto __pyx_L1_error;
      __pyx_L38_exit_scope:;
    } /* exit inner scope */

    /* "discodop/disambiguation.pyx":465
 * 	result = {}
 * 	for tree in selectedtrees:
 * 		score, deriv = min([(deriv.count('(') -             # <<<<<<<<<<<<<<
 * 				len([a for a in deriv.split() if '@' in a or '}<' in a]),
 * 				deriv)
 */
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 465, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_min, __pyx_t_1, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 465, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
      PyObject* sequence = __pyx_t_4;
      #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_1 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_12 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_12 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_12);
      #else
      __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 465, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_12 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 465, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      #endif
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_16 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 465, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __pyx_t_20 = Py_TYPE(__pyx_t_16)->tp_iternext;
      index = 0; __pyx_t_1 = __pyx_t_20(__pyx_t_16); if (unlikely(!__pyx_t_1)) goto __pyx_L39_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_1);
      index = 1; __pyx_t_12 = __pyx_t_20(__pyx_t_16); if (unlikely(!__pyx_t_12)) goto __pyx_L39_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_12);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_20(__pyx_t_16), 2) < 0) __PYX_ERR(0, 465, __pyx_L1_error)
      __pyx_t_20 = NULL;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      goto __pyx_L40_unpacking_done;
      __pyx_L39_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __pyx_t_20 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 465, __pyx_L1_error)
      __pyx_L40_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_score, __pyx_t_1);
    __pyx_t_1 = 0;
    __Pyx_XDECREF_SET(__pyx_v_deriv, __pyx_t_12);
    __pyx_t_12 = 0;

    /* "discodop/disambiguation.pyx":469
 * 				deriv)
 * 				for deriv in derivsfortree[tree]])
 * 		result[tree] = (-score, parsetreeprob[tree])             # <<<<<<<<<<<<<<
 * 		derivs[tree] = fragmentsinderiv(
 * 				deriv if bitpar or backtransform is None else keys[deriv],
 */
    __pyx_t_4 = PyNumber_Negative(__pyx_v_score); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 469, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_12 = __Pyx_PyDict_GetItem(__pyx_v_parsetreeprob, __pyx_v_tree); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 469, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 469, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
    __Pyx_GIVEREF(__pyx_t_12);
    PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_12);
    __pyx_t_4 = 0;
    __pyx_t_12 = 0;
    if (unlikely(PyDict_SetItem(__pyx_v_result, __pyx_v_tree, __pyx_t_1) < 0)) __PYX_ERR(0, 469, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "discodop/disambiguation.pyx":470
 * 				for deriv in derivsfortree[tree]])
 * 		result[tree] = (-score, parsetreeprob[tree])
 * 		derivs[tree] = fragmentsinderiv(             # <<<<<<<<<<<<<<
 * 				deriv if bitpar or backtransform is None else keys[deriv],
 * 				chart, backtransform)
 */
    __pyx_t_12 = __Pyx_GetModuleGlobalName(__pyx_n_s_fragmentsinderiv); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 470, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);

    /* "discodop/disambiguation.pyx":471
 * 		result[tree] = (-score, parsetreeprob[tree])
 * 		derivs[tree] = fragmentsinderiv(
 * 				deriv if bitpar or backtransform is None else keys[deriv],             # <<<<<<<<<<<<<<
 * 				chart, backtransform)
 * 	msg = '(%d derivations, %d of %d parsetrees)' % (
 */
    __pyx_t_5 = (__pyx_v_bitpar != 0);
    if (!__pyx_t_5) {
    } else {
      __pyx_t_6 = __pyx_t_5;
      goto __pyx_L41_bool_binop_done;
    }
    __pyx_t_5 = (__pyx_v_backtransform == ((PyObject*)Py_None));
    __pyx_t_19 = (__pyx_t_5 != 0);
    __pyx_t_6 = __pyx_t_19;
    __pyx_L41_bool_binop_done:;
    if (__pyx_t_6) {
      __Pyx_INCREF(__pyx_v_deriv);
      __pyx_t_4 = __pyx_v_deriv;
    } else {
      __pyx_t_16 = __Pyx_PyDict_GetItem(__pyx_v_keys, __pyx_v_deriv); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 471, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      __pyx_t_4 = __pyx_t_16;
      __pyx_t_16 = 0;
    }

    /* "discodop/disambiguation.pyx":472
 * 		derivs[tree] = fragmentsinderiv(
 * 				deriv if bitpar or backtransform is None else keys[deriv],
 * 				chart, backtransform)             # <<<<<<<<<<<<<<
 * 	msg = '(%d derivations, %d of %d parsetrees)' % (
 * 			len(derivations), len(result), len(parsetreeprob))
 */
    __pyx_t_16 = NULL;
    __pyx_t_9 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_12))) {
      __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_12);
      if (likely(__pyx_t_16)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
        __Pyx_INCREF(__pyx_t_16);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_12, function);
        __pyx_t_9 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_12)) {
      PyObject *__pyx_temp[4] = {__pyx_t_16, __pyx_t_4, ((PyObject *)__pyx_v_chart), __pyx_v_backtransform};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 470, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) {
      PyObject *__pyx_temp[4] = {__pyx_t_16, __pyx_t_4, ((PyObject *)__pyx_v_chart), __pyx_v_backtransform};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-__pyx_t_9, 3+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 470, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    } else
    #endif
    {
      __pyx_t_11 = PyTuple_New(3+__pyx_t_9); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 470, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      if (__pyx_t_16) {
        __Pyx_GIVEREF(__pyx_t_16); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_16); __pyx_t_16 = NULL;
      }
      __Pyx_GIVEREF(__pyx_t_4);
      PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_9, __pyx_t_4);
      __Pyx_INCREF(((PyObject *)__pyx_v_chart));
      __Pyx_GIVEREF(((PyObject *)__pyx_v_chart));
      PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_9, ((PyObject *)__pyx_v_chart));
      __Pyx_INCREF(__pyx_v_backtransform);
      __Pyx_GIVEREF(__pyx_v_backtransform);
      PyTuple_SET_ITEM(__pyx_t_11, 2+__pyx_t_9, __pyx_v_backtransform);
      __pyx_t_4 = 0;
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_11, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 470, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    }
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;

    /* "discodop/disambiguation.pyx":470
 * 				for deriv in derivsfortree[tree]])
 * 		result[tree] = (-score, parsetreeprob[tree])
 * 		derivs[tree] = fragmentsinderiv(             # <<<<<<<<<<<<<<
 * 				deriv if bitpar or backtransform is None else keys[deriv],
 * 				chart, backtransform)
 */
    if (unlikely(PyDict_SetItem(__pyx_v_derivs, __pyx_v_tree, __pyx_t_1) < 0)) __PYX_ERR(0, 470, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "discodop/disambiguation.pyx":464
 * 	# (addressed) nodes.
 * 	result = {}
 * 	for tree in selectedtrees:             # <<<<<<<<<<<<<<
 * 		score, deriv = min([(deriv.count('(') -
 * 				len([a for a in deriv.split() if '@' in a or '}<' in a]),
 */
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "discodop/disambiguation.pyx":474
 * 				chart, backtransform)
 * 	msg = '(%d derivations, %d of %d parsetrees)' % (
 * 			len(derivations), len(result), len(parsetreeprob))             # <<<<<<<<<<<<<<
 * 	return [(tree, result[tree], derivs[tree]) for tree in result], msg
 * 
 */
  if (unlikely(__pyx_v_derivations == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
    __PYX_ERR(0, 474, __pyx_L1_error)
  }
  __pyx_t_8 = PyDict_Size(__pyx_v_derivations); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(0, 474, __pyx_L1_error)
  __pyx_t_3 = PyInt_FromSsize_t(__pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 474, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_8 = PyDict_Size(__pyx_v_result); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(0, 474, __pyx_L1_error)
  __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 474, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = PyDict_Size(__pyx_v_parsetreeprob); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(0, 474, __pyx_L1_error)
  __pyx_t_12 = PyInt_FromSsize_t(__pyx_t_8); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 474, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __pyx_t_11 = PyTuple_New(3); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 474, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_12);
  PyTuple_SET_ITEM(__pyx_t_11, 2, __pyx_t_12);
  __pyx_t_3 = 0;
  __pyx_t_1 = 0;
  __pyx_t_12 = 0;

  /* "discodop/disambiguation.pyx":473
 * 				deriv if bitpar or backtransform is None else keys[deriv],
 * 				chart, backtransform)
 * 	msg = '(%d derivations, %d of %d parsetrees)' % (             # <<<<<<<<<<<<<<
 * 			len(derivations), len(result), len(parsetreeprob))
 * 	return [(tree, result[tree], derivs[tree]) for tree in result], msg
 */
  __pyx_t_12 = PyUnicode_Format(__pyx_kp_u_d_derivations_d_of_d_parsetrees, __pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 473, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_v_msg = ((PyObject*)__pyx_t_12);
  __pyx_t_12 = 0;

  /* "discodop/disambiguation.pyx":475
 * 	msg = '(%d derivations, %d of %d parsetrees)' % (
 * 			len(derivations), len(result), len(parsetreeprob))
 * 	return [(tree, result[tree], derivs[tree]) for tree in result], msg             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  { /* enter inner scope */
    PyObject *__pyx_9genexpr16__pyx_v_tree = NULL;
    __pyx_t_12 = PyList_New(0); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 475, __pyx_L45_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_8 = 0;
    __pyx_t_1 = __Pyx_dict_iterator(__pyx_v_result, 1, ((PyObject *)NULL), (&__pyx_t_7), (&__pyx_t_9)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 475, __pyx_L45_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF(__pyx_t_11);
    __pyx_t_11 = __pyx_t_1;
    __pyx_t_1 = 0;
    while (1) {
      __pyx_t_10 = __Pyx_dict_iter_next(__pyx_t_11, __pyx_t_7, &__pyx_t_8, &__pyx_t_1, NULL, NULL, __pyx_t_9);
      if (unlikely(__pyx_t_10 == 0)) break;
      if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 475, __pyx_L45_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_XDECREF_SET(__pyx_9genexpr16__pyx_v_tree, __pyx_t_1);
      __pyx_t_1 = 0;
      __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_result, __pyx_9genexpr16__pyx_v_tree); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 475, __pyx_L45_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_derivs, __pyx_9genexpr16__pyx_v_tree); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 475, __pyx_L45_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 475, __pyx_L45_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_INCREF(__pyx_9genexpr16__pyx_v_tree);
      __Pyx_GIVEREF(__pyx_9genexpr16__pyx_v_tree);
      PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_9genexpr16__pyx_v_tree);
      __Pyx_GIVEREF(__pyx_t_1);
      PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_1);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_3);
      __pyx_t_1 = 0;
      __pyx_t_3 = 0;
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_12, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 475, __pyx_L45_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    }
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_XDECREF(__pyx_9genexpr16__pyx_v_tree);
    goto __pyx_L48_exit_scope;
    __pyx_L45_error:;
    __Pyx_XDECREF(__pyx_9genexpr16__pyx_v_tree);
    goto __pyx_L1_error;
    __pyx_L48_exit_scope:;
  } /* exit inner scope */
  __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 475, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __Pyx_GIVEREF(__pyx_t_12);
  PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_12);
  __Pyx_INCREF(__pyx_v_msg);
  __Pyx_GIVEREF(__pyx_v_msg);
  PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_v_msg);
  __pyx_t_12 = 0;
  __pyx_r = __pyx_t_11;
  __pyx_t_11 = 0;
  goto __pyx_L0;

  /* "discodop/disambiguation.pyx":426
 * 
 * 
 * cdef sldop_simple(dict derivations, list entries, int sldop_n,             # <<<<<<<<<<<<<<
 * 		Chart chart, list backtransform, bint bitpar):
 * 	"""Simple sl-dop method.
 */

  /* 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_11);
  __Pyx_XDECREF(__pyx_t_12);
  __Pyx_XDECREF(__pyx_t_16);
  __Pyx_XDECREF(__pyx_t_17);
  __Pyx_AddTraceback("discodop.disambiguation.sldop_simple", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF((PyObject *)__pyx_v_entry);
  __Pyx_XDECREF(__pyx_v_derivs);
  __Pyx_XDECREF(__pyx_v_keys);
  __Pyx_XDECREF(__pyx_v_derivsfortree);
  __Pyx_XDECREF(__pyx_v_deriv);
  __Pyx_XDECREF(__pyx_v_tree);
  __Pyx_XDECREF(__pyx_v_parsetreeprob);
  __Pyx_XDECREF(__pyx_v_selectedtrees);
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_score);
  __Pyx_XDECREF(__pyx_v_msg);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* "discodop/disambiguation.pyx":478
 * 
 * 
 * cpdef str recoverfragments(deriv, Chart chart, list backtransform):             # <<<<<<<<<<<<<<
 * 	"""Reconstruct a DOP derivation from a derivation with flattened fragments.
 * 
 */

static PyObject *__pyx_pw_8discodop_14disambiguation_7recoverfragments(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_8discodop_14disambiguation_recoverfragments(PyObject *__pyx_v_deriv, struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, PyObject *__pyx_v_backtransform, CYTHON_UNUSED int __pyx_skip_dispatch) {
  PyObject *__pyx_v_result = 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;
  PyObject *__pyx_t_5 = NULL;
  PyObject *__pyx_t_6 = NULL;
  int __pyx_t_7;
  __Pyx_RefNannySetupContext("recoverfragments", 0);
  __Pyx_INCREF(__pyx_v_deriv);

  /* "discodop/disambiguation.pyx":496
 * 	been called on `chart.grammar`, even when not doing coarse-to-fine
 * 	parsing."""
 * 	if isinstance(deriv, RankedEdge):             # <<<<<<<<<<<<<<
 * 		result = recoverfragments_(deriv, chart, backtransform)
 * 	elif isinstance(deriv, str):
 */
  __pyx_t_1 = __Pyx_TypeCheck(__pyx_v_deriv, __pyx_ptype_8discodop_10containers_RankedEdge); 
  __pyx_t_2 = (__pyx_t_1 != 0);
  if (__pyx_t_2) {

    /* "discodop/disambiguation.pyx":497
 * 	parsing."""
 * 	if isinstance(deriv, RankedEdge):
 * 		result = recoverfragments_(deriv, chart, backtransform)             # <<<<<<<<<<<<<<
 * 	elif isinstance(deriv, str):
 * 		deriv = Tree(deriv)
 */
    if (!(likely(((__pyx_v_deriv) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_deriv, __pyx_ptype_8discodop_10containers_RankedEdge))))) __PYX_ERR(0, 497, __pyx_L1_error)
    __pyx_t_3 = __pyx_f_8discodop_14disambiguation_recoverfragments_(((struct __pyx_obj_8discodop_10containers_RankedEdge *)__pyx_v_deriv), __pyx_v_chart, __pyx_v_backtransform); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 497, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_result = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "discodop/disambiguation.pyx":496
 * 	been called on `chart.grammar`, even when not doing coarse-to-fine
 * 	parsing."""
 * 	if isinstance(deriv, RankedEdge):             # <<<<<<<<<<<<<<
 * 		result = recoverfragments_(deriv, chart, backtransform)
 * 	elif isinstance(deriv, str):
 */
    goto __pyx_L3;
  }

  /* "discodop/disambiguation.pyx":498
 * 	if isinstance(deriv, RankedEdge):
 * 		result = recoverfragments_(deriv, chart, backtransform)
 * 	elif isinstance(deriv, str):             # <<<<<<<<<<<<<<
 * 		deriv = Tree(deriv)
 * 		result = recoverfragments_str(deriv, chart, backtransform)
 */
  __pyx_t_2 = PyUnicode_Check(__pyx_v_deriv); 
  __pyx_t_1 = (__pyx_t_2 != 0);
  if (__pyx_t_1) {

    /* "discodop/disambiguation.pyx":499
 * 		result = recoverfragments_(deriv, chart, backtransform)
 * 	elif isinstance(deriv, str):
 * 		deriv = Tree(deriv)             # <<<<<<<<<<<<<<
 * 		result = recoverfragments_str(deriv, chart, backtransform)
 * 	else:
 */
    __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_Tree); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 499, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_5 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(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_v_deriv); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 499, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_4)) {
        PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_deriv};
        __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 499, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
        PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_deriv};
        __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 499, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_3);
      } else
      #endif
      {
        __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 499, __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_INCREF(__pyx_v_deriv);
        __Pyx_GIVEREF(__pyx_v_deriv);
        PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_deriv);
        __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 499, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_DECREF_SET(__pyx_v_deriv, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "discodop/disambiguation.pyx":500
 * 	elif isinstance(deriv, str):
 * 		deriv = Tree(deriv)
 * 		result = recoverfragments_str(deriv, chart, backtransform)             # <<<<<<<<<<<<<<
 * 	else:
 * 		raise ValueError('derivation has unexpected type %r.' % type(deriv))
 */
    __pyx_t_3 = __pyx_f_8discodop_14disambiguation_recoverfragments_str(__pyx_v_deriv, __pyx_v_chart, __pyx_v_backtransform); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 500, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_v_result = ((PyObject*)__pyx_t_3);
    __pyx_t_3 = 0;

    /* "discodop/disambiguation.pyx":498
 * 	if isinstance(deriv, RankedEdge):
 * 		result = recoverfragments_(deriv, chart, backtransform)
 * 	elif isinstance(deriv, str):             # <<<<<<<<<<<<<<
 * 		deriv = Tree(deriv)
 * 		result = recoverfragments_str(deriv, chart, backtransform)
 */
    goto __pyx_L3;
  }

  /* "discodop/disambiguation.pyx":502
 * 		result = recoverfragments_str(deriv, chart, backtransform)
 * 	else:
 * 		raise ValueError('derivation has unexpected type %r.' % type(deriv))             # <<<<<<<<<<<<<<
 * 	return REMOVEWORDTAGS.sub('', result)
 * 
 */
  /*else*/ {
    __pyx_t_3 = PyUnicode_Format(__pyx_kp_u_derivation_has_unexpected_type_r, ((PyObject *)Py_TYPE(__pyx_v_deriv))); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 502, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_4 = PyTuple_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 502, __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 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_t_4, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 502, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_Raise(__pyx_t_3, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __PYX_ERR(0, 502, __pyx_L1_error)
  }
  __pyx_L3:;

  /* "discodop/disambiguation.pyx":503
 * 	else:
 * 		raise ValueError('derivation has unexpected type %r.' % type(deriv))
 * 	return REMOVEWORDTAGS.sub('', result)             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_REMOVEWORDTAGS); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 503, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_sub); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 503, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = NULL;
  __pyx_t_7 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(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);
      __pyx_t_7 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_6)) {
    PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_kp_u__4, __pyx_v_result};
    __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 503, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
    PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_kp_u__4, __pyx_v_result};
    __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 503, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_3);
  } else
  #endif
  {
    __pyx_t_5 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 503, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    if (__pyx_t_4) {
      __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); __pyx_t_4 = NULL;
    }
    __Pyx_INCREF(__pyx_kp_u__4);
    __Pyx_GIVEREF(__pyx_kp_u__4);
    PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_7, __pyx_kp_u__4);
    __Pyx_INCREF(__pyx_v_result);
    __Pyx_GIVEREF(__pyx_v_result);
    PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_7, __pyx_v_result);
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_5, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 503, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  if (!(likely(PyUnicode_CheckExact(__pyx_t_3))||((__pyx_t_3) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_3)->tp_name), 0))) __PYX_ERR(0, 503, __pyx_L1_error)
  __pyx_r = ((PyObject*)__pyx_t_3);
  __pyx_t_3 = 0;
  goto __pyx_L0;

  /* "discodop/disambiguation.pyx":478
 * 
 * 
 * cpdef str recoverfragments(deriv, Chart chart, list backtransform):             # <<<<<<<<<<<<<<
 * 	"""Reconstruct a DOP derivation from a derivation with flattened fragments.
 * 
 */

  /* function exit code */
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  __Pyx_XDECREF(__pyx_t_6);
  __Pyx_AddTraceback("discodop.disambiguation.recoverfragments", __pyx_clineno, __pyx_lineno, __pyx_filename);
  __pyx_r = 0;
  __pyx_L0:;
  __Pyx_XDECREF(__pyx_v_result);
  __Pyx_XDECREF(__pyx_v_deriv);
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_8discodop_14disambiguation_7recoverfragments(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8discodop_14disambiguation_6recoverfragments[] = "recoverfragments(deriv, Chart chart, list backtransform) -> unicode\nReconstruct a DOP derivation from a derivation with flattened fragments.\n\n\t:param deriv: a RankedEdge or a string representing a derivation.\n\t:param backtransform: a list with fragments (as string templates)\n\t\tcorresponding to grammar rules.\n\t:returns: expanded derivation as a string.\n\n\tThe flattened fragments in the derivation should be left-binarized, expect\n\twhen ``deriv`` is a string in which case the derivation does not have to be\n\tbinarized.\n\n\tDoes on-the-fly debinarization following labels that are not mapped to a\n\tlabel in the coarse grammar, i.e., it assumes that neverblockre is only\n\tused to avoid blocking nonterminals from the double-dop binarization\n\t(containing the string '}<'). Note that this means getmapping() has to have\n\tbeen called on `chart.grammar`, even when not doing coarse-to-fine\n\tparsing.";
static PyObject *__pyx_pw_8discodop_14disambiguation_7recoverfragments(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_deriv = 0;
struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart = 0;
PyObject *__pyx_v_backtransform = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("recoverfragments (wrapper)", 0);
{
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_deriv,&__pyx_n_s_chart,&__pyx_n_s_backtransform,0};
  PyObject* values[3] = {0,0,0};
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args;
    const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
    switch (pos_args) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    kw_args = PyDict_Size(__pyx_kwds);
    switch (pos_args) {
      case  0:
      if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_deriv)) != 0)) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chart)) != 0)) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("recoverfragments", 1, 3, 3, 1); __PYX_ERR(0, 478, __pyx_L3_error)
      }
      case  2:
      if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_backtransform)) != 0)) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("recoverfragments", 1, 3, 3, 2); __PYX_ERR(0, 478, __pyx_L3_error)
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "recoverfragments") < 0)) __PYX_ERR(0, 478, __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_deriv = values[0];
  __pyx_v_chart = ((struct __pyx_obj_8discodop_10containers_Chart *)values[1]);
  __pyx_v_backtransform = ((PyObject*)values[2]);
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("recoverfragments", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 478, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("discodop.disambiguation.recoverfragments", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_chart), __pyx_ptype_8discodop_10containers_Chart, 1, "chart", 0))) __PYX_ERR(0, 478, __pyx_L1_error)
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_backtransform), (&PyList_Type), 1, "backtransform", 1))) __PYX_ERR(0, 478, __pyx_L1_error)
__pyx_r = __pyx_pf_8discodop_14disambiguation_6recoverfragments(__pyx_self, __pyx_v_deriv, __pyx_v_chart, __pyx_v_backtransform);

/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

static PyObject *__pyx_pf_8discodop_14disambiguation_6recoverfragments(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_deriv, struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, PyObject *__pyx_v_backtransform) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
__Pyx_RefNannySetupContext("recoverfragments", 0);
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __pyx_f_8discodop_14disambiguation_recoverfragments(__pyx_v_deriv, __pyx_v_chart, __pyx_v_backtransform, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 478, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("discodop.disambiguation.recoverfragments", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":506
 * 
 * 
 * cdef str recoverfragments_(RankedEdge deriv, Chart chart,             # <<<<<<<<<<<<<<
 * 		list backtransform):
 * 	cdef RankedEdge child
 */

static PyObject *__pyx_f_8discodop_14disambiguation_recoverfragments_(struct __pyx_obj_8discodop_10containers_RankedEdge *__pyx_v_deriv, struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, PyObject *__pyx_v_backtransform) {
PyObject *__pyx_v_children = 0;
PyObject *__pyx_v_frag = 0;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
int __pyx_t_2;
PyObject *__pyx_t_3 = NULL;
int __pyx_t_4;
Py_ssize_t __pyx_t_5;
PyObject *__pyx_t_6 = NULL;
PyObject *__pyx_t_7 = NULL;
uint32_t __pyx_t_8;
PyObject *__pyx_t_9 = NULL;
__Pyx_RefNannySetupContext("recoverfragments_", 0);
__Pyx_INCREF((PyObject *)__pyx_v_deriv);

/* "discodop/disambiguation.pyx":509
 * 		list backtransform):
 * 	cdef RankedEdge child
 * 	cdef list children = []             # <<<<<<<<<<<<<<
 * 	cdef str frag = backtransform[deriv.edge.rule.no]  # template
 * 	# NB: this is the only code that uses the .head field of RankedEdge
 */
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 509, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_children = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":510
 * 	cdef RankedEdge child
 * 	cdef list children = []
 * 	cdef str frag = backtransform[deriv.edge.rule.no]  # template             # <<<<<<<<<<<<<<
 * 	# NB: this is the only code that uses the .head field of RankedEdge
 * 
 */
if (unlikely(__pyx_v_backtransform == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
  __PYX_ERR(0, 510, __pyx_L1_error)
}
if (!(likely(PyUnicode_CheckExact(PyList_GET_ITEM(__pyx_v_backtransform, __pyx_v_deriv->edge->rule->no)))||((PyList_GET_ITEM(__pyx_v_backtransform, __pyx_v_deriv->edge->rule->no)) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(PyList_GET_ITEM(__pyx_v_backtransform, __pyx_v_deriv->edge->rule->no))->tp_name), 0))) __PYX_ERR(0, 510, __pyx_L1_error)
__pyx_t_1 = PyList_GET_ITEM(__pyx_v_backtransform, __pyx_v_deriv->edge->rule->no);
__Pyx_INCREF(__pyx_t_1);
__pyx_v_frag = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":514
 * 
 * 	# collect all children w/on the fly left-factored debinarization
 * 	if deriv.edge.rule.rhs2:  # is there a right child?             # <<<<<<<<<<<<<<
 * 		# keep going while left child is part of same binarized constituent
 * 		# instead of looking for a binarization marker in the label string, we
 */
__pyx_t_2 = (__pyx_v_deriv->edge->rule->rhs2 != 0);
if (__pyx_t_2) {

  /* "discodop/disambiguation.pyx":518
 * 		# instead of looking for a binarization marker in the label string, we
 * 		# use the fact that such labels do not have a mapping as proxy.
 * 		while chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:             # <<<<<<<<<<<<<<
 * 			# one of the right children
 * 			children.append((<DoubleEntry>chart.rankededges[
 */
  while (1) {
    __pyx_t_2 = (((__pyx_v_chart->grammar->mapping[__pyx_v_deriv->edge->rule->rhs1]) == 0) != 0);
    if (!__pyx_t_2) break;

    /* "discodop/disambiguation.pyx":520
 * 		while chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 			# one of the right children
 * 			children.append((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 					chart.right(deriv)][deriv.right]).key)
 * 			# move on to next node in this binarized constituent
 */
    if (unlikely(__pyx_v_chart->rankededges == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 520, __pyx_L1_error)
    }

    /* "discodop/disambiguation.pyx":521
 * 			# one of the right children
 * 			children.append((<DoubleEntry>chart.rankededges[
 * 					chart.right(deriv)][deriv.right]).key)             # <<<<<<<<<<<<<<
 * 			# move on to next node in this binarized constituent
 * 			deriv = (<DoubleEntry>chart.rankededges[
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->right(__pyx_v_chart, __pyx_v_deriv); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 521, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "discodop/disambiguation.pyx":520
 * 		while chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 			# one of the right children
 * 			children.append((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 					chart.right(deriv)][deriv.right]).key)
 * 			# move on to next node in this binarized constituent
 */
    __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_chart->rankededges, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 520, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "discodop/disambiguation.pyx":521
 * 			# one of the right children
 * 			children.append((<DoubleEntry>chart.rankededges[
 * 					chart.right(deriv)][deriv.right]).key)             # <<<<<<<<<<<<<<
 * 			# move on to next node in this binarized constituent
 * 			deriv = (<DoubleEntry>chart.rankededges[
 */
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_3, __pyx_v_deriv->right, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 521, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "discodop/disambiguation.pyx":520
 * 		while chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 			# one of the right children
 * 			children.append((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 					chart.right(deriv)][deriv.right]).key)
 * 			# move on to next node in this binarized constituent
 */
    __pyx_t_3 = ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_1)->key;
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_children, __pyx_t_3); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(0, 520, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "discodop/disambiguation.pyx":523
 * 					chart.right(deriv)][deriv.right]).key)
 * 			# move on to next node in this binarized constituent
 * 			deriv = (<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 					chart.left(deriv)][deriv.left]).key
 * 		# last right child
 */
    if (unlikely(__pyx_v_chart->rankededges == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 523, __pyx_L1_error)
    }

    /* "discodop/disambiguation.pyx":524
 * 			# move on to next node in this binarized constituent
 * 			deriv = (<DoubleEntry>chart.rankededges[
 * 					chart.left(deriv)][deriv.left]).key             # <<<<<<<<<<<<<<
 * 		# last right child
 * 		if deriv.edge.rule.rhs2:  # is there a right child?
 */
    __pyx_t_3 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->left(__pyx_v_chart, __pyx_v_deriv); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 524, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);

    /* "discodop/disambiguation.pyx":523
 * 					chart.right(deriv)][deriv.right]).key)
 * 			# move on to next node in this binarized constituent
 * 			deriv = (<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 					chart.left(deriv)][deriv.left]).key
 * 		# last right child
 */
    __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_chart->rankededges, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 523, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "discodop/disambiguation.pyx":524
 * 			# move on to next node in this binarized constituent
 * 			deriv = (<DoubleEntry>chart.rankededges[
 * 					chart.left(deriv)][deriv.left]).key             # <<<<<<<<<<<<<<
 * 		# last right child
 * 		if deriv.edge.rule.rhs2:  # is there a right child?
 */
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_1, __pyx_v_deriv->left, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 524, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "discodop/disambiguation.pyx":523
 * 					chart.right(deriv)][deriv.right]).key)
 * 			# move on to next node in this binarized constituent
 * 			deriv = (<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 					chart.left(deriv)][deriv.left]).key
 * 		# last right child
 */
    if (!(likely(((((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_3)->key) == Py_None) || likely(__Pyx_TypeTest(((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_3)->key, __pyx_ptype_8discodop_10containers_RankedEdge))))) __PYX_ERR(0, 524, __pyx_L1_error)

    /* "discodop/disambiguation.pyx":524
 * 			# move on to next node in this binarized constituent
 * 			deriv = (<DoubleEntry>chart.rankededges[
 * 					chart.left(deriv)][deriv.left]).key             # <<<<<<<<<<<<<<
 * 		# last right child
 * 		if deriv.edge.rule.rhs2:  # is there a right child?
 */
    __pyx_t_1 = ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_3)->key;
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_deriv, ((struct __pyx_obj_8discodop_10containers_RankedEdge *)__pyx_t_1));
    __pyx_t_1 = 0;
  }

  /* "discodop/disambiguation.pyx":526
 * 					chart.left(deriv)][deriv.left]).key
 * 		# last right child
 * 		if deriv.edge.rule.rhs2:  # is there a right child?             # <<<<<<<<<<<<<<
 * 			children.append((<DoubleEntry>chart.rankededges[
 * 					chart.right(deriv)][deriv.right]).key)
 */
  __pyx_t_2 = (__pyx_v_deriv->edge->rule->rhs2 != 0);
  if (__pyx_t_2) {

    /* "discodop/disambiguation.pyx":527
 * 		# last right child
 * 		if deriv.edge.rule.rhs2:  # is there a right child?
 * 			children.append((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 					chart.right(deriv)][deriv.right]).key)
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 */
    if (unlikely(__pyx_v_chart->rankededges == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 527, __pyx_L1_error)
    }

    /* "discodop/disambiguation.pyx":528
 * 		if deriv.edge.rule.rhs2:  # is there a right child?
 * 			children.append((<DoubleEntry>chart.rankededges[
 * 					chart.right(deriv)][deriv.right]).key)             # <<<<<<<<<<<<<<
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 		deriv = (<DoubleEntry>chart.rankededges[
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->right(__pyx_v_chart, __pyx_v_deriv); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 528, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "discodop/disambiguation.pyx":527
 * 		# last right child
 * 		if deriv.edge.rule.rhs2:  # is there a right child?
 * 			children.append((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 					chart.right(deriv)][deriv.right]).key)
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 */
    __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_chart->rankededges, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 527, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "discodop/disambiguation.pyx":528
 * 		if deriv.edge.rule.rhs2:  # is there a right child?
 * 			children.append((<DoubleEntry>chart.rankededges[
 * 					chart.right(deriv)][deriv.right]).key)             # <<<<<<<<<<<<<<
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 		deriv = (<DoubleEntry>chart.rankededges[
 */
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_3, __pyx_v_deriv->right, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 528, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "discodop/disambiguation.pyx":527
 * 		# last right child
 * 		if deriv.edge.rule.rhs2:  # is there a right child?
 * 			children.append((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 					chart.right(deriv)][deriv.right]).key)
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 */
    __pyx_t_3 = ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_1)->key;
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_children, __pyx_t_3); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(0, 527, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "discodop/disambiguation.pyx":526
 * 					chart.left(deriv)][deriv.left]).key
 * 		# last right child
 * 		if deriv.edge.rule.rhs2:  # is there a right child?             # <<<<<<<<<<<<<<
 * 			children.append((<DoubleEntry>chart.rankededges[
 * 					chart.right(deriv)][deriv.right]).key)
 */
  }

  /* "discodop/disambiguation.pyx":514
 * 
 * 	# collect all children w/on the fly left-factored debinarization
 * 	if deriv.edge.rule.rhs2:  # is there a right child?             # <<<<<<<<<<<<<<
 * 		# keep going while left child is part of same binarized constituent
 * 		# instead of looking for a binarization marker in the label string, we
 */
  goto __pyx_L3;
}

/* "discodop/disambiguation.pyx":529
 * 			children.append((<DoubleEntry>chart.rankededges[
 * 					chart.right(deriv)][deriv.right]).key)
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:             # <<<<<<<<<<<<<<
 * 		deriv = (<DoubleEntry>chart.rankededges[
 * 				chart.left(deriv)][deriv.left]).key
 */
__pyx_t_2 = (((__pyx_v_chart->grammar->mapping[__pyx_v_deriv->edge->rule->rhs1]) == 0) != 0);
if (__pyx_t_2) {

  /* "discodop/disambiguation.pyx":530
 * 					chart.right(deriv)][deriv.right]).key)
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 		deriv = (<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 				chart.left(deriv)][deriv.left]).key
 * 	# left-most child
 */
  if (unlikely(__pyx_v_chart->rankededges == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 530, __pyx_L1_error)
  }

  /* "discodop/disambiguation.pyx":531
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 		deriv = (<DoubleEntry>chart.rankededges[
 * 				chart.left(deriv)][deriv.left]).key             # <<<<<<<<<<<<<<
 * 	# left-most child
 * 	children.append((<DoubleEntry>chart.rankededges[
 */
  __pyx_t_3 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->left(__pyx_v_chart, __pyx_v_deriv); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 531, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);

  /* "discodop/disambiguation.pyx":530
 * 					chart.right(deriv)][deriv.right]).key)
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 		deriv = (<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 				chart.left(deriv)][deriv.left]).key
 * 	# left-most child
 */
  __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_chart->rankededges, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 530, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "discodop/disambiguation.pyx":531
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 		deriv = (<DoubleEntry>chart.rankededges[
 * 				chart.left(deriv)][deriv.left]).key             # <<<<<<<<<<<<<<
 * 	# left-most child
 * 	children.append((<DoubleEntry>chart.rankededges[
 */
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_1, __pyx_v_deriv->left, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 531, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":530
 * 					chart.right(deriv)][deriv.right]).key)
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 		deriv = (<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 				chart.left(deriv)][deriv.left]).key
 * 	# left-most child
 */
  if (!(likely(((((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_3)->key) == Py_None) || likely(__Pyx_TypeTest(((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_3)->key, __pyx_ptype_8discodop_10containers_RankedEdge))))) __PYX_ERR(0, 531, __pyx_L1_error)

  /* "discodop/disambiguation.pyx":531
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 		deriv = (<DoubleEntry>chart.rankededges[
 * 				chart.left(deriv)][deriv.left]).key             # <<<<<<<<<<<<<<
 * 	# left-most child
 * 	children.append((<DoubleEntry>chart.rankededges[
 */
  __pyx_t_1 = ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_3)->key;
  __Pyx_INCREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF_SET(__pyx_v_deriv, ((struct __pyx_obj_8discodop_10containers_RankedEdge *)__pyx_t_1));
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":529
 * 			children.append((<DoubleEntry>chart.rankededges[
 * 					chart.right(deriv)][deriv.right]).key)
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:             # <<<<<<<<<<<<<<
 * 		deriv = (<DoubleEntry>chart.rankededges[
 * 				chart.left(deriv)][deriv.left]).key
 */
}
__pyx_L3:;

/* "discodop/disambiguation.pyx":533
 * 				chart.left(deriv)][deriv.left]).key
 * 	# left-most child
 * 	children.append((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 			chart.left(deriv)][deriv.left]).key)
 * 
 */
if (unlikely(__pyx_v_chart->rankededges == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
  __PYX_ERR(0, 533, __pyx_L1_error)
}

/* "discodop/disambiguation.pyx":534
 * 	# left-most child
 * 	children.append((<DoubleEntry>chart.rankededges[
 * 			chart.left(deriv)][deriv.left]).key)             # <<<<<<<<<<<<<<
 * 
 * 	# recursively expand all substitution sites
 */
__pyx_t_1 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->left(__pyx_v_chart, __pyx_v_deriv); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 534, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);

/* "discodop/disambiguation.pyx":533
 * 				chart.left(deriv)][deriv.left]).key
 * 	# left-most child
 * 	children.append((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 			chart.left(deriv)][deriv.left]).key)
 * 
 */
__pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_chart->rankededges, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 533, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":534
 * 	# left-most child
 * 	children.append((<DoubleEntry>chart.rankededges[
 * 			chart.left(deriv)][deriv.left]).key)             # <<<<<<<<<<<<<<
 * 
 * 	# recursively expand all substitution sites
 */
__pyx_t_1 = __Pyx_GetItemInt(__pyx_t_3, __pyx_v_deriv->left, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 534, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

/* "discodop/disambiguation.pyx":533
 * 				chart.left(deriv)][deriv.left]).key
 * 	# left-most child
 * 	children.append((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 			chart.left(deriv)][deriv.left]).key)
 * 
 */
__pyx_t_3 = ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_1)->key;
__Pyx_INCREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_4 = __Pyx_PyList_Append(__pyx_v_children, __pyx_t_3); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(0, 533, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

/* "discodop/disambiguation.pyx":537
 * 
 * 	# recursively expand all substitution sites
 * 	children = ['(%s %d)' % (chart.grammar.tolabel[chart.label(child.head)],             # <<<<<<<<<<<<<<
 * 			chart.lexidx(child.edge)) if child.edge.rule is NULL
 * 			else recoverfragments_(child, chart, backtransform)
 */
{ /* enter inner scope */
  struct __pyx_obj_8discodop_10containers_RankedEdge *__pyx_9genexpr17__pyx_v_child = NULL;
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 537, __pyx_L9_error)
  __Pyx_GOTREF(__pyx_t_3);

  /* "discodop/disambiguation.pyx":540
 * 			chart.lexidx(child.edge)) if child.edge.rule is NULL
 * 			else recoverfragments_(child, chart, backtransform)
 * 			for child in reversed(children)]             # <<<<<<<<<<<<<<
 * 
 * 	# substitute results in template
 */
  __pyx_t_1 = __pyx_v_children; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = PyList_GET_SIZE(__pyx_t_1) - 1;
  for (;;) {
    if (__pyx_t_5 < 0) break;
    if (__pyx_t_5 >= 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_5); __Pyx_INCREF(__pyx_t_6); __pyx_t_5--; if (unlikely(0 < 0)) __PYX_ERR(0, 540, __pyx_L9_error)
    #else
    __pyx_t_6 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5--; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 540, __pyx_L9_error)
    __Pyx_GOTREF(__pyx_t_6);
    #endif
    if (!(likely(((__pyx_t_6) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_6, __pyx_ptype_8discodop_10containers_RankedEdge))))) __PYX_ERR(0, 540, __pyx_L9_error)
    __Pyx_XDECREF_SET(__pyx_9genexpr17__pyx_v_child, ((struct __pyx_obj_8discodop_10containers_RankedEdge *)__pyx_t_6));
    __pyx_t_6 = 0;

    /* "discodop/disambiguation.pyx":538
 * 	# recursively expand all substitution sites
 * 	children = ['(%s %d)' % (chart.grammar.tolabel[chart.label(child.head)],
 * 			chart.lexidx(child.edge)) if child.edge.rule is NULL             # <<<<<<<<<<<<<<
 * 			else recoverfragments_(child, chart, backtransform)
 * 			for child in reversed(children)]
 */
    if (((__pyx_9genexpr17__pyx_v_child->edge->rule == NULL) != 0)) {

      /* "discodop/disambiguation.pyx":537
 * 
 * 	# recursively expand all substitution sites
 * 	children = ['(%s %d)' % (chart.grammar.tolabel[chart.label(child.head)],             # <<<<<<<<<<<<<<
 * 			chart.lexidx(child.edge)) if child.edge.rule is NULL
 * 			else recoverfragments_(child, chart, backtransform)
 */
      if (unlikely(__pyx_v_chart->grammar->tolabel == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 537, __pyx_L9_error)
      }
      __pyx_t_7 = __pyx_9genexpr17__pyx_v_child->head;
      __Pyx_INCREF(__pyx_t_7);
      __pyx_t_8 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->label(__pyx_v_chart, __pyx_t_7);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

      /* "discodop/disambiguation.pyx":538
 * 	# recursively expand all substitution sites
 * 	children = ['(%s %d)' % (chart.grammar.tolabel[chart.label(child.head)],
 * 			chart.lexidx(child.edge)) if child.edge.rule is NULL             # <<<<<<<<<<<<<<
 * 			else recoverfragments_(child, chart, backtransform)
 * 			for child in reversed(children)]
 */
      __pyx_t_7 = __Pyx_PyInt_From_int(((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->lexidx(__pyx_v_chart, __pyx_9genexpr17__pyx_v_child->edge)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 538, __pyx_L9_error)
      __Pyx_GOTREF(__pyx_t_7);

      /* "discodop/disambiguation.pyx":537
 * 
 * 	# recursively expand all substitution sites
 * 	children = ['(%s %d)' % (chart.grammar.tolabel[chart.label(child.head)],             # <<<<<<<<<<<<<<
 * 			chart.lexidx(child.edge)) if child.edge.rule is NULL
 * 			else recoverfragments_(child, chart, backtransform)
 */
      __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 537, __pyx_L9_error)
      __Pyx_GOTREF(__pyx_t_9);
      __Pyx_INCREF(PyList_GET_ITEM(__pyx_v_chart->grammar->tolabel, __pyx_t_8));
      __Pyx_GIVEREF(PyList_GET_ITEM(__pyx_v_chart->grammar->tolabel, __pyx_t_8));
      PyTuple_SET_ITEM(__pyx_t_9, 0, PyList_GET_ITEM(__pyx_v_chart->grammar->tolabel, __pyx_t_8));
      __Pyx_GIVEREF(__pyx_t_7);
      PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_7);
      __pyx_t_7 = 0;
      __pyx_t_7 = PyUnicode_Format(__pyx_kp_u_s_d, __pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 537, __pyx_L9_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_6 = __pyx_t_7;
      __pyx_t_7 = 0;
    } else {

      /* "discodop/disambiguation.pyx":539
 * 	children = ['(%s %d)' % (chart.grammar.tolabel[chart.label(child.head)],
 * 			chart.lexidx(child.edge)) if child.edge.rule is NULL
 * 			else recoverfragments_(child, chart, backtransform)             # <<<<<<<<<<<<<<
 * 			for child in reversed(children)]
 * 
 */
      __pyx_t_7 = __pyx_f_8discodop_14disambiguation_recoverfragments_(__pyx_9genexpr17__pyx_v_child, __pyx_v_chart, __pyx_v_backtransform); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 539, __pyx_L9_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = __pyx_t_7;
      __pyx_t_7 = 0;
    }
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 537, __pyx_L9_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

    /* "discodop/disambiguation.pyx":540
 * 			chart.lexidx(child.edge)) if child.edge.rule is NULL
 * 			else recoverfragments_(child, chart, backtransform)
 * 			for child in reversed(children)]             # <<<<<<<<<<<<<<
 * 
 * 	# substitute results in template
 */
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_XDECREF((PyObject *)__pyx_9genexpr17__pyx_v_child);
  goto __pyx_L12_exit_scope;
  __pyx_L9_error:;
  __Pyx_XDECREF((PyObject *)__pyx_9genexpr17__pyx_v_child);
  goto __pyx_L1_error;
  __pyx_L12_exit_scope:;
} /* exit inner scope */
__Pyx_DECREF_SET(__pyx_v_children, ((PyObject*)__pyx_t_3));
__pyx_t_3 = 0;

/* "discodop/disambiguation.pyx":543
 * 
 * 	# substitute results in template
 * 	return frag.format(*children)             # <<<<<<<<<<<<<<
 * 
 * 	# even better: build result incrementally; use a list of strings
 */
__Pyx_XDECREF(__pyx_r);
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_frag, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 543, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_1 = PySequence_Tuple(__pyx_v_children); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 543, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 543, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (!(likely(PyUnicode_CheckExact(__pyx_t_6))||((__pyx_t_6) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_6)->tp_name), 0))) __PYX_ERR(0, 543, __pyx_L1_error)
__pyx_r = ((PyObject*)__pyx_t_6);
__pyx_t_6 = 0;
goto __pyx_L0;

/* "discodop/disambiguation.pyx":506
 * 
 * 
 * cdef str recoverfragments_(RankedEdge deriv, Chart chart,             # <<<<<<<<<<<<<<
 * 		list backtransform):
 * 	cdef RankedEdge child
 */

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_9);
__Pyx_AddTraceback("discodop.disambiguation.recoverfragments_", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_children);
__Pyx_XDECREF(__pyx_v_frag);
__Pyx_XDECREF((PyObject *)__pyx_v_deriv);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":562
 * 
 * 
 * cdef str recoverfragments_str(deriv, Chart chart, list backtransform):             # <<<<<<<<<<<<<<
 * 	cdef list children = []
 * 	cdef str frag
 */

static PyObject *__pyx_f_8discodop_14disambiguation_recoverfragments_str(PyObject *__pyx_v_deriv, struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, PyObject *__pyx_v_backtransform) {
PyObject *__pyx_v_children = 0;
PyObject *__pyx_v_frag = 0;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
Py_ssize_t __pyx_t_3;
int __pyx_t_4;
int __pyx_t_5;
int __pyx_t_6;
PyObject *__pyx_t_7 = NULL;
PyObject *__pyx_t_8 = NULL;
PyObject *__pyx_t_9 = NULL;
PyObject *__pyx_t_10 = NULL;
__Pyx_RefNannySetupContext("recoverfragments_str", 0);
__Pyx_INCREF(__pyx_v_deriv);

/* "discodop/disambiguation.pyx":563
 * 
 * cdef str recoverfragments_str(deriv, Chart chart, list backtransform):
 * 	cdef list children = []             # <<<<<<<<<<<<<<
 * 	cdef str frag
 * 	frag = backtransform[chart.grammar.rulenos[nodeprod(deriv)]]
 */
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 563, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_children = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":565
 * 	cdef list children = []
 * 	cdef str frag
 * 	frag = backtransform[chart.grammar.rulenos[nodeprod(deriv)]]             # <<<<<<<<<<<<<<
 * 	# collect children w/on the fly left-factored debinarization
 * 	if len(deriv) >= 2:  # is there a right child?
 */
if (unlikely(__pyx_v_backtransform == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
  __PYX_ERR(0, 565, __pyx_L1_error)
}
if (unlikely(__pyx_v_chart->grammar->rulenos == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
  __PYX_ERR(0, 565, __pyx_L1_error)
}
__pyx_t_1 = __pyx_f_8discodop_14disambiguation_nodeprod(__pyx_v_deriv); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 565, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_chart->grammar->rulenos, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 565, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = PyObject_GetItem(__pyx_v_backtransform, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 565, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 565, __pyx_L1_error)
__pyx_v_frag = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":567
 * 	frag = backtransform[chart.grammar.rulenos[nodeprod(deriv)]]
 * 	# collect children w/on the fly left-factored debinarization
 * 	if len(deriv) >= 2:  # is there a right child?             # <<<<<<<<<<<<<<
 * 		# keep going while left child is part of same binarized constituent
 * 		# this shortcut assumes that neverblockre is only used to avoid
 */
__pyx_t_3 = PyObject_Length(__pyx_v_deriv); if (unlikely(__pyx_t_3 == -1)) __PYX_ERR(0, 567, __pyx_L1_error)
__pyx_t_4 = ((__pyx_t_3 >= 2) != 0);
if (__pyx_t_4) {

  /* "discodop/disambiguation.pyx":571
 * 		# this shortcut assumes that neverblockre is only used to avoid
 * 		# blocking nonterminals from the double-dop binarization.
 * 		while '}<' in deriv[0].label:             # <<<<<<<<<<<<<<
 * 			# one of the right children
 * 			children.extend(reversed(deriv[1:]))
 */
  while (1) {
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_deriv, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 571, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_label); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 571, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_4 = (__Pyx_PySequence_ContainsTF(__pyx_kp_u__13, __pyx_t_2, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 571, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_5 = (__pyx_t_4 != 0);
    if (!__pyx_t_5) break;

    /* "discodop/disambiguation.pyx":573
 * 		while '}<' in deriv[0].label:
 * 			# one of the right children
 * 			children.extend(reversed(deriv[1:]))             # <<<<<<<<<<<<<<
 * 			# move on to next node in this binarized constituent
 * 			deriv = deriv[0]
 */
    __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_deriv, 1, 0, NULL, NULL, &__pyx_slice__17, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 573, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 573, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_reversed, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 573, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_6 = __Pyx_PyList_Extend(__pyx_v_children, __pyx_t_2); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 573, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "discodop/disambiguation.pyx":575
 * 			children.extend(reversed(deriv[1:]))
 * 			# move on to next node in this binarized constituent
 * 			deriv = deriv[0]             # <<<<<<<<<<<<<<
 * 		# last right child
 * 		children.extend(reversed(deriv[1:]))
 */
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_deriv, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 575, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF_SET(__pyx_v_deriv, __pyx_t_2);
    __pyx_t_2 = 0;
  }

  /* "discodop/disambiguation.pyx":577
 * 			deriv = deriv[0]
 * 		# last right child
 * 		children.extend(reversed(deriv[1:]))             # <<<<<<<<<<<<<<
 * 	elif '}<' in deriv[0].label:
 * 		deriv = deriv[0]
 */
  __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_deriv, 1, 0, NULL, NULL, &__pyx_slice__18, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_reversed, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyList_Extend(__pyx_v_children, __pyx_t_2); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 577, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "discodop/disambiguation.pyx":567
 * 	frag = backtransform[chart.grammar.rulenos[nodeprod(deriv)]]
 * 	# collect children w/on the fly left-factored debinarization
 * 	if len(deriv) >= 2:  # is there a right child?             # <<<<<<<<<<<<<<
 * 		# keep going while left child is part of same binarized constituent
 * 		# this shortcut assumes that neverblockre is only used to avoid
 */
  goto __pyx_L3;
}

/* "discodop/disambiguation.pyx":578
 * 		# last right child
 * 		children.extend(reversed(deriv[1:]))
 * 	elif '}<' in deriv[0].label:             # <<<<<<<<<<<<<<
 * 		deriv = deriv[0]
 * 	# left-most child
 */
__pyx_t_2 = __Pyx_GetItemInt(__pyx_v_deriv, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 578, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_label); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 578, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_5 = (__Pyx_PySequence_ContainsTF(__pyx_kp_u__13, __pyx_t_1, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 578, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_4 = (__pyx_t_5 != 0);
if (__pyx_t_4) {

  /* "discodop/disambiguation.pyx":579
 * 		children.extend(reversed(deriv[1:]))
 * 	elif '}<' in deriv[0].label:
 * 		deriv = deriv[0]             # <<<<<<<<<<<<<<
 * 	# left-most child
 * 	children.append(deriv[0])
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_deriv, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 579, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF_SET(__pyx_v_deriv, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":578
 * 		# last right child
 * 		children.extend(reversed(deriv[1:]))
 * 	elif '}<' in deriv[0].label:             # <<<<<<<<<<<<<<
 * 		deriv = deriv[0]
 * 	# left-most child
 */
}
__pyx_L3:;

/* "discodop/disambiguation.pyx":581
 * 		deriv = deriv[0]
 * 	# left-most child
 * 	children.append(deriv[0])             # <<<<<<<<<<<<<<
 * 
 * 	# recursively expand all substitution sites
 */
__pyx_t_1 = __Pyx_GetItemInt(__pyx_v_deriv, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 581, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_6 = __Pyx_PyList_Append(__pyx_v_children, __pyx_t_1); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 581, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":584
 * 
 * 	# recursively expand all substitution sites
 * 	children = [recoverfragments_str(child, chart, backtransform)             # <<<<<<<<<<<<<<
 * 			if isinstance(child[0], Tree)
 * 			else ('(%s %d)' % (child.label, child[0]))
 */
{ /* enter inner scope */
  PyObject *__pyx_9genexpr18__pyx_v_child = NULL;
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 584, __pyx_L8_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "discodop/disambiguation.pyx":587
 * 			if isinstance(child[0], Tree)
 * 			else ('(%s %d)' % (child.label, child[0]))
 * 			for child in reversed(children)]             # <<<<<<<<<<<<<<
 * 
 * 	# substitute results in template
 */
  __pyx_t_2 = __pyx_v_children; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = PyList_GET_SIZE(__pyx_t_2) - 1;
  for (;;) {
    if (__pyx_t_3 < 0) break;
    if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_7 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_7); __pyx_t_3--; if (unlikely(0 < 0)) __PYX_ERR(0, 587, __pyx_L8_error)
    #else
    __pyx_t_7 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3--; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 587, __pyx_L8_error)
    __Pyx_GOTREF(__pyx_t_7);
    #endif
    __Pyx_XDECREF_SET(__pyx_9genexpr18__pyx_v_child, __pyx_t_7);
    __pyx_t_7 = 0;

    /* "discodop/disambiguation.pyx":585
 * 	# recursively expand all substitution sites
 * 	children = [recoverfragments_str(child, chart, backtransform)
 * 			if isinstance(child[0], Tree)             # <<<<<<<<<<<<<<
 * 			else ('(%s %d)' % (child.label, child[0]))
 * 			for child in reversed(children)]
 */
    __pyx_t_8 = __Pyx_GetItemInt(__pyx_9genexpr18__pyx_v_child, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 585, __pyx_L8_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_Tree); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 585, __pyx_L8_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_4 = PyObject_IsInstance(__pyx_t_8, __pyx_t_9); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(0, 585, __pyx_L8_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if ((__pyx_t_4 != 0)) {

      /* "discodop/disambiguation.pyx":584
 * 
 * 	# recursively expand all substitution sites
 * 	children = [recoverfragments_str(child, chart, backtransform)             # <<<<<<<<<<<<<<
 * 			if isinstance(child[0], Tree)
 * 			else ('(%s %d)' % (child.label, child[0]))
 */
      __pyx_t_9 = __pyx_f_8discodop_14disambiguation_recoverfragments_str(__pyx_9genexpr18__pyx_v_child, __pyx_v_chart, __pyx_v_backtransform); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 584, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_7 = __pyx_t_9;
      __pyx_t_9 = 0;
    } else {

      /* "discodop/disambiguation.pyx":586
 * 	children = [recoverfragments_str(child, chart, backtransform)
 * 			if isinstance(child[0], Tree)
 * 			else ('(%s %d)' % (child.label, child[0]))             # <<<<<<<<<<<<<<
 * 			for child in reversed(children)]
 * 
 */
      __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_9genexpr18__pyx_v_child, __pyx_n_s_label); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 586, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_9);
      __pyx_t_8 = __Pyx_GetItemInt(__pyx_9genexpr18__pyx_v_child, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 586, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 586, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_GIVEREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_8);
      PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_8);
      __pyx_t_9 = 0;
      __pyx_t_8 = 0;
      __pyx_t_8 = PyUnicode_Format(__pyx_kp_u_s_d, __pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 586, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_7 = __pyx_t_8;
      __pyx_t_8 = 0;
    }
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_7))) __PYX_ERR(0, 584, __pyx_L8_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "discodop/disambiguation.pyx":587
 * 			if isinstance(child[0], Tree)
 * 			else ('(%s %d)' % (child.label, child[0]))
 * 			for child in reversed(children)]             # <<<<<<<<<<<<<<
 * 
 * 	# substitute results in template
 */
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_XDECREF(__pyx_9genexpr18__pyx_v_child);
  goto __pyx_L11_exit_scope;
  __pyx_L8_error:;
  __Pyx_XDECREF(__pyx_9genexpr18__pyx_v_child);
  goto __pyx_L1_error;
  __pyx_L11_exit_scope:;
} /* exit inner scope */
__Pyx_DECREF_SET(__pyx_v_children, ((PyObject*)__pyx_t_1));
__pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":590
 * 
 * 	# substitute results in template
 * 	return frag.format(*children)             # <<<<<<<<<<<<<<
 * 
 * 
 */
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_frag, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 590, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PySequence_Tuple(__pyx_v_children); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 590, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 590, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (!(likely(PyUnicode_CheckExact(__pyx_t_7))||((__pyx_t_7) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_7)->tp_name), 0))) __PYX_ERR(0, 590, __pyx_L1_error)
__pyx_r = ((PyObject*)__pyx_t_7);
__pyx_t_7 = 0;
goto __pyx_L0;

/* "discodop/disambiguation.pyx":562
 * 
 * 
 * cdef str recoverfragments_str(deriv, Chart chart, list backtransform):             # <<<<<<<<<<<<<<
 * 	cdef list children = []
 * 	cdef str frag
 */

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_XDECREF(__pyx_t_9);
__Pyx_XDECREF(__pyx_t_10);
__Pyx_AddTraceback("discodop.disambiguation.recoverfragments_str", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_children);
__Pyx_XDECREF(__pyx_v_frag);
__Pyx_XDECREF(__pyx_v_deriv);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":593
 * 
 * 
 * def fragmentsinderiv(deriv, chart, list backtransform):             # <<<<<<<<<<<<<<
 * 	"""Extract the list of fragments that were used in a given derivation.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_8discodop_14disambiguation_9fragmentsinderiv(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8discodop_14disambiguation_8fragmentsinderiv[] = "fragmentsinderiv(deriv, chart, list backtransform)\nExtract the list of fragments that were used in a given derivation.\n\n\t:returns: a list of fragments of the form ``(frag, sent)`` where frag is a\n\t\tstring and sent is a list of tokens; in ``sent``, ``None`` indicates a\n\t\tfrontier non-terminal, and a string indicates a token. ";
static PyMethodDef __pyx_mdef_8discodop_14disambiguation_9fragmentsinderiv = {"fragmentsinderiv", (PyCFunction)__pyx_pw_8discodop_14disambiguation_9fragmentsinderiv, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8discodop_14disambiguation_8fragmentsinderiv};
static PyObject *__pyx_pw_8discodop_14disambiguation_9fragmentsinderiv(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_deriv = 0;
PyObject *__pyx_v_chart = 0;
PyObject *__pyx_v_backtransform = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("fragmentsinderiv (wrapper)", 0);
{
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_deriv,&__pyx_n_s_chart,&__pyx_n_s_backtransform,0};
  PyObject* values[3] = {0,0,0};
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args;
    const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
    switch (pos_args) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    kw_args = PyDict_Size(__pyx_kwds);
    switch (pos_args) {
      case  0:
      if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_deriv)) != 0)) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chart)) != 0)) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("fragmentsinderiv", 1, 3, 3, 1); __PYX_ERR(0, 593, __pyx_L3_error)
      }
      case  2:
      if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_backtransform)) != 0)) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("fragmentsinderiv", 1, 3, 3, 2); __PYX_ERR(0, 593, __pyx_L3_error)
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "fragmentsinderiv") < 0)) __PYX_ERR(0, 593, __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_deriv = values[0];
  __pyx_v_chart = values[1];
  __pyx_v_backtransform = ((PyObject*)values[2]);
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("fragmentsinderiv", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 593, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("discodop.disambiguation.fragmentsinderiv", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_backtransform), (&PyList_Type), 1, "backtransform", 1))) __PYX_ERR(0, 593, __pyx_L1_error)
__pyx_r = __pyx_pf_8discodop_14disambiguation_8fragmentsinderiv(__pyx_self, __pyx_v_deriv, __pyx_v_chart, __pyx_v_backtransform);

/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

static PyObject *__pyx_pf_8discodop_14disambiguation_8fragmentsinderiv(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_deriv, PyObject *__pyx_v_chart, PyObject *__pyx_v_backtransform) {
PyObject *__pyx_v_result = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
int __pyx_t_2;
int __pyx_t_3;
int __pyx_t_4;
PyObject *__pyx_t_5 = NULL;
PyObject *__pyx_t_6 = NULL;
PyObject *__pyx_t_7 = NULL;
PyObject *__pyx_t_8 = NULL;
PyObject *__pyx_t_9 = NULL;
Py_ssize_t __pyx_t_10;
PyObject *(*__pyx_t_11)(PyObject *);
PyObject *__pyx_t_12 = NULL;
PyObject *__pyx_t_13 = NULL;
PyObject *__pyx_t_14 = NULL;
PyObject *__pyx_t_15 = NULL;
PyObject *__pyx_t_16 = NULL;
int __pyx_t_17;
__Pyx_RefNannySetupContext("fragmentsinderiv", 0);
__Pyx_INCREF(__pyx_v_deriv);

/* "discodop/disambiguation.pyx":599
 * 		string and sent is a list of tokens; in ``sent``, ``None`` indicates a
 * 		frontier non-terminal, and a string indicates a token. """
 * 	result = []             # <<<<<<<<<<<<<<
 * 	if isinstance(deriv, RankedEdge):
 * 		fragmentsinderiv_(deriv, chart, backtransform, result)
 */
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 599, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_result = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":600
 * 		frontier non-terminal, and a string indicates a token. """
 * 	result = []
 * 	if isinstance(deriv, RankedEdge):             # <<<<<<<<<<<<<<
 * 		fragmentsinderiv_(deriv, chart, backtransform, result)
 * 	elif isinstance(deriv, str) and backtransform is None:
 */
__pyx_t_2 = __Pyx_TypeCheck(__pyx_v_deriv, __pyx_ptype_8discodop_10containers_RankedEdge); 
__pyx_t_3 = (__pyx_t_2 != 0);
if (__pyx_t_3) {

  /* "discodop/disambiguation.pyx":601
 * 	result = []
 * 	if isinstance(deriv, RankedEdge):
 * 		fragmentsinderiv_(deriv, chart, backtransform, result)             # <<<<<<<<<<<<<<
 * 	elif isinstance(deriv, str) and backtransform is None:
 * 		deriv = Tree(deriv)
 */
  if (!(likely(((__pyx_v_deriv) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_deriv, __pyx_ptype_8discodop_10containers_RankedEdge))))) __PYX_ERR(0, 601, __pyx_L1_error)
  if (!(likely(((__pyx_v_chart) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_chart, __pyx_ptype_8discodop_10containers_Chart))))) __PYX_ERR(0, 601, __pyx_L1_error)
  __pyx_t_1 = __pyx_f_8discodop_14disambiguation_fragmentsinderiv_(((struct __pyx_obj_8discodop_10containers_RankedEdge *)__pyx_v_deriv), ((struct __pyx_obj_8discodop_10containers_Chart *)__pyx_v_chart), __pyx_v_backtransform, __pyx_v_result); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 601, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":600
 * 		frontier non-terminal, and a string indicates a token. """
 * 	result = []
 * 	if isinstance(deriv, RankedEdge):             # <<<<<<<<<<<<<<
 * 		fragmentsinderiv_(deriv, chart, backtransform, result)
 * 	elif isinstance(deriv, str) and backtransform is None:
 */
  goto __pyx_L3;
}

/* "discodop/disambiguation.pyx":602
 * 	if isinstance(deriv, RankedEdge):
 * 		fragmentsinderiv_(deriv, chart, backtransform, result)
 * 	elif isinstance(deriv, str) and backtransform is None:             # <<<<<<<<<<<<<<
 * 		deriv = Tree(deriv)
 * 		result = [writediscbrackettree(
 */
__pyx_t_2 = PyUnicode_Check(__pyx_v_deriv); 
__pyx_t_4 = (__pyx_t_2 != 0);
if (__pyx_t_4) {
} else {
  __pyx_t_3 = __pyx_t_4;
  goto __pyx_L4_bool_binop_done;
}
__pyx_t_4 = (__pyx_v_backtransform == ((PyObject*)Py_None));
__pyx_t_2 = (__pyx_t_4 != 0);
__pyx_t_3 = __pyx_t_2;
__pyx_L4_bool_binop_done:;
if (__pyx_t_3) {

  /* "discodop/disambiguation.pyx":603
 * 		fragmentsinderiv_(deriv, chart, backtransform, result)
 * 	elif isinstance(deriv, str) and backtransform is None:
 * 		deriv = Tree(deriv)             # <<<<<<<<<<<<<<
 * 		result = [writediscbrackettree(
 * 				REMOVEIDS.sub('', str(splitfrag(node))),
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_Tree); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 603, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_6 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(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_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_v_deriv); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 603, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_deriv};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 603, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_deriv};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 603, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 603, __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_INCREF(__pyx_v_deriv);
      __Pyx_GIVEREF(__pyx_v_deriv);
      PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_deriv);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 603, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF_SET(__pyx_v_deriv, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":604
 * 	elif isinstance(deriv, str) and backtransform is None:
 * 		deriv = Tree(deriv)
 * 		result = [writediscbrackettree(             # <<<<<<<<<<<<<<
 * 				REMOVEIDS.sub('', str(splitfrag(node))),
 * 				chart.sent).rstrip()
 */
  { /* enter inner scope */
    PyObject *__pyx_9genexpr19__pyx_v_node = NULL;
    __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 604, __pyx_L8_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "discodop/disambiguation.pyx":607
 * 				REMOVEIDS.sub('', str(splitfrag(node))),
 * 				chart.sent).rstrip()
 * 				for node in deriv.subtrees(frontiernt)]             # <<<<<<<<<<<<<<
 * 	elif isinstance(deriv, str):
 * 		deriv = Tree(deriv)
 */
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_deriv, __pyx_n_s_subtrees); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 607, __pyx_L8_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_frontiernt); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 607, __pyx_L8_error)
    __Pyx_GOTREF(__pyx_t_6);
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_7))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_7, function);
      }
    }
    if (!__pyx_t_8) {
      __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 607, __pyx_L8_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_5);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6};
        __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 607, __pyx_L8_error)
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_7)) {
        PyObject *__pyx_temp[2] = {__pyx_t_8, __pyx_t_6};
        __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 607, __pyx_L8_error)
        __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      } else
      #endif
      {
        __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 607, __pyx_L8_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_6);
        PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_t_6);
        __pyx_t_6 = 0;
        __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_9, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 607, __pyx_L8_error)
        __Pyx_GOTREF(__pyx_t_5);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    if (likely(PyList_CheckExact(__pyx_t_5)) || PyTuple_CheckExact(__pyx_t_5)) {
      __pyx_t_7 = __pyx_t_5; __Pyx_INCREF(__pyx_t_7); __pyx_t_10 = 0;
      __pyx_t_11 = NULL;
    } else {
      __pyx_t_10 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 607, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_11 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 607, __pyx_L8_error)
    }
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    for (;;) {
      if (likely(!__pyx_t_11)) {
        if (likely(PyList_CheckExact(__pyx_t_7))) {
          if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_7)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_5 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_10); __Pyx_INCREF(__pyx_t_5); __pyx_t_10++; if (unlikely(0 < 0)) __PYX_ERR(0, 607, __pyx_L8_error)
          #else
          __pyx_t_5 = PySequence_ITEM(__pyx_t_7, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 607, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_5);
          #endif
        } else {
          if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_10); __Pyx_INCREF(__pyx_t_5); __pyx_t_10++; if (unlikely(0 < 0)) __PYX_ERR(0, 607, __pyx_L8_error)
          #else
          __pyx_t_5 = PySequence_ITEM(__pyx_t_7, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 607, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_5);
          #endif
        }
      } else {
        __pyx_t_5 = __pyx_t_11(__pyx_t_7);
        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, 607, __pyx_L8_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_5);
      }
      __Pyx_XDECREF_SET(__pyx_9genexpr19__pyx_v_node, __pyx_t_5);
      __pyx_t_5 = 0;

      /* "discodop/disambiguation.pyx":604
 * 	elif isinstance(deriv, str) and backtransform is None:
 * 		deriv = Tree(deriv)
 * 		result = [writediscbrackettree(             # <<<<<<<<<<<<<<
 * 				REMOVEIDS.sub('', str(splitfrag(node))),
 * 				chart.sent).rstrip()
 */
      __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_writediscbrackettree); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 604, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_6);

      /* "discodop/disambiguation.pyx":605
 * 		deriv = Tree(deriv)
 * 		result = [writediscbrackettree(
 * 				REMOVEIDS.sub('', str(splitfrag(node))),             # <<<<<<<<<<<<<<
 * 				chart.sent).rstrip()
 * 				for node in deriv.subtrees(frontiernt)]
 */
      __pyx_t_12 = __Pyx_GetModuleGlobalName(__pyx_n_s_REMOVEIDS); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 605, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_12);
      __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_sub); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 605, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_13);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_14 = __Pyx_GetModuleGlobalName(__pyx_n_s_splitfrag); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 605, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_14);
      __pyx_t_15 = NULL;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_14))) {
        __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_14);
        if (likely(__pyx_t_15)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_14);
          __Pyx_INCREF(__pyx_t_15);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_14, function);
        }
      }
      if (!__pyx_t_15) {
        __pyx_t_12 = __Pyx_PyObject_CallOneArg(__pyx_t_14, __pyx_9genexpr19__pyx_v_node); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 605, __pyx_L8_error)
        __Pyx_GOTREF(__pyx_t_12);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_14)) {
          PyObject *__pyx_temp[2] = {__pyx_t_15, __pyx_9genexpr19__pyx_v_node};
          __pyx_t_12 = __Pyx_PyFunction_FastCall(__pyx_t_14, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 605, __pyx_L8_error)
          __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
          __Pyx_GOTREF(__pyx_t_12);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_14)) {
          PyObject *__pyx_temp[2] = {__pyx_t_15, __pyx_9genexpr19__pyx_v_node};
          __pyx_t_12 = __Pyx_PyCFunction_FastCall(__pyx_t_14, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 605, __pyx_L8_error)
          __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
          __Pyx_GOTREF(__pyx_t_12);
        } else
        #endif
        {
          __pyx_t_16 = PyTuple_New(1+1); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 605, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_16);
          __Pyx_GIVEREF(__pyx_t_15); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_15); __pyx_t_15 = NULL;
          __Pyx_INCREF(__pyx_9genexpr19__pyx_v_node);
          __Pyx_GIVEREF(__pyx_9genexpr19__pyx_v_node);
          PyTuple_SET_ITEM(__pyx_t_16, 0+1, __pyx_9genexpr19__pyx_v_node);
          __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_14, __pyx_t_16, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 605, __pyx_L8_error)
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_14 = PyTuple_New(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 605, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_14);
      __Pyx_GIVEREF(__pyx_t_12);
      PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_12);
      __pyx_t_12 = 0;
      __pyx_t_12 = __Pyx_PyObject_Call(((PyObject *)(&PyUnicode_Type)), __pyx_t_14, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 605, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_14 = NULL;
      __pyx_t_17 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_13))) {
        __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_13);
        if (likely(__pyx_t_14)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13);
          __Pyx_INCREF(__pyx_t_14);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_13, function);
          __pyx_t_17 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_13)) {
        PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_kp_u__4, __pyx_t_12};
        __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 605, __pyx_L8_error)
        __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_13)) {
        PyObject *__pyx_temp[3] = {__pyx_t_14, __pyx_kp_u__4, __pyx_t_12};
        __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_13, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 605, __pyx_L8_error)
        __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      } else
      #endif
      {
        __pyx_t_16 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 605, __pyx_L8_error)
        __Pyx_GOTREF(__pyx_t_16);
        if (__pyx_t_14) {
          __Pyx_GIVEREF(__pyx_t_14); PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_14); __pyx_t_14 = NULL;
        }
        __Pyx_INCREF(__pyx_kp_u__4);
        __Pyx_GIVEREF(__pyx_kp_u__4);
        PyTuple_SET_ITEM(__pyx_t_16, 0+__pyx_t_17, __pyx_kp_u__4);
        __Pyx_GIVEREF(__pyx_t_12);
        PyTuple_SET_ITEM(__pyx_t_16, 1+__pyx_t_17, __pyx_t_12);
        __pyx_t_12 = 0;
        __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_16, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 605, __pyx_L8_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      }
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;

      /* "discodop/disambiguation.pyx":606
 * 		result = [writediscbrackettree(
 * 				REMOVEIDS.sub('', str(splitfrag(node))),
 * 				chart.sent).rstrip()             # <<<<<<<<<<<<<<
 * 				for node in deriv.subtrees(frontiernt)]
 * 	elif isinstance(deriv, str):
 */
      __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_v_chart, __pyx_n_s_sent); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 606, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_13);
      __pyx_t_16 = NULL;
      __pyx_t_17 = 0;
      if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_16)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_16);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
          __pyx_t_17 = 1;
        }
      }
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_t_8, __pyx_t_13};
        __pyx_t_9 = __Pyx_PyFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 604, __pyx_L8_error)
        __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_6)) {
        PyObject *__pyx_temp[3] = {__pyx_t_16, __pyx_t_8, __pyx_t_13};
        __pyx_t_9 = __Pyx_PyCFunction_FastCall(__pyx_t_6, __pyx_temp+1-__pyx_t_17, 2+__pyx_t_17); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 604, __pyx_L8_error)
        __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      } else
      #endif
      {
        __pyx_t_12 = PyTuple_New(2+__pyx_t_17); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 604, __pyx_L8_error)
        __Pyx_GOTREF(__pyx_t_12);
        if (__pyx_t_16) {
          __Pyx_GIVEREF(__pyx_t_16); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_16); __pyx_t_16 = NULL;
        }
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_17, __pyx_t_8);
        __Pyx_GIVEREF(__pyx_t_13);
        PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_17, __pyx_t_13);
        __pyx_t_8 = 0;
        __pyx_t_13 = 0;
        __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_12, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 604, __pyx_L8_error)
        __Pyx_GOTREF(__pyx_t_9);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      }
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_rstrip); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 606, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_9 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_6))) {
        __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_6);
        if (likely(__pyx_t_9)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6);
          __Pyx_INCREF(__pyx_t_9);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_6, function);
        }
      }
      if (__pyx_t_9) {
        __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_t_6, __pyx_t_9); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 606, __pyx_L8_error)
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      } else {
        __pyx_t_5 = __Pyx_PyObject_CallNoArg(__pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 606, __pyx_L8_error)
      }
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_5))) __PYX_ERR(0, 604, __pyx_L8_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

      /* "discodop/disambiguation.pyx":607
 * 				REMOVEIDS.sub('', str(splitfrag(node))),
 * 				chart.sent).rstrip()
 * 				for node in deriv.subtrees(frontiernt)]             # <<<<<<<<<<<<<<
 * 	elif isinstance(deriv, str):
 * 		deriv = Tree(deriv)
 */
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_XDECREF(__pyx_9genexpr19__pyx_v_node);
    goto __pyx_L11_exit_scope;
    __pyx_L8_error:;
    __Pyx_XDECREF(__pyx_9genexpr19__pyx_v_node);
    goto __pyx_L1_error;
    __pyx_L11_exit_scope:;
  } /* exit inner scope */
  __Pyx_DECREF_SET(__pyx_v_result, ((PyObject*)__pyx_t_1));
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":602
 * 	if isinstance(deriv, RankedEdge):
 * 		fragmentsinderiv_(deriv, chart, backtransform, result)
 * 	elif isinstance(deriv, str) and backtransform is None:             # <<<<<<<<<<<<<<
 * 		deriv = Tree(deriv)
 * 		result = [writediscbrackettree(
 */
  goto __pyx_L3;
}

/* "discodop/disambiguation.pyx":608
 * 				chart.sent).rstrip()
 * 				for node in deriv.subtrees(frontiernt)]
 * 	elif isinstance(deriv, str):             # <<<<<<<<<<<<<<
 * 		deriv = Tree(deriv)
 * 		fragmentsinderiv_str(deriv, chart, backtransform, result)
 */
__pyx_t_3 = PyUnicode_Check(__pyx_v_deriv); 
__pyx_t_2 = (__pyx_t_3 != 0);
if (__pyx_t_2) {

  /* "discodop/disambiguation.pyx":609
 * 				for node in deriv.subtrees(frontiernt)]
 * 	elif isinstance(deriv, str):
 * 		deriv = Tree(deriv)             # <<<<<<<<<<<<<<
 * 		fragmentsinderiv_str(deriv, chart, backtransform, result)
 * 	else:
 */
  __pyx_t_7 = __Pyx_GetModuleGlobalName(__pyx_n_s_Tree); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 609, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_5 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(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_1 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_v_deriv); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 609, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_7)) {
      PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_deriv};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 609, __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_7)) {
      PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_v_deriv};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_7, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 609, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else
    #endif
    {
      __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 609, __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_INCREF(__pyx_v_deriv);
      __Pyx_GIVEREF(__pyx_v_deriv);
      PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_deriv);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 609, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF_SET(__pyx_v_deriv, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":610
 * 	elif isinstance(deriv, str):
 * 		deriv = Tree(deriv)
 * 		fragmentsinderiv_str(deriv, chart, backtransform, result)             # <<<<<<<<<<<<<<
 * 	else:
 * 		raise ValueError('deriv should be a RankedEdge or a string.')
 */
  if (!(likely(((__pyx_v_chart) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_chart, __pyx_ptype_8discodop_10containers_Chart))))) __PYX_ERR(0, 610, __pyx_L1_error)
  __pyx_t_1 = __pyx_f_8discodop_14disambiguation_fragmentsinderiv_str(__pyx_v_deriv, ((struct __pyx_obj_8discodop_10containers_Chart *)__pyx_v_chart), __pyx_v_backtransform, __pyx_v_result); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 610, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":608
 * 				chart.sent).rstrip()
 * 				for node in deriv.subtrees(frontiernt)]
 * 	elif isinstance(deriv, str):             # <<<<<<<<<<<<<<
 * 		deriv = Tree(deriv)
 * 		fragmentsinderiv_str(deriv, chart, backtransform, result)
 */
  goto __pyx_L3;
}

/* "discodop/disambiguation.pyx":612
 * 		fragmentsinderiv_str(deriv, chart, backtransform, result)
 * 	else:
 * 		raise ValueError('deriv should be a RankedEdge or a string.')             # <<<<<<<<<<<<<<
 * 	return [_fragments.pygetsent(frag) for frag in result]
 * 
 */
/*else*/ {
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__19, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(0, 612, __pyx_L1_error)
}
__pyx_L3:;

/* "discodop/disambiguation.pyx":613
 * 	else:
 * 		raise ValueError('deriv should be a RankedEdge or a string.')
 * 	return [_fragments.pygetsent(frag) for frag in result]             # <<<<<<<<<<<<<<
 * 
 * 
 */
__Pyx_XDECREF(__pyx_r);
{ /* enter inner scope */
  PyObject *__pyx_9genexpr20__pyx_v_frag = NULL;
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 613, __pyx_L14_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = __pyx_v_result; __Pyx_INCREF(__pyx_t_7); __pyx_t_10 = 0;
  for (;;) {
    if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_7)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_6 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_10); __Pyx_INCREF(__pyx_t_6); __pyx_t_10++; if (unlikely(0 < 0)) __PYX_ERR(0, 613, __pyx_L14_error)
    #else
    __pyx_t_6 = PySequence_ITEM(__pyx_t_7, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 613, __pyx_L14_error)
    __Pyx_GOTREF(__pyx_t_6);
    #endif
    __Pyx_XDECREF_SET(__pyx_9genexpr20__pyx_v_frag, __pyx_t_6);
    __pyx_t_6 = 0;
    __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_fragments); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 613, __pyx_L14_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_pygetsent); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 613, __pyx_L14_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __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_6 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_9genexpr20__pyx_v_frag); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 613, __pyx_L14_error)
      __Pyx_GOTREF(__pyx_t_6);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_9)) {
        PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_9genexpr20__pyx_v_frag};
        __pyx_t_6 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 613, __pyx_L14_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_9)) {
        PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_9genexpr20__pyx_v_frag};
        __pyx_t_6 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 613, __pyx_L14_error)
        __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
        __Pyx_GOTREF(__pyx_t_6);
      } else
      #endif
      {
        __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 613, __pyx_L14_error)
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_5); __pyx_t_5 = NULL;
        __Pyx_INCREF(__pyx_9genexpr20__pyx_v_frag);
        __Pyx_GIVEREF(__pyx_9genexpr20__pyx_v_frag);
        PyTuple_SET_ITEM(__pyx_t_12, 0+1, __pyx_9genexpr20__pyx_v_frag);
        __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_12, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 613, __pyx_L14_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 613, __pyx_L14_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_XDECREF(__pyx_9genexpr20__pyx_v_frag);
  goto __pyx_L17_exit_scope;
  __pyx_L14_error:;
  __Pyx_XDECREF(__pyx_9genexpr20__pyx_v_frag);
  goto __pyx_L1_error;
  __pyx_L17_exit_scope:;
} /* exit inner scope */
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;

/* "discodop/disambiguation.pyx":593
 * 
 * 
 * def fragmentsinderiv(deriv, chart, list backtransform):             # <<<<<<<<<<<<<<
 * 	"""Extract the list of fragments that were used in a given derivation.
 * 
 */

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_XDECREF(__pyx_t_9);
__Pyx_XDECREF(__pyx_t_12);
__Pyx_XDECREF(__pyx_t_13);
__Pyx_XDECREF(__pyx_t_14);
__Pyx_XDECREF(__pyx_t_15);
__Pyx_XDECREF(__pyx_t_16);
__Pyx_AddTraceback("discodop.disambiguation.fragmentsinderiv", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_result);
__Pyx_XDECREF(__pyx_v_deriv);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":616
 * 
 * 
 * cdef fragmentsinderiv_(RankedEdge deriv, Chart chart,             # <<<<<<<<<<<<<<
 * 		list backtransform, list result):
 * 	cdef RankedEdge child
 */

static PyObject *__pyx_f_8discodop_14disambiguation_fragmentsinderiv_(struct __pyx_obj_8discodop_10containers_RankedEdge *__pyx_v_deriv, struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, PyObject *__pyx_v_backtransform, PyObject *__pyx_v_result) {
struct __pyx_obj_8discodop_10containers_RankedEdge *__pyx_v_child = 0;
PyObject *__pyx_v_children = 0;
PyObject *__pyx_v_frag = 0;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
int __pyx_t_2;
PyObject *__pyx_t_3 = NULL;
int __pyx_t_4;
PyObject *__pyx_t_5 = NULL;
Py_ssize_t __pyx_t_6;
PyObject *__pyx_t_7 = NULL;
uint32_t __pyx_t_8;
PyObject *__pyx_t_9 = NULL;
PyObject *__pyx_t_10 = NULL;
int __pyx_t_11;
PyObject *__pyx_t_12 = NULL;
PyObject *__pyx_t_13 = NULL;
PyObject *__pyx_t_14 = NULL;
int __pyx_t_15;
__Pyx_RefNannySetupContext("fragmentsinderiv_", 0);
__Pyx_INCREF((PyObject *)__pyx_v_deriv);

/* "discodop/disambiguation.pyx":619
 * 		list backtransform, list result):
 * 	cdef RankedEdge child
 * 	cdef list children = []             # <<<<<<<<<<<<<<
 * 	cdef str frag = backtransform[deriv.edge.rule.no]  # template
 * 
 */
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 619, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_children = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":620
 * 	cdef RankedEdge child
 * 	cdef list children = []
 * 	cdef str frag = backtransform[deriv.edge.rule.no]  # template             # <<<<<<<<<<<<<<
 * 
 * 	# collect all children w/on the fly left-factored debinarization
 */
if (unlikely(__pyx_v_backtransform == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
  __PYX_ERR(0, 620, __pyx_L1_error)
}
if (!(likely(PyUnicode_CheckExact(PyList_GET_ITEM(__pyx_v_backtransform, __pyx_v_deriv->edge->rule->no)))||((PyList_GET_ITEM(__pyx_v_backtransform, __pyx_v_deriv->edge->rule->no)) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(PyList_GET_ITEM(__pyx_v_backtransform, __pyx_v_deriv->edge->rule->no))->tp_name), 0))) __PYX_ERR(0, 620, __pyx_L1_error)
__pyx_t_1 = PyList_GET_ITEM(__pyx_v_backtransform, __pyx_v_deriv->edge->rule->no);
__Pyx_INCREF(__pyx_t_1);
__pyx_v_frag = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":623
 * 
 * 	# collect all children w/on the fly left-factored debinarization
 * 	if deriv.edge.rule.rhs2:  # is there a right child?             # <<<<<<<<<<<<<<
 * 		# keep going while left child is part of same binarized constituent
 * 		# instead of looking for a binarization marker in the label string, we
 */
__pyx_t_2 = (__pyx_v_deriv->edge->rule->rhs2 != 0);
if (__pyx_t_2) {

  /* "discodop/disambiguation.pyx":627
 * 		# instead of looking for a binarization marker in the label string, we
 * 		# use the fact that such labels do not have a mapping as proxy.
 * 		while chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:             # <<<<<<<<<<<<<<
 * 			# one of the right children
 * 			children.append((<DoubleEntry>chart.rankededges[
 */
  while (1) {
    __pyx_t_2 = (((__pyx_v_chart->grammar->mapping[__pyx_v_deriv->edge->rule->rhs1]) == 0) != 0);
    if (!__pyx_t_2) break;

    /* "discodop/disambiguation.pyx":629
 * 		while chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 			# one of the right children
 * 			children.append((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 					chart.right(deriv)][deriv.right]).key)
 * 			# move on to next node in this binarized constituent
 */
    if (unlikely(__pyx_v_chart->rankededges == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 629, __pyx_L1_error)
    }

    /* "discodop/disambiguation.pyx":630
 * 			# one of the right children
 * 			children.append((<DoubleEntry>chart.rankededges[
 * 					chart.right(deriv)][deriv.right]).key)             # <<<<<<<<<<<<<<
 * 			# move on to next node in this binarized constituent
 * 			deriv = (<DoubleEntry>chart.rankededges[
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->right(__pyx_v_chart, __pyx_v_deriv); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 630, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "discodop/disambiguation.pyx":629
 * 		while chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 			# one of the right children
 * 			children.append((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 					chart.right(deriv)][deriv.right]).key)
 * 			# move on to next node in this binarized constituent
 */
    __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_chart->rankededges, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 629, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "discodop/disambiguation.pyx":630
 * 			# one of the right children
 * 			children.append((<DoubleEntry>chart.rankededges[
 * 					chart.right(deriv)][deriv.right]).key)             # <<<<<<<<<<<<<<
 * 			# move on to next node in this binarized constituent
 * 			deriv = (<DoubleEntry>chart.rankededges[
 */
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_3, __pyx_v_deriv->right, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 630, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "discodop/disambiguation.pyx":629
 * 		while chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 			# one of the right children
 * 			children.append((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 					chart.right(deriv)][deriv.right]).key)
 * 			# move on to next node in this binarized constituent
 */
    __pyx_t_3 = ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_1)->key;
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_children, __pyx_t_3); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(0, 629, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "discodop/disambiguation.pyx":632
 * 					chart.right(deriv)][deriv.right]).key)
 * 			# move on to next node in this binarized constituent
 * 			deriv = (<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 					chart.left(deriv)][deriv.left]).key
 * 		# last right child
 */
    if (unlikely(__pyx_v_chart->rankededges == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 632, __pyx_L1_error)
    }

    /* "discodop/disambiguation.pyx":633
 * 			# move on to next node in this binarized constituent
 * 			deriv = (<DoubleEntry>chart.rankededges[
 * 					chart.left(deriv)][deriv.left]).key             # <<<<<<<<<<<<<<
 * 		# last right child
 * 		if deriv.edge.rule.rhs2:  # is there a right child?
 */
    __pyx_t_3 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->left(__pyx_v_chart, __pyx_v_deriv); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 633, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);

    /* "discodop/disambiguation.pyx":632
 * 					chart.right(deriv)][deriv.right]).key)
 * 			# move on to next node in this binarized constituent
 * 			deriv = (<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 					chart.left(deriv)][deriv.left]).key
 * 		# last right child
 */
    __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_chart->rankededges, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 632, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "discodop/disambiguation.pyx":633
 * 			# move on to next node in this binarized constituent
 * 			deriv = (<DoubleEntry>chart.rankededges[
 * 					chart.left(deriv)][deriv.left]).key             # <<<<<<<<<<<<<<
 * 		# last right child
 * 		if deriv.edge.rule.rhs2:  # is there a right child?
 */
    __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_1, __pyx_v_deriv->left, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 633, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "discodop/disambiguation.pyx":632
 * 					chart.right(deriv)][deriv.right]).key)
 * 			# move on to next node in this binarized constituent
 * 			deriv = (<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 					chart.left(deriv)][deriv.left]).key
 * 		# last right child
 */
    if (!(likely(((((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_3)->key) == Py_None) || likely(__Pyx_TypeTest(((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_3)->key, __pyx_ptype_8discodop_10containers_RankedEdge))))) __PYX_ERR(0, 633, __pyx_L1_error)

    /* "discodop/disambiguation.pyx":633
 * 			# move on to next node in this binarized constituent
 * 			deriv = (<DoubleEntry>chart.rankededges[
 * 					chart.left(deriv)][deriv.left]).key             # <<<<<<<<<<<<<<
 * 		# last right child
 * 		if deriv.edge.rule.rhs2:  # is there a right child?
 */
    __pyx_t_1 = ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_3)->key;
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF_SET(__pyx_v_deriv, ((struct __pyx_obj_8discodop_10containers_RankedEdge *)__pyx_t_1));
    __pyx_t_1 = 0;
  }

  /* "discodop/disambiguation.pyx":635
 * 					chart.left(deriv)][deriv.left]).key
 * 		# last right child
 * 		if deriv.edge.rule.rhs2:  # is there a right child?             # <<<<<<<<<<<<<<
 * 			children.append((<DoubleEntry>chart.rankededges[
 * 					chart.right(deriv)][deriv.right]).key)
 */
  __pyx_t_2 = (__pyx_v_deriv->edge->rule->rhs2 != 0);
  if (__pyx_t_2) {

    /* "discodop/disambiguation.pyx":636
 * 		# last right child
 * 		if deriv.edge.rule.rhs2:  # is there a right child?
 * 			children.append((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 					chart.right(deriv)][deriv.right]).key)
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 */
    if (unlikely(__pyx_v_chart->rankededges == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 636, __pyx_L1_error)
    }

    /* "discodop/disambiguation.pyx":637
 * 		if deriv.edge.rule.rhs2:  # is there a right child?
 * 			children.append((<DoubleEntry>chart.rankededges[
 * 					chart.right(deriv)][deriv.right]).key)             # <<<<<<<<<<<<<<
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 		deriv = (<DoubleEntry>chart.rankededges[
 */
    __pyx_t_1 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->right(__pyx_v_chart, __pyx_v_deriv); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 637, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);

    /* "discodop/disambiguation.pyx":636
 * 		# last right child
 * 		if deriv.edge.rule.rhs2:  # is there a right child?
 * 			children.append((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 					chart.right(deriv)][deriv.right]).key)
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 */
    __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_chart->rankededges, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 636, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "discodop/disambiguation.pyx":637
 * 		if deriv.edge.rule.rhs2:  # is there a right child?
 * 			children.append((<DoubleEntry>chart.rankededges[
 * 					chart.right(deriv)][deriv.right]).key)             # <<<<<<<<<<<<<<
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 		deriv = (<DoubleEntry>chart.rankededges[
 */
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_t_3, __pyx_v_deriv->right, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 637, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "discodop/disambiguation.pyx":636
 * 		# last right child
 * 		if deriv.edge.rule.rhs2:  # is there a right child?
 * 			children.append((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 					chart.right(deriv)][deriv.right]).key)
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 */
    __pyx_t_3 = ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_1)->key;
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_children, __pyx_t_3); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(0, 636, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "discodop/disambiguation.pyx":635
 * 					chart.left(deriv)][deriv.left]).key
 * 		# last right child
 * 		if deriv.edge.rule.rhs2:  # is there a right child?             # <<<<<<<<<<<<<<
 * 			children.append((<DoubleEntry>chart.rankededges[
 * 					chart.right(deriv)][deriv.right]).key)
 */
  }

  /* "discodop/disambiguation.pyx":623
 * 
 * 	# collect all children w/on the fly left-factored debinarization
 * 	if deriv.edge.rule.rhs2:  # is there a right child?             # <<<<<<<<<<<<<<
 * 		# keep going while left child is part of same binarized constituent
 * 		# instead of looking for a binarization marker in the label string, we
 */
  goto __pyx_L3;
}

/* "discodop/disambiguation.pyx":638
 * 			children.append((<DoubleEntry>chart.rankededges[
 * 					chart.right(deriv)][deriv.right]).key)
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:             # <<<<<<<<<<<<<<
 * 		deriv = (<DoubleEntry>chart.rankededges[
 * 				chart.left(deriv)][deriv.left]).key
 */
__pyx_t_2 = (((__pyx_v_chart->grammar->mapping[__pyx_v_deriv->edge->rule->rhs1]) == 0) != 0);
if (__pyx_t_2) {

  /* "discodop/disambiguation.pyx":639
 * 					chart.right(deriv)][deriv.right]).key)
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 		deriv = (<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 				chart.left(deriv)][deriv.left]).key
 * 	# left-most child
 */
  if (unlikely(__pyx_v_chart->rankededges == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 639, __pyx_L1_error)
  }

  /* "discodop/disambiguation.pyx":640
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 		deriv = (<DoubleEntry>chart.rankededges[
 * 				chart.left(deriv)][deriv.left]).key             # <<<<<<<<<<<<<<
 * 	# left-most child
 * 	children.append((<DoubleEntry>chart.rankededges[
 */
  __pyx_t_3 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->left(__pyx_v_chart, __pyx_v_deriv); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 640, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);

  /* "discodop/disambiguation.pyx":639
 * 					chart.right(deriv)][deriv.right]).key)
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 		deriv = (<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 				chart.left(deriv)][deriv.left]).key
 * 	# left-most child
 */
  __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_chart->rankededges, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 639, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "discodop/disambiguation.pyx":640
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 		deriv = (<DoubleEntry>chart.rankededges[
 * 				chart.left(deriv)][deriv.left]).key             # <<<<<<<<<<<<<<
 * 	# left-most child
 * 	children.append((<DoubleEntry>chart.rankededges[
 */
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_t_1, __pyx_v_deriv->left, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 640, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":639
 * 					chart.right(deriv)][deriv.right]).key)
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 		deriv = (<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 				chart.left(deriv)][deriv.left]).key
 * 	# left-most child
 */
  if (!(likely(((((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_3)->key) == Py_None) || likely(__Pyx_TypeTest(((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_3)->key, __pyx_ptype_8discodop_10containers_RankedEdge))))) __PYX_ERR(0, 640, __pyx_L1_error)

  /* "discodop/disambiguation.pyx":640
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:
 * 		deriv = (<DoubleEntry>chart.rankededges[
 * 				chart.left(deriv)][deriv.left]).key             # <<<<<<<<<<<<<<
 * 	# left-most child
 * 	children.append((<DoubleEntry>chart.rankededges[
 */
  __pyx_t_1 = ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_3)->key;
  __Pyx_INCREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF_SET(__pyx_v_deriv, ((struct __pyx_obj_8discodop_10containers_RankedEdge *)__pyx_t_1));
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":638
 * 			children.append((<DoubleEntry>chart.rankededges[
 * 					chart.right(deriv)][deriv.right]).key)
 * 	elif chart.grammar.mapping[deriv.edge.rule.rhs1] == 0:             # <<<<<<<<<<<<<<
 * 		deriv = (<DoubleEntry>chart.rankededges[
 * 				chart.left(deriv)][deriv.left]).key
 */
}
__pyx_L3:;

/* "discodop/disambiguation.pyx":642
 * 				chart.left(deriv)][deriv.left]).key
 * 	# left-most child
 * 	children.append((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 			chart.left(deriv)][deriv.left]).key)
 * 
 */
if (unlikely(__pyx_v_chart->rankededges == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
  __PYX_ERR(0, 642, __pyx_L1_error)
}

/* "discodop/disambiguation.pyx":643
 * 	# left-most child
 * 	children.append((<DoubleEntry>chart.rankededges[
 * 			chart.left(deriv)][deriv.left]).key)             # <<<<<<<<<<<<<<
 * 
 * 	result.append(frag.format(*['(%s %s)' % (
 */
__pyx_t_1 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->left(__pyx_v_chart, __pyx_v_deriv); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 643, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);

/* "discodop/disambiguation.pyx":642
 * 				chart.left(deriv)][deriv.left]).key
 * 	# left-most child
 * 	children.append((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 			chart.left(deriv)][deriv.left]).key)
 * 
 */
__pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_chart->rankededges, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 642, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":643
 * 	# left-most child
 * 	children.append((<DoubleEntry>chart.rankededges[
 * 			chart.left(deriv)][deriv.left]).key)             # <<<<<<<<<<<<<<
 * 
 * 	result.append(frag.format(*['(%s %s)' % (
 */
__pyx_t_1 = __Pyx_GetItemInt(__pyx_t_3, __pyx_v_deriv->left, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 643, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

/* "discodop/disambiguation.pyx":642
 * 				chart.left(deriv)][deriv.left]).key
 * 	# left-most child
 * 	children.append((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 			chart.left(deriv)][deriv.left]).key)
 * 
 */
__pyx_t_3 = ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_1)->key;
__Pyx_INCREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_4 = __Pyx_PyList_Append(__pyx_v_children, __pyx_t_3); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(0, 642, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

/* "discodop/disambiguation.pyx":645
 * 			chart.left(deriv)][deriv.left]).key)
 * 
 * 	result.append(frag.format(*['(%s %s)' % (             # <<<<<<<<<<<<<<
 * 				chart.grammar.tolabel[chart.label(deriv.head)].split('@')[0],
 * 				('%d=%s' % (chart.lexidx(deriv.edge),
 */
if (unlikely(__pyx_v_result == Py_None)) {
  PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "append");
  __PYX_ERR(0, 645, __pyx_L1_error)
}
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_frag, __pyx_n_s_format); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 645, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
{ /* enter inner scope */
  struct __pyx_obj_8discodop_10containers_RankedEdge *__pyx_9genexpr21__pyx_v_deriv = NULL;
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 645, __pyx_L9_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "discodop/disambiguation.pyx":651
 * 					if '@' in chart.grammar.tolabel[chart.label(deriv.head)]
 * 					else yieldranges(chart.indices(deriv.head))))
 * 				for deriv in reversed(children)]))             # <<<<<<<<<<<<<<
 * 	# recursively visit all substitution sites
 * 	for child in reversed(children):
 */
  __pyx_t_5 = __pyx_v_children; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = PyList_GET_SIZE(__pyx_t_5) - 1;
  for (;;) {
    if (__pyx_t_6 < 0) break;
    if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_7 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_7); __pyx_t_6--; if (unlikely(0 < 0)) __PYX_ERR(0, 651, __pyx_L9_error)
    #else
    __pyx_t_7 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6--; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 651, __pyx_L9_error)
    __Pyx_GOTREF(__pyx_t_7);
    #endif
    if (!(likely(((__pyx_t_7) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_7, __pyx_ptype_8discodop_10containers_RankedEdge))))) __PYX_ERR(0, 651, __pyx_L9_error)
    __Pyx_XDECREF_SET(__pyx_9genexpr21__pyx_v_deriv, ((struct __pyx_obj_8discodop_10containers_RankedEdge *)__pyx_t_7));
    __pyx_t_7 = 0;

    /* "discodop/disambiguation.pyx":646
 * 
 * 	result.append(frag.format(*['(%s %s)' % (
 * 				chart.grammar.tolabel[chart.label(deriv.head)].split('@')[0],             # <<<<<<<<<<<<<<
 * 				('%d=%s' % (chart.lexidx(deriv.edge),
 * 					chart.sent[chart.lexidx(deriv.edge)])
 */
    if (unlikely(__pyx_v_chart->grammar->tolabel == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 646, __pyx_L9_error)
    }
    __pyx_t_7 = __pyx_9genexpr21__pyx_v_deriv->head;
    __Pyx_INCREF(__pyx_t_7);
    __pyx_t_8 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->label(__pyx_v_chart, __pyx_t_7);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(PyList_GET_ITEM(__pyx_v_chart->grammar->tolabel, __pyx_t_8), __pyx_n_s_split); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 646, __pyx_L9_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_tuple__20, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 646, __pyx_L9_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_9, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 646, __pyx_L9_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "discodop/disambiguation.pyx":649
 * 				('%d=%s' % (chart.lexidx(deriv.edge),
 * 					chart.sent[chart.lexidx(deriv.edge)])
 * 					if '@' in chart.grammar.tolabel[chart.label(deriv.head)]             # <<<<<<<<<<<<<<
 * 					else yieldranges(chart.indices(deriv.head))))
 * 				for deriv in reversed(children)]))
 */
    if (unlikely(__pyx_v_chart->grammar->tolabel == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 649, __pyx_L9_error)
    }
    __pyx_t_10 = __pyx_9genexpr21__pyx_v_deriv->head;
    __Pyx_INCREF(__pyx_t_10);
    __pyx_t_8 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->label(__pyx_v_chart, __pyx_t_10);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_kp_u__16, PyList_GET_ITEM(__pyx_v_chart->grammar->tolabel, __pyx_t_8), Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 649, __pyx_L9_error)
    if ((__pyx_t_2 != 0)) {

      /* "discodop/disambiguation.pyx":647
 * 	result.append(frag.format(*['(%s %s)' % (
 * 				chart.grammar.tolabel[chart.label(deriv.head)].split('@')[0],
 * 				('%d=%s' % (chart.lexidx(deriv.edge),             # <<<<<<<<<<<<<<
 * 					chart.sent[chart.lexidx(deriv.edge)])
 * 					if '@' in chart.grammar.tolabel[chart.label(deriv.head)]
 */
      __pyx_t_10 = __Pyx_PyInt_From_int(((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->lexidx(__pyx_v_chart, __pyx_9genexpr21__pyx_v_deriv->edge)); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 647, __pyx_L9_error)
      __Pyx_GOTREF(__pyx_t_10);

      /* "discodop/disambiguation.pyx":648
 * 				chart.grammar.tolabel[chart.label(deriv.head)].split('@')[0],
 * 				('%d=%s' % (chart.lexidx(deriv.edge),
 * 					chart.sent[chart.lexidx(deriv.edge)])             # <<<<<<<<<<<<<<
 * 					if '@' in chart.grammar.tolabel[chart.label(deriv.head)]
 * 					else yieldranges(chart.indices(deriv.head))))
 */
      if (unlikely(__pyx_v_chart->sent == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 648, __pyx_L9_error)
      }
      __pyx_t_11 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->lexidx(__pyx_v_chart, __pyx_9genexpr21__pyx_v_deriv->edge);

      /* "discodop/disambiguation.pyx":647
 * 	result.append(frag.format(*['(%s %s)' % (
 * 				chart.grammar.tolabel[chart.label(deriv.head)].split('@')[0],
 * 				('%d=%s' % (chart.lexidx(deriv.edge),             # <<<<<<<<<<<<<<
 * 					chart.sent[chart.lexidx(deriv.edge)])
 * 					if '@' in chart.grammar.tolabel[chart.label(deriv.head)]
 */
      __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 647, __pyx_L9_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_GIVEREF(__pyx_t_10);
      PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_10);
      __Pyx_INCREF(PyList_GET_ITEM(__pyx_v_chart->sent, __pyx_t_11));
      __Pyx_GIVEREF(PyList_GET_ITEM(__pyx_v_chart->sent, __pyx_t_11));
      PyTuple_SET_ITEM(__pyx_t_12, 1, PyList_GET_ITEM(__pyx_v_chart->sent, __pyx_t_11));
      __pyx_t_10 = 0;
      __pyx_t_10 = PyUnicode_Format(__pyx_kp_u_d_s, __pyx_t_12); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 647, __pyx_L9_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_9 = __pyx_t_10;
      __pyx_t_10 = 0;
    } else {

      /* "discodop/disambiguation.pyx":650
 * 					chart.sent[chart.lexidx(deriv.edge)])
 * 					if '@' in chart.grammar.tolabel[chart.label(deriv.head)]
 * 					else yieldranges(chart.indices(deriv.head))))             # <<<<<<<<<<<<<<
 * 				for deriv in reversed(children)]))
 * 	# recursively visit all substitution sites
 */
      __pyx_t_12 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_chart), __pyx_n_s_indices); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 650, __pyx_L9_error)
      __Pyx_GOTREF(__pyx_t_12);
      __pyx_t_13 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) {
        __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12);
        if (likely(__pyx_t_13)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
          __Pyx_INCREF(__pyx_t_13);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_12, function);
        }
      }
      if (!__pyx_t_13) {
        __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_9genexpr21__pyx_v_deriv->head); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 650, __pyx_L9_error)
        __Pyx_GOTREF(__pyx_t_10);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_12)) {
          PyObject *__pyx_temp[2] = {__pyx_t_13, __pyx_9genexpr21__pyx_v_deriv->head};
          __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_12, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 650, __pyx_L9_error)
          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
          __Pyx_GOTREF(__pyx_t_10);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_12)) {
          PyObject *__pyx_temp[2] = {__pyx_t_13, __pyx_9genexpr21__pyx_v_deriv->head};
          __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_12, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 650, __pyx_L9_error)
          __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
          __Pyx_GOTREF(__pyx_t_10);
        } else
        #endif
        {
          __pyx_t_14 = PyTuple_New(1+1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 650, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_14);
          __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_13); __pyx_t_13 = NULL;
          __Pyx_INCREF(__pyx_9genexpr21__pyx_v_deriv->head);
          __Pyx_GIVEREF(__pyx_9genexpr21__pyx_v_deriv->head);
          PyTuple_SET_ITEM(__pyx_t_14, 0+1, __pyx_9genexpr21__pyx_v_deriv->head);
          __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_12, __pyx_t_14, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 650, __pyx_L9_error)
          __Pyx_GOTREF(__pyx_t_10);
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      if (!(likely(PyList_CheckExact(__pyx_t_10))||((__pyx_t_10) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_10)->tp_name), 0))) __PYX_ERR(0, 650, __pyx_L9_error)
      __pyx_t_12 = __pyx_f_8discodop_10containers_yieldranges(((PyObject*)__pyx_t_10)); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 650, __pyx_L9_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_9 = __pyx_t_12;
      __pyx_t_12 = 0;
    }

    /* "discodop/disambiguation.pyx":646
 * 
 * 	result.append(frag.format(*['(%s %s)' % (
 * 				chart.grammar.tolabel[chart.label(deriv.head)].split('@')[0],             # <<<<<<<<<<<<<<
 * 				('%d=%s' % (chart.lexidx(deriv.edge),
 * 					chart.sent[chart.lexidx(deriv.edge)])
 */
    __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 646, __pyx_L9_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_9);
    __pyx_t_7 = 0;
    __pyx_t_9 = 0;

    /* "discodop/disambiguation.pyx":645
 * 			chart.left(deriv)][deriv.left]).key)
 * 
 * 	result.append(frag.format(*['(%s %s)' % (             # <<<<<<<<<<<<<<
 * 				chart.grammar.tolabel[chart.label(deriv.head)].split('@')[0],
 * 				('%d=%s' % (chart.lexidx(deriv.edge),
 */
    __pyx_t_9 = PyUnicode_Format(__pyx_kp_u_s_s_2, __pyx_t_12); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 645, __pyx_L9_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_9))) __PYX_ERR(0, 645, __pyx_L9_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

    /* "discodop/disambiguation.pyx":651
 * 					if '@' in chart.grammar.tolabel[chart.label(deriv.head)]
 * 					else yieldranges(chart.indices(deriv.head))))
 * 				for deriv in reversed(children)]))             # <<<<<<<<<<<<<<
 * 	# recursively visit all substitution sites
 * 	for child in reversed(children):
 */
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_XDECREF((PyObject *)__pyx_9genexpr21__pyx_v_deriv);
  goto __pyx_L12_exit_scope;
  __pyx_L9_error:;
  __Pyx_XDECREF((PyObject *)__pyx_9genexpr21__pyx_v_deriv);
  goto __pyx_L1_error;
  __pyx_L12_exit_scope:;
} /* exit inner scope */

/* "discodop/disambiguation.pyx":645
 * 			chart.left(deriv)][deriv.left]).key)
 * 
 * 	result.append(frag.format(*['(%s %s)' % (             # <<<<<<<<<<<<<<
 * 				chart.grammar.tolabel[chart.label(deriv.head)].split('@')[0],
 * 				('%d=%s' % (chart.lexidx(deriv.edge),
 */
__pyx_t_5 = PySequence_Tuple(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 645, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 645, __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_4 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(0, 645, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":653
 * 				for deriv in reversed(children)]))
 * 	# recursively visit all substitution sites
 * 	for child in reversed(children):             # <<<<<<<<<<<<<<
 * 		if child.edge.rule is not NULL:
 * 			fragmentsinderiv_(child, chart, backtransform, result)
 */
__pyx_t_1 = __pyx_v_children; __Pyx_INCREF(__pyx_t_1); __pyx_t_6 = PyList_GET_SIZE(__pyx_t_1) - 1;
for (;;) {
  if (__pyx_t_6 < 0) break;
  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, 653, __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, 653, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  #endif
  if (!(likely(((__pyx_t_5) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_5, __pyx_ptype_8discodop_10containers_RankedEdge))))) __PYX_ERR(0, 653, __pyx_L1_error)
  __Pyx_XDECREF_SET(__pyx_v_child, ((struct __pyx_obj_8discodop_10containers_RankedEdge *)__pyx_t_5));
  __pyx_t_5 = 0;

  /* "discodop/disambiguation.pyx":654
 * 	# recursively visit all substitution sites
 * 	for child in reversed(children):
 * 		if child.edge.rule is not NULL:             # <<<<<<<<<<<<<<
 * 			fragmentsinderiv_(child, chart, backtransform, result)
 * 		elif '@' not in chart.grammar.tolabel[chart.label(child.head)]:
 */
  __pyx_t_2 = ((__pyx_v_child->edge->rule != NULL) != 0);
  if (__pyx_t_2) {

    /* "discodop/disambiguation.pyx":655
 * 	for child in reversed(children):
 * 		if child.edge.rule is not NULL:
 * 			fragmentsinderiv_(child, chart, backtransform, result)             # <<<<<<<<<<<<<<
 * 		elif '@' not in chart.grammar.tolabel[chart.label(child.head)]:
 * 			result.append('(%s %d=%s)' % (
 */
    __pyx_t_5 = __pyx_f_8discodop_14disambiguation_fragmentsinderiv_(__pyx_v_child, __pyx_v_chart, __pyx_v_backtransform, __pyx_v_result); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 655, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "discodop/disambiguation.pyx":654
 * 	# recursively visit all substitution sites
 * 	for child in reversed(children):
 * 		if child.edge.rule is not NULL:             # <<<<<<<<<<<<<<
 * 			fragmentsinderiv_(child, chart, backtransform, result)
 * 		elif '@' not in chart.grammar.tolabel[chart.label(child.head)]:
 */
    goto __pyx_L15;
  }

  /* "discodop/disambiguation.pyx":656
 * 		if child.edge.rule is not NULL:
 * 			fragmentsinderiv_(child, chart, backtransform, result)
 * 		elif '@' not in chart.grammar.tolabel[chart.label(child.head)]:             # <<<<<<<<<<<<<<
 * 			result.append('(%s %d=%s)' % (
 * 					chart.grammar.tolabel[chart.label(child.head)],
 */
  if (unlikely(__pyx_v_chart->grammar->tolabel == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 656, __pyx_L1_error)
  }
  __pyx_t_5 = __pyx_v_child->head;
  __Pyx_INCREF(__pyx_t_5);
  __pyx_t_8 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->label(__pyx_v_chart, __pyx_t_5);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_kp_u__16, PyList_GET_ITEM(__pyx_v_chart->grammar->tolabel, __pyx_t_8), Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 656, __pyx_L1_error)
  __pyx_t_15 = (__pyx_t_2 != 0);
  if (__pyx_t_15) {

    /* "discodop/disambiguation.pyx":657
 * 			fragmentsinderiv_(child, chart, backtransform, result)
 * 		elif '@' not in chart.grammar.tolabel[chart.label(child.head)]:
 * 			result.append('(%s %d=%s)' % (             # <<<<<<<<<<<<<<
 * 					chart.grammar.tolabel[chart.label(child.head)],
 * 					chart.lexidx(child.edge),
 */
    if (unlikely(__pyx_v_result == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "append");
      __PYX_ERR(0, 657, __pyx_L1_error)
    }

    /* "discodop/disambiguation.pyx":658
 * 		elif '@' not in chart.grammar.tolabel[chart.label(child.head)]:
 * 			result.append('(%s %d=%s)' % (
 * 					chart.grammar.tolabel[chart.label(child.head)],             # <<<<<<<<<<<<<<
 * 					chart.lexidx(child.edge),
 * 					chart.sent[chart.lexidx(child.edge)]))
 */
    if (unlikely(__pyx_v_chart->grammar->tolabel == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 658, __pyx_L1_error)
    }
    __pyx_t_5 = __pyx_v_child->head;
    __Pyx_INCREF(__pyx_t_5);
    __pyx_t_8 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->label(__pyx_v_chart, __pyx_t_5);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "discodop/disambiguation.pyx":659
 * 			result.append('(%s %d=%s)' % (
 * 					chart.grammar.tolabel[chart.label(child.head)],
 * 					chart.lexidx(child.edge),             # <<<<<<<<<<<<<<
 * 					chart.sent[chart.lexidx(child.edge)]))
 * 
 */
    __pyx_t_5 = __Pyx_PyInt_From_int(((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->lexidx(__pyx_v_chart, __pyx_v_child->edge)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 659, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);

    /* "discodop/disambiguation.pyx":660
 * 					chart.grammar.tolabel[chart.label(child.head)],
 * 					chart.lexidx(child.edge),
 * 					chart.sent[chart.lexidx(child.edge)]))             # <<<<<<<<<<<<<<
 * 
 * 
 */
    if (unlikely(__pyx_v_chart->sent == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 660, __pyx_L1_error)
    }
    __pyx_t_11 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->lexidx(__pyx_v_chart, __pyx_v_child->edge);

    /* "discodop/disambiguation.pyx":658
 * 		elif '@' not in chart.grammar.tolabel[chart.label(child.head)]:
 * 			result.append('(%s %d=%s)' % (
 * 					chart.grammar.tolabel[chart.label(child.head)],             # <<<<<<<<<<<<<<
 * 					chart.lexidx(child.edge),
 * 					chart.sent[chart.lexidx(child.edge)]))
 */
    __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 658, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_INCREF(PyList_GET_ITEM(__pyx_v_chart->grammar->tolabel, __pyx_t_8));
    __Pyx_GIVEREF(PyList_GET_ITEM(__pyx_v_chart->grammar->tolabel, __pyx_t_8));
    PyTuple_SET_ITEM(__pyx_t_3, 0, PyList_GET_ITEM(__pyx_v_chart->grammar->tolabel, __pyx_t_8));
    __Pyx_GIVEREF(__pyx_t_5);
    PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_5);
    __Pyx_INCREF(PyList_GET_ITEM(__pyx_v_chart->sent, __pyx_t_11));
    __Pyx_GIVEREF(PyList_GET_ITEM(__pyx_v_chart->sent, __pyx_t_11));
    PyTuple_SET_ITEM(__pyx_t_3, 2, PyList_GET_ITEM(__pyx_v_chart->sent, __pyx_t_11));
    __pyx_t_5 = 0;

    /* "discodop/disambiguation.pyx":657
 * 			fragmentsinderiv_(child, chart, backtransform, result)
 * 		elif '@' not in chart.grammar.tolabel[chart.label(child.head)]:
 * 			result.append('(%s %d=%s)' % (             # <<<<<<<<<<<<<<
 * 					chart.grammar.tolabel[chart.label(child.head)],
 * 					chart.lexidx(child.edge),
 */
    __pyx_t_5 = PyUnicode_Format(__pyx_kp_u_s_d_s, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 657, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_4 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_5); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(0, 657, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

    /* "discodop/disambiguation.pyx":656
 * 		if child.edge.rule is not NULL:
 * 			fragmentsinderiv_(child, chart, backtransform, result)
 * 		elif '@' not in chart.grammar.tolabel[chart.label(child.head)]:             # <<<<<<<<<<<<<<
 * 			result.append('(%s %d=%s)' % (
 * 					chart.grammar.tolabel[chart.label(child.head)],
 */
  }
  __pyx_L15:;

  /* "discodop/disambiguation.pyx":653
 * 				for deriv in reversed(children)]))
 * 	# recursively visit all substitution sites
 * 	for child in reversed(children):             # <<<<<<<<<<<<<<
 * 		if child.edge.rule is not NULL:
 * 			fragmentsinderiv_(child, chart, backtransform, result)
 */
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":616
 * 
 * 
 * cdef fragmentsinderiv_(RankedEdge deriv, Chart chart,             # <<<<<<<<<<<<<<
 * 		list backtransform, list result):
 * 	cdef RankedEdge child
 */

/* 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_5);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_9);
__Pyx_XDECREF(__pyx_t_10);
__Pyx_XDECREF(__pyx_t_12);
__Pyx_XDECREF(__pyx_t_13);
__Pyx_XDECREF(__pyx_t_14);
__Pyx_AddTraceback("discodop.disambiguation.fragmentsinderiv_", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_child);
__Pyx_XDECREF(__pyx_v_children);
__Pyx_XDECREF(__pyx_v_frag);
__Pyx_XDECREF((PyObject *)__pyx_v_deriv);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":663
 * 
 * 
 * cdef fragmentsinderiv_str(deriv, Chart chart, list backtransform, list result):             # <<<<<<<<<<<<<<
 * 	cdef list children = []
 * 	cdef str frag
 */

static PyObject *__pyx_f_8discodop_14disambiguation_fragmentsinderiv_str(PyObject *__pyx_v_deriv, struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, PyObject *__pyx_v_backtransform, PyObject *__pyx_v_result) {
PyObject *__pyx_v_children = 0;
PyObject *__pyx_v_frag = 0;
PyObject *__pyx_v_child = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
Py_ssize_t __pyx_t_3;
int __pyx_t_4;
int __pyx_t_5;
int __pyx_t_6;
PyObject *__pyx_t_7 = NULL;
PyObject *__pyx_t_8 = NULL;
PyObject *__pyx_t_9 = NULL;
PyObject *__pyx_t_10 = NULL;
PyObject *__pyx_t_11 = NULL;
PyObject *__pyx_t_12 = NULL;
PyObject *__pyx_t_13 = NULL;
__Pyx_RefNannySetupContext("fragmentsinderiv_str", 0);
__Pyx_INCREF(__pyx_v_deriv);

/* "discodop/disambiguation.pyx":664
 * 
 * cdef fragmentsinderiv_str(deriv, Chart chart, list backtransform, list result):
 * 	cdef list children = []             # <<<<<<<<<<<<<<
 * 	cdef str frag
 * 	frag = backtransform[chart.grammar.rulenos[nodeprod(deriv)]]
 */
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 664, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_children = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":666
 * 	cdef list children = []
 * 	cdef str frag
 * 	frag = backtransform[chart.grammar.rulenos[nodeprod(deriv)]]             # <<<<<<<<<<<<<<
 * 	# collect children w/on the fly left-factored debinarization
 * 	if len(deriv) >= 2:  # is there a right child?
 */
if (unlikely(__pyx_v_backtransform == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
  __PYX_ERR(0, 666, __pyx_L1_error)
}
if (unlikely(__pyx_v_chart->grammar->rulenos == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
  __PYX_ERR(0, 666, __pyx_L1_error)
}
__pyx_t_1 = __pyx_f_8discodop_14disambiguation_nodeprod(__pyx_v_deriv); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 666, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_chart->grammar->rulenos, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 666, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = PyObject_GetItem(__pyx_v_backtransform, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 666, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 666, __pyx_L1_error)
__pyx_v_frag = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":668
 * 	frag = backtransform[chart.grammar.rulenos[nodeprod(deriv)]]
 * 	# collect children w/on the fly left-factored debinarization
 * 	if len(deriv) >= 2:  # is there a right child?             # <<<<<<<<<<<<<<
 * 		# keep going while left child is part of same binarized constituent
 * 		# this shortcut assumes that neverblockre is only used to avoid
 */
__pyx_t_3 = PyObject_Length(__pyx_v_deriv); if (unlikely(__pyx_t_3 == -1)) __PYX_ERR(0, 668, __pyx_L1_error)
__pyx_t_4 = ((__pyx_t_3 >= 2) != 0);
if (__pyx_t_4) {

  /* "discodop/disambiguation.pyx":672
 * 		# this shortcut assumes that neverblockre is only used to avoid
 * 		# blocking nonterminals from the double-dop binarization.
 * 		while '}<' in deriv[0].label:             # <<<<<<<<<<<<<<
 * 			# one of the right children
 * 			children.extend(reversed(deriv[1:]))
 */
  while (1) {
    __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_deriv, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 672, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_label); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 672, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_4 = (__Pyx_PySequence_ContainsTF(__pyx_kp_u__13, __pyx_t_2, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 672, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_5 = (__pyx_t_4 != 0);
    if (!__pyx_t_5) break;

    /* "discodop/disambiguation.pyx":674
 * 		while '}<' in deriv[0].label:
 * 			# one of the right children
 * 			children.extend(reversed(deriv[1:]))             # <<<<<<<<<<<<<<
 * 			# move on to next node in this binarized constituent
 * 			deriv = deriv[0]
 */
    __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_deriv, 1, 0, NULL, NULL, &__pyx_slice__21, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 674, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 674, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_reversed, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 674, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_6 = __Pyx_PyList_Extend(__pyx_v_children, __pyx_t_2); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 674, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

    /* "discodop/disambiguation.pyx":676
 * 			children.extend(reversed(deriv[1:]))
 * 			# move on to next node in this binarized constituent
 * 			deriv = deriv[0]             # <<<<<<<<<<<<<<
 * 		# last right child
 * 		children.extend(reversed(deriv[1:]))
 */
    __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_deriv, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 676, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF_SET(__pyx_v_deriv, __pyx_t_2);
    __pyx_t_2 = 0;
  }

  /* "discodop/disambiguation.pyx":678
 * 			deriv = deriv[0]
 * 		# last right child
 * 		children.extend(reversed(deriv[1:]))             # <<<<<<<<<<<<<<
 * 	elif '}<' in deriv[0].label:
 * 		deriv = deriv[0]
 */
  __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_deriv, 1, 0, NULL, NULL, &__pyx_slice__22, 1, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 678, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 678, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_reversed, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 678, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_6 = __Pyx_PyList_Extend(__pyx_v_children, __pyx_t_2); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 678, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "discodop/disambiguation.pyx":668
 * 	frag = backtransform[chart.grammar.rulenos[nodeprod(deriv)]]
 * 	# collect children w/on the fly left-factored debinarization
 * 	if len(deriv) >= 2:  # is there a right child?             # <<<<<<<<<<<<<<
 * 		# keep going while left child is part of same binarized constituent
 * 		# this shortcut assumes that neverblockre is only used to avoid
 */
  goto __pyx_L3;
}

/* "discodop/disambiguation.pyx":679
 * 		# last right child
 * 		children.extend(reversed(deriv[1:]))
 * 	elif '}<' in deriv[0].label:             # <<<<<<<<<<<<<<
 * 		deriv = deriv[0]
 * 	# left-most child
 */
__pyx_t_2 = __Pyx_GetItemInt(__pyx_v_deriv, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 679, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_label); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 679, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_5 = (__Pyx_PySequence_ContainsTF(__pyx_kp_u__13, __pyx_t_1, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 679, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_4 = (__pyx_t_5 != 0);
if (__pyx_t_4) {

  /* "discodop/disambiguation.pyx":680
 * 		children.extend(reversed(deriv[1:]))
 * 	elif '}<' in deriv[0].label:
 * 		deriv = deriv[0]             # <<<<<<<<<<<<<<
 * 	# left-most child
 * 	children.append(deriv[0])
 */
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_deriv, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 680, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF_SET(__pyx_v_deriv, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":679
 * 		# last right child
 * 		children.extend(reversed(deriv[1:]))
 * 	elif '}<' in deriv[0].label:             # <<<<<<<<<<<<<<
 * 		deriv = deriv[0]
 * 	# left-most child
 */
}
__pyx_L3:;

/* "discodop/disambiguation.pyx":682
 * 		deriv = deriv[0]
 * 	# left-most child
 * 	children.append(deriv[0])             # <<<<<<<<<<<<<<
 * 
 * 	result.append(frag.format(*['(%s %s)' % (
 */
__pyx_t_1 = __Pyx_GetItemInt(__pyx_v_deriv, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 682, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_6 = __Pyx_PyList_Append(__pyx_v_children, __pyx_t_1); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 682, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":684
 * 	children.append(deriv[0])
 * 
 * 	result.append(frag.format(*['(%s %s)' % (             # <<<<<<<<<<<<<<
 * 			child.label.split('@')[0],
 * 			('%d=%s' % (child[0], chart.sent[child[0]]) if '@' in child.label
 */
if (unlikely(__pyx_v_result == Py_None)) {
  PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "append");
  __PYX_ERR(0, 684, __pyx_L1_error)
}
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_frag, __pyx_n_s_format); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 684, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
{ /* enter inner scope */
  PyObject *__pyx_9genexpr22__pyx_v_child = NULL;
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 684, __pyx_L8_error)
  __Pyx_GOTREF(__pyx_t_2);

  /* "discodop/disambiguation.pyx":688
 * 			('%d=%s' % (child[0], chart.sent[child[0]]) if '@' in child.label
 * 				else yieldranges(sorted(child.leaves()))))
 * 			for child in reversed(children)]))             # <<<<<<<<<<<<<<
 * 	# recursively visit all substitution sites
 * 	for child in reversed(children):
 */
  __pyx_t_7 = __pyx_v_children; __Pyx_INCREF(__pyx_t_7); __pyx_t_3 = PyList_GET_SIZE(__pyx_t_7) - 1;
  for (;;) {
    if (__pyx_t_3 < 0) break;
    if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_7)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_8 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_3); __Pyx_INCREF(__pyx_t_8); __pyx_t_3--; if (unlikely(0 < 0)) __PYX_ERR(0, 688, __pyx_L8_error)
    #else
    __pyx_t_8 = PySequence_ITEM(__pyx_t_7, __pyx_t_3); __pyx_t_3--; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 688, __pyx_L8_error)
    __Pyx_GOTREF(__pyx_t_8);
    #endif
    __Pyx_XDECREF_SET(__pyx_9genexpr22__pyx_v_child, __pyx_t_8);
    __pyx_t_8 = 0;

    /* "discodop/disambiguation.pyx":685
 * 
 * 	result.append(frag.format(*['(%s %s)' % (
 * 			child.label.split('@')[0],             # <<<<<<<<<<<<<<
 * 			('%d=%s' % (child[0], chart.sent[child[0]]) if '@' in child.label
 * 				else yieldranges(sorted(child.leaves()))))
 */
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_9genexpr22__pyx_v_child, __pyx_n_s_label); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 685, __pyx_L8_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_split); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 685, __pyx_L8_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_tuple__23, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 685, __pyx_L8_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = __Pyx_GetItemInt(__pyx_t_8, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 685, __pyx_L8_error)
    __Pyx_GOTREF(__pyx_t_9);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "discodop/disambiguation.pyx":686
 * 	result.append(frag.format(*['(%s %s)' % (
 * 			child.label.split('@')[0],
 * 			('%d=%s' % (child[0], chart.sent[child[0]]) if '@' in child.label             # <<<<<<<<<<<<<<
 * 				else yieldranges(sorted(child.leaves()))))
 * 			for child in reversed(children)]))
 */
    __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_9genexpr22__pyx_v_child, __pyx_n_s_label); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 686, __pyx_L8_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_4 = (__Pyx_PySequence_ContainsTF(__pyx_kp_u__16, __pyx_t_10, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 686, __pyx_L8_error)
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    if ((__pyx_t_4 != 0)) {
      __pyx_t_10 = __Pyx_GetItemInt(__pyx_9genexpr22__pyx_v_child, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 686, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_10);
      if (unlikely(__pyx_v_chart->sent == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 686, __pyx_L8_error)
      }
      __pyx_t_11 = __Pyx_GetItemInt(__pyx_9genexpr22__pyx_v_child, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 686, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_12 = PyObject_GetItem(__pyx_v_chart->sent, __pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 686, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 686, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_GIVEREF(__pyx_t_10);
      PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10);
      __Pyx_GIVEREF(__pyx_t_12);
      PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_12);
      __pyx_t_10 = 0;
      __pyx_t_12 = 0;
      __pyx_t_12 = PyUnicode_Format(__pyx_kp_u_d_s, __pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 686, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_8 = __pyx_t_12;
      __pyx_t_12 = 0;
    } else {

      /* "discodop/disambiguation.pyx":687
 * 			child.label.split('@')[0],
 * 			('%d=%s' % (child[0], chart.sent[child[0]]) if '@' in child.label
 * 				else yieldranges(sorted(child.leaves()))))             # <<<<<<<<<<<<<<
 * 			for child in reversed(children)]))
 * 	# recursively visit all substitution sites
 */
      __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_9genexpr22__pyx_v_child, __pyx_n_s_leaves); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 687, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_10);
      __pyx_t_13 = NULL;
      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);
        }
      }
      if (__pyx_t_13) {
        __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_13); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 687, __pyx_L8_error)
        __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
      } else {
        __pyx_t_11 = __Pyx_PyObject_CallNoArg(__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 687, __pyx_L8_error)
      }
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_10 = PySequence_List(__pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 687, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      __pyx_t_12 = ((PyObject*)__pyx_t_10);
      __pyx_t_10 = 0;
      __pyx_t_6 = PyList_Sort(__pyx_t_12); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 687, __pyx_L8_error)
      __pyx_t_10 = __pyx_f_8discodop_10containers_yieldranges(((PyObject*)__pyx_t_12)); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 687, __pyx_L8_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_8 = __pyx_t_10;
      __pyx_t_10 = 0;
    }

    /* "discodop/disambiguation.pyx":685
 * 
 * 	result.append(frag.format(*['(%s %s)' % (
 * 			child.label.split('@')[0],             # <<<<<<<<<<<<<<
 * 			('%d=%s' % (child[0], chart.sent[child[0]]) if '@' in child.label
 * 				else yieldranges(sorted(child.leaves()))))
 */
    __pyx_t_10 = PyTuple_New(2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 685, __pyx_L8_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_9);
    PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_9);
    __Pyx_GIVEREF(__pyx_t_8);
    PyTuple_SET_ITEM(__pyx_t_10, 1, __pyx_t_8);
    __pyx_t_9 = 0;
    __pyx_t_8 = 0;

    /* "discodop/disambiguation.pyx":684
 * 	children.append(deriv[0])
 * 
 * 	result.append(frag.format(*['(%s %s)' % (             # <<<<<<<<<<<<<<
 * 			child.label.split('@')[0],
 * 			('%d=%s' % (child[0], chart.sent[child[0]]) if '@' in child.label
 */
    __pyx_t_8 = PyUnicode_Format(__pyx_kp_u_s_s_2, __pyx_t_10); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 684, __pyx_L8_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_8))) __PYX_ERR(0, 684, __pyx_L8_error)
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "discodop/disambiguation.pyx":688
 * 			('%d=%s' % (child[0], chart.sent[child[0]]) if '@' in child.label
 * 				else yieldranges(sorted(child.leaves()))))
 * 			for child in reversed(children)]))             # <<<<<<<<<<<<<<
 * 	# recursively visit all substitution sites
 * 	for child in reversed(children):
 */
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_XDECREF(__pyx_9genexpr22__pyx_v_child);
  goto __pyx_L11_exit_scope;
  __pyx_L8_error:;
  __Pyx_XDECREF(__pyx_9genexpr22__pyx_v_child);
  goto __pyx_L1_error;
  __pyx_L11_exit_scope:;
} /* exit inner scope */

/* "discodop/disambiguation.pyx":684
 * 	children.append(deriv[0])
 * 
 * 	result.append(frag.format(*['(%s %s)' % (             # <<<<<<<<<<<<<<
 * 			child.label.split('@')[0],
 * 			('%d=%s' % (child[0], chart.sent[child[0]]) if '@' in child.label
 */
__pyx_t_7 = PySequence_Tuple(__pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 684, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 684, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_6 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_2); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 684, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":690
 * 			for child in reversed(children)]))
 * 	# recursively visit all substitution sites
 * 	for child in reversed(children):             # <<<<<<<<<<<<<<
 * 		if isinstance(child[0], Tree):
 * 			fragmentsinderiv_str(child, chart, backtransform, result)
 */
__pyx_t_2 = __pyx_v_children; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = PyList_GET_SIZE(__pyx_t_2) - 1;
for (;;) {
  if (__pyx_t_3 < 0) break;
  if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
  #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
  __pyx_t_7 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_7); __pyx_t_3--; if (unlikely(0 < 0)) __PYX_ERR(0, 690, __pyx_L1_error)
  #else
  __pyx_t_7 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3--; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 690, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  #endif
  __Pyx_XDECREF_SET(__pyx_v_child, __pyx_t_7);
  __pyx_t_7 = 0;

  /* "discodop/disambiguation.pyx":691
 * 	# recursively visit all substitution sites
 * 	for child in reversed(children):
 * 		if isinstance(child[0], Tree):             # <<<<<<<<<<<<<<
 * 			fragmentsinderiv_str(child, chart, backtransform, result)
 * 		elif '@' not in child.label:
 */
  __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_child, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 691, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_Tree); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 691, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_4 = PyObject_IsInstance(__pyx_t_7, __pyx_t_1); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(0, 691, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_5 = (__pyx_t_4 != 0);
  if (__pyx_t_5) {

    /* "discodop/disambiguation.pyx":692
 * 	for child in reversed(children):
 * 		if isinstance(child[0], Tree):
 * 			fragmentsinderiv_str(child, chart, backtransform, result)             # <<<<<<<<<<<<<<
 * 		elif '@' not in child.label:
 * 			result.append('(%s %d=%s)' % (child.label, child[0],
 */
    __pyx_t_1 = __pyx_f_8discodop_14disambiguation_fragmentsinderiv_str(__pyx_v_child, __pyx_v_chart, __pyx_v_backtransform, __pyx_v_result); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 692, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "discodop/disambiguation.pyx":691
 * 	# recursively visit all substitution sites
 * 	for child in reversed(children):
 * 		if isinstance(child[0], Tree):             # <<<<<<<<<<<<<<
 * 			fragmentsinderiv_str(child, chart, backtransform, result)
 * 		elif '@' not in child.label:
 */
    goto __pyx_L14;
  }

  /* "discodop/disambiguation.pyx":693
 * 		if isinstance(child[0], Tree):
 * 			fragmentsinderiv_str(child, chart, backtransform, result)
 * 		elif '@' not in child.label:             # <<<<<<<<<<<<<<
 * 			result.append('(%s %d=%s)' % (child.label, child[0],
 * 					chart.sent[child[0]]))
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_child, __pyx_n_s_label); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 693, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = (__Pyx_PySequence_ContainsTF(__pyx_kp_u__16, __pyx_t_1, Py_NE)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 693, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_4 = (__pyx_t_5 != 0);
  if (__pyx_t_4) {

    /* "discodop/disambiguation.pyx":694
 * 			fragmentsinderiv_str(child, chart, backtransform, result)
 * 		elif '@' not in child.label:
 * 			result.append('(%s %d=%s)' % (child.label, child[0],             # <<<<<<<<<<<<<<
 * 					chart.sent[child[0]]))
 * 
 */
    if (unlikely(__pyx_v_result == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "append");
      __PYX_ERR(0, 694, __pyx_L1_error)
    }
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_child, __pyx_n_s_label); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 694, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_child, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 694, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);

    /* "discodop/disambiguation.pyx":695
 * 		elif '@' not in child.label:
 * 			result.append('(%s %d=%s)' % (child.label, child[0],
 * 					chart.sent[child[0]]))             # <<<<<<<<<<<<<<
 * 
 * 
 */
    if (unlikely(__pyx_v_chart->sent == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 695, __pyx_L1_error)
    }
    __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_child, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 695, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_10 = PyObject_GetItem(__pyx_v_chart->sent, __pyx_t_8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 695, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "discodop/disambiguation.pyx":694
 * 			fragmentsinderiv_str(child, chart, backtransform, result)
 * 		elif '@' not in child.label:
 * 			result.append('(%s %d=%s)' % (child.label, child[0],             # <<<<<<<<<<<<<<
 * 					chart.sent[child[0]]))
 * 
 */
    __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 694, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_GIVEREF(__pyx_t_1);
    PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1);
    __Pyx_GIVEREF(__pyx_t_7);
    PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_10);
    PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_10);
    __pyx_t_1 = 0;
    __pyx_t_7 = 0;
    __pyx_t_10 = 0;
    __pyx_t_10 = PyUnicode_Format(__pyx_kp_u_s_d_s, __pyx_t_8); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 694, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_6 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_10); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 694, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

    /* "discodop/disambiguation.pyx":693
 * 		if isinstance(child[0], Tree):
 * 			fragmentsinderiv_str(child, chart, backtransform, result)
 * 		elif '@' not in child.label:             # <<<<<<<<<<<<<<
 * 			result.append('(%s %d=%s)' % (child.label, child[0],
 * 					chart.sent[child[0]]))
 */
  }
  __pyx_L14:;

  /* "discodop/disambiguation.pyx":690
 * 			for child in reversed(children)]))
 * 	# recursively visit all substitution sites
 * 	for child in reversed(children):             # <<<<<<<<<<<<<<
 * 		if isinstance(child[0], Tree):
 * 			fragmentsinderiv_str(child, chart, backtransform, result)
 */
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":663
 * 
 * 
 * cdef fragmentsinderiv_str(deriv, Chart chart, list backtransform, list result):             # <<<<<<<<<<<<<<
 * 	cdef list children = []
 * 	cdef str frag
 */

/* 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_7);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_XDECREF(__pyx_t_9);
__Pyx_XDECREF(__pyx_t_10);
__Pyx_XDECREF(__pyx_t_11);
__Pyx_XDECREF(__pyx_t_12);
__Pyx_XDECREF(__pyx_t_13);
__Pyx_AddTraceback("discodop.disambiguation.fragmentsinderiv_str", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_children);
__Pyx_XDECREF(__pyx_v_frag);
__Pyx_XDECREF(__pyx_v_child);
__Pyx_XDECREF(__pyx_v_deriv);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":698
 * 
 * 
 * def frontiernt(node):             # <<<<<<<<<<<<<<
 * 	"""Test whether node from a DOP derivation is a frontier nonterminal."""
 * 	return '@' not in node.label
 */

/* Python wrapper */
static PyObject *__pyx_pw_8discodop_14disambiguation_11frontiernt(PyObject *__pyx_self, PyObject *__pyx_v_node); /*proto*/
static char __pyx_doc_8discodop_14disambiguation_10frontiernt[] = "frontiernt(node)\nTest whether node from a DOP derivation is a frontier nonterminal.";
static PyMethodDef __pyx_mdef_8discodop_14disambiguation_11frontiernt = {"frontiernt", (PyCFunction)__pyx_pw_8discodop_14disambiguation_11frontiernt, METH_O, __pyx_doc_8discodop_14disambiguation_10frontiernt};
static PyObject *__pyx_pw_8discodop_14disambiguation_11frontiernt(PyObject *__pyx_self, PyObject *__pyx_v_node) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("frontiernt (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_14disambiguation_10frontiernt(__pyx_self, ((PyObject *)__pyx_v_node));

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

static PyObject *__pyx_pf_8discodop_14disambiguation_10frontiernt(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_node) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
int __pyx_t_2;
__Pyx_RefNannySetupContext("frontiernt", 0);

/* "discodop/disambiguation.pyx":700
 * def frontiernt(node):
 * 	"""Test whether node from a DOP derivation is a frontier nonterminal."""
 * 	return '@' not in node.label             # <<<<<<<<<<<<<<
 * 
 * 
 */
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_label); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 700, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_kp_u__16, __pyx_t_1, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 700, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 700, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;

/* "discodop/disambiguation.pyx":698
 * 
 * 
 * def frontiernt(node):             # <<<<<<<<<<<<<<
 * 	"""Test whether node from a DOP derivation is a frontier nonterminal."""
 * 	return '@' not in node.label
 */

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("discodop.disambiguation.frontiernt", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":703
 * 
 * 
 * def splitfrag(node):             # <<<<<<<<<<<<<<
 * 	"""Return a copy of a tree with subtrees labeled without '@' removed."""
 * 	children = []
 */

/* Python wrapper */
static PyObject *__pyx_pw_8discodop_14disambiguation_13splitfrag(PyObject *__pyx_self, PyObject *__pyx_v_node); /*proto*/
static char __pyx_doc_8discodop_14disambiguation_12splitfrag[] = "splitfrag(node)\nReturn a copy of a tree with subtrees labeled without '@' removed.";
static PyMethodDef __pyx_mdef_8discodop_14disambiguation_13splitfrag = {"splitfrag", (PyCFunction)__pyx_pw_8discodop_14disambiguation_13splitfrag, METH_O, __pyx_doc_8discodop_14disambiguation_12splitfrag};
static PyObject *__pyx_pw_8discodop_14disambiguation_13splitfrag(PyObject *__pyx_self, PyObject *__pyx_v_node) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("splitfrag (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_14disambiguation_12splitfrag(__pyx_self, ((PyObject *)__pyx_v_node));

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

static PyObject *__pyx_pf_8discodop_14disambiguation_12splitfrag(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_node) {
PyObject *__pyx_v_children = NULL;
PyObject *__pyx_v_child = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
Py_ssize_t __pyx_t_2;
PyObject *(*__pyx_t_3)(PyObject *);
PyObject *__pyx_t_4 = NULL;
int __pyx_t_5;
int __pyx_t_6;
int __pyx_t_7;
PyObject *__pyx_t_8 = NULL;
PyObject *__pyx_t_9 = NULL;
PyObject *__pyx_t_10 = NULL;
PyObject *__pyx_t_11 = NULL;
PyObject *__pyx_t_12 = NULL;
PyObject *__pyx_t_13 = NULL;
int __pyx_t_14;
__Pyx_RefNannySetupContext("splitfrag", 0);

/* "discodop/disambiguation.pyx":705
 * def splitfrag(node):
 * 	"""Return a copy of a tree with subtrees labeled without '@' removed."""
 * 	children = []             # <<<<<<<<<<<<<<
 * 	for child in node:
 * 		if not isinstance(child, Tree):
 */
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 705, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_children = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":706
 * 	"""Return a copy of a tree with subtrees labeled without '@' removed."""
 * 	children = []
 * 	for child in node:             # <<<<<<<<<<<<<<
 * 		if not isinstance(child, Tree):
 * 			children.append(child)
 */
if (likely(PyList_CheckExact(__pyx_v_node)) || PyTuple_CheckExact(__pyx_v_node)) {
  __pyx_t_1 = __pyx_v_node; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
  __pyx_t_3 = NULL;
} else {
  __pyx_t_2 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_v_node); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 706, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 706, __pyx_L1_error)
}
for (;;) {
  if (likely(!__pyx_t_3)) {
    if (likely(PyList_CheckExact(__pyx_t_1))) {
      if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_4 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 706, __pyx_L1_error)
      #else
      __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 706, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      #endif
    } else {
      if (__pyx_t_2 >= PyTuple_GET_SIZE(__pyx_t_1)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_4 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_4); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(0, 706, __pyx_L1_error)
      #else
      __pyx_t_4 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 706, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      #endif
    }
  } else {
    __pyx_t_4 = __pyx_t_3(__pyx_t_1);
    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, 706, __pyx_L1_error)
      }
      break;
    }
    __Pyx_GOTREF(__pyx_t_4);
  }
  __Pyx_XDECREF_SET(__pyx_v_child, __pyx_t_4);
  __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":707
 * 	children = []
 * 	for child in node:
 * 		if not isinstance(child, Tree):             # <<<<<<<<<<<<<<
 * 			children.append(child)
 * 		elif '@' in child.label:
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_Tree); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 707, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = PyObject_IsInstance(__pyx_v_child, __pyx_t_4); if (unlikely(__pyx_t_5 == -1)) __PYX_ERR(0, 707, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = ((!(__pyx_t_5 != 0)) != 0);
  if (__pyx_t_6) {

    /* "discodop/disambiguation.pyx":708
 * 	for child in node:
 * 		if not isinstance(child, Tree):
 * 			children.append(child)             # <<<<<<<<<<<<<<
 * 		elif '@' in child.label:
 * 			children.append(child if isinstance(child[0], int)
 */
    __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_children, __pyx_v_child); if (unlikely(__pyx_t_7 == -1)) __PYX_ERR(0, 708, __pyx_L1_error)

    /* "discodop/disambiguation.pyx":707
 * 	children = []
 * 	for child in node:
 * 		if not isinstance(child, Tree):             # <<<<<<<<<<<<<<
 * 			children.append(child)
 * 		elif '@' in child.label:
 */
    goto __pyx_L5;
  }

  /* "discodop/disambiguation.pyx":709
 * 		if not isinstance(child, Tree):
 * 			children.append(child)
 * 		elif '@' in child.label:             # <<<<<<<<<<<<<<
 * 			children.append(child if isinstance(child[0], int)
 * 					else splitfrag(child))
 */
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_child, __pyx_n_s_label); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 709, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_6 = (__Pyx_PySequence_ContainsTF(__pyx_kp_u__16, __pyx_t_4, Py_EQ)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 709, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_5 = (__pyx_t_6 != 0);
  if (__pyx_t_5) {

    /* "discodop/disambiguation.pyx":710
 * 			children.append(child)
 * 		elif '@' in child.label:
 * 			children.append(child if isinstance(child[0], int)             # <<<<<<<<<<<<<<
 * 					else splitfrag(child))
 * 		else:
 */
    __pyx_t_8 = __Pyx_GetItemInt(__pyx_v_child, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 710, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_5 = PyInt_Check(__pyx_t_8); 
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if ((__pyx_t_5 != 0)) {
      __Pyx_INCREF(__pyx_v_child);
      __pyx_t_4 = __pyx_v_child;
    } else {

      /* "discodop/disambiguation.pyx":711
 * 		elif '@' in child.label:
 * 			children.append(child if isinstance(child[0], int)
 * 					else splitfrag(child))             # <<<<<<<<<<<<<<
 * 		else:
 * 			children.append(Tree(child.label,
 */
      __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_splitfrag); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 711, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_9);
      __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_8 = __Pyx_PyObject_CallOneArg(__pyx_t_9, __pyx_v_child); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 711, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_9)) {
          PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_child};
          __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 711, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_GOTREF(__pyx_t_8);
        } else
        #endif
        #if CYTHON_FAST_PYCCALL
        if (__Pyx_PyFastCFunction_Check(__pyx_t_9)) {
          PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_v_child};
          __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 711, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_GOTREF(__pyx_t_8);
        } else
        #endif
        {
          __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 711, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_11);
          __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10); __pyx_t_10 = NULL;
          __Pyx_INCREF(__pyx_v_child);
          __Pyx_GIVEREF(__pyx_v_child);
          PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_v_child);
          __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_11, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 711, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __pyx_t_4 = __pyx_t_8;
      __pyx_t_8 = 0;
    }

    /* "discodop/disambiguation.pyx":710
 * 			children.append(child)
 * 		elif '@' in child.label:
 * 			children.append(child if isinstance(child[0], int)             # <<<<<<<<<<<<<<
 * 					else splitfrag(child))
 * 		else:
 */
    __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_children, __pyx_t_4); if (unlikely(__pyx_t_7 == -1)) __PYX_ERR(0, 710, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

    /* "discodop/disambiguation.pyx":709
 * 		if not isinstance(child, Tree):
 * 			children.append(child)
 * 		elif '@' in child.label:             # <<<<<<<<<<<<<<
 * 			children.append(child if isinstance(child[0], int)
 * 					else splitfrag(child))
 */
    goto __pyx_L5;
  }

  /* "discodop/disambiguation.pyx":713
 * 					else splitfrag(child))
 * 		else:
 * 			children.append(Tree(child.label,             # <<<<<<<<<<<<<<
 * 					['%d:%d' % (min(child.leaves()), max(child.leaves()))]))
 * 	return Tree(node.label, children)
 */
  /*else*/ {
    __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_Tree); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 713, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_child, __pyx_n_s_label); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 713, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);

    /* "discodop/disambiguation.pyx":714
 * 		else:
 * 			children.append(Tree(child.label,
 * 					['%d:%d' % (min(child.leaves()), max(child.leaves()))]))             # <<<<<<<<<<<<<<
 * 	return Tree(node.label, children)
 * 
 */
    __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_child, __pyx_n_s_leaves); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 714, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_12 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) {
      __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_10);
      if (likely(__pyx_t_12)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_10);
        __Pyx_INCREF(__pyx_t_12);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_10, function);
      }
    }
    if (__pyx_t_12) {
      __pyx_t_11 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_12); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 714, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    } else {
      __pyx_t_11 = __Pyx_PyObject_CallNoArg(__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 714, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_10 = PyTuple_New(1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 714, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_GIVEREF(__pyx_t_11);
    PyTuple_SET_ITEM(__pyx_t_10, 0, __pyx_t_11);
    __pyx_t_11 = 0;
    __pyx_t_11 = __Pyx_PyObject_Call(__pyx_builtin_min, __pyx_t_10, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 714, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_child, __pyx_n_s_leaves); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 714, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_13 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) {
      __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_12);
      if (likely(__pyx_t_13)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
        __Pyx_INCREF(__pyx_t_13);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_12, function);
      }
    }
    if (__pyx_t_13) {
      __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_13); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 714, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    } else {
      __pyx_t_10 = __Pyx_PyObject_CallNoArg(__pyx_t_12); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 714, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 714, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_GIVEREF(__pyx_t_10);
    PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_10);
    __pyx_t_10 = 0;
    __pyx_t_10 = __Pyx_PyObject_Call(__pyx_builtin_max, __pyx_t_12, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 714, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 714, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_GIVEREF(__pyx_t_11);
    PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11);
    __Pyx_GIVEREF(__pyx_t_10);
    PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_10);
    __pyx_t_11 = 0;
    __pyx_t_10 = 0;
    __pyx_t_10 = PyUnicode_Format(__pyx_kp_u_d_d, __pyx_t_12); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 714, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __pyx_t_12 = PyList_New(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 714, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __Pyx_GIVEREF(__pyx_t_10);
    PyList_SET_ITEM(__pyx_t_12, 0, __pyx_t_10);
    __pyx_t_10 = 0;
    __pyx_t_10 = NULL;
    __pyx_t_14 = 0;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_10)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_10);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
        __pyx_t_14 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_8)) {
      PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_t_9, __pyx_t_12};
      __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 713, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
      PyObject *__pyx_temp[3] = {__pyx_t_10, __pyx_t_9, __pyx_t_12};
      __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 713, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    } else
    #endif
    {
      __pyx_t_11 = PyTuple_New(2+__pyx_t_14); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 713, __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_GIVEREF(__pyx_t_9);
      PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_14, __pyx_t_9);
      __Pyx_GIVEREF(__pyx_t_12);
      PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_14, __pyx_t_12);
      __pyx_t_9 = 0;
      __pyx_t_12 = 0;
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_11, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 713, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    }
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "discodop/disambiguation.pyx":713
 * 					else splitfrag(child))
 * 		else:
 * 			children.append(Tree(child.label,             # <<<<<<<<<<<<<<
 * 					['%d:%d' % (min(child.leaves()), max(child.leaves()))]))
 * 	return Tree(node.label, children)
 */
    __pyx_t_7 = __Pyx_PyList_Append(__pyx_v_children, __pyx_t_4); if (unlikely(__pyx_t_7 == -1)) __PYX_ERR(0, 713, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __pyx_L5:;

  /* "discodop/disambiguation.pyx":706
 * 	"""Return a copy of a tree with subtrees labeled without '@' removed."""
 * 	children = []
 * 	for child in node:             # <<<<<<<<<<<<<<
 * 		if not isinstance(child, Tree):
 * 			children.append(child)
 */
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":715
 * 			children.append(Tree(child.label,
 * 					['%d:%d' % (min(child.leaves()), max(child.leaves()))]))
 * 	return Tree(node.label, children)             # <<<<<<<<<<<<<<
 * 
 * 
 */
__Pyx_XDECREF(__pyx_r);
__pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_Tree); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 715, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_label); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 715, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__pyx_t_11 = NULL;
__pyx_t_14 = 0;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) {
  __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_4);
  if (likely(__pyx_t_11)) {
    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_11);
    __Pyx_INCREF(function);
    __Pyx_DECREF_SET(__pyx_t_4, function);
    __pyx_t_14 = 1;
  }
}
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_4)) {
  PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_t_8, __pyx_v_children};
  __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 715, __pyx_L1_error)
  __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
  PyObject *__pyx_temp[3] = {__pyx_t_11, __pyx_t_8, __pyx_v_children};
  __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_14, 2+__pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 715, __pyx_L1_error)
  __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0;
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
} else
#endif
{
  __pyx_t_12 = PyTuple_New(2+__pyx_t_14); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 715, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_12);
  if (__pyx_t_11) {
    __Pyx_GIVEREF(__pyx_t_11); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_11); __pyx_t_11 = NULL;
  }
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_14, __pyx_t_8);
  __Pyx_INCREF(__pyx_v_children);
  __Pyx_GIVEREF(__pyx_v_children);
  PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_14, __pyx_v_children);
  __pyx_t_8 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_12, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 715, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;

/* "discodop/disambiguation.pyx":703
 * 
 * 
 * def splitfrag(node):             # <<<<<<<<<<<<<<
 * 	"""Return a copy of a tree with subtrees labeled without '@' removed."""
 * 	children = []
 */

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_XDECREF(__pyx_t_9);
__Pyx_XDECREF(__pyx_t_10);
__Pyx_XDECREF(__pyx_t_11);
__Pyx_XDECREF(__pyx_t_12);
__Pyx_XDECREF(__pyx_t_13);
__Pyx_AddTraceback("discodop.disambiguation.splitfrag", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_children);
__Pyx_XDECREF(__pyx_v_child);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":718
 * 
 * 
 * def treeparsing(trees, sent, Grammar grammar, int m, backtransform, tags=None,             # <<<<<<<<<<<<<<
 * 		maskrules=False):
 * 	"""Assign probabilities to a sequence of trees with a DOP grammar.
 */

/* Python wrapper */
static PyObject *__pyx_pw_8discodop_14disambiguation_15treeparsing(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8discodop_14disambiguation_14treeparsing[] = "treeparsing(trees, sent, Grammar grammar, int m, backtransform, tags=None, maskrules=False)\nAssign probabilities to a sequence of trees with a DOP grammar.\n\n\tGiven a sequence of trees (as strings), parse them with a DOP grammar\n\tto get parse tree probabilities; will consider multiple derivations.\n\n\t:param maskrules: If True, prune any grammar rule not in the trees.\n\t\tExploits rulemapping of grammar which should be mapped to itself;\n\t\te.g., 'NP@2 => DT@3 NN' should be mapped to 'NP => DT NN' in the\n\t\tsame grammar. To remove the mask, issue ``grammar.setmask(None)``\n\t";
static PyMethodDef __pyx_mdef_8discodop_14disambiguation_15treeparsing = {"treeparsing", (PyCFunction)__pyx_pw_8discodop_14disambiguation_15treeparsing, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8discodop_14disambiguation_14treeparsing};
static PyObject *__pyx_pw_8discodop_14disambiguation_15treeparsing(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_trees = 0;
PyObject *__pyx_v_sent = 0;
struct __pyx_obj_8discodop_10containers_Grammar *__pyx_v_grammar = 0;
int __pyx_v_m;
PyObject *__pyx_v_backtransform = 0;
PyObject *__pyx_v_tags = 0;
PyObject *__pyx_v_maskrules = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("treeparsing (wrapper)", 0);
{
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_trees,&__pyx_n_s_sent,&__pyx_n_s_grammar,&__pyx_n_s_m,&__pyx_n_s_backtransform,&__pyx_n_s_tags,&__pyx_n_s_maskrules,0};
  PyObject* values[7] = {0,0,0,0,0,0,0};
  values[5] = ((PyObject *)Py_None);

  /* "discodop/disambiguation.pyx":719
 * 
 * def treeparsing(trees, sent, Grammar grammar, int m, backtransform, tags=None,
 * 		maskrules=False):             # <<<<<<<<<<<<<<
 * 	"""Assign probabilities to a sequence of trees with a DOP grammar.
 * 
 */
  values[6] = ((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  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
      case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    kw_args = PyDict_Size(__pyx_kwds);
    switch (pos_args) {
      case  0:
      if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_trees)) != 0)) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sent)) != 0)) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("treeparsing", 0, 5, 7, 1); __PYX_ERR(0, 718, __pyx_L3_error)
      }
      case  2:
      if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_grammar)) != 0)) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("treeparsing", 0, 5, 7, 2); __PYX_ERR(0, 718, __pyx_L3_error)
      }
      case  3:
      if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_m)) != 0)) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("treeparsing", 0, 5, 7, 3); __PYX_ERR(0, 718, __pyx_L3_error)
      }
      case  4:
      if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_backtransform)) != 0)) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("treeparsing", 0, 5, 7, 4); __PYX_ERR(0, 718, __pyx_L3_error)
      }
      case  5:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tags);
        if (value) { values[5] = value; kw_args--; }
      }
      case  6:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_maskrules);
        if (value) { values[6] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "treeparsing") < 0)) __PYX_ERR(0, 718, __pyx_L3_error)
    }
  } else {
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6);
      case  6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5);
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  __pyx_v_trees = values[0];
  __pyx_v_sent = values[1];
  __pyx_v_grammar = ((struct __pyx_obj_8discodop_10containers_Grammar *)values[2]);
  __pyx_v_m = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_m == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 718, __pyx_L3_error)
  __pyx_v_backtransform = values[4];
  __pyx_v_tags = values[5];
  __pyx_v_maskrules = values[6];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("treeparsing", 0, 5, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 718, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("discodop.disambiguation.treeparsing", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_grammar), __pyx_ptype_8discodop_10containers_Grammar, 1, "grammar", 0))) __PYX_ERR(0, 718, __pyx_L1_error)
__pyx_r = __pyx_pf_8discodop_14disambiguation_14treeparsing(__pyx_self, __pyx_v_trees, __pyx_v_sent, __pyx_v_grammar, __pyx_v_m, __pyx_v_backtransform, __pyx_v_tags, __pyx_v_maskrules);

/* "discodop/disambiguation.pyx":718
 * 
 * 
 * def treeparsing(trees, sent, Grammar grammar, int m, backtransform, tags=None,             # <<<<<<<<<<<<<<
 * 		maskrules=False):
 * 	"""Assign probabilities to a sequence of trees with a DOP grammar.
 */

/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

static PyObject *__pyx_pf_8discodop_14disambiguation_14treeparsing(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_trees, PyObject *__pyx_v_sent, struct __pyx_obj_8discodop_10containers_Grammar *__pyx_v_grammar, int __pyx_v_m, PyObject *__pyx_v_backtransform, PyObject *__pyx_v_tags, PyObject *__pyx_v_maskrules) {
struct __pyx_obj_8discodop_10containers_FatChartItem *__pyx_v_fitem = 0;
int __pyx_v_n;
int __pyx_v_lensent;
PyObject *__pyx_v_whitelist = NULL;
PyObject *__pyx_v_treestr = NULL;
PyObject *__pyx_v_tree = NULL;
PyObject *__pyx_v_node = NULL;
PyObject *__pyx_v_r = NULL;
PyObject *__pyx_v_yf = NULL;
PyObject *__pyx_v_leaves = NULL;
PyObject *__pyx_v_item = NULL;
PyObject *__pyx_v_ruleno = NULL;
PyObject *__pyx_v_label = NULL;
PyObject *__pyx_v_chart = NULL;
CYTHON_UNUSED PyObject *__pyx_v__ = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
Py_ssize_t __pyx_t_1;
PyObject *__pyx_t_2 = NULL;
PyObject *__pyx_t_3 = NULL;
Py_ssize_t __pyx_t_4;
int __pyx_t_5;
PyObject *__pyx_t_6 = NULL;
int __pyx_t_7;
int __pyx_t_8;
PyObject *__pyx_t_9 = NULL;
PyObject *__pyx_t_10 = NULL;
PyObject *(*__pyx_t_11)(PyObject *);
PyObject *__pyx_t_12 = NULL;
PyObject *(*__pyx_t_13)(PyObject *);
PyObject *(*__pyx_t_14)(PyObject *);
PyObject *__pyx_t_15 = NULL;
PyObject *__pyx_t_16 = NULL;
Py_ssize_t __pyx_t_17;
PyObject *(*__pyx_t_18)(PyObject *);
PyObject *__pyx_t_19 = NULL;
PyObject *__pyx_t_20 = NULL;
PyObject *__pyx_t_21 = NULL;
int __pyx_t_22;
int __pyx_t_23;
__Pyx_RefNannySetupContext("treeparsing", 0);

/* "discodop/disambiguation.pyx":735
 * 	# do not apply directly.
 * 	cdef FatChartItem fitem
 * 	cdef int n, lensent = len(sent)             # <<<<<<<<<<<<<<
 * 	# cdef int selected = 0
 * 	whitelist = [set() for _ in grammar.toid]
 */
__pyx_t_1 = PyObject_Length(__pyx_v_sent); if (unlikely(__pyx_t_1 == -1)) __PYX_ERR(0, 735, __pyx_L1_error)
__pyx_v_lensent = __pyx_t_1;

/* "discodop/disambiguation.pyx":737
 * 	cdef int n, lensent = len(sent)
 * 	# cdef int selected = 0
 * 	whitelist = [set() for _ in grammar.toid]             # <<<<<<<<<<<<<<
 * 	if maskrules:
 * 		grammar.setmask([])  # block all rules
 */
{ /* enter inner scope */
  CYTHON_UNUSED PyObject *__pyx_9genexpr23__pyx_v__ = NULL;
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 737, __pyx_L5_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = 0;
  if (unlikely(__pyx_v_grammar->toid == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(0, 737, __pyx_L5_error)
  }
  __pyx_t_6 = __Pyx_dict_iterator(__pyx_v_grammar->toid, 1, ((PyObject *)NULL), (&__pyx_t_4), (&__pyx_t_5)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 737, __pyx_L5_error)
  __Pyx_GOTREF(__pyx_t_6);
  __Pyx_XDECREF(__pyx_t_3);
  __pyx_t_3 = __pyx_t_6;
  __pyx_t_6 = 0;
  while (1) {
    __pyx_t_7 = __Pyx_dict_iter_next(__pyx_t_3, __pyx_t_4, &__pyx_t_1, &__pyx_t_6, NULL, NULL, __pyx_t_5);
    if (unlikely(__pyx_t_7 == 0)) break;
    if (unlikely(__pyx_t_7 == -1)) __PYX_ERR(0, 737, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_XDECREF_SET(__pyx_9genexpr23__pyx_v__, __pyx_t_6);
    __pyx_t_6 = 0;
    __pyx_t_6 = PySet_New(0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 737, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_6);
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_6))) __PYX_ERR(0, 737, __pyx_L5_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_XDECREF(__pyx_9genexpr23__pyx_v__);
  goto __pyx_L8_exit_scope;
  __pyx_L5_error:;
  __Pyx_XDECREF(__pyx_9genexpr23__pyx_v__);
  goto __pyx_L1_error;
  __pyx_L8_exit_scope:;
} /* exit inner scope */
__pyx_v_whitelist = ((PyObject*)__pyx_t_2);
__pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":738
 * 	# cdef int selected = 0
 * 	whitelist = [set() for _ in grammar.toid]
 * 	if maskrules:             # <<<<<<<<<<<<<<
 * 		grammar.setmask([])  # block all rules
 * 	for treestr in trees:
 */
__pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_maskrules); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 738, __pyx_L1_error)
if (__pyx_t_8) {

  /* "discodop/disambiguation.pyx":739
 * 	whitelist = [set() for _ in grammar.toid]
 * 	if maskrules:
 * 		grammar.setmask([])  # block all rules             # <<<<<<<<<<<<<<
 * 	for treestr in trees:
 * 		tree = Tree(treestr)
 */
  __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_grammar), __pyx_n_s_setmask); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 739, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 739, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_6);
  __pyx_t_9 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
    __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_3);
    if (likely(__pyx_t_9)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_9);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_3, function);
    }
  }
  if (!__pyx_t_9) {
    __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 739, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_2);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_6};
      __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 739, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
      PyObject *__pyx_temp[2] = {__pyx_t_9, __pyx_t_6};
      __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 739, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    } else
    #endif
    {
      __pyx_t_10 = PyTuple_New(1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 739, __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_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_10, 0+1, __pyx_t_6);
      __pyx_t_6 = 0;
      __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_10, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 739, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "discodop/disambiguation.pyx":738
 * 	# cdef int selected = 0
 * 	whitelist = [set() for _ in grammar.toid]
 * 	if maskrules:             # <<<<<<<<<<<<<<
 * 		grammar.setmask([])  # block all rules
 * 	for treestr in trees:
 */
}

/* "discodop/disambiguation.pyx":740
 * 	if maskrules:
 * 		grammar.setmask([])  # block all rules
 * 	for treestr in trees:             # <<<<<<<<<<<<<<
 * 		tree = Tree(treestr)
 * 		for node, (r, yf) in zip(tree.subtrees(),
 */
if (likely(PyList_CheckExact(__pyx_v_trees)) || PyTuple_CheckExact(__pyx_v_trees)) {
  __pyx_t_2 = __pyx_v_trees; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0;
  __pyx_t_11 = NULL;
} else {
  __pyx_t_4 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_trees); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 740, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_11 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 740, __pyx_L1_error)
}
for (;;) {
  if (likely(!__pyx_t_11)) {
    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_3 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 740, __pyx_L1_error)
      #else
      __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 740, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      #endif
    } else {
      if (__pyx_t_4 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_4); __Pyx_INCREF(__pyx_t_3); __pyx_t_4++; if (unlikely(0 < 0)) __PYX_ERR(0, 740, __pyx_L1_error)
      #else
      __pyx_t_3 = PySequence_ITEM(__pyx_t_2, __pyx_t_4); __pyx_t_4++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 740, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      #endif
    }
  } else {
    __pyx_t_3 = __pyx_t_11(__pyx_t_2);
    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, 740, __pyx_L1_error)
      }
      break;
    }
    __Pyx_GOTREF(__pyx_t_3);
  }
  __Pyx_XDECREF_SET(__pyx_v_treestr, __pyx_t_3);
  __pyx_t_3 = 0;

  /* "discodop/disambiguation.pyx":741
 * 		grammar.setmask([])  # block all rules
 * 	for treestr in trees:
 * 		tree = Tree(treestr)             # <<<<<<<<<<<<<<
 * 		for node, (r, yf) in zip(tree.subtrees(),
 * 				lcfrsproductions(tree, sent)):
 */
  __pyx_t_10 = __Pyx_GetModuleGlobalName(__pyx_n_s_Tree); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 741, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __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_3 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_v_treestr); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 741, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_10)) {
      PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_treestr};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 741, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) {
      PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_treestr};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 741, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else
    #endif
    {
      __pyx_t_9 = PyTuple_New(1+1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 741, __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_INCREF(__pyx_v_treestr);
      __Pyx_GIVEREF(__pyx_v_treestr);
      PyTuple_SET_ITEM(__pyx_t_9, 0+1, __pyx_v_treestr);
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_9, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 741, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __Pyx_XDECREF_SET(__pyx_v_tree, __pyx_t_3);
  __pyx_t_3 = 0;

  /* "discodop/disambiguation.pyx":742
 * 	for treestr in trees:
 * 		tree = Tree(treestr)
 * 		for node, (r, yf) in zip(tree.subtrees(),             # <<<<<<<<<<<<<<
 * 				lcfrsproductions(tree, sent)):
 * 			leaves = node.leaves()
 */
  __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_subtrees); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 742, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_9 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(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_3 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 742, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  } else {
    __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 742, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

  /* "discodop/disambiguation.pyx":743
 * 		tree = Tree(treestr)
 * 		for node, (r, yf) in zip(tree.subtrees(),
 * 				lcfrsproductions(tree, sent)):             # <<<<<<<<<<<<<<
 * 			leaves = node.leaves()
 * 			if lensent < sizeof(uint64_t) * 8:
 */
  __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_lcfrsproductions); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 743, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __pyx_t_6 = NULL;
  __pyx_t_5 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_9))) {
    __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_9);
    if (likely(__pyx_t_6)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9);
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_9, function);
      __pyx_t_5 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_9)) {
    PyObject *__pyx_temp[3] = {__pyx_t_6, __pyx_v_tree, __pyx_v_sent};
    __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 743, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 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_6, __pyx_v_tree, __pyx_v_sent};
    __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_9, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 743, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_10);
  } else
  #endif
  {
    __pyx_t_12 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 743, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    if (__pyx_t_6) {
      __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_6); __pyx_t_6 = NULL;
    }
    __Pyx_INCREF(__pyx_v_tree);
    __Pyx_GIVEREF(__pyx_v_tree);
    PyTuple_SET_ITEM(__pyx_t_12, 0+__pyx_t_5, __pyx_v_tree);
    __Pyx_INCREF(__pyx_v_sent);
    __Pyx_GIVEREF(__pyx_v_sent);
    PyTuple_SET_ITEM(__pyx_t_12, 1+__pyx_t_5, __pyx_v_sent);
    __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_9, __pyx_t_12, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 743, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
  }
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "discodop/disambiguation.pyx":742
 * 	for treestr in trees:
 * 		tree = Tree(treestr)
 * 		for node, (r, yf) in zip(tree.subtrees(),             # <<<<<<<<<<<<<<
 * 				lcfrsproductions(tree, sent)):
 * 			leaves = node.leaves()
 */
  __pyx_t_9 = PyTuple_New(2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 742, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_10);
  PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_t_10);
  __pyx_t_3 = 0;
  __pyx_t_10 = 0;
  __pyx_t_10 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_9, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 742, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
  if (likely(PyList_CheckExact(__pyx_t_10)) || PyTuple_CheckExact(__pyx_t_10)) {
    __pyx_t_9 = __pyx_t_10; __Pyx_INCREF(__pyx_t_9); __pyx_t_1 = 0;
    __pyx_t_13 = NULL;
  } else {
    __pyx_t_1 = -1; __pyx_t_9 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 742, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_13 = Py_TYPE(__pyx_t_9)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 742, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  for (;;) {
    if (likely(!__pyx_t_13)) {
      if (likely(PyList_CheckExact(__pyx_t_9))) {
        if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_9)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_10 = PyList_GET_ITEM(__pyx_t_9, __pyx_t_1); __Pyx_INCREF(__pyx_t_10); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 742, __pyx_L1_error)
        #else
        __pyx_t_10 = PySequence_ITEM(__pyx_t_9, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 742, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        #endif
      } else {
        if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_9)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_10 = PyTuple_GET_ITEM(__pyx_t_9, __pyx_t_1); __Pyx_INCREF(__pyx_t_10); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 742, __pyx_L1_error)
        #else
        __pyx_t_10 = PySequence_ITEM(__pyx_t_9, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 742, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        #endif
      }
    } else {
      __pyx_t_10 = __pyx_t_13(__pyx_t_9);
      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, 742, __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, 742, __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_12 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_12 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_3);
      __Pyx_INCREF(__pyx_t_12);
      #else
      __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 742, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_12 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 742, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      #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, 742, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      __pyx_t_14 = Py_TYPE(__pyx_t_6)->tp_iternext;
      index = 0; __pyx_t_3 = __pyx_t_14(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L14_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_3);
      index = 1; __pyx_t_12 = __pyx_t_14(__pyx_t_6); if (unlikely(!__pyx_t_12)) goto __pyx_L14_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_12);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_6), 2) < 0) __PYX_ERR(0, 742, __pyx_L1_error)
      __pyx_t_14 = NULL;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      goto __pyx_L15_unpacking_done;
      __pyx_L14_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
      __pyx_t_14 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 742, __pyx_L1_error)
      __pyx_L15_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_node, __pyx_t_3);
    __pyx_t_3 = 0;
    if ((likely(PyTuple_CheckExact(__pyx_t_12))) || (PyList_CheckExact(__pyx_t_12))) {
      PyObject* sequence = __pyx_t_12;
      #if !CYTHON_COMPILING_IN_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, 742, __pyx_L1_error)
      }
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      if (likely(PyTuple_CheckExact(sequence))) {
        __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); 
        __pyx_t_15 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_6 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_15 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_6);
      __Pyx_INCREF(__pyx_t_15);
      #else
      __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 742, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_15 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 742, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      #endif
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_16 = PyObject_GetIter(__pyx_t_12); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 742, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_14 = Py_TYPE(__pyx_t_16)->tp_iternext;
      index = 0; __pyx_t_6 = __pyx_t_14(__pyx_t_16); if (unlikely(!__pyx_t_6)) goto __pyx_L16_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_6);
      index = 1; __pyx_t_15 = __pyx_t_14(__pyx_t_16); if (unlikely(!__pyx_t_15)) goto __pyx_L16_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_15);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_16), 2) < 0) __PYX_ERR(0, 742, __pyx_L1_error)
      __pyx_t_14 = NULL;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      goto __pyx_L17_unpacking_done;
      __pyx_L16_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __pyx_t_14 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 742, __pyx_L1_error)
      __pyx_L17_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_r, __pyx_t_6);
    __pyx_t_6 = 0;
    __Pyx_XDECREF_SET(__pyx_v_yf, __pyx_t_15);
    __pyx_t_15 = 0;

    /* "discodop/disambiguation.pyx":744
 * 		for node, (r, yf) in zip(tree.subtrees(),
 * 				lcfrsproductions(tree, sent)):
 * 			leaves = node.leaves()             # <<<<<<<<<<<<<<
 * 			if lensent < sizeof(uint64_t) * 8:
 * 				item = SmallChartItem(0, sum([1L << n for n in leaves]))
 */
    __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_leaves); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 744, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_12);
    __pyx_t_3 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_12))) {
      __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_12);
      if (likely(__pyx_t_3)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_12);
        __Pyx_INCREF(__pyx_t_3);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_12, function);
      }
    }
    if (__pyx_t_3) {
      __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_t_12, __pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 744, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else {
      __pyx_t_10 = __Pyx_PyObject_CallNoArg(__pyx_t_12); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 744, __pyx_L1_error)
    }
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
    __Pyx_XDECREF_SET(__pyx_v_leaves, __pyx_t_10);
    __pyx_t_10 = 0;

    /* "discodop/disambiguation.pyx":745
 * 				lcfrsproductions(tree, sent)):
 * 			leaves = node.leaves()
 * 			if lensent < sizeof(uint64_t) * 8:             # <<<<<<<<<<<<<<
 * 				item = SmallChartItem(0, sum([1L << n for n in leaves]))
 * 			else:
 */
    __pyx_t_8 = ((__pyx_v_lensent < ((sizeof(uint64_t)) * 8)) != 0);
    if (__pyx_t_8) {

      /* "discodop/disambiguation.pyx":746
 * 			leaves = node.leaves()
 * 			if lensent < sizeof(uint64_t) * 8:
 * 				item = SmallChartItem(0, sum([1L << n for n in leaves]))             # <<<<<<<<<<<<<<
 * 			else:
 * 				fitem = item = FatChartItem(0)
 */
      { /* enter inner scope */
        int __pyx_9genexpr24__pyx_v_n;
        __pyx_t_10 = PyList_New(0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 746, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        if (likely(PyList_CheckExact(__pyx_v_leaves)) || PyTuple_CheckExact(__pyx_v_leaves)) {
          __pyx_t_12 = __pyx_v_leaves; __Pyx_INCREF(__pyx_t_12); __pyx_t_17 = 0;
          __pyx_t_18 = NULL;
        } else {
          __pyx_t_17 = -1; __pyx_t_12 = PyObject_GetIter(__pyx_v_leaves); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 746, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_12);
          __pyx_t_18 = Py_TYPE(__pyx_t_12)->tp_iternext; if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 746, __pyx_L1_error)
        }
        for (;;) {
          if (likely(!__pyx_t_18)) {
            if (likely(PyList_CheckExact(__pyx_t_12))) {
              if (__pyx_t_17 >= PyList_GET_SIZE(__pyx_t_12)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_3 = PyList_GET_ITEM(__pyx_t_12, __pyx_t_17); __Pyx_INCREF(__pyx_t_3); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 746, __pyx_L1_error)
              #else
              __pyx_t_3 = PySequence_ITEM(__pyx_t_12, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 746, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_3);
              #endif
            } else {
              if (__pyx_t_17 >= PyTuple_GET_SIZE(__pyx_t_12)) break;
              #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
              __pyx_t_3 = PyTuple_GET_ITEM(__pyx_t_12, __pyx_t_17); __Pyx_INCREF(__pyx_t_3); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 746, __pyx_L1_error)
              #else
              __pyx_t_3 = PySequence_ITEM(__pyx_t_12, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 746, __pyx_L1_error)
              __Pyx_GOTREF(__pyx_t_3);
              #endif
            }
          } else {
            __pyx_t_3 = __pyx_t_18(__pyx_t_12);
            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, 746, __pyx_L1_error)
              }
              break;
            }
            __Pyx_GOTREF(__pyx_t_3);
          }
          __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 746, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __pyx_9genexpr24__pyx_v_n = __pyx_t_5;
          __pyx_t_3 = __Pyx_PyInt_From_long((1L << __pyx_9genexpr24__pyx_v_n)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 746, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          if (unlikely(__Pyx_ListComp_Append(__pyx_t_10, (PyObject*)__pyx_t_3))) __PYX_ERR(0, 746, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        }
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      } /* exit inner scope */
      __pyx_t_12 = PyTuple_New(1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 746, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_GIVEREF(__pyx_t_10);
      PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_t_10);
      __pyx_t_10 = 0;
      __pyx_t_10 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_12, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 746, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __pyx_t_12 = PyTuple_New(2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 746, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_12);
      __Pyx_INCREF(__pyx_int_0);
      __Pyx_GIVEREF(__pyx_int_0);
      PyTuple_SET_ITEM(__pyx_t_12, 0, __pyx_int_0);
      __Pyx_GIVEREF(__pyx_t_10);
      PyTuple_SET_ITEM(__pyx_t_12, 1, __pyx_t_10);
      __pyx_t_10 = 0;
      __pyx_t_10 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_8discodop_10containers_SmallChartItem), __pyx_t_12, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 746, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
      __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_10);
      __pyx_t_10 = 0;

      /* "discodop/disambiguation.pyx":745
 * 				lcfrsproductions(tree, sent)):
 * 			leaves = node.leaves()
 * 			if lensent < sizeof(uint64_t) * 8:             # <<<<<<<<<<<<<<
 * 				item = SmallChartItem(0, sum([1L << n for n in leaves]))
 * 			else:
 */
      goto __pyx_L18;
    }

    /* "discodop/disambiguation.pyx":748
 * 				item = SmallChartItem(0, sum([1L << n for n in leaves]))
 * 			else:
 * 				fitem = item = FatChartItem(0)             # <<<<<<<<<<<<<<
 * 				for n in leaves:
 * 					SETBIT(fitem.vec, n)
 */
    /*else*/ {
      __pyx_t_10 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_8discodop_10containers_FatChartItem), __pyx_tuple__24, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 748, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      __Pyx_INCREF(__pyx_t_10);
      __Pyx_XDECREF_SET(__pyx_v_fitem, ((struct __pyx_obj_8discodop_10containers_FatChartItem *)__pyx_t_10));
      __Pyx_INCREF(__pyx_t_10);
      __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_10);
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

      /* "discodop/disambiguation.pyx":749
 * 			else:
 * 				fitem = item = FatChartItem(0)
 * 				for n in leaves:             # <<<<<<<<<<<<<<
 * 					SETBIT(fitem.vec, n)
 * 			try:
 */
      if (likely(PyList_CheckExact(__pyx_v_leaves)) || PyTuple_CheckExact(__pyx_v_leaves)) {
        __pyx_t_10 = __pyx_v_leaves; __Pyx_INCREF(__pyx_t_10); __pyx_t_17 = 0;
        __pyx_t_18 = NULL;
      } else {
        __pyx_t_17 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_v_leaves); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 749, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_18 = Py_TYPE(__pyx_t_10)->tp_iternext; if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 749, __pyx_L1_error)
      }
      for (;;) {
        if (likely(!__pyx_t_18)) {
          if (likely(PyList_CheckExact(__pyx_t_10))) {
            if (__pyx_t_17 >= PyList_GET_SIZE(__pyx_t_10)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_12 = PyList_GET_ITEM(__pyx_t_10, __pyx_t_17); __Pyx_INCREF(__pyx_t_12); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 749, __pyx_L1_error)
            #else
            __pyx_t_12 = PySequence_ITEM(__pyx_t_10, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 749, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_12);
            #endif
          } else {
            if (__pyx_t_17 >= PyTuple_GET_SIZE(__pyx_t_10)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_12 = PyTuple_GET_ITEM(__pyx_t_10, __pyx_t_17); __Pyx_INCREF(__pyx_t_12); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 749, __pyx_L1_error)
            #else
            __pyx_t_12 = PySequence_ITEM(__pyx_t_10, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 749, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_12);
            #endif
          }
        } else {
          __pyx_t_12 = __pyx_t_18(__pyx_t_10);
          if (unlikely(!__pyx_t_12)) {
            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, 749, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_12);
        }
        __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_12); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 749, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __pyx_v_n = __pyx_t_5;

        /* "discodop/disambiguation.pyx":750
 * 				fitem = item = FatChartItem(0)
 * 				for n in leaves:
 * 					SETBIT(fitem.vec, n)             # <<<<<<<<<<<<<<
 * 			try:
 * 				whitelist[grammar.toid[node.label]].add(item)
 */
        SETBIT(__pyx_v_fitem->vec, __pyx_v_n);

        /* "discodop/disambiguation.pyx":749
 * 			else:
 * 				fitem = item = FatChartItem(0)
 * 				for n in leaves:             # <<<<<<<<<<<<<<
 * 					SETBIT(fitem.vec, n)
 * 			try:
 */
      }
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    }
    __pyx_L18:;

    /* "discodop/disambiguation.pyx":751
 * 				for n in leaves:
 * 					SETBIT(fitem.vec, n)
 * 			try:             # <<<<<<<<<<<<<<
 * 				whitelist[grammar.toid[node.label]].add(item)
 * 			except KeyError:
 */
    {
      __Pyx_PyThreadState_declare
      __Pyx_PyThreadState_assign
      __Pyx_ExceptionSave(&__pyx_t_19, &__pyx_t_20, &__pyx_t_21);
      __Pyx_XGOTREF(__pyx_t_19);
      __Pyx_XGOTREF(__pyx_t_20);
      __Pyx_XGOTREF(__pyx_t_21);
      /*try:*/ {

        /* "discodop/disambiguation.pyx":752
 * 					SETBIT(fitem.vec, n)
 * 			try:
 * 				whitelist[grammar.toid[node.label]].add(item)             # <<<<<<<<<<<<<<
 * 			except KeyError:
 * 				return [], "'%s' not in grammar" % node.label, None
 */
        if (unlikely(__pyx_v_grammar->toid == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
          __PYX_ERR(0, 752, __pyx_L23_error)
        }
        __pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_label); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 752, __pyx_L23_error)
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_grammar->toid, __pyx_t_12); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 752, __pyx_L23_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __pyx_t_12 = PyObject_GetItem(__pyx_v_whitelist, __pyx_t_3); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 752, __pyx_L23_error)
        __Pyx_GOTREF(__pyx_t_12);
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_add); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 752, __pyx_L23_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0;
        __pyx_t_12 = NULL;
        if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
          __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_3);
          if (likely(__pyx_t_12)) {
            PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
            __Pyx_INCREF(__pyx_t_12);
            __Pyx_INCREF(function);
            __Pyx_DECREF_SET(__pyx_t_3, function);
          }
        }
        if (!__pyx_t_12) {
          __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_item); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 752, __pyx_L23_error)
          __Pyx_GOTREF(__pyx_t_10);
        } else {
          #if CYTHON_FAST_PYCALL
          if (PyFunction_Check(__pyx_t_3)) {
            PyObject *__pyx_temp[2] = {__pyx_t_12, __pyx_v_item};
            __pyx_t_10 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 752, __pyx_L23_error)
            __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
            __Pyx_GOTREF(__pyx_t_10);
          } else
          #endif
          #if CYTHON_FAST_PYCCALL
          if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
            PyObject *__pyx_temp[2] = {__pyx_t_12, __pyx_v_item};
            __pyx_t_10 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 752, __pyx_L23_error)
            __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
            __Pyx_GOTREF(__pyx_t_10);
          } else
          #endif
          {
            __pyx_t_15 = PyTuple_New(1+1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 752, __pyx_L23_error)
            __Pyx_GOTREF(__pyx_t_15);
            __Pyx_GIVEREF(__pyx_t_12); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_12); __pyx_t_12 = NULL;
            __Pyx_INCREF(__pyx_v_item);
            __Pyx_GIVEREF(__pyx_v_item);
            PyTuple_SET_ITEM(__pyx_t_15, 0+1, __pyx_v_item);
            __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_15, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 752, __pyx_L23_error)
            __Pyx_GOTREF(__pyx_t_10);
            __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
          }
        }
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;

        /* "discodop/disambiguation.pyx":751
 * 				for n in leaves:
 * 					SETBIT(fitem.vec, n)
 * 			try:             # <<<<<<<<<<<<<<
 * 				whitelist[grammar.toid[node.label]].add(item)
 * 			except KeyError:
 */
      }
      __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
      __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
      __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0;
      goto __pyx_L30_try_end;
      __pyx_L23_error:;
      __Pyx_PyThreadState_assign
      __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
      __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
      __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;
      __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
      __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;

      /* "discodop/disambiguation.pyx":753
 * 			try:
 * 				whitelist[grammar.toid[node.label]].add(item)
 * 			except KeyError:             # <<<<<<<<<<<<<<
 * 				return [], "'%s' not in grammar" % node.label, None
 * 
 */
      __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
      if (__pyx_t_5) {
        __Pyx_AddTraceback("discodop.disambiguation.treeparsing", __pyx_clineno, __pyx_lineno, __pyx_filename);
        if (__Pyx_GetException(&__pyx_t_10, &__pyx_t_3, &__pyx_t_15) < 0) __PYX_ERR(0, 753, __pyx_L25_except_error)
        __Pyx_GOTREF(__pyx_t_10);
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GOTREF(__pyx_t_15);

        /* "discodop/disambiguation.pyx":754
 * 				whitelist[grammar.toid[node.label]].add(item)
 * 			except KeyError:
 * 				return [], "'%s' not in grammar" % node.label, None             # <<<<<<<<<<<<<<
 * 
 * 			if maskrules and isinstance(node[0], Tree):
 */
        __Pyx_XDECREF(__pyx_r);
        __pyx_t_12 = PyList_New(0); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 754, __pyx_L25_except_error)
        __Pyx_GOTREF(__pyx_t_12);
        __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_label); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 754, __pyx_L25_except_error)
        __Pyx_GOTREF(__pyx_t_6);
        __pyx_t_16 = PyUnicode_Format(__pyx_kp_u_s_not_in_grammar, __pyx_t_6); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 754, __pyx_L25_except_error)
        __Pyx_GOTREF(__pyx_t_16);
        __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
        __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 754, __pyx_L25_except_error)
        __Pyx_GOTREF(__pyx_t_6);
        __Pyx_GIVEREF(__pyx_t_12);
        PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_12);
        __Pyx_GIVEREF(__pyx_t_16);
        PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_16);
        __Pyx_INCREF(Py_None);
        __Pyx_GIVEREF(Py_None);
        PyTuple_SET_ITEM(__pyx_t_6, 2, Py_None);
        __pyx_t_12 = 0;
        __pyx_t_16 = 0;
        __pyx_r = __pyx_t_6;
        __pyx_t_6 = 0;
        __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
        goto __pyx_L26_except_return;
      }
      goto __pyx_L25_except_error;
      __pyx_L25_except_error:;

      /* "discodop/disambiguation.pyx":751
 * 				for n in leaves:
 * 					SETBIT(fitem.vec, n)
 * 			try:             # <<<<<<<<<<<<<<
 * 				whitelist[grammar.toid[node.label]].add(item)
 * 			except KeyError:
 */
      __Pyx_PyThreadState_assign
      __Pyx_XGIVEREF(__pyx_t_19);
      __Pyx_XGIVEREF(__pyx_t_20);
      __Pyx_XGIVEREF(__pyx_t_21);
      __Pyx_ExceptionReset(__pyx_t_19, __pyx_t_20, __pyx_t_21);
      goto __pyx_L1_error;
      __pyx_L26_except_return:;
      __Pyx_PyThreadState_assign
      __Pyx_XGIVEREF(__pyx_t_19);
      __Pyx_XGIVEREF(__pyx_t_20);
      __Pyx_XGIVEREF(__pyx_t_21);
      __Pyx_ExceptionReset(__pyx_t_19, __pyx_t_20, __pyx_t_21);
      goto __pyx_L0;
      __pyx_L30_try_end:;
    }

    /* "discodop/disambiguation.pyx":756
 * 				return [], "'%s' not in grammar" % node.label, None
 * 
 * 			if maskrules and isinstance(node[0], Tree):             # <<<<<<<<<<<<<<
 * 				try:
 * 					ruleno = grammar.rulenos[prodrepr(r, yf)]
 */
    __pyx_t_22 = __Pyx_PyObject_IsTrue(__pyx_v_maskrules); if (unlikely(__pyx_t_22 < 0)) __PYX_ERR(0, 756, __pyx_L1_error)
    if (__pyx_t_22) {
    } else {
      __pyx_t_8 = __pyx_t_22;
      goto __pyx_L34_bool_binop_done;
    }
    __pyx_t_15 = __Pyx_GetItemInt(__pyx_v_node, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 756, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_15);
    __pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_Tree); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 756, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_22 = PyObject_IsInstance(__pyx_t_15, __pyx_t_3); if (unlikely(__pyx_t_22 == -1)) __PYX_ERR(0, 756, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_23 = (__pyx_t_22 != 0);
    __pyx_t_8 = __pyx_t_23;
    __pyx_L34_bool_binop_done:;
    if (__pyx_t_8) {

      /* "discodop/disambiguation.pyx":757
 * 
 * 			if maskrules and isinstance(node[0], Tree):
 * 				try:             # <<<<<<<<<<<<<<
 * 					ruleno = grammar.rulenos[prodrepr(r, yf)]
 * 				except KeyError:
 */
      {
        __Pyx_PyThreadState_declare
        __Pyx_PyThreadState_assign
        __Pyx_ExceptionSave(&__pyx_t_21, &__pyx_t_20, &__pyx_t_19);
        __Pyx_XGOTREF(__pyx_t_21);
        __Pyx_XGOTREF(__pyx_t_20);
        __Pyx_XGOTREF(__pyx_t_19);
        /*try:*/ {

          /* "discodop/disambiguation.pyx":758
 * 			if maskrules and isinstance(node[0], Tree):
 * 				try:
 * 					ruleno = grammar.rulenos[prodrepr(r, yf)]             # <<<<<<<<<<<<<<
 * 				except KeyError:
 * 					return [], "'%s' not in grammar" % prodrepr(r, yf), None
 */
          if (unlikely(__pyx_v_grammar->rulenos == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 758, __pyx_L36_error)
          }
          __pyx_t_3 = __pyx_f_8discodop_14disambiguation_prodrepr(__pyx_v_r, __pyx_v_yf); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 758, __pyx_L36_error)
          __Pyx_GOTREF(__pyx_t_3);
          __pyx_t_15 = __Pyx_PyDict_GetItem(__pyx_v_grammar->rulenos, __pyx_t_3); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 758, __pyx_L36_error)
          __Pyx_GOTREF(__pyx_t_15);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_XDECREF_SET(__pyx_v_ruleno, __pyx_t_15);
          __pyx_t_15 = 0;

          /* "discodop/disambiguation.pyx":757
 * 
 * 			if maskrules and isinstance(node[0], Tree):
 * 				try:             # <<<<<<<<<<<<<<
 * 					ruleno = grammar.rulenos[prodrepr(r, yf)]
 * 				except KeyError:
 */
        }
        __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0;
        __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
        __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0;
        goto __pyx_L43_try_end;
        __pyx_L36_error:;
        __Pyx_PyThreadState_assign
        __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0;
        __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0;
        __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0;

        /* "discodop/disambiguation.pyx":759
 * 				try:
 * 					ruleno = grammar.rulenos[prodrepr(r, yf)]
 * 				except KeyError:             # <<<<<<<<<<<<<<
 * 					return [], "'%s' not in grammar" % prodrepr(r, yf), None
 * 				for n in grammar.rulemapping[ruleno]:
 */
        __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError);
        if (__pyx_t_5) {
          __Pyx_AddTraceback("discodop.disambiguation.treeparsing", __pyx_clineno, __pyx_lineno, __pyx_filename);
          if (__Pyx_GetException(&__pyx_t_15, &__pyx_t_3, &__pyx_t_10) < 0) __PYX_ERR(0, 759, __pyx_L38_except_error)
          __Pyx_GOTREF(__pyx_t_15);
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_GOTREF(__pyx_t_10);

          /* "discodop/disambiguation.pyx":760
 * 					ruleno = grammar.rulenos[prodrepr(r, yf)]
 * 				except KeyError:
 * 					return [], "'%s' not in grammar" % prodrepr(r, yf), None             # <<<<<<<<<<<<<<
 * 				for n in grammar.rulemapping[ruleno]:
 * 					CLEARBIT(grammar.mask, n)
 */
          __Pyx_XDECREF(__pyx_r);
          __pyx_t_6 = PyList_New(0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 760, __pyx_L38_except_error)
          __Pyx_GOTREF(__pyx_t_6);
          __pyx_t_16 = __pyx_f_8discodop_14disambiguation_prodrepr(__pyx_v_r, __pyx_v_yf); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 760, __pyx_L38_except_error)
          __Pyx_GOTREF(__pyx_t_16);
          __pyx_t_12 = PyUnicode_Format(__pyx_kp_u_s_not_in_grammar, __pyx_t_16); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 760, __pyx_L38_except_error)
          __Pyx_GOTREF(__pyx_t_12);
          __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
          __pyx_t_16 = PyTuple_New(3); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 760, __pyx_L38_except_error)
          __Pyx_GOTREF(__pyx_t_16);
          __Pyx_GIVEREF(__pyx_t_6);
          PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_t_6);
          __Pyx_GIVEREF(__pyx_t_12);
          PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_t_12);
          __Pyx_INCREF(Py_None);
          __Pyx_GIVEREF(Py_None);
          PyTuple_SET_ITEM(__pyx_t_16, 2, Py_None);
          __pyx_t_6 = 0;
          __pyx_t_12 = 0;
          __pyx_r = __pyx_t_16;
          __pyx_t_16 = 0;
          __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
          __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
          __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
          goto __pyx_L39_except_return;
        }
        goto __pyx_L38_except_error;
        __pyx_L38_except_error:;

        /* "discodop/disambiguation.pyx":757
 * 
 * 			if maskrules and isinstance(node[0], Tree):
 * 				try:             # <<<<<<<<<<<<<<
 * 					ruleno = grammar.rulenos[prodrepr(r, yf)]
 * 				except KeyError:
 */
        __Pyx_PyThreadState_assign
        __Pyx_XGIVEREF(__pyx_t_21);
        __Pyx_XGIVEREF(__pyx_t_20);
        __Pyx_XGIVEREF(__pyx_t_19);
        __Pyx_ExceptionReset(__pyx_t_21, __pyx_t_20, __pyx_t_19);
        goto __pyx_L1_error;
        __pyx_L39_except_return:;
        __Pyx_PyThreadState_assign
        __Pyx_XGIVEREF(__pyx_t_21);
        __Pyx_XGIVEREF(__pyx_t_20);
        __Pyx_XGIVEREF(__pyx_t_19);
        __Pyx_ExceptionReset(__pyx_t_21, __pyx_t_20, __pyx_t_19);
        goto __pyx_L0;
        __pyx_L43_try_end:;
      }

      /* "discodop/disambiguation.pyx":761
 * 				except KeyError:
 * 					return [], "'%s' not in grammar" % prodrepr(r, yf), None
 * 				for n in grammar.rulemapping[ruleno]:             # <<<<<<<<<<<<<<
 * 					CLEARBIT(grammar.mask, n)
 * 					# if TESTBIT(grammar.mask, n):
 */
      if (unlikely(__pyx_v_grammar->rulemapping == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
        __PYX_ERR(0, 761, __pyx_L1_error)
      }
      __pyx_t_10 = PyObject_GetItem(__pyx_v_grammar->rulemapping, __pyx_v_ruleno); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 761, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      if (likely(PyList_CheckExact(__pyx_t_10)) || PyTuple_CheckExact(__pyx_t_10)) {
        __pyx_t_3 = __pyx_t_10; __Pyx_INCREF(__pyx_t_3); __pyx_t_17 = 0;
        __pyx_t_18 = NULL;
      } else {
        __pyx_t_17 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 761, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_18 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 761, __pyx_L1_error)
      }
      __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
      for (;;) {
        if (likely(!__pyx_t_18)) {
          if (likely(PyList_CheckExact(__pyx_t_3))) {
            if (__pyx_t_17 >= PyList_GET_SIZE(__pyx_t_3)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_10 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_17); __Pyx_INCREF(__pyx_t_10); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 761, __pyx_L1_error)
            #else
            __pyx_t_10 = PySequence_ITEM(__pyx_t_3, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 761, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_10);
            #endif
          } else {
            if (__pyx_t_17 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
            #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
            __pyx_t_10 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_17); __Pyx_INCREF(__pyx_t_10); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 761, __pyx_L1_error)
            #else
            __pyx_t_10 = PySequence_ITEM(__pyx_t_3, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 761, __pyx_L1_error)
            __Pyx_GOTREF(__pyx_t_10);
            #endif
          }
        } else {
          __pyx_t_10 = __pyx_t_18(__pyx_t_3);
          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, 761, __pyx_L1_error)
            }
            break;
          }
          __Pyx_GOTREF(__pyx_t_10);
        }
        __pyx_t_5 = __Pyx_PyInt_As_int(__pyx_t_10); if (unlikely((__pyx_t_5 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 761, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
        __pyx_v_n = __pyx_t_5;

        /* "discodop/disambiguation.pyx":762
 * 					return [], "'%s' not in grammar" % prodrepr(r, yf), None
 * 				for n in grammar.rulemapping[ruleno]:
 * 					CLEARBIT(grammar.mask, n)             # <<<<<<<<<<<<<<
 * 					# if TESTBIT(grammar.mask, n):
 * 					# 	CLEARBIT(grammar.mask, n)
 */
        CLEARBIT(__pyx_v_grammar->mask, __pyx_v_n);

        /* "discodop/disambiguation.pyx":761
 * 				except KeyError:
 * 					return [], "'%s' not in grammar" % prodrepr(r, yf), None
 * 				for n in grammar.rulemapping[ruleno]:             # <<<<<<<<<<<<<<
 * 					CLEARBIT(grammar.mask, n)
 * 					# if TESTBIT(grammar.mask, n):
 */
      }
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

      /* "discodop/disambiguation.pyx":756
 * 				return [], "'%s' not in grammar" % node.label, None
 * 
 * 			if maskrules and isinstance(node[0], Tree):             # <<<<<<<<<<<<<<
 * 				try:
 * 					ruleno = grammar.rulenos[prodrepr(r, yf)]
 */
    }

    /* "discodop/disambiguation.pyx":742
 * 	for treestr in trees:
 * 		tree = Tree(treestr)
 * 		for node, (r, yf) in zip(tree.subtrees(),             # <<<<<<<<<<<<<<
 * 				lcfrsproductions(tree, sent)):
 * 			leaves = node.leaves()
 */
  }
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;

  /* "discodop/disambiguation.pyx":740
 * 	if maskrules:
 * 		grammar.setmask([])  # block all rules
 * 	for treestr in trees:             # <<<<<<<<<<<<<<
 * 		tree = Tree(treestr)
 * 		for node, (r, yf) in zip(tree.subtrees(),
 */
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":771
 * 	# Project labels to all possible labels that generate that label. For DOP
 * 	# reduction, all possible ids; for Double DOP, ignore artificial labels.
 * 	for label, n in grammar.toid.items():             # <<<<<<<<<<<<<<
 * 		if backtransform is None:
 * 			whitelist[n] = whitelist[grammar.toid[REMOVEIDS.sub('', label)]]
 */
__pyx_t_4 = 0;
if (unlikely(__pyx_v_grammar->toid == Py_None)) {
  PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "items");
  __PYX_ERR(0, 771, __pyx_L1_error)
}
__pyx_t_9 = __Pyx_dict_iterator(__pyx_v_grammar->toid, 1, __pyx_n_s_items, (&__pyx_t_1), (&__pyx_t_5)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 771, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_9);
__Pyx_XDECREF(__pyx_t_2);
__pyx_t_2 = __pyx_t_9;
__pyx_t_9 = 0;
while (1) {
  __pyx_t_7 = __Pyx_dict_iter_next(__pyx_t_2, __pyx_t_1, &__pyx_t_4, &__pyx_t_9, &__pyx_t_3, NULL, __pyx_t_5);
  if (unlikely(__pyx_t_7 == 0)) break;
  if (unlikely(__pyx_t_7 == -1)) __PYX_ERR(0, 771, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 771, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_XDECREF_SET(__pyx_v_label, __pyx_t_9);
  __pyx_t_9 = 0;
  __pyx_v_n = __pyx_t_7;

  /* "discodop/disambiguation.pyx":772
 * 	# reduction, all possible ids; for Double DOP, ignore artificial labels.
 * 	for label, n in grammar.toid.items():
 * 		if backtransform is None:             # <<<<<<<<<<<<<<
 * 			whitelist[n] = whitelist[grammar.toid[REMOVEIDS.sub('', label)]]
 * 		elif '@' in label or '}<' in label:
 */
  __pyx_t_8 = (__pyx_v_backtransform == Py_None);
  __pyx_t_23 = (__pyx_t_8 != 0);
  if (__pyx_t_23) {

    /* "discodop/disambiguation.pyx":773
 * 	for label, n in grammar.toid.items():
 * 		if backtransform is None:
 * 			whitelist[n] = whitelist[grammar.toid[REMOVEIDS.sub('', label)]]             # <<<<<<<<<<<<<<
 * 		elif '@' in label or '}<' in label:
 * 			whitelist[n] = None  # do not prune item
 */
    if (unlikely(__pyx_v_grammar->toid == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 773, __pyx_L1_error)
    }
    __pyx_t_9 = __Pyx_GetModuleGlobalName(__pyx_n_s_REMOVEIDS); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 773, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_sub); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 773, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
    __pyx_t_9 = NULL;
    __pyx_t_7 = 0;
    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);
        __pyx_t_7 = 1;
      }
    }
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_10)) {
      PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_kp_u__4, __pyx_v_label};
      __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 773, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) {
      PyObject *__pyx_temp[3] = {__pyx_t_9, __pyx_kp_u__4, __pyx_v_label};
      __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-__pyx_t_7, 2+__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 773, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_GOTREF(__pyx_t_3);
    } else
    #endif
    {
      __pyx_t_15 = PyTuple_New(2+__pyx_t_7); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 773, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_15);
      if (__pyx_t_9) {
        __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_t_9); __pyx_t_9 = NULL;
      }
      __Pyx_INCREF(__pyx_kp_u__4);
      __Pyx_GIVEREF(__pyx_kp_u__4);
      PyTuple_SET_ITEM(__pyx_t_15, 0+__pyx_t_7, __pyx_kp_u__4);
      __Pyx_INCREF(__pyx_v_label);
      __Pyx_GIVEREF(__pyx_v_label);
      PyTuple_SET_ITEM(__pyx_t_15, 1+__pyx_t_7, __pyx_v_label);
      __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_15, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 773, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
    }
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    __pyx_t_10 = __Pyx_PyDict_GetItem(__pyx_v_grammar->toid, __pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 773, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_3 = PyObject_GetItem(__pyx_v_whitelist, __pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 773, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
    if (unlikely(__Pyx_SetItemInt(__pyx_v_whitelist, __pyx_v_n, __pyx_t_3, int, 1, __Pyx_PyInt_From_int, 1, 0, 0) < 0)) __PYX_ERR(0, 773, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

    /* "discodop/disambiguation.pyx":772
 * 	# reduction, all possible ids; for Double DOP, ignore artificial labels.
 * 	for label, n in grammar.toid.items():
 * 		if backtransform is None:             # <<<<<<<<<<<<<<
 * 			whitelist[n] = whitelist[grammar.toid[REMOVEIDS.sub('', label)]]
 * 		elif '@' in label or '}<' in label:
 */
    goto __pyx_L50;
  }

  /* "discodop/disambiguation.pyx":774
 * 		if backtransform is None:
 * 			whitelist[n] = whitelist[grammar.toid[REMOVEIDS.sub('', label)]]
 * 		elif '@' in label or '}<' in label:             # <<<<<<<<<<<<<<
 * 			whitelist[n] = None  # do not prune item
 * 
 */
  __pyx_t_8 = (__Pyx_PySequence_ContainsTF(__pyx_kp_u__16, __pyx_v_label, Py_EQ)); if (unlikely(__pyx_t_8 < 0)) __PYX_ERR(0, 774, __pyx_L1_error)
  __pyx_t_22 = (__pyx_t_8 != 0);
  if (!__pyx_t_22) {
  } else {
    __pyx_t_23 = __pyx_t_22;
    goto __pyx_L51_bool_binop_done;
  }
  __pyx_t_22 = (__Pyx_PySequence_ContainsTF(__pyx_kp_u__13, __pyx_v_label, Py_EQ)); if (unlikely(__pyx_t_22 < 0)) __PYX_ERR(0, 774, __pyx_L1_error)
  __pyx_t_8 = (__pyx_t_22 != 0);
  __pyx_t_23 = __pyx_t_8;
  __pyx_L51_bool_binop_done:;
  if (__pyx_t_23) {

    /* "discodop/disambiguation.pyx":775
 * 			whitelist[n] = whitelist[grammar.toid[REMOVEIDS.sub('', label)]]
 * 		elif '@' in label or '}<' in label:
 * 			whitelist[n] = None  # do not prune item             # <<<<<<<<<<<<<<
 * 
 * 	# finally, we parse with the small set of allowed labeled spans.
 */
    if (unlikely(__Pyx_SetItemInt(__pyx_v_whitelist, __pyx_v_n, Py_None, int, 1, __Pyx_PyInt_From_int, 1, 0, 0) < 0)) __PYX_ERR(0, 775, __pyx_L1_error)

    /* "discodop/disambiguation.pyx":774
 * 		if backtransform is None:
 * 			whitelist[n] = whitelist[grammar.toid[REMOVEIDS.sub('', label)]]
 * 		elif '@' in label or '}<' in label:             # <<<<<<<<<<<<<<
 * 			whitelist[n] = None  # do not prune item
 * 
 */
  }
  __pyx_L50:;
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":780
 * 	# we do not parse with the PCFG parser even if possible, because that
 * 	# requires a different way of pruning.
 * 	chart, _ = plcfrs.parse(sent, grammar, tags=tags, whitelist=whitelist)             # <<<<<<<<<<<<<<
 * 
 * 	if not chart:
 */
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_plcfrs); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 780, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_parse); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 780, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 780, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(__pyx_v_sent);
__Pyx_GIVEREF(__pyx_v_sent);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_sent);
__Pyx_INCREF(((PyObject *)__pyx_v_grammar));
__Pyx_GIVEREF(((PyObject *)__pyx_v_grammar));
PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_v_grammar));
__pyx_t_10 = PyDict_New(); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 780, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_10);
if (PyDict_SetItem(__pyx_t_10, __pyx_n_s_tags, __pyx_v_tags) < 0) __PYX_ERR(0, 780, __pyx_L1_error)
if (PyDict_SetItem(__pyx_t_10, __pyx_n_s_whitelist, __pyx_v_whitelist) < 0) __PYX_ERR(0, 780, __pyx_L1_error)
__pyx_t_15 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, __pyx_t_10); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 780, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_15);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
if ((likely(PyTuple_CheckExact(__pyx_t_15))) || (PyList_CheckExact(__pyx_t_15))) {
  PyObject* sequence = __pyx_t_15;
  #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, 780, __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_2 = PyTuple_GET_ITEM(sequence, 1); 
  } else {
    __pyx_t_10 = PyList_GET_ITEM(sequence, 0); 
    __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
  }
  __Pyx_INCREF(__pyx_t_10);
  __Pyx_INCREF(__pyx_t_2);
  #else
  __pyx_t_10 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 780, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 780, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  #endif
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
} else {
  Py_ssize_t index = -1;
  __pyx_t_3 = PyObject_GetIter(__pyx_t_15); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 780, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
  __pyx_t_14 = Py_TYPE(__pyx_t_3)->tp_iternext;
  index = 0; __pyx_t_10 = __pyx_t_14(__pyx_t_3); if (unlikely(!__pyx_t_10)) goto __pyx_L53_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_10);
  index = 1; __pyx_t_2 = __pyx_t_14(__pyx_t_3); if (unlikely(!__pyx_t_2)) goto __pyx_L53_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_3), 2) < 0) __PYX_ERR(0, 780, __pyx_L1_error)
  __pyx_t_14 = NULL;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  goto __pyx_L54_unpacking_done;
  __pyx_L53_unpacking_failed:;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_14 = NULL;
  if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
  __PYX_ERR(0, 780, __pyx_L1_error)
  __pyx_L54_unpacking_done:;
}
__pyx_v_chart = __pyx_t_10;
__pyx_t_10 = 0;
__pyx_v__ = __pyx_t_2;
__pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":782
 * 	chart, _ = plcfrs.parse(sent, grammar, tags=tags, whitelist=whitelist)
 * 
 * 	if not chart:             # <<<<<<<<<<<<<<
 * 		return [], 'tree parsing failed', None
 * 	return lazykbest(chart, m) + (chart, )
 */
__pyx_t_23 = __Pyx_PyObject_IsTrue(__pyx_v_chart); if (unlikely(__pyx_t_23 < 0)) __PYX_ERR(0, 782, __pyx_L1_error)
__pyx_t_8 = ((!__pyx_t_23) != 0);
if (__pyx_t_8) {

  /* "discodop/disambiguation.pyx":783
 * 
 * 	if not chart:
 * 		return [], 'tree parsing failed', None             # <<<<<<<<<<<<<<
 * 	return lazykbest(chart, m) + (chart, )
 * 
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_15 = PyList_New(0); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 783, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_15);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 783, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_15);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_15);
  __Pyx_INCREF(__pyx_kp_u_tree_parsing_failed);
  __Pyx_GIVEREF(__pyx_kp_u_tree_parsing_failed);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_kp_u_tree_parsing_failed);
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  PyTuple_SET_ITEM(__pyx_t_2, 2, Py_None);
  __pyx_t_15 = 0;
  __pyx_r = __pyx_t_2;
  __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "discodop/disambiguation.pyx":782
 * 	chart, _ = plcfrs.parse(sent, grammar, tags=tags, whitelist=whitelist)
 * 
 * 	if not chart:             # <<<<<<<<<<<<<<
 * 		return [], 'tree parsing failed', None
 * 	return lazykbest(chart, m) + (chart, )
 */
}

/* "discodop/disambiguation.pyx":784
 * 	if not chart:
 * 		return [], 'tree parsing failed', None
 * 	return lazykbest(chart, m) + (chart, )             # <<<<<<<<<<<<<<
 * 
 * 
 */
__Pyx_XDECREF(__pyx_r);
__pyx_t_15 = __Pyx_GetModuleGlobalName(__pyx_n_s_lazykbest); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 784, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_15);
__pyx_t_10 = __Pyx_PyInt_From_int(__pyx_v_m); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 784, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_10);
__pyx_t_3 = NULL;
__pyx_t_5 = 0;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_15))) {
  __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_15);
  if (likely(__pyx_t_3)) {
    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15);
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(function);
    __Pyx_DECREF_SET(__pyx_t_15, function);
    __pyx_t_5 = 1;
  }
}
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_15)) {
  PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_chart, __pyx_t_10};
  __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 784, __pyx_L1_error)
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 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_15)) {
  PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_chart, __pyx_t_10};
  __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_15, __pyx_temp+1-__pyx_t_5, 2+__pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 784, __pyx_L1_error)
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
} else
#endif
{
  __pyx_t_9 = PyTuple_New(2+__pyx_t_5); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 784, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_9);
  if (__pyx_t_3) {
    __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3); __pyx_t_3 = NULL;
  }
  __Pyx_INCREF(__pyx_v_chart);
  __Pyx_GIVEREF(__pyx_v_chart);
  PyTuple_SET_ITEM(__pyx_t_9, 0+__pyx_t_5, __pyx_v_chart);
  __Pyx_GIVEREF(__pyx_t_10);
  PyTuple_SET_ITEM(__pyx_t_9, 1+__pyx_t_5, __pyx_t_10);
  __pyx_t_10 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_15, __pyx_t_9, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 784, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
}
__Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
__pyx_t_15 = PyTuple_New(1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 784, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_15);
__Pyx_INCREF(__pyx_v_chart);
__Pyx_GIVEREF(__pyx_v_chart);
PyTuple_SET_ITEM(__pyx_t_15, 0, __pyx_v_chart);
__pyx_t_9 = PyNumber_Add(__pyx_t_2, __pyx_t_15); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 784, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_9);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
__pyx_r = __pyx_t_9;
__pyx_t_9 = 0;
goto __pyx_L0;

/* "discodop/disambiguation.pyx":718
 * 
 * 
 * def treeparsing(trees, sent, Grammar grammar, int m, backtransform, tags=None,             # <<<<<<<<<<<<<<
 * 		maskrules=False):
 * 	"""Assign probabilities to a sequence of trees with a DOP grammar.
 */

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_9);
__Pyx_XDECREF(__pyx_t_10);
__Pyx_XDECREF(__pyx_t_12);
__Pyx_XDECREF(__pyx_t_15);
__Pyx_XDECREF(__pyx_t_16);
__Pyx_AddTraceback("discodop.disambiguation.treeparsing", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_fitem);
__Pyx_XDECREF(__pyx_v_whitelist);
__Pyx_XDECREF(__pyx_v_treestr);
__Pyx_XDECREF(__pyx_v_tree);
__Pyx_XDECREF(__pyx_v_node);
__Pyx_XDECREF(__pyx_v_r);
__Pyx_XDECREF(__pyx_v_yf);
__Pyx_XDECREF(__pyx_v_leaves);
__Pyx_XDECREF(__pyx_v_item);
__Pyx_XDECREF(__pyx_v_ruleno);
__Pyx_XDECREF(__pyx_v_label);
__Pyx_XDECREF(__pyx_v_chart);
__Pyx_XDECREF(__pyx_v__);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":787
 * 
 * 
 * cdef double getderivprob(RankedEdge deriv, Chart chart, list sent):             # <<<<<<<<<<<<<<
 * 	"""Recursively calculate probability of a derivation.
 * 
 */

static double __pyx_f_8discodop_14disambiguation_getderivprob(struct __pyx_obj_8discodop_10containers_RankedEdge *__pyx_v_deriv, struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, PyObject *__pyx_v_sent) {
double __pyx_v_result;
uint32_t __pyx_v_label;
PyObject *__pyx_v_word = NULL;
double __pyx_r;
__Pyx_RefNannyDeclarations
int __pyx_t_1;
PyObject *__pyx_t_2 = NULL;
int __pyx_t_3;
PyObject *__pyx_t_4 = NULL;
double __pyx_t_5;
__Pyx_RefNannySetupContext("getderivprob", 0);

/* "discodop/disambiguation.pyx":793
 * 	model of the same grammar."""
 * 	cdef double result
 * 	if deriv.edge.rule is NULL:  # is terminal             # <<<<<<<<<<<<<<
 * 		label = chart.label(deriv.head)
 * 		word = sent[chart.lexidx(deriv.edge)]
 */
__pyx_t_1 = ((__pyx_v_deriv->edge->rule == NULL) != 0);
if (__pyx_t_1) {

  /* "discodop/disambiguation.pyx":794
 * 	cdef double result
 * 	if deriv.edge.rule is NULL:  # is terminal
 * 		label = chart.label(deriv.head)             # <<<<<<<<<<<<<<
 * 		word = sent[chart.lexidx(deriv.edge)]
 * 		return (<LexicalRule>chart.grammar.lexicalbylhs[label][word]).prob
 */
  __pyx_t_2 = __pyx_v_deriv->head;
  __Pyx_INCREF(__pyx_t_2);
  __pyx_v_label = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->label(__pyx_v_chart, __pyx_t_2);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "discodop/disambiguation.pyx":795
 * 	if deriv.edge.rule is NULL:  # is terminal
 * 		label = chart.label(deriv.head)
 * 		word = sent[chart.lexidx(deriv.edge)]             # <<<<<<<<<<<<<<
 * 		return (<LexicalRule>chart.grammar.lexicalbylhs[label][word]).prob
 * 	result = deriv.edge.rule.prob
 */
  if (unlikely(__pyx_v_sent == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 795, __pyx_L1_error)
  }
  __pyx_t_3 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->lexidx(__pyx_v_chart, __pyx_v_deriv->edge);
  __pyx_t_2 = PyList_GET_ITEM(__pyx_v_sent, __pyx_t_3);
  __Pyx_INCREF(__pyx_t_2);
  __pyx_v_word = __pyx_t_2;
  __pyx_t_2 = 0;

  /* "discodop/disambiguation.pyx":796
 * 		label = chart.label(deriv.head)
 * 		word = sent[chart.lexidx(deriv.edge)]
 * 		return (<LexicalRule>chart.grammar.lexicalbylhs[label][word]).prob             # <<<<<<<<<<<<<<
 * 	result = deriv.edge.rule.prob
 * 	result += getderivprob((<DoubleEntry>chart.rankededges[
 */
  if (unlikely(__pyx_v_chart->grammar->lexicalbylhs == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 796, __pyx_L1_error)
  }
  __pyx_t_2 = __Pyx_PyInt_From_uint32_t(__pyx_v_label); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 796, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_chart->grammar->lexicalbylhs, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 796, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_2 = PyObject_GetItem(__pyx_t_4, __pyx_v_word); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 796, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_r = ((struct __pyx_obj_8discodop_10containers_LexicalRule *)__pyx_t_2)->prob;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  goto __pyx_L0;

  /* "discodop/disambiguation.pyx":793
 * 	model of the same grammar."""
 * 	cdef double result
 * 	if deriv.edge.rule is NULL:  # is terminal             # <<<<<<<<<<<<<<
 * 		label = chart.label(deriv.head)
 * 		word = sent[chart.lexidx(deriv.edge)]
 */
}

/* "discodop/disambiguation.pyx":797
 * 		word = sent[chart.lexidx(deriv.edge)]
 * 		return (<LexicalRule>chart.grammar.lexicalbylhs[label][word]).prob
 * 	result = deriv.edge.rule.prob             # <<<<<<<<<<<<<<
 * 	result += getderivprob((<DoubleEntry>chart.rankededges[
 * 			chart.left(deriv)][deriv.left]).key,
 */
__pyx_t_5 = __pyx_v_deriv->edge->rule->prob;
__pyx_v_result = __pyx_t_5;

/* "discodop/disambiguation.pyx":798
 * 		return (<LexicalRule>chart.grammar.lexicalbylhs[label][word]).prob
 * 	result = deriv.edge.rule.prob
 * 	result += getderivprob((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 			chart.left(deriv)][deriv.left]).key,
 * 			chart, sent)
 */
if (unlikely(__pyx_v_chart->rankededges == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
  __PYX_ERR(0, 798, __pyx_L1_error)
}

/* "discodop/disambiguation.pyx":799
 * 	result = deriv.edge.rule.prob
 * 	result += getderivprob((<DoubleEntry>chart.rankededges[
 * 			chart.left(deriv)][deriv.left]).key,             # <<<<<<<<<<<<<<
 * 			chart, sent)
 * 	if deriv.edge.rule.rhs2:
 */
__pyx_t_2 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->left(__pyx_v_chart, __pyx_v_deriv); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 799, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);

/* "discodop/disambiguation.pyx":798
 * 		return (<LexicalRule>chart.grammar.lexicalbylhs[label][word]).prob
 * 	result = deriv.edge.rule.prob
 * 	result += getderivprob((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 			chart.left(deriv)][deriv.left]).key,
 * 			chart, sent)
 */
__pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_chart->rankededges, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 798, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":799
 * 	result = deriv.edge.rule.prob
 * 	result += getderivprob((<DoubleEntry>chart.rankededges[
 * 			chart.left(deriv)][deriv.left]).key,             # <<<<<<<<<<<<<<
 * 			chart, sent)
 * 	if deriv.edge.rule.rhs2:
 */
__pyx_t_2 = __Pyx_GetItemInt(__pyx_t_4, __pyx_v_deriv->left, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 799, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

/* "discodop/disambiguation.pyx":798
 * 		return (<LexicalRule>chart.grammar.lexicalbylhs[label][word]).prob
 * 	result = deriv.edge.rule.prob
 * 	result += getderivprob((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 			chart.left(deriv)][deriv.left]).key,
 * 			chart, sent)
 */
if (!(likely(((((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_2)->key) == Py_None) || likely(__Pyx_TypeTest(((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_2)->key, __pyx_ptype_8discodop_10containers_RankedEdge))))) __PYX_ERR(0, 799, __pyx_L1_error)

/* "discodop/disambiguation.pyx":799
 * 	result = deriv.edge.rule.prob
 * 	result += getderivprob((<DoubleEntry>chart.rankededges[
 * 			chart.left(deriv)][deriv.left]).key,             # <<<<<<<<<<<<<<
 * 			chart, sent)
 * 	if deriv.edge.rule.rhs2:
 */
__pyx_t_4 = ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_2)->key;
__Pyx_INCREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":798
 * 		return (<LexicalRule>chart.grammar.lexicalbylhs[label][word]).prob
 * 	result = deriv.edge.rule.prob
 * 	result += getderivprob((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 			chart.left(deriv)][deriv.left]).key,
 * 			chart, sent)
 */
__pyx_v_result = (__pyx_v_result + __pyx_f_8discodop_14disambiguation_getderivprob(((struct __pyx_obj_8discodop_10containers_RankedEdge *)__pyx_t_4), __pyx_v_chart, __pyx_v_sent));
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

/* "discodop/disambiguation.pyx":801
 * 			chart.left(deriv)][deriv.left]).key,
 * 			chart, sent)
 * 	if deriv.edge.rule.rhs2:             # <<<<<<<<<<<<<<
 * 		result += getderivprob((<DoubleEntry>chart.rankededges[
 * 				chart.right(deriv)][deriv.right]).key,
 */
__pyx_t_1 = (__pyx_v_deriv->edge->rule->rhs2 != 0);
if (__pyx_t_1) {

  /* "discodop/disambiguation.pyx":802
 * 			chart, sent)
 * 	if deriv.edge.rule.rhs2:
 * 		result += getderivprob((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 				chart.right(deriv)][deriv.right]).key,
 * 				chart, sent)
 */
  if (unlikely(__pyx_v_chart->rankededges == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 802, __pyx_L1_error)
  }

  /* "discodop/disambiguation.pyx":803
 * 	if deriv.edge.rule.rhs2:
 * 		result += getderivprob((<DoubleEntry>chart.rankededges[
 * 				chart.right(deriv)][deriv.right]).key,             # <<<<<<<<<<<<<<
 * 				chart, sent)
 * 	return result
 */
  __pyx_t_4 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->right(__pyx_v_chart, __pyx_v_deriv); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 803, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);

  /* "discodop/disambiguation.pyx":802
 * 			chart, sent)
 * 	if deriv.edge.rule.rhs2:
 * 		result += getderivprob((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 				chart.right(deriv)][deriv.right]).key,
 * 				chart, sent)
 */
  __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_chart->rankededges, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 802, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":803
 * 	if deriv.edge.rule.rhs2:
 * 		result += getderivprob((<DoubleEntry>chart.rankededges[
 * 				chart.right(deriv)][deriv.right]).key,             # <<<<<<<<<<<<<<
 * 				chart, sent)
 * 	return result
 */
  __pyx_t_4 = __Pyx_GetItemInt(__pyx_t_2, __pyx_v_deriv->right, int, 1, __Pyx_PyInt_From_int, 0, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 803, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "discodop/disambiguation.pyx":802
 * 			chart, sent)
 * 	if deriv.edge.rule.rhs2:
 * 		result += getderivprob((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 				chart.right(deriv)][deriv.right]).key,
 * 				chart, sent)
 */
  if (!(likely(((((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_4)->key) == Py_None) || likely(__Pyx_TypeTest(((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_4)->key, __pyx_ptype_8discodop_10containers_RankedEdge))))) __PYX_ERR(0, 803, __pyx_L1_error)

  /* "discodop/disambiguation.pyx":803
 * 	if deriv.edge.rule.rhs2:
 * 		result += getderivprob((<DoubleEntry>chart.rankededges[
 * 				chart.right(deriv)][deriv.right]).key,             # <<<<<<<<<<<<<<
 * 				chart, sent)
 * 	return result
 */
  __pyx_t_2 = ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_4)->key;
  __Pyx_INCREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":802
 * 			chart, sent)
 * 	if deriv.edge.rule.rhs2:
 * 		result += getderivprob((<DoubleEntry>chart.rankededges[             # <<<<<<<<<<<<<<
 * 				chart.right(deriv)][deriv.right]).key,
 * 				chart, sent)
 */
  __pyx_v_result = (__pyx_v_result + __pyx_f_8discodop_14disambiguation_getderivprob(((struct __pyx_obj_8discodop_10containers_RankedEdge *)__pyx_t_2), __pyx_v_chart, __pyx_v_sent));
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "discodop/disambiguation.pyx":801
 * 			chart.left(deriv)][deriv.left]).key,
 * 			chart, sent)
 * 	if deriv.edge.rule.rhs2:             # <<<<<<<<<<<<<<
 * 		result += getderivprob((<DoubleEntry>chart.rankededges[
 * 				chart.right(deriv)][deriv.right]).key,
 */
}

/* "discodop/disambiguation.pyx":805
 * 				chart.right(deriv)][deriv.right]).key,
 * 				chart, sent)
 * 	return result             # <<<<<<<<<<<<<<
 * 
 * cpdef viterbiderivation(Chart chart):
 */
__pyx_r = __pyx_v_result;
goto __pyx_L0;

/* "discodop/disambiguation.pyx":787
 * 
 * 
 * cdef double getderivprob(RankedEdge deriv, Chart chart, list sent):             # <<<<<<<<<<<<<<
 * 	"""Recursively calculate probability of a derivation.
 * 
 */

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_WriteUnraisable("discodop.disambiguation.getderivprob", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_word);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":807
 * 	return result
 * 
 * cpdef viterbiderivation(Chart chart):             # <<<<<<<<<<<<<<
 * 	"""Wrapper to get Viterbi derivation from chart."""
 * 	# Ask for at least 10 derivations because unary cycles.
 */

static PyObject *__pyx_pw_8discodop_14disambiguation_17viterbiderivation(PyObject *__pyx_self, PyObject *__pyx_v_chart); /*proto*/
static PyObject *__pyx_f_8discodop_14disambiguation_viterbiderivation(struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, CYTHON_UNUSED int __pyx_skip_dispatch) {
PyObject *__pyx_v_derivations = 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("viterbiderivation", 0);

/* "discodop/disambiguation.pyx":810
 * 	"""Wrapper to get Viterbi derivation from chart."""
 * 	# Ask for at least 10 derivations because unary cycles.
 * 	derivations = lazykbest(chart, 10)[0]             # <<<<<<<<<<<<<<
 * 	return derivations[0]
 * 
 */
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_lazykbest); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 810, __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, ((PyObject *)__pyx_v_chart), __pyx_int_10};
  __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 810, __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[3] = {__pyx_t_3, ((PyObject *)__pyx_v_chart), __pyx_int_10};
  __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 810, __pyx_L1_error)
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 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, 810, __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(((PyObject *)__pyx_v_chart));
  __Pyx_GIVEREF(((PyObject *)__pyx_v_chart));
  PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, ((PyObject *)__pyx_v_chart));
  __Pyx_INCREF(__pyx_int_10);
  __Pyx_GIVEREF(__pyx_int_10);
  PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_int_10);
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 810, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 810, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_derivations = __pyx_t_2;
__pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":811
 * 	# Ask for at least 10 derivations because unary cycles.
 * 	derivations = lazykbest(chart, 10)[0]
 * 	return derivations[0]             # <<<<<<<<<<<<<<
 * 
 * 
 */
__Pyx_XDECREF(__pyx_r);
__pyx_t_2 = __Pyx_GetItemInt(__pyx_v_derivations, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 811, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
goto __pyx_L0;

/* "discodop/disambiguation.pyx":807
 * 	return result
 * 
 * cpdef viterbiderivation(Chart chart):             # <<<<<<<<<<<<<<
 * 	"""Wrapper to get Viterbi derivation from chart."""
 * 	# Ask for at least 10 derivations because unary cycles.
 */

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_AddTraceback("discodop.disambiguation.viterbiderivation", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_derivations);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* Python wrapper */
static PyObject *__pyx_pw_8discodop_14disambiguation_17viterbiderivation(PyObject *__pyx_self, PyObject *__pyx_v_chart); /*proto*/
static char __pyx_doc_8discodop_14disambiguation_16viterbiderivation[] = "viterbiderivation(Chart chart)\nWrapper to get Viterbi derivation from chart.";
static PyObject *__pyx_pw_8discodop_14disambiguation_17viterbiderivation(PyObject *__pyx_self, PyObject *__pyx_v_chart) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("viterbiderivation (wrapper)", 0);
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_chart), __pyx_ptype_8discodop_10containers_Chart, 1, "chart", 0))) __PYX_ERR(0, 807, __pyx_L1_error)
__pyx_r = __pyx_pf_8discodop_14disambiguation_16viterbiderivation(__pyx_self, ((struct __pyx_obj_8discodop_10containers_Chart *)__pyx_v_chart));

/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

static PyObject *__pyx_pf_8discodop_14disambiguation_16viterbiderivation(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
__Pyx_RefNannySetupContext("viterbiderivation", 0);
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = __pyx_f_8discodop_14disambiguation_viterbiderivation(__pyx_v_chart, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 807, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("discodop.disambiguation.viterbiderivation", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":814
 * 
 * 
 * def getsamples(Chart chart, k, debin=None):             # <<<<<<<<<<<<<<
 * 	"""Samples *k* derivations from a chart."""
 * 	cdef dict tables = {}
 */

/* Python wrapper */
static PyObject *__pyx_pw_8discodop_14disambiguation_19getsamples(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8discodop_14disambiguation_18getsamples[] = "getsamples(Chart chart, k, debin=None)\nSamples *k* derivations from a chart.";
static PyMethodDef __pyx_mdef_8discodop_14disambiguation_19getsamples = {"getsamples", (PyCFunction)__pyx_pw_8discodop_14disambiguation_19getsamples, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8discodop_14disambiguation_18getsamples};
static PyObject *__pyx_pw_8discodop_14disambiguation_19getsamples(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart = 0;
PyObject *__pyx_v_k = 0;
PyObject *__pyx_v_debin = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("getsamples (wrapper)", 0);
{
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_chart,&__pyx_n_s_k,&__pyx_n_s_debin,0};
  PyObject* values[3] = {0,0,0};
  values[2] = ((PyObject *)Py_None);
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args;
    const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
    switch (pos_args) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    kw_args = PyDict_Size(__pyx_kwds);
    switch (pos_args) {
      case  0:
      if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_chart)) != 0)) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_k)) != 0)) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("getsamples", 0, 2, 3, 1); __PYX_ERR(0, 814, __pyx_L3_error)
      }
      case  2:
      if (kw_args > 0) {
        PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s_debin);
        if (value) { values[2] = value; kw_args--; }
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "getsamples") < 0)) __PYX_ERR(0, 814, __pyx_L3_error)
    }
  } else {
    switch (PyTuple_GET_SIZE(__pyx_args)) {
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      break;
      default: goto __pyx_L5_argtuple_error;
    }
  }
  __pyx_v_chart = ((struct __pyx_obj_8discodop_10containers_Chart *)values[0]);
  __pyx_v_k = values[1];
  __pyx_v_debin = values[2];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("getsamples", 0, 2, 3, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 814, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("discodop.disambiguation.getsamples", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_chart), __pyx_ptype_8discodop_10containers_Chart, 1, "chart", 0))) __PYX_ERR(0, 814, __pyx_L1_error)
__pyx_r = __pyx_pf_8discodop_14disambiguation_18getsamples(__pyx_self, __pyx_v_chart, __pyx_v_k, __pyx_v_debin);

/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

static PyObject *__pyx_pf_8discodop_14disambiguation_18getsamples(CYTHON_UNUSED PyObject *__pyx_self, struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, PyObject *__pyx_v_k, PyObject *__pyx_v_debin) {
PyObject *__pyx_v_tables = 0;
struct __pyx_t_8discodop_10containers_Edge *__pyx_v_edge;
struct __pyx_obj_8discodop_10containers_Edges *__pyx_v_edges = 0;
struct __pyx_t_8discodop_10containers_MoreEdges *__pyx_v_edgelist;
double __pyx_v_prob;
double __pyx_v_prev;
size_t __pyx_v_n;
PyObject *__pyx_v_chartidx = NULL;
PyObject *__pyx_v_item = NULL;
CYTHON_UNUSED PyObject *__pyx_v__ = NULL;
PyObject *__pyx_v_result = 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 *);
struct __pyx_t_8discodop_10containers_MoreEdges *__pyx_t_6;
int __pyx_t_7;
long __pyx_t_8;
size_t __pyx_t_9;
PyObject *__pyx_t_10 = NULL;
PyObject *__pyx_t_11 = NULL;
int __pyx_t_12;
double __pyx_t_13;
Py_ssize_t __pyx_t_14;
int __pyx_t_15;
int __pyx_t_16;
Py_ssize_t __pyx_t_17;
PyObject *__pyx_t_18 = NULL;
PyObject *(*__pyx_t_19)(PyObject *);
PyObject *__pyx_t_20 = NULL;
PyObject *__pyx_t_21 = NULL;
__Pyx_RefNannySetupContext("getsamples", 0);

/* "discodop/disambiguation.pyx":816
 * def getsamples(Chart chart, k, debin=None):
 * 	"""Samples *k* derivations from a chart."""
 * 	cdef dict tables = {}             # <<<<<<<<<<<<<<
 * 	cdef Edge *edge
 * 	cdef Edges edges
 */
__pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 816, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_tables = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":822
 * 	cdef double prob, prev
 * 	cdef size_t n
 * 	chartidx = {}             # <<<<<<<<<<<<<<
 * 	for item in chart.getitems():
 * 		chartidx[item] = []
 */
__pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 822, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_chartidx = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":823
 * 	cdef size_t n
 * 	chartidx = {}
 * 	for item in chart.getitems():             # <<<<<<<<<<<<<<
 * 		chartidx[item] = []
 * 		edges = chart.getedges(item)
 */
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_chart), __pyx_n_s_getitems); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 823, __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, 823, __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, 823, __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, 823, __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, 823, __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, 823, __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, 823, __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, 823, __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, 823, __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, 823, __pyx_L1_error)
      }
      break;
    }
    __Pyx_GOTREF(__pyx_t_1);
  }
  __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":824
 * 	chartidx = {}
 * 	for item in chart.getitems():
 * 		chartidx[item] = []             # <<<<<<<<<<<<<<
 * 		edges = chart.getedges(item)
 * 		edgelist = edges.head if edges is not None else NULL
 */
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 824, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (unlikely(PyDict_SetItem(__pyx_v_chartidx, __pyx_v_item, __pyx_t_1) < 0)) __PYX_ERR(0, 824, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":825
 * 	for item in chart.getitems():
 * 		chartidx[item] = []
 * 		edges = chart.getedges(item)             # <<<<<<<<<<<<<<
 * 		edgelist = edges.head if edges is not None else NULL
 * 		while edgelist is not NULL:
 */
  __pyx_t_1 = ((PyObject *)((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->getedges(__pyx_v_chart, __pyx_v_item)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 825, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_XDECREF_SET(__pyx_v_edges, ((struct __pyx_obj_8discodop_10containers_Edges *)__pyx_t_1));
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":826
 * 		chartidx[item] = []
 * 		edges = chart.getedges(item)
 * 		edgelist = edges.head if edges is not None else NULL             # <<<<<<<<<<<<<<
 * 		while edgelist is not NULL:
 * 			for n in range(edges.len if edgelist is edges.head
 */
  __pyx_t_7 = (((PyObject *)__pyx_v_edges) != Py_None);
  if ((__pyx_t_7 != 0)) {
    __pyx_t_6 = __pyx_v_edges->head;
  } else {
    __pyx_t_6 = NULL;
  }
  __pyx_v_edgelist = __pyx_t_6;

  /* "discodop/disambiguation.pyx":827
 * 		edges = chart.getedges(item)
 * 		edgelist = edges.head if edges is not None else NULL
 * 		while edgelist is not NULL:             # <<<<<<<<<<<<<<
 * 			for n in range(edges.len if edgelist is edges.head
 * 					else EDGES_SIZE):
 */
  while (1) {
    __pyx_t_7 = ((__pyx_v_edgelist != NULL) != 0);
    if (!__pyx_t_7) break;

    /* "discodop/disambiguation.pyx":828
 * 		edgelist = edges.head if edges is not None else NULL
 * 		while edgelist is not NULL:
 * 			for n in range(edges.len if edgelist is edges.head             # <<<<<<<<<<<<<<
 * 					else EDGES_SIZE):
 * 				edge = &(edgelist.data[n])
 */
    if (((__pyx_v_edgelist == __pyx_v_edges->head) != 0)) {
      __pyx_t_8 = __pyx_v_edges->len;
    } else {
      __pyx_t_8 = 15;
    }
    for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) {
      __pyx_v_n = __pyx_t_9;

      /* "discodop/disambiguation.pyx":830
 * 			for n in range(edges.len if edgelist is edges.head
 * 					else EDGES_SIZE):
 * 				edge = &(edgelist.data[n])             # <<<<<<<<<<<<<<
 * 				# HACK: store pointer to edge as Python int
 * 				if edge.rule is NULL:
 */
      __pyx_v_edge = (&(__pyx_v_edgelist->data[__pyx_v_n]));

      /* "discodop/disambiguation.pyx":832
 * 				edge = &(edgelist.data[n])
 * 				# HACK: store pointer to edge as Python int
 * 				if edge.rule is NULL:             # <<<<<<<<<<<<<<
 * 					chartidx[item].append(
 * 							(chart.subtreeprob(item), <intptr_t>edge))
 */
      __pyx_t_7 = ((__pyx_v_edge->rule == NULL) != 0);
      if (__pyx_t_7) {

        /* "discodop/disambiguation.pyx":833
 * 				# HACK: store pointer to edge as Python int
 * 				if edge.rule is NULL:
 * 					chartidx[item].append(             # <<<<<<<<<<<<<<
 * 							(chart.subtreeprob(item), <intptr_t>edge))
 * 				else:
 */
        __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_chartidx, __pyx_v_item); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 833, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);

        /* "discodop/disambiguation.pyx":834
 * 				if edge.rule is NULL:
 * 					chartidx[item].append(
 * 							(chart.subtreeprob(item), <intptr_t>edge))             # <<<<<<<<<<<<<<
 * 				else:
 * 					prob = edge.rule.prob
 */
        __pyx_t_3 = PyFloat_FromDouble(((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->subtreeprob(__pyx_v_chart, __pyx_v_item)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 834, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_10 = PyInt_FromSsize_t(((intptr_t)__pyx_v_edge)); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 834, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 834, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_GIVEREF(__pyx_t_3);
        PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_10);
        PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_10);
        __pyx_t_3 = 0;
        __pyx_t_10 = 0;

        /* "discodop/disambiguation.pyx":833
 * 				# HACK: store pointer to edge as Python int
 * 				if edge.rule is NULL:
 * 					chartidx[item].append(             # <<<<<<<<<<<<<<
 * 							(chart.subtreeprob(item), <intptr_t>edge))
 * 				else:
 */
        __pyx_t_12 = __Pyx_PyObject_Append(__pyx_t_1, __pyx_t_11); if (unlikely(__pyx_t_12 == -1)) __PYX_ERR(0, 833, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

        /* "discodop/disambiguation.pyx":832
 * 				edge = &(edgelist.data[n])
 * 				# HACK: store pointer to edge as Python int
 * 				if edge.rule is NULL:             # <<<<<<<<<<<<<<
 * 					chartidx[item].append(
 * 							(chart.subtreeprob(item), <intptr_t>edge))
 */
        goto __pyx_L9;
      }

      /* "discodop/disambiguation.pyx":836
 * 							(chart.subtreeprob(item), <intptr_t>edge))
 * 				else:
 * 					prob = edge.rule.prob             # <<<<<<<<<<<<<<
 * 					# FIXME: work w/inside prob?
 * 					# prob += chart.subtreeprob(chart._left(item, edge))
 */
      /*else*/ {
        __pyx_t_13 = __pyx_v_edge->rule->prob;
        __pyx_v_prob = __pyx_t_13;

        /* "discodop/disambiguation.pyx":841
 * 					# if edge.rule.rhs2:
 * 					# 	prob += chart.subtreeprob(chart._right(item, edge))
 * 					chartidx[item].append((prob, <intptr_t>edge))             # <<<<<<<<<<<<<<
 * 			edgelist = edgelist.prev
 * 		# sort edges so that highest prob (=lowest neglogprob) comes first
 */
        __pyx_t_11 = __Pyx_PyDict_GetItem(__pyx_v_chartidx, __pyx_v_item); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 841, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_11);
        __pyx_t_1 = PyFloat_FromDouble(__pyx_v_prob); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 841, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __pyx_t_10 = PyInt_FromSsize_t(((intptr_t)__pyx_v_edge)); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 841, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_10);
        __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 841, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __Pyx_GIVEREF(__pyx_t_1);
        PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_1);
        __Pyx_GIVEREF(__pyx_t_10);
        PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_10);
        __pyx_t_1 = 0;
        __pyx_t_10 = 0;
        __pyx_t_12 = __Pyx_PyObject_Append(__pyx_t_11, __pyx_t_3); if (unlikely(__pyx_t_12 == -1)) __PYX_ERR(0, 841, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      }
      __pyx_L9:;
    }

    /* "discodop/disambiguation.pyx":842
 * 					# 	prob += chart.subtreeprob(chart._right(item, edge))
 * 					chartidx[item].append((prob, <intptr_t>edge))
 * 			edgelist = edgelist.prev             # <<<<<<<<<<<<<<
 * 		# sort edges so that highest prob (=lowest neglogprob) comes first
 * 		chartidx[item].sort()
 */
    __pyx_t_6 = __pyx_v_edgelist->prev;
    __pyx_v_edgelist = __pyx_t_6;
  }

  /* "discodop/disambiguation.pyx":844
 * 			edgelist = edgelist.prev
 * 		# sort edges so that highest prob (=lowest neglogprob) comes first
 * 		chartidx[item].sort()             # <<<<<<<<<<<<<<
 * 	for item in chartidx:
 * 		tables[item] = []
 */
  __pyx_t_11 = __Pyx_PyDict_GetItem(__pyx_v_chartidx, __pyx_v_item); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 844, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_11);
  __pyx_t_10 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_sort); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 844, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  __pyx_t_11 = NULL;
  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);
    }
  }
  if (__pyx_t_11) {
    __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 844, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  } else {
    __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_10); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 844, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "discodop/disambiguation.pyx":823
 * 	cdef size_t n
 * 	chartidx = {}
 * 	for item in chart.getitems():             # <<<<<<<<<<<<<<
 * 		chartidx[item] = []
 * 		edges = chart.getedges(item)
 */
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":845
 * 		# sort edges so that highest prob (=lowest neglogprob) comes first
 * 		chartidx[item].sort()
 * 	for item in chartidx:             # <<<<<<<<<<<<<<
 * 		tables[item] = []
 * 		prev = 0.0
 */
__pyx_t_4 = 0;
__pyx_t_3 = __Pyx_dict_iterator(__pyx_v_chartidx, 1, ((PyObject *)NULL), (&__pyx_t_14), (&__pyx_t_15)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 845, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_2);
__pyx_t_2 = __pyx_t_3;
__pyx_t_3 = 0;
while (1) {
  __pyx_t_16 = __Pyx_dict_iter_next(__pyx_t_2, __pyx_t_14, &__pyx_t_4, &__pyx_t_3, NULL, NULL, __pyx_t_15);
  if (unlikely(__pyx_t_16 == 0)) break;
  if (unlikely(__pyx_t_16 == -1)) __PYX_ERR(0, 845, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_XDECREF_SET(__pyx_v_item, __pyx_t_3);
  __pyx_t_3 = 0;

  /* "discodop/disambiguation.pyx":846
 * 		chartidx[item].sort()
 * 	for item in chartidx:
 * 		tables[item] = []             # <<<<<<<<<<<<<<
 * 		prev = 0.0
 * 		for prob, _ in chartidx[item]:
 */
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 846, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (unlikely(PyDict_SetItem(__pyx_v_tables, __pyx_v_item, __pyx_t_3) < 0)) __PYX_ERR(0, 846, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "discodop/disambiguation.pyx":847
 * 	for item in chartidx:
 * 		tables[item] = []
 * 		prev = 0.0             # <<<<<<<<<<<<<<
 * 		for prob, _ in chartidx[item]:
 * 			prev += exp(-prob)
 */
  __pyx_v_prev = 0.0;

  /* "discodop/disambiguation.pyx":848
 * 		tables[item] = []
 * 		prev = 0.0
 * 		for prob, _ in chartidx[item]:             # <<<<<<<<<<<<<<
 * 			prev += exp(-prob)
 * 			tables[item].append(prev)
 */
  __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_chartidx, __pyx_v_item); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 848, __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_17 = 0;
    __pyx_t_5 = NULL;
  } else {
    __pyx_t_17 = -1; __pyx_t_10 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 848, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_10);
    __pyx_t_5 = Py_TYPE(__pyx_t_10)->tp_iternext; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 848, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  for (;;) {
    if (likely(!__pyx_t_5)) {
      if (likely(PyList_CheckExact(__pyx_t_10))) {
        if (__pyx_t_17 >= 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_17); __Pyx_INCREF(__pyx_t_3); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 848, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_10, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 848, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      } else {
        if (__pyx_t_17 >= 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_17); __Pyx_INCREF(__pyx_t_3); __pyx_t_17++; if (unlikely(0 < 0)) __PYX_ERR(0, 848, __pyx_L1_error)
        #else
        __pyx_t_3 = PySequence_ITEM(__pyx_t_10, __pyx_t_17); __pyx_t_17++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 848, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        #endif
      }
    } else {
      __pyx_t_3 = __pyx_t_5(__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, 848, __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, 848, __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_1 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_11 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_11);
      __Pyx_INCREF(__pyx_t_1);
      #else
      __pyx_t_11 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 848, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 848, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      #endif
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_18 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 848, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_18);
      __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
      __pyx_t_19 = Py_TYPE(__pyx_t_18)->tp_iternext;
      index = 0; __pyx_t_11 = __pyx_t_19(__pyx_t_18); if (unlikely(!__pyx_t_11)) goto __pyx_L14_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_11);
      index = 1; __pyx_t_1 = __pyx_t_19(__pyx_t_18); if (unlikely(!__pyx_t_1)) goto __pyx_L14_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_1);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_19(__pyx_t_18), 2) < 0) __PYX_ERR(0, 848, __pyx_L1_error)
      __pyx_t_19 = NULL;
      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
      goto __pyx_L15_unpacking_done;
      __pyx_L14_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
      __pyx_t_19 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 848, __pyx_L1_error)
      __pyx_L15_unpacking_done:;
    }
    __pyx_t_13 = __pyx_PyFloat_AsDouble(__pyx_t_11); if (unlikely((__pyx_t_13 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 848, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_v_prob = __pyx_t_13;
    __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_1);
    __pyx_t_1 = 0;

    /* "discodop/disambiguation.pyx":849
 * 		prev = 0.0
 * 		for prob, _ in chartidx[item]:
 * 			prev += exp(-prob)             # <<<<<<<<<<<<<<
 * 			tables[item].append(prev)
 * 	result = []
 */
    __pyx_t_3 = PyFloat_FromDouble(__pyx_v_prev); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 849, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_11 = __Pyx_GetModuleGlobalName(__pyx_n_s_exp); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 849, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_18 = PyFloat_FromDouble((-__pyx_v_prob)); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 849, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_18);
    __pyx_t_20 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_11))) {
      __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_11);
      if (likely(__pyx_t_20)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11);
        __Pyx_INCREF(__pyx_t_20);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_11, function);
      }
    }
    if (!__pyx_t_20) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_11, __pyx_t_18); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 849, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_11)) {
        PyObject *__pyx_temp[2] = {__pyx_t_20, __pyx_t_18};
        __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_11, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 849, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_11)) {
        PyObject *__pyx_temp[2] = {__pyx_t_20, __pyx_t_18};
        __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_11, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 849, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
      } else
      #endif
      {
        __pyx_t_21 = PyTuple_New(1+1); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 849, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_21);
        __Pyx_GIVEREF(__pyx_t_20); PyTuple_SET_ITEM(__pyx_t_21, 0, __pyx_t_20); __pyx_t_20 = NULL;
        __Pyx_GIVEREF(__pyx_t_18);
        PyTuple_SET_ITEM(__pyx_t_21, 0+1, __pyx_t_18);
        __pyx_t_18 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_11, __pyx_t_21, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 849, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_t_11 = PyNumber_InPlaceAdd(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 849, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_13 = __pyx_PyFloat_AsDouble(__pyx_t_11); if (unlikely((__pyx_t_13 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 849, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __pyx_v_prev = __pyx_t_13;

    /* "discodop/disambiguation.pyx":850
 * 		for prob, _ in chartidx[item]:
 * 			prev += exp(-prob)
 * 			tables[item].append(prev)             # <<<<<<<<<<<<<<
 * 	result = []
 * 	for _ in range(k):
 */
    __pyx_t_11 = __Pyx_PyDict_GetItem(__pyx_v_tables, __pyx_v_item); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 850, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    __pyx_t_1 = PyFloat_FromDouble(__pyx_v_prev); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 850, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_12 = __Pyx_PyObject_Append(__pyx_t_11, __pyx_t_1); if (unlikely(__pyx_t_12 == -1)) __PYX_ERR(0, 850, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "discodop/disambiguation.pyx":848
 * 		tables[item] = []
 * 		prev = 0.0
 * 		for prob, _ in chartidx[item]:             # <<<<<<<<<<<<<<
 * 			prev += exp(-prob)
 * 			tables[item].append(prev)
 */
  }
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":851
 * 			prev += exp(-prob)
 * 			tables[item].append(prev)
 * 	result = []             # <<<<<<<<<<<<<<
 * 	for _ in range(k):
 * 		result.append(samplechart(
 */
__pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 851, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_v_result = ((PyObject*)__pyx_t_2);
__pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":852
 * 			tables[item].append(prev)
 * 	result = []
 * 	for _ in range(k):             # <<<<<<<<<<<<<<
 * 		result.append(samplechart(
 * 				chart.root(), chart, chartidx, tables, debin))
 */
__pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 852, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(__pyx_v_k);
__Pyx_GIVEREF(__pyx_v_k);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_k);
__pyx_t_10 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_2, NULL); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 852, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_10);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (likely(PyList_CheckExact(__pyx_t_10)) || PyTuple_CheckExact(__pyx_t_10)) {
  __pyx_t_2 = __pyx_t_10; __Pyx_INCREF(__pyx_t_2); __pyx_t_14 = 0;
  __pyx_t_5 = NULL;
} else {
  __pyx_t_14 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 852, __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, 852, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
for (;;) {
  if (likely(!__pyx_t_5)) {
    if (likely(PyList_CheckExact(__pyx_t_2))) {
      if (__pyx_t_14 >= PyList_GET_SIZE(__pyx_t_2)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_10 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_14); __Pyx_INCREF(__pyx_t_10); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 852, __pyx_L1_error)
      #else
      __pyx_t_10 = PySequence_ITEM(__pyx_t_2, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 852, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      #endif
    } else {
      if (__pyx_t_14 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_10 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_14); __Pyx_INCREF(__pyx_t_10); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 852, __pyx_L1_error)
      #else
      __pyx_t_10 = PySequence_ITEM(__pyx_t_2, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 852, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_10);
      #endif
    }
  } else {
    __pyx_t_10 = __pyx_t_5(__pyx_t_2);
    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, 852, __pyx_L1_error)
      }
      break;
    }
    __Pyx_GOTREF(__pyx_t_10);
  }
  __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_10);
  __pyx_t_10 = 0;

  /* "discodop/disambiguation.pyx":854
 * 	for _ in range(k):
 * 		result.append(samplechart(
 * 				chart.root(), chart, chartidx, tables, debin))             # <<<<<<<<<<<<<<
 * 	return result
 * 
 */
  __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_chart), __pyx_n_s_root); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 854, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_11 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_11)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_11);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
    }
  }
  if (__pyx_t_11) {
    __pyx_t_10 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 854, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  } else {
    __pyx_t_10 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 854, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_10);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (!(likely(PyUnicode_CheckExact(__pyx_v_debin))||((__pyx_v_debin) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_debin)->tp_name), 0))) __PYX_ERR(0, 854, __pyx_L1_error)

  /* "discodop/disambiguation.pyx":853
 * 	result = []
 * 	for _ in range(k):
 * 		result.append(samplechart(             # <<<<<<<<<<<<<<
 * 				chart.root(), chart, chartidx, tables, debin))
 * 	return result
 */
  __pyx_t_1 = __pyx_f_8discodop_14disambiguation_samplechart(__pyx_t_10, __pyx_v_chart, __pyx_v_chartidx, __pyx_v_tables, ((PyObject*)__pyx_v_debin)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 853, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
  __pyx_t_12 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_1); if (unlikely(__pyx_t_12 == -1)) __PYX_ERR(0, 853, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":852
 * 			tables[item].append(prev)
 * 	result = []
 * 	for _ in range(k):             # <<<<<<<<<<<<<<
 * 		result.append(samplechart(
 * 				chart.root(), chart, chartidx, tables, debin))
 */
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":855
 * 		result.append(samplechart(
 * 				chart.root(), chart, chartidx, tables, debin))
 * 	return result             # <<<<<<<<<<<<<<
 * 
 * 
 */
__Pyx_XDECREF(__pyx_r);
__Pyx_INCREF(__pyx_v_result);
__pyx_r = __pyx_v_result;
goto __pyx_L0;

/* "discodop/disambiguation.pyx":814
 * 
 * 
 * def getsamples(Chart chart, k, debin=None):             # <<<<<<<<<<<<<<
 * 	"""Samples *k* derivations from a chart."""
 * 	cdef dict tables = {}
 */

/* 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_10);
__Pyx_XDECREF(__pyx_t_11);
__Pyx_XDECREF(__pyx_t_18);
__Pyx_XDECREF(__pyx_t_20);
__Pyx_XDECREF(__pyx_t_21);
__Pyx_AddTraceback("discodop.disambiguation.getsamples", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_tables);
__Pyx_XDECREF((PyObject *)__pyx_v_edges);
__Pyx_XDECREF(__pyx_v_chartidx);
__Pyx_XDECREF(__pyx_v_item);
__Pyx_XDECREF(__pyx_v__);
__Pyx_XDECREF(__pyx_v_result);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":858
 * 
 * 
 * cdef samplechart(item, Chart chart,             # <<<<<<<<<<<<<<
 * 		dict chartidx, dict tables, str debin):
 * 	"""Samples a derivation from a chart."""
 */

static PyObject *__pyx_f_8discodop_14disambiguation_samplechart(PyObject *__pyx_v_item, struct __pyx_obj_8discodop_10containers_Chart *__pyx_v_chart, PyObject *__pyx_v_chartidx, PyObject *__pyx_v_tables, PyObject *__pyx_v_debin) {
struct __pyx_t_8discodop_10containers_Edge *__pyx_v_edge;
struct __pyx_obj_8discodop_10containers_RankedEdge *__pyx_v_rankededge = 0;
double __pyx_v_prob;
PyObject *__pyx_v_lst = 0;
PyObject *__pyx_v_rnd = NULL;
PyObject *__pyx_v_idx = NULL;
CYTHON_UNUSED PyObject *__pyx_v__ = NULL;
PyObject *__pyx_v_ptr = NULL;
uint32_t __pyx_v_label;
PyObject *__pyx_v_deriv = NULL;
PyObject *__pyx_v_tree = NULL;
PyObject *__pyx_v_p1 = NULL;
PyObject *__pyx_v_tree2 = NULL;
PyObject *__pyx_v_p2 = 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;
Py_ssize_t __pyx_t_5;
int __pyx_t_6;
PyObject *__pyx_t_7 = NULL;
PyObject *(*__pyx_t_8)(PyObject *);
intptr_t __pyx_t_9;
int __pyx_t_10;
int __pyx_t_11;
double __pyx_t_12;
int __pyx_t_13;
int __pyx_t_14;
Py_ssize_t __pyx_t_15;
__Pyx_RefNannySetupContext("samplechart", 0);

/* "discodop/disambiguation.pyx":864
 * 	cdef RankedEdge rankededge
 * 	cdef double prob
 * 	cdef list lst = tables[item]             # <<<<<<<<<<<<<<
 * 	rnd = random() * lst[len(lst) - 1]
 * 	idx = bisect_right(lst, rnd)
 */
if (unlikely(__pyx_v_tables == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
  __PYX_ERR(0, 864, __pyx_L1_error)
}
__pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_tables, __pyx_v_item); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 864, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 864, __pyx_L1_error)
__pyx_v_lst = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":865
 * 	cdef double prob
 * 	cdef list lst = tables[item]
 * 	rnd = random() * lst[len(lst) - 1]             # <<<<<<<<<<<<<<
 * 	idx = bisect_right(lst, rnd)
 * 	_, ptr = chartidx[item][idx]
 */
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_random); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 865, __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_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 865, __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, 865, __pyx_L1_error)
}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (unlikely(__pyx_v_lst == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
  __PYX_ERR(0, 865, __pyx_L1_error)
}
if (unlikely(__pyx_v_lst == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
  __PYX_ERR(0, 865, __pyx_L1_error)
}
__pyx_t_4 = PyList_GET_SIZE(__pyx_v_lst); if (unlikely(__pyx_t_4 == -1)) __PYX_ERR(0, 865, __pyx_L1_error)
__pyx_t_5 = (__pyx_t_4 - 1);
__pyx_t_2 = PyNumber_Multiply(__pyx_t_1, PyList_GET_ITEM(__pyx_v_lst, __pyx_t_5)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 865, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_rnd = __pyx_t_2;
__pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":866
 * 	cdef list lst = tables[item]
 * 	rnd = random() * lst[len(lst) - 1]
 * 	idx = bisect_right(lst, rnd)             # <<<<<<<<<<<<<<
 * 	_, ptr = chartidx[item][idx]
 * 	edge = <Edge *><intptr_t>ptr  # hack: convert Python int into pointer
 */
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_bisect_right); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 866, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_3 = NULL;
__pyx_t_6 = 0;
if (CYTHON_UNPACK_METHODS && unlikely(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);
    __pyx_t_6 = 1;
  }
}
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_1)) {
  PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_lst, __pyx_v_rnd};
  __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 866, __pyx_L1_error)
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_GOTREF(__pyx_t_2);
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
  PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_lst, __pyx_v_rnd};
  __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 866, __pyx_L1_error)
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_GOTREF(__pyx_t_2);
} else
#endif
{
  __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 866, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (__pyx_t_3) {
    __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3); __pyx_t_3 = NULL;
  }
  __Pyx_INCREF(__pyx_v_lst);
  __Pyx_GIVEREF(__pyx_v_lst);
  PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_lst);
  __Pyx_INCREF(__pyx_v_rnd);
  __Pyx_GIVEREF(__pyx_v_rnd);
  PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_v_rnd);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 866, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_idx = __pyx_t_2;
__pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":867
 * 	rnd = random() * lst[len(lst) - 1]
 * 	idx = bisect_right(lst, rnd)
 * 	_, ptr = chartidx[item][idx]             # <<<<<<<<<<<<<<
 * 	edge = <Edge *><intptr_t>ptr  # hack: convert Python int into pointer
 * 	label = chart.label(item)
 */
if (unlikely(__pyx_v_chartidx == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
  __PYX_ERR(0, 867, __pyx_L1_error)
}
__pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_chartidx, __pyx_v_item); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 867, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_1 = PyObject_GetItem(__pyx_t_2, __pyx_v_idx); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 867, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) {
  PyObject* sequence = __pyx_t_1;
  #if !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, 867, __pyx_L1_error)
  }
  #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
  if (likely(PyTuple_CheckExact(sequence))) {
    __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
    __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); 
  } else {
    __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
    __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
  }
  __Pyx_INCREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_t_7);
  #else
  __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  #endif
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
} else {
  Py_ssize_t index = -1;
  __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 867, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_8 = Py_TYPE(__pyx_t_3)->tp_iternext;
  index = 0; __pyx_t_2 = __pyx_t_8(__pyx_t_3); if (unlikely(!__pyx_t_2)) goto __pyx_L3_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_2);
  index = 1; __pyx_t_7 = __pyx_t_8(__pyx_t_3); if (unlikely(!__pyx_t_7)) goto __pyx_L3_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_7);
  if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_3), 2) < 0) __PYX_ERR(0, 867, __pyx_L1_error)
  __pyx_t_8 = NULL;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  goto __pyx_L4_unpacking_done;
  __pyx_L3_unpacking_failed:;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_8 = NULL;
  if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
  __PYX_ERR(0, 867, __pyx_L1_error)
  __pyx_L4_unpacking_done:;
}
__pyx_v__ = __pyx_t_2;
__pyx_t_2 = 0;
__pyx_v_ptr = __pyx_t_7;
__pyx_t_7 = 0;

/* "discodop/disambiguation.pyx":868
 * 	idx = bisect_right(lst, rnd)
 * 	_, ptr = chartidx[item][idx]
 * 	edge = <Edge *><intptr_t>ptr  # hack: convert Python int into pointer             # <<<<<<<<<<<<<<
 * 	label = chart.label(item)
 * 	if edge.rule is NULL:  # terminal
 */
__pyx_t_9 = PyInt_AsSsize_t(__pyx_v_ptr); if (unlikely((__pyx_t_9 == ((intptr_t)-1)) && PyErr_Occurred())) __PYX_ERR(0, 868, __pyx_L1_error)
__pyx_v_edge = ((struct __pyx_t_8discodop_10containers_Edge *)((intptr_t)__pyx_t_9));

/* "discodop/disambiguation.pyx":869
 * 	_, ptr = chartidx[item][idx]
 * 	edge = <Edge *><intptr_t>ptr  # hack: convert Python int into pointer
 * 	label = chart.label(item)             # <<<<<<<<<<<<<<
 * 	if edge.rule is NULL:  # terminal
 * 		idx = chart.lexidx(edge)
 */
__pyx_v_label = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->label(__pyx_v_chart, __pyx_v_item);

/* "discodop/disambiguation.pyx":870
 * 	edge = <Edge *><intptr_t>ptr  # hack: convert Python int into pointer
 * 	label = chart.label(item)
 * 	if edge.rule is NULL:  # terminal             # <<<<<<<<<<<<<<
 * 		idx = chart.lexidx(edge)
 * 		rankededge = new_RankedEdge(item, edge, -1, -1)
 */
__pyx_t_10 = ((__pyx_v_edge->rule == NULL) != 0);
if (__pyx_t_10) {

  /* "discodop/disambiguation.pyx":871
 * 	label = chart.label(item)
 * 	if edge.rule is NULL:  # terminal
 * 		idx = chart.lexidx(edge)             # <<<<<<<<<<<<<<
 * 		rankededge = new_RankedEdge(item, edge, -1, -1)
 * 		chart.rankededges.setdefault(item, []).append(
 */
  __pyx_t_1 = __Pyx_PyInt_From_int(((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->lexidx(__pyx_v_chart, __pyx_v_edge)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 871, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF_SET(__pyx_v_idx, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":872
 * 	if edge.rule is NULL:  # terminal
 * 		idx = chart.lexidx(edge)
 * 		rankededge = new_RankedEdge(item, edge, -1, -1)             # <<<<<<<<<<<<<<
 * 		chart.rankededges.setdefault(item, []).append(
 * 				new_DoubleEntry(rankededge, chart.subtreeprob(item), 0))
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_8discodop_10containers_new_RankedEdge(__pyx_v_item, __pyx_v_edge, -1, -1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 872, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_v_rankededge = ((struct __pyx_obj_8discodop_10containers_RankedEdge *)__pyx_t_1);
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":873
 * 		idx = chart.lexidx(edge)
 * 		rankededge = new_RankedEdge(item, edge, -1, -1)
 * 		chart.rankededges.setdefault(item, []).append(             # <<<<<<<<<<<<<<
 * 				new_DoubleEntry(rankededge, chart.subtreeprob(item), 0))
 * 		deriv = '(%s %d)' % (chart.grammar.tolabel[label], idx)
 */
  if (unlikely(__pyx_v_chart->rankededges == Py_None)) {
    PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "setdefault");
    __PYX_ERR(0, 873, __pyx_L1_error)
  }
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 873, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = __Pyx_PyDict_SetDefault(__pyx_v_chart->rankededges, __pyx_v_item, __pyx_t_1, -1L); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 873, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":874
 * 		rankededge = new_RankedEdge(item, edge, -1, -1)
 * 		chart.rankededges.setdefault(item, []).append(
 * 				new_DoubleEntry(rankededge, chart.subtreeprob(item), 0))             # <<<<<<<<<<<<<<
 * 		deriv = '(%s %d)' % (chart.grammar.tolabel[label], idx)
 * 		return deriv, chart.subtreeprob(item)
 */
  __pyx_t_1 = ((PyObject *)__pyx_f_8discodop_6plcfrs_new_DoubleEntry(((PyObject *)__pyx_v_rankededge), ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->subtreeprob(__pyx_v_chart, __pyx_v_item), 0)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 874, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "discodop/disambiguation.pyx":873
 * 		idx = chart.lexidx(edge)
 * 		rankededge = new_RankedEdge(item, edge, -1, -1)
 * 		chart.rankededges.setdefault(item, []).append(             # <<<<<<<<<<<<<<
 * 				new_DoubleEntry(rankededge, chart.subtreeprob(item), 0))
 * 		deriv = '(%s %d)' % (chart.grammar.tolabel[label], idx)
 */
  __pyx_t_11 = __Pyx_PyObject_Append(__pyx_t_7, __pyx_t_1); if (unlikely(__pyx_t_11 == -1)) __PYX_ERR(0, 873, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":875
 * 		chart.rankededges.setdefault(item, []).append(
 * 				new_DoubleEntry(rankededge, chart.subtreeprob(item), 0))
 * 		deriv = '(%s %d)' % (chart.grammar.tolabel[label], idx)             # <<<<<<<<<<<<<<
 * 		return deriv, chart.subtreeprob(item)
 * 	tree, p1 = samplechart(chart.copy(chart._left(item, edge)),
 */
  if (unlikely(__pyx_v_chart->grammar->tolabel == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 875, __pyx_L1_error)
  }
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 875, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(PyList_GET_ITEM(__pyx_v_chart->grammar->tolabel, __pyx_v_label));
  __Pyx_GIVEREF(PyList_GET_ITEM(__pyx_v_chart->grammar->tolabel, __pyx_v_label));
  PyTuple_SET_ITEM(__pyx_t_1, 0, PyList_GET_ITEM(__pyx_v_chart->grammar->tolabel, __pyx_v_label));
  __Pyx_INCREF(__pyx_v_idx);
  __Pyx_GIVEREF(__pyx_v_idx);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_idx);
  __pyx_t_7 = PyUnicode_Format(__pyx_kp_u_s_d, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 875, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_v_deriv = ((PyObject*)__pyx_t_7);
  __pyx_t_7 = 0;

  /* "discodop/disambiguation.pyx":876
 * 				new_DoubleEntry(rankededge, chart.subtreeprob(item), 0))
 * 		deriv = '(%s %d)' % (chart.grammar.tolabel[label], idx)
 * 		return deriv, chart.subtreeprob(item)             # <<<<<<<<<<<<<<
 * 	tree, p1 = samplechart(chart.copy(chart._left(item, edge)),
 * 			chart, chartidx, tables, debin)
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_7 = PyFloat_FromDouble(((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->subtreeprob(__pyx_v_chart, __pyx_v_item)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 876, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 876, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_deriv);
  __Pyx_GIVEREF(__pyx_v_deriv);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_deriv);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_7);
  __pyx_t_7 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "discodop/disambiguation.pyx":870
 * 	edge = <Edge *><intptr_t>ptr  # hack: convert Python int into pointer
 * 	label = chart.label(item)
 * 	if edge.rule is NULL:  # terminal             # <<<<<<<<<<<<<<
 * 		idx = chart.lexidx(edge)
 * 		rankededge = new_RankedEdge(item, edge, -1, -1)
 */
}

/* "discodop/disambiguation.pyx":877
 * 		deriv = '(%s %d)' % (chart.grammar.tolabel[label], idx)
 * 		return deriv, chart.subtreeprob(item)
 * 	tree, p1 = samplechart(chart.copy(chart._left(item, edge)),             # <<<<<<<<<<<<<<
 * 			chart, chartidx, tables, debin)
 * 	prob = edge.rule.prob + p1
 */
__pyx_t_1 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->_left(__pyx_v_chart, __pyx_v_item, __pyx_v_edge); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 877, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_7 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->copy(__pyx_v_chart, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 877, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":878
 * 		return deriv, chart.subtreeprob(item)
 * 	tree, p1 = samplechart(chart.copy(chart._left(item, edge)),
 * 			chart, chartidx, tables, debin)             # <<<<<<<<<<<<<<
 * 	prob = edge.rule.prob + p1
 * 	if edge.rule.rhs2:
 */
__pyx_t_1 = __pyx_f_8discodop_14disambiguation_samplechart(__pyx_t_7, __pyx_v_chart, __pyx_v_chartidx, __pyx_v_tables, __pyx_v_debin); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 877, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
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, 877, __pyx_L1_error)
  }
  #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
  if (likely(PyTuple_CheckExact(sequence))) {
    __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); 
    __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); 
  } else {
    __pyx_t_7 = PyList_GET_ITEM(sequence, 0); 
    __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
  }
  __Pyx_INCREF(__pyx_t_7);
  __Pyx_INCREF(__pyx_t_2);
  #else
  __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 877, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 877, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  #endif
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
} else {
  Py_ssize_t index = -1;
  __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 877, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_8 = Py_TYPE(__pyx_t_3)->tp_iternext;
  index = 0; __pyx_t_7 = __pyx_t_8(__pyx_t_3); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_7);
  index = 1; __pyx_t_2 = __pyx_t_8(__pyx_t_3); if (unlikely(!__pyx_t_2)) goto __pyx_L6_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_3), 2) < 0) __PYX_ERR(0, 877, __pyx_L1_error)
  __pyx_t_8 = NULL;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  goto __pyx_L7_unpacking_done;
  __pyx_L6_unpacking_failed:;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_8 = NULL;
  if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
  __PYX_ERR(0, 877, __pyx_L1_error)
  __pyx_L7_unpacking_done:;
}

/* "discodop/disambiguation.pyx":877
 * 		deriv = '(%s %d)' % (chart.grammar.tolabel[label], idx)
 * 		return deriv, chart.subtreeprob(item)
 * 	tree, p1 = samplechart(chart.copy(chart._left(item, edge)),             # <<<<<<<<<<<<<<
 * 			chart, chartidx, tables, debin)
 * 	prob = edge.rule.prob + p1
 */
__pyx_v_tree = __pyx_t_7;
__pyx_t_7 = 0;
__pyx_v_p1 = __pyx_t_2;
__pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":879
 * 	tree, p1 = samplechart(chart.copy(chart._left(item, edge)),
 * 			chart, chartidx, tables, debin)
 * 	prob = edge.rule.prob + p1             # <<<<<<<<<<<<<<
 * 	if edge.rule.rhs2:
 * 		tree2, p2 = samplechart(chart.copy(chart._right(item, edge)),
 */
__pyx_t_1 = PyFloat_FromDouble(__pyx_v_edge->rule->prob); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 879, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_v_p1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 879, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_12 = __pyx_PyFloat_AsDouble(__pyx_t_2); if (unlikely((__pyx_t_12 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 879, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_v_prob = __pyx_t_12;

/* "discodop/disambiguation.pyx":880
 * 			chart, chartidx, tables, debin)
 * 	prob = edge.rule.prob + p1
 * 	if edge.rule.rhs2:             # <<<<<<<<<<<<<<
 * 		tree2, p2 = samplechart(chart.copy(chart._right(item, edge)),
 * 					chart, chartidx, tables, debin)
 */
__pyx_t_10 = (__pyx_v_edge->rule->rhs2 != 0);
if (__pyx_t_10) {

  /* "discodop/disambiguation.pyx":881
 * 	prob = edge.rule.prob + p1
 * 	if edge.rule.rhs2:
 * 		tree2, p2 = samplechart(chart.copy(chart._right(item, edge)),             # <<<<<<<<<<<<<<
 * 					chart, chartidx, tables, debin)
 * 		tree += ' ' + tree2
 */
  __pyx_t_2 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->_right(__pyx_v_chart, __pyx_v_item, __pyx_v_edge); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 881, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->copy(__pyx_v_chart, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 881, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "discodop/disambiguation.pyx":882
 * 	if edge.rule.rhs2:
 * 		tree2, p2 = samplechart(chart.copy(chart._right(item, edge)),
 * 					chart, chartidx, tables, debin)             # <<<<<<<<<<<<<<
 * 		tree += ' ' + tree2
 * 		prob += p2
 */
  __pyx_t_2 = __pyx_f_8discodop_14disambiguation_samplechart(__pyx_t_1, __pyx_v_chart, __pyx_v_chartidx, __pyx_v_tables, __pyx_v_debin); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 881, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) {
    PyObject* sequence = __pyx_t_2;
    #if !CYTHON_COMPILING_IN_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, 881, __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_7 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_7);
    #else
    __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 881, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 881, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    #endif
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 881, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __pyx_t_8 = Py_TYPE(__pyx_t_3)->tp_iternext;
    index = 0; __pyx_t_1 = __pyx_t_8(__pyx_t_3); if (unlikely(!__pyx_t_1)) goto __pyx_L9_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    index = 1; __pyx_t_7 = __pyx_t_8(__pyx_t_3); if (unlikely(!__pyx_t_7)) goto __pyx_L9_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_7);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_3), 2) < 0) __PYX_ERR(0, 881, __pyx_L1_error)
    __pyx_t_8 = NULL;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    goto __pyx_L10_unpacking_done;
    __pyx_L9_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
    __pyx_t_8 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 881, __pyx_L1_error)
    __pyx_L10_unpacking_done:;
  }

  /* "discodop/disambiguation.pyx":881
 * 	prob = edge.rule.prob + p1
 * 	if edge.rule.rhs2:
 * 		tree2, p2 = samplechart(chart.copy(chart._right(item, edge)),             # <<<<<<<<<<<<<<
 * 					chart, chartidx, tables, debin)
 * 		tree += ' ' + tree2
 */
  __pyx_v_tree2 = __pyx_t_1;
  __pyx_t_1 = 0;
  __pyx_v_p2 = __pyx_t_7;
  __pyx_t_7 = 0;

  /* "discodop/disambiguation.pyx":883
 * 		tree2, p2 = samplechart(chart.copy(chart._right(item, edge)),
 * 					chart, chartidx, tables, debin)
 * 		tree += ' ' + tree2             # <<<<<<<<<<<<<<
 * 		prob += p2
 * 	if debin is None or debin not in chart.grammar.tolabel[label]:
 */
  __pyx_t_2 = PyNumber_Add(__pyx_kp_u__25, __pyx_v_tree2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 883, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = PyNumber_InPlaceAdd(__pyx_v_tree, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 883, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF_SET(__pyx_v_tree, __pyx_t_7);
  __pyx_t_7 = 0;

  /* "discodop/disambiguation.pyx":884
 * 					chart, chartidx, tables, debin)
 * 		tree += ' ' + tree2
 * 		prob += p2             # <<<<<<<<<<<<<<
 * 	if debin is None or debin not in chart.grammar.tolabel[label]:
 * 		tree = '(%s %s)' % (chart.grammar.tolabel[label], tree)
 */
  __pyx_t_7 = PyFloat_FromDouble(__pyx_v_prob); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 884, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_2 = PyNumber_InPlaceAdd(__pyx_t_7, __pyx_v_p2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 884, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_12 = __pyx_PyFloat_AsDouble(__pyx_t_2); if (unlikely((__pyx_t_12 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 884, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_v_prob = __pyx_t_12;

  /* "discodop/disambiguation.pyx":880
 * 			chart, chartidx, tables, debin)
 * 	prob = edge.rule.prob + p1
 * 	if edge.rule.rhs2:             # <<<<<<<<<<<<<<
 * 		tree2, p2 = samplechart(chart.copy(chart._right(item, edge)),
 * 					chart, chartidx, tables, debin)
 */
}

/* "discodop/disambiguation.pyx":885
 * 		tree += ' ' + tree2
 * 		prob += p2
 * 	if debin is None or debin not in chart.grammar.tolabel[label]:             # <<<<<<<<<<<<<<
 * 		tree = '(%s %s)' % (chart.grammar.tolabel[label], tree)
 * 	# create an edge that has as children the edges that were just created
 */
__pyx_t_13 = (__pyx_v_debin == ((PyObject*)Py_None));
__pyx_t_14 = (__pyx_t_13 != 0);
if (!__pyx_t_14) {
} else {
  __pyx_t_10 = __pyx_t_14;
  goto __pyx_L12_bool_binop_done;
}
if (unlikely(__pyx_v_chart->grammar->tolabel == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
  __PYX_ERR(0, 885, __pyx_L1_error)
}
__pyx_t_14 = (__Pyx_PySequence_ContainsTF(__pyx_v_debin, PyList_GET_ITEM(__pyx_v_chart->grammar->tolabel, __pyx_v_label), Py_NE)); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 885, __pyx_L1_error)
__pyx_t_13 = (__pyx_t_14 != 0);
__pyx_t_10 = __pyx_t_13;
__pyx_L12_bool_binop_done:;
if (__pyx_t_10) {

  /* "discodop/disambiguation.pyx":886
 * 		prob += p2
 * 	if debin is None or debin not in chart.grammar.tolabel[label]:
 * 		tree = '(%s %s)' % (chart.grammar.tolabel[label], tree)             # <<<<<<<<<<<<<<
 * 	# create an edge that has as children the edges that were just created
 * 	# by our recursive calls
 */
  if (unlikely(__pyx_v_chart->grammar->tolabel == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 886, __pyx_L1_error)
  }
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 886, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(PyList_GET_ITEM(__pyx_v_chart->grammar->tolabel, __pyx_v_label));
  __Pyx_GIVEREF(PyList_GET_ITEM(__pyx_v_chart->grammar->tolabel, __pyx_v_label));
  PyTuple_SET_ITEM(__pyx_t_2, 0, PyList_GET_ITEM(__pyx_v_chart->grammar->tolabel, __pyx_v_label));
  __Pyx_INCREF(__pyx_v_tree);
  __Pyx_GIVEREF(__pyx_v_tree);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_tree);
  __pyx_t_7 = PyUnicode_Format(__pyx_kp_u_s_s_2, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 886, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF_SET(__pyx_v_tree, __pyx_t_7);
  __pyx_t_7 = 0;

  /* "discodop/disambiguation.pyx":885
 * 		tree += ' ' + tree2
 * 		prob += p2
 * 	if debin is None or debin not in chart.grammar.tolabel[label]:             # <<<<<<<<<<<<<<
 * 		tree = '(%s %s)' % (chart.grammar.tolabel[label], tree)
 * 	# create an edge that has as children the edges that were just created
 */
}

/* "discodop/disambiguation.pyx":890
 * 	# by our recursive calls
 * 	rankededge = new_RankedEdge(item, edge,
 * 			len(chart.rankededges[chart._left(item, edge)]) - 1,             # <<<<<<<<<<<<<<
 * 			(len(chart.rankededges[chart._right(item, edge)]) - 1)
 * 				if edge.rule.rhs2 else -1)
 */
if (unlikely(__pyx_v_chart->rankededges == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
  __PYX_ERR(0, 890, __pyx_L1_error)
}
__pyx_t_7 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->_left(__pyx_v_chart, __pyx_v_item, __pyx_v_edge); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 890, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_chart->rankededges, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 890, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_5 = PyObject_Length(__pyx_t_2); if (unlikely(__pyx_t_5 == -1)) __PYX_ERR(0, 890, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":892
 * 			len(chart.rankededges[chart._left(item, edge)]) - 1,
 * 			(len(chart.rankededges[chart._right(item, edge)]) - 1)
 * 				if edge.rule.rhs2 else -1)             # <<<<<<<<<<<<<<
 * 	# NB: this is actually 'samplededges', not 'rankededges'
 * 	chart.rankededges.setdefault(item, []).append(
 */
if ((__pyx_v_edge->rule->rhs2 != 0)) {

  /* "discodop/disambiguation.pyx":891
 * 	rankededge = new_RankedEdge(item, edge,
 * 			len(chart.rankededges[chart._left(item, edge)]) - 1,
 * 			(len(chart.rankededges[chart._right(item, edge)]) - 1)             # <<<<<<<<<<<<<<
 * 				if edge.rule.rhs2 else -1)
 * 	# NB: this is actually 'samplededges', not 'rankededges'
 */
  if (unlikely(__pyx_v_chart->rankededges == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 891, __pyx_L1_error)
  }
  __pyx_t_2 = ((struct __pyx_vtabstruct_8discodop_10containers_Chart *)__pyx_v_chart->__pyx_vtab)->_right(__pyx_v_chart, __pyx_v_item, __pyx_v_edge); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 891, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_chart->rankededges, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 891, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_15 = PyObject_Length(__pyx_t_7); if (unlikely(__pyx_t_15 == -1)) __PYX_ERR(0, 891, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __pyx_t_4 = (__pyx_t_15 - 1);
} else {
  __pyx_t_4 = -1;
}

/* "discodop/disambiguation.pyx":889
 * 	# create an edge that has as children the edges that were just created
 * 	# by our recursive calls
 * 	rankededge = new_RankedEdge(item, edge,             # <<<<<<<<<<<<<<
 * 			len(chart.rankededges[chart._left(item, edge)]) - 1,
 * 			(len(chart.rankededges[chart._right(item, edge)]) - 1)
 */
__pyx_t_7 = ((PyObject *)__pyx_f_8discodop_10containers_new_RankedEdge(__pyx_v_item, __pyx_v_edge, (__pyx_t_5 - 1), __pyx_t_4)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 889, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_v_rankededge = ((struct __pyx_obj_8discodop_10containers_RankedEdge *)__pyx_t_7);
__pyx_t_7 = 0;

/* "discodop/disambiguation.pyx":894
 * 				if edge.rule.rhs2 else -1)
 * 	# NB: this is actually 'samplededges', not 'rankededges'
 * 	chart.rankededges.setdefault(item, []).append(             # <<<<<<<<<<<<<<
 * 			new_DoubleEntry(rankededge, prob, 0))
 * 	return tree, prob
 */
if (unlikely(__pyx_v_chart->rankededges == Py_None)) {
  PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "setdefault");
  __PYX_ERR(0, 894, __pyx_L1_error)
}
__pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 894, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_2 = __Pyx_PyDict_SetDefault(__pyx_v_chart->rankededges, __pyx_v_item, __pyx_t_7, -1L); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 894, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

/* "discodop/disambiguation.pyx":895
 * 	# NB: this is actually 'samplededges', not 'rankededges'
 * 	chart.rankededges.setdefault(item, []).append(
 * 			new_DoubleEntry(rankededge, prob, 0))             # <<<<<<<<<<<<<<
 * 	return tree, prob
 * 
 */
__pyx_t_7 = ((PyObject *)__pyx_f_8discodop_6plcfrs_new_DoubleEntry(((PyObject *)__pyx_v_rankededge), __pyx_v_prob, 0)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 895, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);

/* "discodop/disambiguation.pyx":894
 * 				if edge.rule.rhs2 else -1)
 * 	# NB: this is actually 'samplededges', not 'rankededges'
 * 	chart.rankededges.setdefault(item, []).append(             # <<<<<<<<<<<<<<
 * 			new_DoubleEntry(rankededge, prob, 0))
 * 	return tree, prob
 */
__pyx_t_11 = __Pyx_PyObject_Append(__pyx_t_2, __pyx_t_7); if (unlikely(__pyx_t_11 == -1)) __PYX_ERR(0, 894, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

/* "discodop/disambiguation.pyx":896
 * 	chart.rankededges.setdefault(item, []).append(
 * 			new_DoubleEntry(rankededge, prob, 0))
 * 	return tree, prob             # <<<<<<<<<<<<<<
 * 
 * 
 */
__Pyx_XDECREF(__pyx_r);
__pyx_t_7 = PyFloat_FromDouble(__pyx_v_prob); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 896, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 896, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(__pyx_v_tree);
__Pyx_GIVEREF(__pyx_v_tree);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_tree);
__Pyx_GIVEREF(__pyx_t_7);
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_7);
__pyx_t_7 = 0;
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
goto __pyx_L0;

/* "discodop/disambiguation.pyx":858
 * 
 * 
 * cdef samplechart(item, Chart chart,             # <<<<<<<<<<<<<<
 * 		dict chartidx, dict tables, str debin):
 * 	"""Samples a derivation from a chart."""
 */

/* 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_7);
__Pyx_AddTraceback("discodop.disambiguation.samplechart", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_rankededge);
__Pyx_XDECREF(__pyx_v_lst);
__Pyx_XDECREF(__pyx_v_rnd);
__Pyx_XDECREF(__pyx_v_idx);
__Pyx_XDECREF(__pyx_v__);
__Pyx_XDECREF(__pyx_v_ptr);
__Pyx_XDECREF(__pyx_v_deriv);
__Pyx_XDECREF(__pyx_v_tree);
__Pyx_XDECREF(__pyx_v_p1);
__Pyx_XDECREF(__pyx_v_tree2);
__Pyx_XDECREF(__pyx_v_p2);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":899
 * 
 * 
 * def doprerank(parsetrees, sent, k, Grammar coarse, Grammar fine):             # <<<<<<<<<<<<<<
 * 	"""Rerank *k*-best coarse trees w/parse probabilities of DOP reduction.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_8discodop_14disambiguation_21doprerank(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8discodop_14disambiguation_20doprerank[] = "doprerank(parsetrees, sent, k, Grammar coarse, Grammar fine)\nRerank *k*-best coarse trees w/parse probabilities of DOP reduction.\n\n\tcf. ``dopparseprob()``.";
static PyMethodDef __pyx_mdef_8discodop_14disambiguation_21doprerank = {"doprerank", (PyCFunction)__pyx_pw_8discodop_14disambiguation_21doprerank, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8discodop_14disambiguation_20doprerank};
static PyObject *__pyx_pw_8discodop_14disambiguation_21doprerank(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_parsetrees = 0;
PyObject *__pyx_v_sent = 0;
PyObject *__pyx_v_k = 0;
struct __pyx_obj_8discodop_10containers_Grammar *__pyx_v_coarse = 0;
struct __pyx_obj_8discodop_10containers_Grammar *__pyx_v_fine = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("doprerank (wrapper)", 0);
{
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_parsetrees,&__pyx_n_s_sent,&__pyx_n_s_k,&__pyx_n_s_coarse,&__pyx_n_s_fine,0};
  PyObject* values[5] = {0,0,0,0,0};
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args;
    const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
    switch (pos_args) {
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    kw_args = PyDict_Size(__pyx_kwds);
    switch (pos_args) {
      case  0:
      if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_parsetrees)) != 0)) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sent)) != 0)) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("doprerank", 1, 5, 5, 1); __PYX_ERR(0, 899, __pyx_L3_error)
      }
      case  2:
      if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_k)) != 0)) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("doprerank", 1, 5, 5, 2); __PYX_ERR(0, 899, __pyx_L3_error)
      }
      case  3:
      if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_coarse)) != 0)) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("doprerank", 1, 5, 5, 3); __PYX_ERR(0, 899, __pyx_L3_error)
      }
      case  4:
      if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fine)) != 0)) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("doprerank", 1, 5, 5, 4); __PYX_ERR(0, 899, __pyx_L3_error)
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "doprerank") < 0)) __PYX_ERR(0, 899, __pyx_L3_error)
    }
  } else if (PyTuple_GET_SIZE(__pyx_args) != 5) {
    goto __pyx_L5_argtuple_error;
  } else {
    values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
    values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
  }
  __pyx_v_parsetrees = values[0];
  __pyx_v_sent = values[1];
  __pyx_v_k = values[2];
  __pyx_v_coarse = ((struct __pyx_obj_8discodop_10containers_Grammar *)values[3]);
  __pyx_v_fine = ((struct __pyx_obj_8discodop_10containers_Grammar *)values[4]);
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("doprerank", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 899, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("discodop.disambiguation.doprerank", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_coarse), __pyx_ptype_8discodop_10containers_Grammar, 1, "coarse", 0))) __PYX_ERR(0, 899, __pyx_L1_error)
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fine), __pyx_ptype_8discodop_10containers_Grammar, 1, "fine", 0))) __PYX_ERR(0, 899, __pyx_L1_error)
__pyx_r = __pyx_pf_8discodop_14disambiguation_20doprerank(__pyx_self, __pyx_v_parsetrees, __pyx_v_sent, __pyx_v_k, __pyx_v_coarse, __pyx_v_fine);

/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":910
 * 	msg = 're-ranked %d parse trees; best tree at %d. ' % (
 * 			len(results),
 * 			max(range(len(results)), key=lambda x: results[x][1]) + 1)             # <<<<<<<<<<<<<<
 * 	return results, msg
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_8discodop_14disambiguation_9doprerank_lambda(PyObject *__pyx_self, PyObject *__pyx_v_x); /*proto*/
static PyMethodDef __pyx_mdef_8discodop_14disambiguation_9doprerank_lambda = {"lambda", (PyCFunction)__pyx_pw_8discodop_14disambiguation_9doprerank_lambda, METH_O, 0};
static PyObject *__pyx_pw_8discodop_14disambiguation_9doprerank_lambda(PyObject *__pyx_self, PyObject *__pyx_v_x) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("lambda (wrapper)", 0);
__pyx_r = __pyx_lambda_funcdef_lambda(__pyx_self, ((PyObject *)__pyx_v_x));

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

static PyObject *__pyx_lambda_funcdef_lambda(PyObject *__pyx_self, PyObject *__pyx_v_x) {
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct__doprerank *__pyx_cur_scope;
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct__doprerank *__pyx_outer_scope;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
__Pyx_RefNannySetupContext("lambda", 0);
__pyx_outer_scope = (struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct__doprerank *) __Pyx_CyFunction_GetClosure(__pyx_self);
__pyx_cur_scope = __pyx_outer_scope;
__Pyx_XDECREF(__pyx_r);
if (unlikely(!__pyx_cur_scope->__pyx_v_results)) { __Pyx_RaiseClosureNameError("results"); __PYX_ERR(0, 910, __pyx_L1_error) }
if (unlikely(__pyx_cur_scope->__pyx_v_results == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
  __PYX_ERR(0, 910, __pyx_L1_error)
}
__pyx_t_1 = PyObject_GetItem(__pyx_cur_scope->__pyx_v_results, __pyx_v_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 910, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 910, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
goto __pyx_L0;

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_AddTraceback("discodop.disambiguation.doprerank.lambda", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":899
 * 
 * 
 * def doprerank(parsetrees, sent, k, Grammar coarse, Grammar fine):             # <<<<<<<<<<<<<<
 * 	"""Rerank *k*-best coarse trees w/parse probabilities of DOP reduction.
 * 
 */

static PyObject *__pyx_pf_8discodop_14disambiguation_20doprerank(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_parsetrees, PyObject *__pyx_v_sent, PyObject *__pyx_v_k, struct __pyx_obj_8discodop_10containers_Grammar *__pyx_v_coarse, struct __pyx_obj_8discodop_10containers_Grammar *__pyx_v_fine) {
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct__doprerank *__pyx_cur_scope;
PyObject *__pyx_v_derivstr = NULL;
CYTHON_UNUSED PyObject *__pyx_v__ = NULL;
PyObject *__pyx_v_deriv = NULL;
PyObject *__pyx_v_msg = 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;
Py_ssize_t __pyx_t_6;
PyObject *(*__pyx_t_7)(PyObject *);
PyObject *__pyx_t_8 = NULL;
PyObject *(*__pyx_t_9)(PyObject *);
int __pyx_t_10;
PyObject *__pyx_t_11 = NULL;
int __pyx_t_12;
__Pyx_RefNannySetupContext("doprerank", 0);
__pyx_cur_scope = (struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct__doprerank *)__pyx_tp_new_8discodop_14disambiguation___pyx_scope_struct__doprerank(__pyx_ptype_8discodop_14disambiguation___pyx_scope_struct__doprerank, __pyx_empty_tuple, NULL);
if (unlikely(!__pyx_cur_scope)) {
  __pyx_cur_scope = ((struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct__doprerank *)Py_None);
  __Pyx_INCREF(Py_None);
  __PYX_ERR(0, 899, __pyx_L1_error)
} else {
  __Pyx_GOTREF(__pyx_cur_scope);
}

/* "discodop/disambiguation.pyx":903
 * 
 * 	cf. ``dopparseprob()``."""
 * 	cdef list results = []             # <<<<<<<<<<<<<<
 * 	for derivstr, _, _ in nlargest(k, parsetrees, key=itemgetter(1)):
 * 		deriv = addbitsets(derivstr)
 */
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 903, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_GIVEREF(__pyx_t_1);
__pyx_cur_scope->__pyx_v_results = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":904
 * 	cf. ``dopparseprob()``."""
 * 	cdef list results = []
 * 	for derivstr, _, _ in nlargest(k, parsetrees, key=itemgetter(1)):             # <<<<<<<<<<<<<<
 * 		deriv = addbitsets(derivstr)
 * 		results.append((derivstr, exp(dopparseprob(deriv, sent, coarse, fine)),
 */
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_nlargest); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 904, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 904, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(__pyx_v_k);
__Pyx_GIVEREF(__pyx_v_k);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_k);
__Pyx_INCREF(__pyx_v_parsetrees);
__Pyx_GIVEREF(__pyx_v_parsetrees);
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_parsetrees);
__pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 904, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_itemgetter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 904, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__26, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 904, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_key, __pyx_t_5) < 0) __PYX_ERR(0, 904, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 904, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__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_5)) || PyTuple_CheckExact(__pyx_t_5)) {
  __pyx_t_3 = __pyx_t_5; __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = 0;
  __pyx_t_7 = NULL;
} else {
  __pyx_t_6 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 904, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 904, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
for (;;) {
  if (likely(!__pyx_t_7)) {
    if (likely(PyList_CheckExact(__pyx_t_3))) {
      if (__pyx_t_6 >= 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_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 904, __pyx_L1_error)
      #else
      __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 904, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      #endif
    } else {
      if (__pyx_t_6 >= 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_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 904, __pyx_L1_error)
      #else
      __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 904, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      #endif
    }
  } else {
    __pyx_t_5 = __pyx_t_7(__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, 904, __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 != 3)) {
      if (size > 3) __Pyx_RaiseTooManyValuesError(3);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 904, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 2); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_4 = PyList_GET_ITEM(sequence, 2); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_4);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 904, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 904, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 904, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    #endif
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_8 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 904, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_2)) goto __pyx_L5_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_1 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_1)) goto __pyx_L5_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    index = 2; __pyx_t_4 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_4)) goto __pyx_L5_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_4);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 3) < 0) __PYX_ERR(0, 904, __pyx_L1_error)
    __pyx_t_9 = NULL;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    goto __pyx_L6_unpacking_done;
    __pyx_L5_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_9 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 904, __pyx_L1_error)
    __pyx_L6_unpacking_done:;
  }
  __Pyx_XDECREF_SET(__pyx_v_derivstr, __pyx_t_2);
  __pyx_t_2 = 0;
  __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_1);
  __pyx_t_1 = 0;
  __Pyx_DECREF_SET(__pyx_v__, __pyx_t_4);
  __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":905
 * 	cdef list results = []
 * 	for derivstr, _, _ in nlargest(k, parsetrees, key=itemgetter(1)):
 * 		deriv = addbitsets(derivstr)             # <<<<<<<<<<<<<<
 * 		results.append((derivstr, exp(dopparseprob(deriv, sent, coarse, fine)),
 * 				None))
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_addbitsets); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 905, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(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_5 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_derivstr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 905, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_derivstr};
      __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 905, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_5);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_derivstr};
      __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 905, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_5);
    } else
    #endif
    {
      __pyx_t_2 = PyTuple_New(1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 905, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __pyx_t_1 = NULL;
      __Pyx_INCREF(__pyx_v_derivstr);
      __Pyx_GIVEREF(__pyx_v_derivstr);
      PyTuple_SET_ITEM(__pyx_t_2, 0+1, __pyx_v_derivstr);
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_2, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 905, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_XDECREF_SET(__pyx_v_deriv, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "discodop/disambiguation.pyx":906
 * 	for derivstr, _, _ in nlargest(k, parsetrees, key=itemgetter(1)):
 * 		deriv = addbitsets(derivstr)
 * 		results.append((derivstr, exp(dopparseprob(deriv, sent, coarse, fine)),             # <<<<<<<<<<<<<<
 * 				None))
 * 	msg = 're-ranked %d parse trees; best tree at %d. ' % (
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_exp); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 906, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_dopparseprob); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 906, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_8 = NULL;
  __pyx_t_10 = 0;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_1))) {
    __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1);
    if (likely(__pyx_t_8)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_8);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_1, function);
      __pyx_t_10 = 1;
    }
  }
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[5] = {__pyx_t_8, __pyx_v_deriv, __pyx_v_sent, ((PyObject *)__pyx_v_coarse), ((PyObject *)__pyx_v_fine)};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 4+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 906, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GOTREF(__pyx_t_2);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[5] = {__pyx_t_8, __pyx_v_deriv, __pyx_v_sent, ((PyObject *)__pyx_v_coarse), ((PyObject *)__pyx_v_fine)};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_10, 4+__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 906, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_GOTREF(__pyx_t_2);
  } else
  #endif
  {
    __pyx_t_11 = PyTuple_New(4+__pyx_t_10); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 906, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_11);
    if (__pyx_t_8) {
      __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_8); __pyx_t_8 = NULL;
    }
    __Pyx_INCREF(__pyx_v_deriv);
    __Pyx_GIVEREF(__pyx_v_deriv);
    PyTuple_SET_ITEM(__pyx_t_11, 0+__pyx_t_10, __pyx_v_deriv);
    __Pyx_INCREF(__pyx_v_sent);
    __Pyx_GIVEREF(__pyx_v_sent);
    PyTuple_SET_ITEM(__pyx_t_11, 1+__pyx_t_10, __pyx_v_sent);
    __Pyx_INCREF(((PyObject *)__pyx_v_coarse));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_coarse));
    PyTuple_SET_ITEM(__pyx_t_11, 2+__pyx_t_10, ((PyObject *)__pyx_v_coarse));
    __Pyx_INCREF(((PyObject *)__pyx_v_fine));
    __Pyx_GIVEREF(((PyObject *)__pyx_v_fine));
    PyTuple_SET_ITEM(__pyx_t_11, 3+__pyx_t_10, ((PyObject *)__pyx_v_fine));
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_11, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 906, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(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_5 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 906, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    __Pyx_GOTREF(__pyx_t_5);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_4)) {
      PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_t_2};
      __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 906, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_5);
      __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_1, __pyx_t_2};
      __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 906, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
    } else
    #endif
    {
      __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 906, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_11);
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_1); __pyx_t_1 = NULL;
      __Pyx_GIVEREF(__pyx_t_2);
      PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_t_2);
      __pyx_t_2 = 0;
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_11, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 906, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":907
 * 		deriv = addbitsets(derivstr)
 * 		results.append((derivstr, exp(dopparseprob(deriv, sent, coarse, fine)),
 * 				None))             # <<<<<<<<<<<<<<
 * 	msg = 're-ranked %d parse trees; best tree at %d. ' % (
 * 			len(results),
 */
  __pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 906, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_v_derivstr);
  __Pyx_GIVEREF(__pyx_v_derivstr);
  PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_derivstr);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5);
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  PyTuple_SET_ITEM(__pyx_t_4, 2, Py_None);
  __pyx_t_5 = 0;

  /* "discodop/disambiguation.pyx":906
 * 	for derivstr, _, _ in nlargest(k, parsetrees, key=itemgetter(1)):
 * 		deriv = addbitsets(derivstr)
 * 		results.append((derivstr, exp(dopparseprob(deriv, sent, coarse, fine)),             # <<<<<<<<<<<<<<
 * 				None))
 * 	msg = 're-ranked %d parse trees; best tree at %d. ' % (
 */
  __pyx_t_12 = __Pyx_PyList_Append(__pyx_cur_scope->__pyx_v_results, __pyx_t_4); if (unlikely(__pyx_t_12 == -1)) __PYX_ERR(0, 906, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":904
 * 	cf. ``dopparseprob()``."""
 * 	cdef list results = []
 * 	for derivstr, _, _ in nlargest(k, parsetrees, key=itemgetter(1)):             # <<<<<<<<<<<<<<
 * 		deriv = addbitsets(derivstr)
 * 		results.append((derivstr, exp(dopparseprob(deriv, sent, coarse, fine)),
 */
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

/* "discodop/disambiguation.pyx":909
 * 				None))
 * 	msg = 're-ranked %d parse trees; best tree at %d. ' % (
 * 			len(results),             # <<<<<<<<<<<<<<
 * 			max(range(len(results)), key=lambda x: results[x][1]) + 1)
 * 	return results, msg
 */
__pyx_t_3 = __pyx_cur_scope->__pyx_v_results;
__Pyx_INCREF(__pyx_t_3);
if (unlikely(__pyx_t_3 == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
  __PYX_ERR(0, 909, __pyx_L1_error)
}
__pyx_t_6 = PyList_GET_SIZE(__pyx_t_3); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 909, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_3 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 909, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);

/* "discodop/disambiguation.pyx":910
 * 	msg = 're-ranked %d parse trees; best tree at %d. ' % (
 * 			len(results),
 * 			max(range(len(results)), key=lambda x: results[x][1]) + 1)             # <<<<<<<<<<<<<<
 * 	return results, msg
 * 
 */
__pyx_t_4 = __pyx_cur_scope->__pyx_v_results;
__Pyx_INCREF(__pyx_t_4);
if (unlikely(__pyx_t_4 == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
  __PYX_ERR(0, 910, __pyx_L1_error)
}
__pyx_t_6 = PyList_GET_SIZE(__pyx_t_4); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 910, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 910, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 910, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_GIVEREF(__pyx_t_4);
PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
__pyx_t_4 = 0;
__pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_5, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 910, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 910, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_GIVEREF(__pyx_t_4);
PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4);
__pyx_t_4 = 0;
__pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 910, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_11 = __Pyx_CyFunction_NewEx(&__pyx_mdef_8discodop_14disambiguation_9doprerank_lambda, 0, __pyx_n_s_doprerank_locals_lambda, ((PyObject*)__pyx_cur_scope), __pyx_n_s_discodop_disambiguation, __pyx_d, NULL); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 910, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_key, __pyx_t_11) < 0) __PYX_ERR(0, 910, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
__pyx_t_11 = __Pyx_PyObject_Call(__pyx_builtin_max, __pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 910, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_t_11, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 910, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;

/* "discodop/disambiguation.pyx":909
 * 				None))
 * 	msg = 're-ranked %d parse trees; best tree at %d. ' % (
 * 			len(results),             # <<<<<<<<<<<<<<
 * 			max(range(len(results)), key=lambda x: results[x][1]) + 1)
 * 	return results, msg
 */
__pyx_t_11 = PyTuple_New(2); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 909, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_11);
__Pyx_GIVEREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_3);
__Pyx_GIVEREF(__pyx_t_4);
PyTuple_SET_ITEM(__pyx_t_11, 1, __pyx_t_4);
__pyx_t_3 = 0;
__pyx_t_4 = 0;

/* "discodop/disambiguation.pyx":908
 * 		results.append((derivstr, exp(dopparseprob(deriv, sent, coarse, fine)),
 * 				None))
 * 	msg = 're-ranked %d parse trees; best tree at %d. ' % (             # <<<<<<<<<<<<<<
 * 			len(results),
 * 			max(range(len(results)), key=lambda x: results[x][1]) + 1)
 */
__pyx_t_4 = PyUnicode_Format(__pyx_kp_u_re_ranked_d_parse_trees_best_tre, __pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 908, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
__pyx_v_msg = ((PyObject*)__pyx_t_4);
__pyx_t_4 = 0;

/* "discodop/disambiguation.pyx":911
 * 			len(results),
 * 			max(range(len(results)), key=lambda x: results[x][1]) + 1)
 * 	return results, msg             # <<<<<<<<<<<<<<
 * 
 * 
 */
__Pyx_XDECREF(__pyx_r);
__pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 911, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_INCREF(__pyx_cur_scope->__pyx_v_results);
__Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_results);
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_cur_scope->__pyx_v_results);
__Pyx_INCREF(__pyx_v_msg);
__Pyx_GIVEREF(__pyx_v_msg);
PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_msg);
__pyx_r = __pyx_t_4;
__pyx_t_4 = 0;
goto __pyx_L0;

/* "discodop/disambiguation.pyx":899
 * 
 * 
 * def doprerank(parsetrees, sent, k, Grammar coarse, Grammar fine):             # <<<<<<<<<<<<<<
 * 	"""Rerank *k*-best coarse trees w/parse probabilities of DOP reduction.
 * 
 */

/* 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_5);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_XDECREF(__pyx_t_11);
__Pyx_AddTraceback("discodop.disambiguation.doprerank", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_derivstr);
__Pyx_XDECREF(__pyx_v__);
__Pyx_XDECREF(__pyx_v_deriv);
__Pyx_XDECREF(__pyx_v_msg);
__Pyx_DECREF(((PyObject *)__pyx_cur_scope));
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":914
 * 
 * 
 * def dopparseprob(tree, sent, Grammar coarse, Grammar fine):             # <<<<<<<<<<<<<<
 * 	"""Compute the exact DOP parse probability of a Tree in a DOP reduction.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_8discodop_14disambiguation_23dopparseprob(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8discodop_14disambiguation_22dopparseprob[] = "dopparseprob(tree, sent, Grammar coarse, Grammar fine)\nCompute the exact DOP parse probability of a Tree in a DOP reduction.\n\n\tThis follows up on a suggestion made by Goodman (2003, p. 143) of\n\tcalculating DOP probabilities of given parse trees, although I'm not sure\n\tit has complexity *O(nP)* as he suggests (with *n* as number of nodes in\n\tinput, and *P* as max number of rules consistent with a node in the input).\n\tFurthermore, the idea of sampling trees \"long enough\" until we have the MPP\n\tis no faster than sampling without applying this procedure, because to\n\tdetermine that some probability *p* is the maximal probability, we need to\n\tcollect the probability mass *p_seen* of enough parse trees such that we\n\thave some parsetree with probability *p* > (1 - *p_seen*), which requires\n\tfirst seeing almost all parse trees, unless *p* is exceptionally high.\n\tHence, this method is mostly useful in a reranking framework where it is\n\tknown in advance that a small set of trees is of interest.\n\n\tExpects a mapping which gives a list of consistent rules from the reduction\n\tas produced by ``fine.getrulemapping(coarse, re.compile('@[-0-9]+$'))``.\n\n\tNB: this algorithm could also be used to determine the probability of\n\tderivations, but then the input would have to distinguish whether nodes are\n\tinternal nodes of fragments, or whether they join two fragments.";
static PyMethodDef __pyx_mdef_8discodop_14disambiguation_23dopparseprob = {"dopparseprob", (PyCFunction)__pyx_pw_8discodop_14disambiguation_23dopparseprob, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8discodop_14disambiguation_22dopparseprob};
static PyObject *__pyx_pw_8discodop_14disambiguation_23dopparseprob(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_tree = 0;
PyObject *__pyx_v_sent = 0;
struct __pyx_obj_8discodop_10containers_Grammar *__pyx_v_coarse = 0;
struct __pyx_obj_8discodop_10containers_Grammar *__pyx_v_fine = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("dopparseprob (wrapper)", 0);
{
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_tree,&__pyx_n_s_sent,&__pyx_n_s_coarse,&__pyx_n_s_fine,0};
  PyObject* values[4] = {0,0,0,0};
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args;
    const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
    switch (pos_args) {
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    kw_args = PyDict_Size(__pyx_kwds);
    switch (pos_args) {
      case  0:
      if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_tree)) != 0)) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sent)) != 0)) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("dopparseprob", 1, 4, 4, 1); __PYX_ERR(0, 914, __pyx_L3_error)
      }
      case  2:
      if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_coarse)) != 0)) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("dopparseprob", 1, 4, 4, 2); __PYX_ERR(0, 914, __pyx_L3_error)
      }
      case  3:
      if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_fine)) != 0)) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("dopparseprob", 1, 4, 4, 3); __PYX_ERR(0, 914, __pyx_L3_error)
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "dopparseprob") < 0)) __PYX_ERR(0, 914, __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_tree = values[0];
  __pyx_v_sent = values[1];
  __pyx_v_coarse = ((struct __pyx_obj_8discodop_10containers_Grammar *)values[2]);
  __pyx_v_fine = ((struct __pyx_obj_8discodop_10containers_Grammar *)values[3]);
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("dopparseprob", 1, 4, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 914, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("discodop.disambiguation.dopparseprob", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_coarse), __pyx_ptype_8discodop_10containers_Grammar, 1, "coarse", 0))) __PYX_ERR(0, 914, __pyx_L1_error)
if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_fine), __pyx_ptype_8discodop_10containers_Grammar, 1, "fine", 0))) __PYX_ERR(0, 914, __pyx_L1_error)
__pyx_r = __pyx_pf_8discodop_14disambiguation_22dopparseprob(__pyx_self, __pyx_v_tree, __pyx_v_sent, __pyx_v_coarse, __pyx_v_fine);

/* function exit code */
goto __pyx_L0;
__pyx_L1_error:;
__pyx_r = NULL;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

static PyObject *__pyx_pf_8discodop_14disambiguation_22dopparseprob(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_tree, PyObject *__pyx_v_sent, struct __pyx_obj_8discodop_10containers_Grammar *__pyx_v_coarse, struct __pyx_obj_8discodop_10containers_Grammar *__pyx_v_fine) {
PyObject *__pyx_v_chart = 0;
PyObject *__pyx_v_cell = 0;
struct __pyx_t_8discodop_10containers_ProbRule *__pyx_v_rule;
struct __pyx_obj_8discodop_10containers_LexicalRule *__pyx_v_lexrule = 0;
PyObject *__pyx_v_n = 0;
PyObject *__pyx_v_pos = 0;
PyObject *__pyx_v_word = NULL;
PyObject *__pyx_v_node = NULL;
PyObject *__pyx_v_r = NULL;
PyObject *__pyx_v_yf = NULL;
PyObject *__pyx_v_prod = NULL;
PyObject *__pyx_v_ruleno = NULL;
PyObject *__pyx_v_leftcell = NULL;
PyObject *__pyx_v_rightcell = NULL;
PyObject *__pyx_v_newprob = 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;
Py_ssize_t __pyx_t_5;
PyObject *(*__pyx_t_6)(PyObject *);
PyObject *__pyx_t_7 = NULL;
PyObject *__pyx_t_8 = NULL;
PyObject *(*__pyx_t_9)(PyObject *);
int __pyx_t_10;
Py_ssize_t __pyx_t_11;
PyObject *(*__pyx_t_12)(PyObject *);
PyObject *__pyx_t_13 = NULL;
PyObject *__pyx_t_14 = NULL;
int __pyx_t_15;
Py_ssize_t __pyx_t_16;
int __pyx_t_17;
__Pyx_RefNannySetupContext("dopparseprob", 0);

/* "discodop/disambiguation.pyx":936
 * 	derivations, but then the input would have to distinguish whether nodes are
 * 	internal nodes of fragments, or whether they join two fragments."""
 * 	cdef dict chart = {}  # chart[bitset][label] = prob             # <<<<<<<<<<<<<<
 * 	cdef dict cell  # chart[bitset] = cell; cell[label] = prob
 * 	cdef ProbRule *rule
 */
__pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 936, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_chart = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":942
 * 	cdef object n  # pyint
 * 	cdef str pos
 * 	if not fine.logprob:             # <<<<<<<<<<<<<<
 * 		raise ValueError('Grammar should have log probabilities.')
 * 	# Log probabilities are not ideal here because we do lots of additions,
 */
__pyx_t_2 = ((!(__pyx_v_fine->logprob != 0)) != 0);
if (__pyx_t_2) {

  /* "discodop/disambiguation.pyx":943
 * 	cdef str pos
 * 	if not fine.logprob:
 * 		raise ValueError('Grammar should have log probabilities.')             # <<<<<<<<<<<<<<
 * 	# Log probabilities are not ideal here because we do lots of additions,
 * 	# but the probabilities are very small.
 */
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__27, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 943, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_Raise(__pyx_t_1, 0, 0, 0);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __PYX_ERR(0, 943, __pyx_L1_error)

  /* "discodop/disambiguation.pyx":942
 * 	cdef object n  # pyint
 * 	cdef str pos
 * 	if not fine.logprob:             # <<<<<<<<<<<<<<
 * 		raise ValueError('Grammar should have log probabilities.')
 * 	# Log probabilities are not ideal here because we do lots of additions,
 */
}

/* "discodop/disambiguation.pyx":949
 * 
 * 	# add all matching POS tags
 * 	for n, pos in tree.pos():             # <<<<<<<<<<<<<<
 * 		word = sent[n]
 * 		chart[1 << n] = cell = {}
 */
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_pos); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 949, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = NULL;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_3))) {
  __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3);
  if (likely(__pyx_t_4)) {
    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(function);
    __Pyx_DECREF_SET(__pyx_t_3, function);
  }
}
if (__pyx_t_4) {
  __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 949, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
} else {
  __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 949, __pyx_L1_error)
}
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
  __pyx_t_3 = __pyx_t_1; __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_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 949, __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, 949, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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_1 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 949, __pyx_L1_error)
      #else
      __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 949, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      #endif
    } else {
      if (__pyx_t_5 >= PyTuple_GET_SIZE(__pyx_t_3)) break;
      #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
      __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_5); __Pyx_INCREF(__pyx_t_1); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 949, __pyx_L1_error)
      #else
      __pyx_t_1 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 949, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      #endif
    }
  } else {
    __pyx_t_1 = __pyx_t_6(__pyx_t_3);
    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, 949, __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, 949, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_4 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_7 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_7);
    #else
    __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 949, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 949, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    #endif
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_8 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 949, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
    index = 0; __pyx_t_4 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_4)) goto __pyx_L6_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_4);
    index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L6_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_7);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < 0) __PYX_ERR(0, 949, __pyx_L1_error)
    __pyx_t_9 = NULL;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    goto __pyx_L7_unpacking_done;
    __pyx_L6_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_9 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 949, __pyx_L1_error)
    __pyx_L7_unpacking_done:;
  }
  if (!(likely(PyUnicode_CheckExact(__pyx_t_7))||((__pyx_t_7) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_7)->tp_name), 0))) __PYX_ERR(0, 949, __pyx_L1_error)
  __Pyx_XDECREF_SET(__pyx_v_n, __pyx_t_4);
  __pyx_t_4 = 0;
  __Pyx_XDECREF_SET(__pyx_v_pos, ((PyObject*)__pyx_t_7));
  __pyx_t_7 = 0;

  /* "discodop/disambiguation.pyx":950
 * 	# add all matching POS tags
 * 	for n, pos in tree.pos():
 * 		word = sent[n]             # <<<<<<<<<<<<<<
 * 		chart[1 << n] = cell = {}
 * 		if word not in fine.lexicalbyword:
 */
  __pyx_t_1 = PyObject_GetItem(__pyx_v_sent, __pyx_v_n); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 950, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_XDECREF_SET(__pyx_v_word, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":951
 * 	for n, pos in tree.pos():
 * 		word = sent[n]
 * 		chart[1 << n] = cell = {}             # <<<<<<<<<<<<<<
 * 		if word not in fine.lexicalbyword:
 * 			cell[fine.toid[pos]] = -0.0
 */
  __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 951, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_7 = PyNumber_Lshift(__pyx_int_1, __pyx_v_n); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 951, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  if (unlikely(PyDict_SetItem(__pyx_v_chart, __pyx_t_7, __pyx_t_1) < 0)) __PYX_ERR(0, 951, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_INCREF(__pyx_t_1);
  __Pyx_XDECREF_SET(__pyx_v_cell, __pyx_t_1);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":952
 * 		word = sent[n]
 * 		chart[1 << n] = cell = {}
 * 		if word not in fine.lexicalbyword:             # <<<<<<<<<<<<<<
 * 			cell[fine.toid[pos]] = -0.0
 * 			continue
 */
  if (unlikely(__pyx_v_fine->lexicalbyword == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(0, 952, __pyx_L1_error)
  }
  __pyx_t_2 = (__Pyx_PyDict_ContainsTF(__pyx_v_word, __pyx_v_fine->lexicalbyword, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 952, __pyx_L1_error)
  __pyx_t_10 = (__pyx_t_2 != 0);
  if (__pyx_t_10) {

    /* "discodop/disambiguation.pyx":953
 * 		chart[1 << n] = cell = {}
 * 		if word not in fine.lexicalbyword:
 * 			cell[fine.toid[pos]] = -0.0             # <<<<<<<<<<<<<<
 * 			continue
 * 		for lexrule in fine.lexicalbyword[word]:
 */
    if (unlikely(__pyx_v_fine->toid == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 953, __pyx_L1_error)
    }
    __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_fine->toid, __pyx_v_pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 953, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    if (unlikely(PyDict_SetItem(__pyx_v_cell, __pyx_t_1, __pyx_float_neg_0_0) < 0)) __PYX_ERR(0, 953, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

    /* "discodop/disambiguation.pyx":954
 * 		if word not in fine.lexicalbyword:
 * 			cell[fine.toid[pos]] = -0.0
 * 			continue             # <<<<<<<<<<<<<<
 * 		for lexrule in fine.lexicalbyword[word]:
 * 			if (fine.tolabel[lexrule.lhs] == pos
 */
    goto __pyx_L4_continue;

    /* "discodop/disambiguation.pyx":952
 * 		word = sent[n]
 * 		chart[1 << n] = cell = {}
 * 		if word not in fine.lexicalbyword:             # <<<<<<<<<<<<<<
 * 			cell[fine.toid[pos]] = -0.0
 * 			continue
 */
  }

  /* "discodop/disambiguation.pyx":955
 * 			cell[fine.toid[pos]] = -0.0
 * 			continue
 * 		for lexrule in fine.lexicalbyword[word]:             # <<<<<<<<<<<<<<
 * 			if (fine.tolabel[lexrule.lhs] == pos
 * 					or fine.tolabel[lexrule.lhs].startswith(pos + '@')):
 */
  if (unlikely(__pyx_v_fine->lexicalbyword == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 955, __pyx_L1_error)
  }
  __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_fine->lexicalbyword, __pyx_v_word); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 955, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (likely(PyList_CheckExact(__pyx_t_1)) || PyTuple_CheckExact(__pyx_t_1)) {
    __pyx_t_7 = __pyx_t_1; __Pyx_INCREF(__pyx_t_7); __pyx_t_11 = 0;
    __pyx_t_12 = NULL;
  } else {
    __pyx_t_11 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 955, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_12 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 955, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  for (;;) {
    if (likely(!__pyx_t_12)) {
      if (likely(PyList_CheckExact(__pyx_t_7))) {
        if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_11); __Pyx_INCREF(__pyx_t_1); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 955, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_7, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 955, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      } else {
        if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_11); __Pyx_INCREF(__pyx_t_1); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 955, __pyx_L1_error)
        #else
        __pyx_t_1 = PySequence_ITEM(__pyx_t_7, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 955, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        #endif
      }
    } else {
      __pyx_t_1 = __pyx_t_12(__pyx_t_7);
      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, 955, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_1);
    }
    if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8discodop_10containers_LexicalRule))))) __PYX_ERR(0, 955, __pyx_L1_error)
    __Pyx_XDECREF_SET(__pyx_v_lexrule, ((struct __pyx_obj_8discodop_10containers_LexicalRule *)__pyx_t_1));
    __pyx_t_1 = 0;

    /* "discodop/disambiguation.pyx":956
 * 			continue
 * 		for lexrule in fine.lexicalbyword[word]:
 * 			if (fine.tolabel[lexrule.lhs] == pos             # <<<<<<<<<<<<<<
 * 					or fine.tolabel[lexrule.lhs].startswith(pos + '@')):
 * 				cell[lexrule.lhs] = -lexrule.prob
 */
    if (unlikely(__pyx_v_fine->tolabel == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 956, __pyx_L1_error)
    }

    /* "discodop/disambiguation.pyx":957
 * 		for lexrule in fine.lexicalbyword[word]:
 * 			if (fine.tolabel[lexrule.lhs] == pos
 * 					or fine.tolabel[lexrule.lhs].startswith(pos + '@')):             # <<<<<<<<<<<<<<
 * 				cell[lexrule.lhs] = -lexrule.prob
 * 
 */
    __pyx_t_2 = (__Pyx_PyUnicode_Equals(PyList_GET_ITEM(__pyx_v_fine->tolabel, __pyx_v_lexrule->lhs), __pyx_v_pos, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 956, __pyx_L1_error)
    if (!__pyx_t_2) {
    } else {
      __pyx_t_10 = __pyx_t_2;
      goto __pyx_L12_bool_binop_done;
    }
    if (unlikely(__pyx_v_fine->tolabel == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 957, __pyx_L1_error)
    }
    __pyx_t_4 = __Pyx_PyObject_GetAttrStr(PyList_GET_ITEM(__pyx_v_fine->tolabel, __pyx_v_lexrule->lhs), __pyx_n_s_startswith); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 957, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = __Pyx_PyUnicode_ConcatSafe(__pyx_v_pos, __pyx_kp_u__16); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 957, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_13 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_4))) {
      __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_4);
      if (likely(__pyx_t_13)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4);
        __Pyx_INCREF(__pyx_t_13);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_4, function);
      }
    }
    if (!__pyx_t_13) {
      __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 957, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __Pyx_GOTREF(__pyx_t_1);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_4)) {
        PyObject *__pyx_temp[2] = {__pyx_t_13, __pyx_t_8};
        __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 957, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
        PyObject *__pyx_temp[2] = {__pyx_t_13, __pyx_t_8};
        __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 957, __pyx_L1_error)
        __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0;
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      } else
      #endif
      {
        __pyx_t_14 = PyTuple_New(1+1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 957, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        __Pyx_GIVEREF(__pyx_t_13); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_13); __pyx_t_13 = NULL;
        __Pyx_GIVEREF(__pyx_t_8);
        PyTuple_SET_ITEM(__pyx_t_14, 0+1, __pyx_t_8);
        __pyx_t_8 = 0;
        __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_14, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 957, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_1);
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 957, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    __pyx_t_10 = __pyx_t_2;
    __pyx_L12_bool_binop_done:;

    /* "discodop/disambiguation.pyx":956
 * 			continue
 * 		for lexrule in fine.lexicalbyword[word]:
 * 			if (fine.tolabel[lexrule.lhs] == pos             # <<<<<<<<<<<<<<
 * 					or fine.tolabel[lexrule.lhs].startswith(pos + '@')):
 * 				cell[lexrule.lhs] = -lexrule.prob
 */
    if (__pyx_t_10) {

      /* "discodop/disambiguation.pyx":958
 * 			if (fine.tolabel[lexrule.lhs] == pos
 * 					or fine.tolabel[lexrule.lhs].startswith(pos + '@')):
 * 				cell[lexrule.lhs] = -lexrule.prob             # <<<<<<<<<<<<<<
 * 
 * 	# do post-order traversal (bottom-up)
 */
      __pyx_t_1 = PyFloat_FromDouble((-__pyx_v_lexrule->prob)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 958, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_4 = __Pyx_PyInt_From_uint32_t(__pyx_v_lexrule->lhs); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 958, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      if (unlikely(PyDict_SetItem(__pyx_v_cell, __pyx_t_4, __pyx_t_1) < 0)) __PYX_ERR(0, 958, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

      /* "discodop/disambiguation.pyx":956
 * 			continue
 * 		for lexrule in fine.lexicalbyword[word]:
 * 			if (fine.tolabel[lexrule.lhs] == pos             # <<<<<<<<<<<<<<
 * 					or fine.tolabel[lexrule.lhs].startswith(pos + '@')):
 * 				cell[lexrule.lhs] = -lexrule.prob
 */
    }

    /* "discodop/disambiguation.pyx":955
 * 			cell[fine.toid[pos]] = -0.0
 * 			continue
 * 		for lexrule in fine.lexicalbyword[word]:             # <<<<<<<<<<<<<<
 * 			if (fine.tolabel[lexrule.lhs] == pos
 * 					or fine.tolabel[lexrule.lhs].startswith(pos + '@')):
 */
  }
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

  /* "discodop/disambiguation.pyx":949
 * 
 * 	# add all matching POS tags
 * 	for n, pos in tree.pos():             # <<<<<<<<<<<<<<
 * 		word = sent[n]
 * 		chart[1 << n] = cell = {}
 */
  __pyx_L4_continue:;
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

/* "discodop/disambiguation.pyx":961
 * 
 * 	# do post-order traversal (bottom-up)
 * 	for node, (r, yf) in list(zip(tree.subtrees(),             # <<<<<<<<<<<<<<
 * 			lcfrsproductions(tree, sent)))[::-1]:
 * 		if not isinstance(node[0], Tree):
 */
__pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_subtrees); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 961, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_1 = NULL;
if (CYTHON_UNPACK_METHODS && likely(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);
  }
}
if (__pyx_t_1) {
  __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_7, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 961, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
} else {
  __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 961, __pyx_L1_error)
}
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

/* "discodop/disambiguation.pyx":962
 * 	# do post-order traversal (bottom-up)
 * 	for node, (r, yf) in list(zip(tree.subtrees(),
 * 			lcfrsproductions(tree, sent)))[::-1]:             # <<<<<<<<<<<<<<
 * 		if not isinstance(node[0], Tree):
 * 			continue
 */
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_lcfrsproductions); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 962, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_4 = NULL;
__pyx_t_15 = 0;
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);
    __pyx_t_15 = 1;
  }
}
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_1)) {
  PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_tree, __pyx_v_sent};
  __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 962, __pyx_L1_error)
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_GOTREF(__pyx_t_7);
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
  PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_v_tree, __pyx_v_sent};
  __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 962, __pyx_L1_error)
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_GOTREF(__pyx_t_7);
} else
#endif
{
  __pyx_t_14 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 962, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  if (__pyx_t_4) {
    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_4); __pyx_t_4 = NULL;
  }
  __Pyx_INCREF(__pyx_v_tree);
  __Pyx_GIVEREF(__pyx_v_tree);
  PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_15, __pyx_v_tree);
  __Pyx_INCREF(__pyx_v_sent);
  __Pyx_GIVEREF(__pyx_v_sent);
  PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_15, __pyx_v_sent);
  __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_14, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 962, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":961
 * 
 * 	# do post-order traversal (bottom-up)
 * 	for node, (r, yf) in list(zip(tree.subtrees(),             # <<<<<<<<<<<<<<
 * 			lcfrsproductions(tree, sent)))[::-1]:
 * 		if not isinstance(node[0], Tree):
 */
__pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 961, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_GIVEREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
__Pyx_GIVEREF(__pyx_t_7);
PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_7);
__pyx_t_3 = 0;
__pyx_t_7 = 0;
__pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_1, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 961, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = PySequence_List(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 961, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

/* "discodop/disambiguation.pyx":962
 * 	# do post-order traversal (bottom-up)
 * 	for node, (r, yf) in list(zip(tree.subtrees(),
 * 			lcfrsproductions(tree, sent)))[::-1]:             # <<<<<<<<<<<<<<
 * 		if not isinstance(node[0], Tree):
 * 			continue
 */
__pyx_t_7 = PyObject_GetItem(__pyx_t_1, __pyx_slice__28); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 962, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":961
 * 
 * 	# do post-order traversal (bottom-up)
 * 	for node, (r, yf) in list(zip(tree.subtrees(),             # <<<<<<<<<<<<<<
 * 			lcfrsproductions(tree, sent)))[::-1]:
 * 		if not isinstance(node[0], Tree):
 */
__pyx_t_1 = __pyx_t_7; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = 0;
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
for (;;) {
  if (__pyx_t_5 >= PyList_GET_SIZE(__pyx_t_1)) break;
  #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
  __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_5); __Pyx_INCREF(__pyx_t_7); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 961, __pyx_L1_error)
  #else
  __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 961, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  #endif
  if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) {
    PyObject* sequence = __pyx_t_7;
    #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, 961, __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_14 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_14 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_3);
    __Pyx_INCREF(__pyx_t_14);
    #else
    __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 961, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_14 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 961, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    #endif
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_4 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 961, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_9 = Py_TYPE(__pyx_t_4)->tp_iternext;
    index = 0; __pyx_t_3 = __pyx_t_9(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L16_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_3);
    index = 1; __pyx_t_14 = __pyx_t_9(__pyx_t_4); if (unlikely(!__pyx_t_14)) goto __pyx_L16_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_14);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_4), 2) < 0) __PYX_ERR(0, 961, __pyx_L1_error)
    __pyx_t_9 = NULL;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    goto __pyx_L17_unpacking_done;
    __pyx_L16_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
    __pyx_t_9 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 961, __pyx_L1_error)
    __pyx_L17_unpacking_done:;
  }
  __Pyx_XDECREF_SET(__pyx_v_node, __pyx_t_3);
  __pyx_t_3 = 0;
  if ((likely(PyTuple_CheckExact(__pyx_t_14))) || (PyList_CheckExact(__pyx_t_14))) {
    PyObject* sequence = __pyx_t_14;
    #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, 961, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_8 = PyTuple_GET_ITEM(sequence, 1); 
    } else {
      __pyx_t_4 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_8 = PyList_GET_ITEM(sequence, 1); 
    }
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(__pyx_t_8);
    #else
    __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 961, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_8 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 961, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    #endif
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_13 = PyObject_GetIter(__pyx_t_14); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 961, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_13);
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    __pyx_t_9 = Py_TYPE(__pyx_t_13)->tp_iternext;
    index = 0; __pyx_t_4 = __pyx_t_9(__pyx_t_13); if (unlikely(!__pyx_t_4)) goto __pyx_L18_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_4);
    index = 1; __pyx_t_8 = __pyx_t_9(__pyx_t_13); if (unlikely(!__pyx_t_8)) goto __pyx_L18_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_8);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_13), 2) < 0) __PYX_ERR(0, 961, __pyx_L1_error)
    __pyx_t_9 = NULL;
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    goto __pyx_L19_unpacking_done;
    __pyx_L18_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0;
    __pyx_t_9 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 961, __pyx_L1_error)
    __pyx_L19_unpacking_done:;
  }
  __Pyx_XDECREF_SET(__pyx_v_r, __pyx_t_4);
  __pyx_t_4 = 0;
  __Pyx_XDECREF_SET(__pyx_v_yf, __pyx_t_8);
  __pyx_t_8 = 0;

  /* "discodop/disambiguation.pyx":963
 * 	for node, (r, yf) in list(zip(tree.subtrees(),
 * 			lcfrsproductions(tree, sent)))[::-1]:
 * 		if not isinstance(node[0], Tree):             # <<<<<<<<<<<<<<
 * 			continue
 * 		if node.bitset not in chart:
 */
  __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_node, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 963, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_14 = __Pyx_GetModuleGlobalName(__pyx_n_s_Tree); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 963, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  __pyx_t_10 = PyObject_IsInstance(__pyx_t_7, __pyx_t_14); if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 963, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  __pyx_t_2 = ((!(__pyx_t_10 != 0)) != 0);
  if (__pyx_t_2) {

    /* "discodop/disambiguation.pyx":964
 * 			lcfrsproductions(tree, sent)))[::-1]:
 * 		if not isinstance(node[0], Tree):
 * 			continue             # <<<<<<<<<<<<<<
 * 		if node.bitset not in chart:
 * 			chart[node.bitset] = {}
 */
    goto __pyx_L14_continue;

    /* "discodop/disambiguation.pyx":963
 * 	for node, (r, yf) in list(zip(tree.subtrees(),
 * 			lcfrsproductions(tree, sent)))[::-1]:
 * 		if not isinstance(node[0], Tree):             # <<<<<<<<<<<<<<
 * 			continue
 * 		if node.bitset not in chart:
 */
  }

  /* "discodop/disambiguation.pyx":965
 * 		if not isinstance(node[0], Tree):
 * 			continue
 * 		if node.bitset not in chart:             # <<<<<<<<<<<<<<
 * 			chart[node.bitset] = {}
 * 		cell = chart[node.bitset]
 */
  __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_bitset); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 965, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  __pyx_t_2 = (__Pyx_PyDict_ContainsTF(__pyx_t_14, __pyx_v_chart, Py_NE)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 965, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  __pyx_t_10 = (__pyx_t_2 != 0);
  if (__pyx_t_10) {

    /* "discodop/disambiguation.pyx":966
 * 			continue
 * 		if node.bitset not in chart:
 * 			chart[node.bitset] = {}             # <<<<<<<<<<<<<<
 * 		cell = chart[node.bitset]
 * 		prod = coarse.rulenos[prodrepr(r, yf)]
 */
    __pyx_t_14 = PyDict_New(); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 966, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_bitset); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 966, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (unlikely(PyDict_SetItem(__pyx_v_chart, __pyx_t_7, __pyx_t_14) < 0)) __PYX_ERR(0, 966, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

    /* "discodop/disambiguation.pyx":965
 * 		if not isinstance(node[0], Tree):
 * 			continue
 * 		if node.bitset not in chart:             # <<<<<<<<<<<<<<
 * 			chart[node.bitset] = {}
 * 		cell = chart[node.bitset]
 */
  }

  /* "discodop/disambiguation.pyx":967
 * 		if node.bitset not in chart:
 * 			chart[node.bitset] = {}
 * 		cell = chart[node.bitset]             # <<<<<<<<<<<<<<
 * 		prod = coarse.rulenos[prodrepr(r, yf)]
 * 		if len(node) == 1:  # unary node
 */
  __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_v_node, __pyx_n_s_bitset); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 967, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_chart, __pyx_t_14); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 967, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
  if (!(likely(PyDict_CheckExact(__pyx_t_7))||((__pyx_t_7) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_t_7)->tp_name), 0))) __PYX_ERR(0, 967, __pyx_L1_error)
  __Pyx_XDECREF_SET(__pyx_v_cell, ((PyObject*)__pyx_t_7));
  __pyx_t_7 = 0;

  /* "discodop/disambiguation.pyx":968
 * 			chart[node.bitset] = {}
 * 		cell = chart[node.bitset]
 * 		prod = coarse.rulenos[prodrepr(r, yf)]             # <<<<<<<<<<<<<<
 * 		if len(node) == 1:  # unary node
 * 			for ruleno in fine.rulemapping[prod]:
 */
  if (unlikely(__pyx_v_coarse->rulenos == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
    __PYX_ERR(0, 968, __pyx_L1_error)
  }
  __pyx_t_7 = __pyx_f_8discodop_14disambiguation_prodrepr(__pyx_v_r, __pyx_v_yf); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 968, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
  __pyx_t_14 = __Pyx_PyDict_GetItem(__pyx_v_coarse->rulenos, __pyx_t_7); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 968, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  __Pyx_XDECREF_SET(__pyx_v_prod, __pyx_t_14);
  __pyx_t_14 = 0;

  /* "discodop/disambiguation.pyx":969
 * 		cell = chart[node.bitset]
 * 		prod = coarse.rulenos[prodrepr(r, yf)]
 * 		if len(node) == 1:  # unary node             # <<<<<<<<<<<<<<
 * 			for ruleno in fine.rulemapping[prod]:
 * 				rule = &(fine.bylhs[0][fine.revmap[ruleno]])
 */
  __pyx_t_11 = PyObject_Length(__pyx_v_node); if (unlikely(__pyx_t_11 == -1)) __PYX_ERR(0, 969, __pyx_L1_error)
  __pyx_t_10 = ((__pyx_t_11 == 1) != 0);
  if (__pyx_t_10) {

    /* "discodop/disambiguation.pyx":970
 * 		prod = coarse.rulenos[prodrepr(r, yf)]
 * 		if len(node) == 1:  # unary node
 * 			for ruleno in fine.rulemapping[prod]:             # <<<<<<<<<<<<<<
 * 				rule = &(fine.bylhs[0][fine.revmap[ruleno]])
 * 				if rule.rhs1 in cell:
 */
    if (unlikely(__pyx_v_fine->rulemapping == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 970, __pyx_L1_error)
    }
    __pyx_t_14 = PyObject_GetItem(__pyx_v_fine->rulemapping, __pyx_v_prod); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 970, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_14);
    if (likely(PyList_CheckExact(__pyx_t_14)) || PyTuple_CheckExact(__pyx_t_14)) {
      __pyx_t_7 = __pyx_t_14; __Pyx_INCREF(__pyx_t_7); __pyx_t_11 = 0;
      __pyx_t_6 = NULL;
    } else {
      __pyx_t_11 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_14); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 970, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_6 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 970, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
    for (;;) {
      if (likely(!__pyx_t_6)) {
        if (likely(PyList_CheckExact(__pyx_t_7))) {
          if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_7)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_14 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_11); __Pyx_INCREF(__pyx_t_14); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 970, __pyx_L1_error)
          #else
          __pyx_t_14 = PySequence_ITEM(__pyx_t_7, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 970, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_14);
          #endif
        } else {
          if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_7)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_14 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_11); __Pyx_INCREF(__pyx_t_14); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 970, __pyx_L1_error)
          #else
          __pyx_t_14 = PySequence_ITEM(__pyx_t_7, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 970, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_14);
          #endif
        }
      } else {
        __pyx_t_14 = __pyx_t_6(__pyx_t_7);
        if (unlikely(!__pyx_t_14)) {
          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, 970, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_14);
      }
      __Pyx_XDECREF_SET(__pyx_v_ruleno, __pyx_t_14);
      __pyx_t_14 = 0;

      /* "discodop/disambiguation.pyx":971
 * 		if len(node) == 1:  # unary node
 * 			for ruleno in fine.rulemapping[prod]:
 * 				rule = &(fine.bylhs[0][fine.revmap[ruleno]])             # <<<<<<<<<<<<<<
 * 				if rule.rhs1 in cell:
 * 					if rule.lhs in cell:
 */
      __pyx_t_16 = __Pyx_PyIndex_AsSsize_t(__pyx_v_ruleno); if (unlikely((__pyx_t_16 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 971, __pyx_L1_error)
      __pyx_v_rule = (&((__pyx_v_fine->bylhs[0])[(__pyx_v_fine->revmap[__pyx_t_16])]));

      /* "discodop/disambiguation.pyx":972
 * 			for ruleno in fine.rulemapping[prod]:
 * 				rule = &(fine.bylhs[0][fine.revmap[ruleno]])
 * 				if rule.rhs1 in cell:             # <<<<<<<<<<<<<<
 * 					if rule.lhs in cell:
 * 						cell[rule.lhs] = logprobadd(cell[rule.lhs],
 */
      __pyx_t_14 = __Pyx_PyInt_From_uint32_t(__pyx_v_rule->rhs1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 972, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_14);
      if (unlikely(__pyx_v_cell == Py_None)) {
        PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
        __PYX_ERR(0, 972, __pyx_L1_error)
      }
      __pyx_t_10 = (__Pyx_PyDict_ContainsTF(__pyx_t_14, __pyx_v_cell, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 972, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
      __pyx_t_2 = (__pyx_t_10 != 0);
      if (__pyx_t_2) {

        /* "discodop/disambiguation.pyx":973
 * 				rule = &(fine.bylhs[0][fine.revmap[ruleno]])
 * 				if rule.rhs1 in cell:
 * 					if rule.lhs in cell:             # <<<<<<<<<<<<<<
 * 						cell[rule.lhs] = logprobadd(cell[rule.lhs],
 * 								-rule.prob + cell[rule.rhs1])
 */
        __pyx_t_14 = __Pyx_PyInt_From_uint32_t(__pyx_v_rule->lhs); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 973, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_14);
        if (unlikely(__pyx_v_cell == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
          __PYX_ERR(0, 973, __pyx_L1_error)
        }
        __pyx_t_2 = (__Pyx_PyDict_ContainsTF(__pyx_t_14, __pyx_v_cell, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 973, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
        __pyx_t_10 = (__pyx_t_2 != 0);
        if (__pyx_t_10) {

          /* "discodop/disambiguation.pyx":974
 * 				if rule.rhs1 in cell:
 * 					if rule.lhs in cell:
 * 						cell[rule.lhs] = logprobadd(cell[rule.lhs],             # <<<<<<<<<<<<<<
 * 								-rule.prob + cell[rule.rhs1])
 * 					else:
 */
          if (unlikely(__pyx_v_cell == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 974, __pyx_L1_error)
          }
          __pyx_t_14 = __Pyx_PyInt_From_uint32_t(__pyx_v_rule->lhs); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 974, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_14);
          __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_cell, __pyx_t_14); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 974, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

          /* "discodop/disambiguation.pyx":975
 * 					if rule.lhs in cell:
 * 						cell[rule.lhs] = logprobadd(cell[rule.lhs],
 * 								-rule.prob + cell[rule.rhs1])             # <<<<<<<<<<<<<<
 * 					else:
 * 						cell[rule.lhs] = (-rule.prob + cell[rule.rhs1])
 */
          __pyx_t_14 = PyFloat_FromDouble((-__pyx_v_rule->prob)); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 975, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_14);
          if (unlikely(__pyx_v_cell == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 975, __pyx_L1_error)
          }
          __pyx_t_8 = __Pyx_PyInt_From_uint32_t(__pyx_v_rule->rhs1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 975, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_cell, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 975, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_8 = PyNumber_Add(__pyx_t_14, __pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 975, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

          /* "discodop/disambiguation.pyx":974
 * 				if rule.rhs1 in cell:
 * 					if rule.lhs in cell:
 * 						cell[rule.lhs] = logprobadd(cell[rule.lhs],             # <<<<<<<<<<<<<<
 * 								-rule.prob + cell[rule.rhs1])
 * 					else:
 */
          __pyx_t_4 = __pyx_f_8discodop_10containers_logprobadd(__pyx_t_3, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 974, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          if (unlikely(__pyx_v_cell == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 974, __pyx_L1_error)
          }
          __pyx_t_8 = __Pyx_PyInt_From_uint32_t(__pyx_v_rule->lhs); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 974, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          if (unlikely(PyDict_SetItem(__pyx_v_cell, __pyx_t_8, __pyx_t_4) < 0)) __PYX_ERR(0, 974, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

          /* "discodop/disambiguation.pyx":973
 * 				rule = &(fine.bylhs[0][fine.revmap[ruleno]])
 * 				if rule.rhs1 in cell:
 * 					if rule.lhs in cell:             # <<<<<<<<<<<<<<
 * 						cell[rule.lhs] = logprobadd(cell[rule.lhs],
 * 								-rule.prob + cell[rule.rhs1])
 */
          goto __pyx_L26;
        }

        /* "discodop/disambiguation.pyx":977
 * 								-rule.prob + cell[rule.rhs1])
 * 					else:
 * 						cell[rule.lhs] = (-rule.prob + cell[rule.rhs1])             # <<<<<<<<<<<<<<
 * 		elif len(node) == 2:  # binary node
 * 			leftcell = chart[node[0].bitset]
 */
        /*else*/ {
          __pyx_t_4 = PyFloat_FromDouble((-__pyx_v_rule->prob)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 977, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_4);
          if (unlikely(__pyx_v_cell == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 977, __pyx_L1_error)
          }
          __pyx_t_8 = __Pyx_PyInt_From_uint32_t(__pyx_v_rule->rhs1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 977, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_cell, __pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 977, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
          __pyx_t_8 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 977, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_8);
          __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          if (unlikely(__pyx_v_cell == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 977, __pyx_L1_error)
          }
          __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_rule->lhs); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 977, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          if (unlikely(PyDict_SetItem(__pyx_v_cell, __pyx_t_3, __pyx_t_8) < 0)) __PYX_ERR(0, 977, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
        }
        __pyx_L26:;

        /* "discodop/disambiguation.pyx":972
 * 			for ruleno in fine.rulemapping[prod]:
 * 				rule = &(fine.bylhs[0][fine.revmap[ruleno]])
 * 				if rule.rhs1 in cell:             # <<<<<<<<<<<<<<
 * 					if rule.lhs in cell:
 * 						cell[rule.lhs] = logprobadd(cell[rule.lhs],
 */
      }

      /* "discodop/disambiguation.pyx":970
 * 		prod = coarse.rulenos[prodrepr(r, yf)]
 * 		if len(node) == 1:  # unary node
 * 			for ruleno in fine.rulemapping[prod]:             # <<<<<<<<<<<<<<
 * 				rule = &(fine.bylhs[0][fine.revmap[ruleno]])
 * 				if rule.rhs1 in cell:
 */
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

    /* "discodop/disambiguation.pyx":969
 * 		cell = chart[node.bitset]
 * 		prod = coarse.rulenos[prodrepr(r, yf)]
 * 		if len(node) == 1:  # unary node             # <<<<<<<<<<<<<<
 * 			for ruleno in fine.rulemapping[prod]:
 * 				rule = &(fine.bylhs[0][fine.revmap[ruleno]])
 */
    goto __pyx_L22;
  }

  /* "discodop/disambiguation.pyx":978
 * 					else:
 * 						cell[rule.lhs] = (-rule.prob + cell[rule.rhs1])
 * 		elif len(node) == 2:  # binary node             # <<<<<<<<<<<<<<
 * 			leftcell = chart[node[0].bitset]
 * 			rightcell = chart[node[1].bitset]
 */
  __pyx_t_11 = PyObject_Length(__pyx_v_node); if (unlikely(__pyx_t_11 == -1)) __PYX_ERR(0, 978, __pyx_L1_error)
  __pyx_t_10 = ((__pyx_t_11 == 2) != 0);
  if (__pyx_t_10) {

    /* "discodop/disambiguation.pyx":979
 * 						cell[rule.lhs] = (-rule.prob + cell[rule.rhs1])
 * 		elif len(node) == 2:  # binary node
 * 			leftcell = chart[node[0].bitset]             # <<<<<<<<<<<<<<
 * 			rightcell = chart[node[1].bitset]
 * 			for ruleno in fine.rulemapping[prod]:
 */
    __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_node, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 979, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_bitset); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 979, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_chart, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 979, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_XDECREF_SET(__pyx_v_leftcell, __pyx_t_7);
    __pyx_t_7 = 0;

    /* "discodop/disambiguation.pyx":980
 * 		elif len(node) == 2:  # binary node
 * 			leftcell = chart[node[0].bitset]
 * 			rightcell = chart[node[1].bitset]             # <<<<<<<<<<<<<<
 * 			for ruleno in fine.rulemapping[prod]:
 * 				rule = &(fine.bylhs[0][fine.revmap[ruleno]])
 */
    __pyx_t_7 = __Pyx_GetItemInt(__pyx_v_node, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 980, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_bitset); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 980, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_chart, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 980, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_XDECREF_SET(__pyx_v_rightcell, __pyx_t_7);
    __pyx_t_7 = 0;

    /* "discodop/disambiguation.pyx":981
 * 			leftcell = chart[node[0].bitset]
 * 			rightcell = chart[node[1].bitset]
 * 			for ruleno in fine.rulemapping[prod]:             # <<<<<<<<<<<<<<
 * 				rule = &(fine.bylhs[0][fine.revmap[ruleno]])
 * 				if (rule.rhs1 in leftcell and rule.rhs2 in rightcell):
 */
    if (unlikely(__pyx_v_fine->rulemapping == Py_None)) {
      PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
      __PYX_ERR(0, 981, __pyx_L1_error)
    }
    __pyx_t_7 = PyObject_GetItem(__pyx_v_fine->rulemapping, __pyx_v_prod); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 981, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) {
      __pyx_t_8 = __pyx_t_7; __Pyx_INCREF(__pyx_t_8); __pyx_t_11 = 0;
      __pyx_t_6 = NULL;
    } else {
      __pyx_t_11 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 981, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_6 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 981, __pyx_L1_error)
    }
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
    for (;;) {
      if (likely(!__pyx_t_6)) {
        if (likely(PyList_CheckExact(__pyx_t_8))) {
          if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_8)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_7 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_11); __Pyx_INCREF(__pyx_t_7); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 981, __pyx_L1_error)
          #else
          __pyx_t_7 = PySequence_ITEM(__pyx_t_8, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 981, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          #endif
        } else {
          if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_11); __Pyx_INCREF(__pyx_t_7); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 981, __pyx_L1_error)
          #else
          __pyx_t_7 = PySequence_ITEM(__pyx_t_8, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 981, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          #endif
        }
      } else {
        __pyx_t_7 = __pyx_t_6(__pyx_t_8);
        if (unlikely(!__pyx_t_7)) {
          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, 981, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_7);
      }
      __Pyx_XDECREF_SET(__pyx_v_ruleno, __pyx_t_7);
      __pyx_t_7 = 0;

      /* "discodop/disambiguation.pyx":982
 * 			rightcell = chart[node[1].bitset]
 * 			for ruleno in fine.rulemapping[prod]:
 * 				rule = &(fine.bylhs[0][fine.revmap[ruleno]])             # <<<<<<<<<<<<<<
 * 				if (rule.rhs1 in leftcell and rule.rhs2 in rightcell):
 * 					newprob = (-rule.prob
 */
      __pyx_t_16 = __Pyx_PyIndex_AsSsize_t(__pyx_v_ruleno); if (unlikely((__pyx_t_16 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 982, __pyx_L1_error)
      __pyx_v_rule = (&((__pyx_v_fine->bylhs[0])[(__pyx_v_fine->revmap[__pyx_t_16])]));

      /* "discodop/disambiguation.pyx":983
 * 			for ruleno in fine.rulemapping[prod]:
 * 				rule = &(fine.bylhs[0][fine.revmap[ruleno]])
 * 				if (rule.rhs1 in leftcell and rule.rhs2 in rightcell):             # <<<<<<<<<<<<<<
 * 					newprob = (-rule.prob
 * 							+ leftcell[rule.rhs1] + rightcell[rule.rhs2])
 */
      __pyx_t_7 = __Pyx_PyInt_From_uint32_t(__pyx_v_rule->rhs1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 983, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_t_7, __pyx_v_leftcell, Py_EQ)); if (unlikely(__pyx_t_2 < 0)) __PYX_ERR(0, 983, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_17 = (__pyx_t_2 != 0);
      if (__pyx_t_17) {
      } else {
        __pyx_t_10 = __pyx_t_17;
        goto __pyx_L30_bool_binop_done;
      }
      __pyx_t_7 = __Pyx_PyInt_From_uint32_t(__pyx_v_rule->rhs2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 983, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __pyx_t_17 = (__Pyx_PySequence_ContainsTF(__pyx_t_7, __pyx_v_rightcell, Py_EQ)); if (unlikely(__pyx_t_17 < 0)) __PYX_ERR(0, 983, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_2 = (__pyx_t_17 != 0);
      __pyx_t_10 = __pyx_t_2;
      __pyx_L30_bool_binop_done:;
      if (__pyx_t_10) {

        /* "discodop/disambiguation.pyx":984
 * 				rule = &(fine.bylhs[0][fine.revmap[ruleno]])
 * 				if (rule.rhs1 in leftcell and rule.rhs2 in rightcell):
 * 					newprob = (-rule.prob             # <<<<<<<<<<<<<<
 * 							+ leftcell[rule.rhs1] + rightcell[rule.rhs2])
 * 					if rule.lhs in cell:
 */
        __pyx_t_7 = PyFloat_FromDouble((-__pyx_v_rule->prob)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 984, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);

        /* "discodop/disambiguation.pyx":985
 * 				if (rule.rhs1 in leftcell and rule.rhs2 in rightcell):
 * 					newprob = (-rule.prob
 * 							+ leftcell[rule.rhs1] + rightcell[rule.rhs2])             # <<<<<<<<<<<<<<
 * 					if rule.lhs in cell:
 * 						cell[rule.lhs] = logprobadd(cell[rule.lhs], newprob)
 */
        __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_leftcell, __pyx_v_rule->rhs1, uint32_t, 0, __Pyx_PyInt_From_uint32_t, 0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 985, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_4 = PyNumber_Add(__pyx_t_7, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 985, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_rightcell, __pyx_v_rule->rhs2, uint32_t, 0, __Pyx_PyInt_From_uint32_t, 0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 985, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_3);
        __pyx_t_7 = PyNumber_Add(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 985, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
        __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
        __Pyx_XDECREF_SET(__pyx_v_newprob, __pyx_t_7);
        __pyx_t_7 = 0;

        /* "discodop/disambiguation.pyx":986
 * 					newprob = (-rule.prob
 * 							+ leftcell[rule.rhs1] + rightcell[rule.rhs2])
 * 					if rule.lhs in cell:             # <<<<<<<<<<<<<<
 * 						cell[rule.lhs] = logprobadd(cell[rule.lhs], newprob)
 * 					else:
 */
        __pyx_t_7 = __Pyx_PyInt_From_uint32_t(__pyx_v_rule->lhs); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 986, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_7);
        if (unlikely(__pyx_v_cell == Py_None)) {
          PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
          __PYX_ERR(0, 986, __pyx_L1_error)
        }
        __pyx_t_10 = (__Pyx_PyDict_ContainsTF(__pyx_t_7, __pyx_v_cell, Py_EQ)); if (unlikely(__pyx_t_10 < 0)) __PYX_ERR(0, 986, __pyx_L1_error)
        __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        __pyx_t_2 = (__pyx_t_10 != 0);
        if (__pyx_t_2) {

          /* "discodop/disambiguation.pyx":987
 * 							+ leftcell[rule.rhs1] + rightcell[rule.rhs2])
 * 					if rule.lhs in cell:
 * 						cell[rule.lhs] = logprobadd(cell[rule.lhs], newprob)             # <<<<<<<<<<<<<<
 * 					else:
 * 						cell[rule.lhs] = newprob
 */
          if (unlikely(__pyx_v_cell == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 987, __pyx_L1_error)
          }
          __pyx_t_7 = __Pyx_PyInt_From_uint32_t(__pyx_v_rule->lhs); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 987, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_cell, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 987, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
          __pyx_t_7 = __pyx_f_8discodop_10containers_logprobadd(__pyx_t_3, __pyx_v_newprob); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 987, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          if (unlikely(__pyx_v_cell == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 987, __pyx_L1_error)
          }
          __pyx_t_3 = __Pyx_PyInt_From_uint32_t(__pyx_v_rule->lhs); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 987, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_3);
          if (unlikely(PyDict_SetItem(__pyx_v_cell, __pyx_t_3, __pyx_t_7) < 0)) __PYX_ERR(0, 987, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;

          /* "discodop/disambiguation.pyx":986
 * 					newprob = (-rule.prob
 * 							+ leftcell[rule.rhs1] + rightcell[rule.rhs2])
 * 					if rule.lhs in cell:             # <<<<<<<<<<<<<<
 * 						cell[rule.lhs] = logprobadd(cell[rule.lhs], newprob)
 * 					else:
 */
          goto __pyx_L32;
        }

        /* "discodop/disambiguation.pyx":989
 * 						cell[rule.lhs] = logprobadd(cell[rule.lhs], newprob)
 * 					else:
 * 						cell[rule.lhs] = newprob             # <<<<<<<<<<<<<<
 * 		else:
 * 			raise ValueError('expected binary tree without empty nodes.')
 */
        /*else*/ {
          if (unlikely(__pyx_v_cell == Py_None)) {
            PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
            __PYX_ERR(0, 989, __pyx_L1_error)
          }
          __pyx_t_7 = __Pyx_PyInt_From_uint32_t(__pyx_v_rule->lhs); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 989, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_7);
          if (unlikely(PyDict_SetItem(__pyx_v_cell, __pyx_t_7, __pyx_v_newprob) < 0)) __PYX_ERR(0, 989, __pyx_L1_error)
          __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
        }
        __pyx_L32:;

        /* "discodop/disambiguation.pyx":983
 * 			for ruleno in fine.rulemapping[prod]:
 * 				rule = &(fine.bylhs[0][fine.revmap[ruleno]])
 * 				if (rule.rhs1 in leftcell and rule.rhs2 in rightcell):             # <<<<<<<<<<<<<<
 * 					newprob = (-rule.prob
 * 							+ leftcell[rule.rhs1] + rightcell[rule.rhs2])
 */
      }

      /* "discodop/disambiguation.pyx":981
 * 			leftcell = chart[node[0].bitset]
 * 			rightcell = chart[node[1].bitset]
 * 			for ruleno in fine.rulemapping[prod]:             # <<<<<<<<<<<<<<
 * 				rule = &(fine.bylhs[0][fine.revmap[ruleno]])
 * 				if (rule.rhs1 in leftcell and rule.rhs2 in rightcell):
 */
    }
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "discodop/disambiguation.pyx":978
 * 					else:
 * 						cell[rule.lhs] = (-rule.prob + cell[rule.rhs1])
 * 		elif len(node) == 2:  # binary node             # <<<<<<<<<<<<<<
 * 			leftcell = chart[node[0].bitset]
 * 			rightcell = chart[node[1].bitset]
 */
    goto __pyx_L22;
  }

  /* "discodop/disambiguation.pyx":991
 * 						cell[rule.lhs] = newprob
 * 		else:
 * 			raise ValueError('expected binary tree without empty nodes.')             # <<<<<<<<<<<<<<
 * 	return chart[tree.bitset].get(fine.toid[tree.label], float('-inf'))
 * 
 */
  /*else*/ {
    __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__29, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 991, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_Raise(__pyx_t_8, 0, 0, 0);
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __PYX_ERR(0, 991, __pyx_L1_error)
  }
  __pyx_L22:;

  /* "discodop/disambiguation.pyx":961
 * 
 * 	# do post-order traversal (bottom-up)
 * 	for node, (r, yf) in list(zip(tree.subtrees(),             # <<<<<<<<<<<<<<
 * 			lcfrsproductions(tree, sent)))[::-1]:
 * 		if not isinstance(node[0], Tree):
 */
  __pyx_L14_continue:;
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":992
 * 		else:
 * 			raise ValueError('expected binary tree without empty nodes.')
 * 	return chart[tree.bitset].get(fine.toid[tree.label], float('-inf'))             # <<<<<<<<<<<<<<
 * 
 * 
 */
__Pyx_XDECREF(__pyx_r);
__pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_bitset); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 992, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_chart, __pyx_t_8); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 992, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
__pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_get); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 992, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
if (unlikely(__pyx_v_fine->toid == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
  __PYX_ERR(0, 992, __pyx_L1_error)
}
__pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_tree, __pyx_n_s_label); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 992, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_fine->toid, __pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 992, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_7 = __Pyx_PyNumber_Float(__pyx_kp_u_inf); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 992, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_4 = NULL;
__pyx_t_15 = 0;
if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_8))) {
  __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_8);
  if (likely(__pyx_t_4)) {
    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_INCREF(function);
    __Pyx_DECREF_SET(__pyx_t_8, function);
    __pyx_t_15 = 1;
  }
}
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_8)) {
  PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_t_3, __pyx_t_7};
  __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 992, __pyx_L1_error)
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
  PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_t_3, __pyx_t_7};
  __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-__pyx_t_15, 2+__pyx_t_15); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 992, __pyx_L1_error)
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
} else
#endif
{
  __pyx_t_14 = PyTuple_New(2+__pyx_t_15); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 992, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_14);
  if (__pyx_t_4) {
    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_4); __pyx_t_4 = NULL;
  }
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_14, 0+__pyx_t_15, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_7);
  PyTuple_SET_ITEM(__pyx_t_14, 1+__pyx_t_15, __pyx_t_7);
  __pyx_t_3 = 0;
  __pyx_t_7 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_14, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 992, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
}
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;

/* "discodop/disambiguation.pyx":914
 * 
 * 
 * def dopparseprob(tree, sent, Grammar coarse, Grammar fine):             # <<<<<<<<<<<<<<
 * 	"""Compute the exact DOP parse probability of a Tree in a DOP reduction.
 * 
 */

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_XDECREF(__pyx_t_13);
__Pyx_XDECREF(__pyx_t_14);
__Pyx_AddTraceback("discodop.disambiguation.dopparseprob", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_chart);
__Pyx_XDECREF(__pyx_v_cell);
__Pyx_XDECREF((PyObject *)__pyx_v_lexrule);
__Pyx_XDECREF(__pyx_v_n);
__Pyx_XDECREF(__pyx_v_pos);
__Pyx_XDECREF(__pyx_v_word);
__Pyx_XDECREF(__pyx_v_node);
__Pyx_XDECREF(__pyx_v_r);
__Pyx_XDECREF(__pyx_v_yf);
__Pyx_XDECREF(__pyx_v_prod);
__Pyx_XDECREF(__pyx_v_ruleno);
__Pyx_XDECREF(__pyx_v_leftcell);
__Pyx_XDECREF(__pyx_v_rightcell);
__Pyx_XDECREF(__pyx_v_newprob);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":995
 * 
 * 
 * def mcrerank(parsetrees, sent, k, trees, vocab):             # <<<<<<<<<<<<<<
 * 	"""Rerank *k*-best trees using tree fragments from training treebank.
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_8discodop_14disambiguation_25mcrerank(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_8discodop_14disambiguation_24mcrerank[] = "mcrerank(parsetrees, sent, k, trees, vocab)\nRerank *k*-best trees using tree fragments from training treebank.\n\n\tSearches for trees that share multiple fragments (multi component).";
static PyMethodDef __pyx_mdef_8discodop_14disambiguation_25mcrerank = {"mcrerank", (PyCFunction)__pyx_pw_8discodop_14disambiguation_25mcrerank, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8discodop_14disambiguation_24mcrerank};
static PyObject *__pyx_pw_8discodop_14disambiguation_25mcrerank(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
PyObject *__pyx_v_parsetrees = 0;
PyObject *__pyx_v_sent = 0;
PyObject *__pyx_v_k = 0;
PyObject *__pyx_v_trees = 0;
PyObject *__pyx_v_vocab = 0;
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("mcrerank (wrapper)", 0);
{
  static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_parsetrees,&__pyx_n_s_sent,&__pyx_n_s_k,&__pyx_n_s_trees,&__pyx_n_s_vocab,0};
  PyObject* values[5] = {0,0,0,0,0};
  if (unlikely(__pyx_kwds)) {
    Py_ssize_t kw_args;
    const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args);
    switch (pos_args) {
      case  5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
      case  4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
      case  3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
      case  2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
      case  1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
      case  0: break;
      default: goto __pyx_L5_argtuple_error;
    }
    kw_args = PyDict_Size(__pyx_kwds);
    switch (pos_args) {
      case  0:
      if (likely((values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_parsetrees)) != 0)) kw_args--;
      else goto __pyx_L5_argtuple_error;
      case  1:
      if (likely((values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_sent)) != 0)) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("mcrerank", 1, 5, 5, 1); __PYX_ERR(0, 995, __pyx_L3_error)
      }
      case  2:
      if (likely((values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_k)) != 0)) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("mcrerank", 1, 5, 5, 2); __PYX_ERR(0, 995, __pyx_L3_error)
      }
      case  3:
      if (likely((values[3] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_trees)) != 0)) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("mcrerank", 1, 5, 5, 3); __PYX_ERR(0, 995, __pyx_L3_error)
      }
      case  4:
      if (likely((values[4] = PyDict_GetItem(__pyx_kwds, __pyx_n_s_vocab)) != 0)) kw_args--;
      else {
        __Pyx_RaiseArgtupleInvalid("mcrerank", 1, 5, 5, 4); __PYX_ERR(0, 995, __pyx_L3_error)
      }
    }
    if (unlikely(kw_args > 0)) {
      if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "mcrerank") < 0)) __PYX_ERR(0, 995, __pyx_L3_error)
    }
  } else if (PyTuple_GET_SIZE(__pyx_args) != 5) {
    goto __pyx_L5_argtuple_error;
  } else {
    values[0] = PyTuple_GET_ITEM(__pyx_args, 0);
    values[1] = PyTuple_GET_ITEM(__pyx_args, 1);
    values[2] = PyTuple_GET_ITEM(__pyx_args, 2);
    values[3] = PyTuple_GET_ITEM(__pyx_args, 3);
    values[4] = PyTuple_GET_ITEM(__pyx_args, 4);
  }
  __pyx_v_parsetrees = values[0];
  __pyx_v_sent = values[1];
  __pyx_v_k = values[2];
  __pyx_v_trees = values[3];
  __pyx_v_vocab = values[4];
}
goto __pyx_L4_argument_unpacking_done;
__pyx_L5_argtuple_error:;
__Pyx_RaiseArgtupleInvalid("mcrerank", 1, 5, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 995, __pyx_L3_error)
__pyx_L3_error:;
__Pyx_AddTraceback("discodop.disambiguation.mcrerank", __pyx_clineno, __pyx_lineno, __pyx_filename);
__Pyx_RefNannyFinishContext();
return NULL;
__pyx_L4_argument_unpacking_done:;
__pyx_r = __pyx_pf_8discodop_14disambiguation_24mcrerank(__pyx_self, __pyx_v_parsetrees, __pyx_v_sent, __pyx_v_k, __pyx_v_trees, __pyx_v_vocab);

/* function exit code */
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
static PyObject *__pyx_gb_8discodop_14disambiguation_8mcrerank_2generator(__pyx_CoroutineObject *__pyx_generator, PyObject *__pyx_sent_value); /* proto */

/* "discodop/disambiguation.pyx":1021
 * 				# score is the total number of nodes
 * 				# of the common fragments consisting of at least 2 parts
 * 				score += sum(frag[0].count('(') for frag in rev[i])             # <<<<<<<<<<<<<<
 * 		# divide by number of nodes in derivation to avoid preferring
 * 		# larger derivations
 */

static PyObject *__pyx_pf_8discodop_14disambiguation_8mcrerank_genexpr(PyObject *__pyx_self) {
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_2_genexpr *__pyx_cur_scope;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("genexpr", 0);
__pyx_cur_scope = (struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_2_genexpr *)__pyx_tp_new_8discodop_14disambiguation___pyx_scope_struct_2_genexpr(__pyx_ptype_8discodop_14disambiguation___pyx_scope_struct_2_genexpr, __pyx_empty_tuple, NULL);
if (unlikely(!__pyx_cur_scope)) {
  __pyx_cur_scope = ((struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_2_genexpr *)Py_None);
  __Pyx_INCREF(Py_None);
  __PYX_ERR(0, 1021, __pyx_L1_error)
} else {
  __Pyx_GOTREF(__pyx_cur_scope);
}
__pyx_cur_scope->__pyx_outer_scope = (struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank *) __pyx_self;
__Pyx_INCREF(((PyObject *)__pyx_cur_scope->__pyx_outer_scope));
__Pyx_GIVEREF(__pyx_cur_scope->__pyx_outer_scope);
{
  __pyx_CoroutineObject *gen = __Pyx_Generator_New((__pyx_coroutine_body_t) __pyx_gb_8discodop_14disambiguation_8mcrerank_2generator, (PyObject *) __pyx_cur_scope, __pyx_n_s_genexpr, __pyx_n_s_mcrerank_locals_genexpr, __pyx_n_s_discodop_disambiguation); if (unlikely(!gen)) __PYX_ERR(0, 1021, __pyx_L1_error)
  __Pyx_DECREF(__pyx_cur_scope);
  __Pyx_RefNannyFinishContext();
  return (PyObject *) gen;
}

/* function exit code */
__pyx_L1_error:;
__Pyx_AddTraceback("discodop.disambiguation.mcrerank.genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__Pyx_DECREF(((PyObject *)__pyx_cur_scope));
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

static PyObject *__pyx_gb_8discodop_14disambiguation_8mcrerank_2generator(__pyx_CoroutineObject *__pyx_generator, PyObject *__pyx_sent_value) /* generator body */
{
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_2_genexpr *__pyx_cur_scope = ((struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_2_genexpr *)__pyx_generator->closure);
PyObject *__pyx_r = NULL;
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
Py_ssize_t __pyx_t_3;
PyObject *(*__pyx_t_4)(PyObject *);
PyObject *__pyx_t_5 = NULL;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("None", 0);
switch (__pyx_generator->resume_label) {
  case 0: goto __pyx_L3_first_run;
  case 1: goto __pyx_L6_resume_from_yield;
  default: /* CPython raises the right error here */
  __Pyx_RefNannyFinishContext();
  return NULL;
}
__pyx_L3_first_run:;
if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1021, __pyx_L1_error)
if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_rev)) { __Pyx_RaiseClosureNameError("rev"); __PYX_ERR(0, 1021, __pyx_L1_error) }
if (unlikely(!__pyx_cur_scope->__pyx_outer_scope->__pyx_v_i)) { __Pyx_RaiseClosureNameError("i"); __PYX_ERR(0, 1021, __pyx_L1_error) }
__pyx_t_1 = PyObject_GetItem(__pyx_cur_scope->__pyx_outer_scope->__pyx_v_rev, __pyx_cur_scope->__pyx_outer_scope->__pyx_v_i); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1021, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
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_3 = 0;
  __pyx_t_4 = NULL;
} else {
  __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1021, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1021, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
for (;;) {
  if (likely(!__pyx_t_4)) {
    if (likely(PyList_CheckExact(__pyx_t_2))) {
      if (__pyx_t_3 >= 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_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 1021, __pyx_L1_error)
      #else
      __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1021, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      #endif
    } else {
      if (__pyx_t_3 >= 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_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 1021, __pyx_L1_error)
      #else
      __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1021, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      #endif
    }
  } else {
    __pyx_t_1 = __pyx_t_4(__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, 1021, __pyx_L1_error)
      }
      break;
    }
    __Pyx_GOTREF(__pyx_t_1);
  }
  __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_frag);
  __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_frag, __pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_1);
  __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_frag, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1021, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_count); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1021, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__30, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1021, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  __Pyx_XGIVEREF(__pyx_t_2);
  __pyx_cur_scope->__pyx_t_0 = __pyx_t_2;
  __pyx_cur_scope->__pyx_t_1 = __pyx_t_3;
  __pyx_cur_scope->__pyx_t_2 = __pyx_t_4;
  __Pyx_XGIVEREF(__pyx_r);
  __Pyx_RefNannyFinishContext();
  /* return from generator, yielding value */
  __pyx_generator->resume_label = 1;
  return __pyx_r;
  __pyx_L6_resume_from_yield:;
  __pyx_t_2 = __pyx_cur_scope->__pyx_t_0;
  __pyx_cur_scope->__pyx_t_0 = 0;
  __Pyx_XGOTREF(__pyx_t_2);
  __pyx_t_3 = __pyx_cur_scope->__pyx_t_1;
  __pyx_t_4 = __pyx_cur_scope->__pyx_t_2;
  if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 1021, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope);

/* function exit code */
PyErr_SetNone(PyExc_StopIteration);
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_AddTraceback("genexpr", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_L0:;
__Pyx_XDECREF(__pyx_r); __pyx_r = 0;
__pyx_generator->resume_label = -1;
__Pyx_Coroutine_clear((PyObject*)__pyx_generator);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":1028
 * 	msg = 're-ranked %d parse trees; best tree at %d. ' % (
 * 			len(results),
 * 			max(range(len(results)), key=lambda x: results[x][1]) + 1)             # <<<<<<<<<<<<<<
 * 	return results, msg
 * 
 */

/* Python wrapper */
static PyObject *__pyx_pw_8discodop_14disambiguation_8mcrerank_3lambda2(PyObject *__pyx_self, PyObject *__pyx_v_x); /*proto*/
static PyMethodDef __pyx_mdef_8discodop_14disambiguation_8mcrerank_3lambda2 = {"lambda2", (PyCFunction)__pyx_pw_8discodop_14disambiguation_8mcrerank_3lambda2, METH_O, 0};
static PyObject *__pyx_pw_8discodop_14disambiguation_8mcrerank_3lambda2(PyObject *__pyx_self, PyObject *__pyx_v_x) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("lambda2 (wrapper)", 0);
__pyx_r = __pyx_lambda_funcdef_lambda2(__pyx_self, ((PyObject *)__pyx_v_x));

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

static PyObject *__pyx_lambda_funcdef_lambda2(PyObject *__pyx_self, PyObject *__pyx_v_x) {
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank *__pyx_cur_scope;
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank *__pyx_outer_scope;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
__Pyx_RefNannySetupContext("lambda2", 0);
__pyx_outer_scope = (struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank *) __Pyx_CyFunction_GetClosure(__pyx_self);
__pyx_cur_scope = __pyx_outer_scope;
__Pyx_XDECREF(__pyx_r);
if (unlikely(!__pyx_cur_scope->__pyx_v_results)) { __Pyx_RaiseClosureNameError("results"); __PYX_ERR(0, 1028, __pyx_L1_error) }
if (unlikely(__pyx_cur_scope->__pyx_v_results == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
  __PYX_ERR(0, 1028, __pyx_L1_error)
}
__pyx_t_1 = PyObject_GetItem(__pyx_cur_scope->__pyx_v_results, __pyx_v_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1028, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = __Pyx_GetItemInt(__pyx_t_1, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1028, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
goto __pyx_L0;

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_AddTraceback("discodop.disambiguation.mcrerank.lambda2", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":995
 * 
 * 
 * def mcrerank(parsetrees, sent, k, trees, vocab):             # <<<<<<<<<<<<<<
 * 	"""Rerank *k*-best trees using tree fragments from training treebank.
 * 
 */

static PyObject *__pyx_pf_8discodop_14disambiguation_24mcrerank(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_parsetrees, PyObject *__pyx_v_sent, PyObject *__pyx_v_k, PyObject *__pyx_v_trees, PyObject *__pyx_v_vocab) {
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank *__pyx_cur_scope;
PyObject *__pyx_v_derivstr = NULL;
PyObject *__pyx_v_prob = NULL;
CYTHON_UNUSED PyObject *__pyx_v__ = NULL;
PyObject *__pyx_v_tmp = NULL;
PyObject *__pyx_v_frags = NULL;
PyObject *__pyx_v_indices = NULL;
PyObject *__pyx_v_score = NULL;
CYTHON_UNUSED PyObject *__pyx_v_n = NULL;
PyObject *__pyx_v_frag = NULL;
PyObject *__pyx_v_idx = NULL;
PyObject *__pyx_v_msg = 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;
Py_ssize_t __pyx_t_6;
PyObject *(*__pyx_t_7)(PyObject *);
PyObject *__pyx_t_8 = NULL;
PyObject *(*__pyx_t_9)(PyObject *);
Py_ssize_t __pyx_t_10;
Py_ssize_t __pyx_t_11;
int __pyx_t_12;
int __pyx_t_13;
int __pyx_t_14;
PyObject *(*__pyx_t_15)(PyObject *);
PyObject *__pyx_t_16 = NULL;
PyObject *(*__pyx_t_17)(PyObject *);
PyObject *__pyx_t_18 = NULL;
int __pyx_t_19;
__Pyx_RefNannySetupContext("mcrerank", 0);
__pyx_cur_scope = (struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank *)__pyx_tp_new_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank(__pyx_ptype_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank, __pyx_empty_tuple, NULL);
if (unlikely(!__pyx_cur_scope)) {
  __pyx_cur_scope = ((struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank *)Py_None);
  __Pyx_INCREF(Py_None);
  __PYX_ERR(0, 995, __pyx_L1_error)
} else {
  __Pyx_GOTREF(__pyx_cur_scope);
}

/* "discodop/disambiguation.pyx":999
 * 
 * 	Searches for trees that share multiple fragments (multi component)."""
 * 	cdef list results = []             # <<<<<<<<<<<<<<
 * 	for derivstr, prob, _ in nlargest(k, parsetrees, key=itemgetter(1)):
 * 		tmp = _fragments.getctrees(
 */
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 999, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_GIVEREF(__pyx_t_1);
__pyx_cur_scope->__pyx_v_results = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":1000
 * 	Searches for trees that share multiple fragments (multi component)."""
 * 	cdef list results = []
 * 	for derivstr, prob, _ in nlargest(k, parsetrees, key=itemgetter(1)):             # <<<<<<<<<<<<<<
 * 		tmp = _fragments.getctrees(
 * 				[(addbitsets(derivstr), sent)], vocab=vocab)
 */
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_nlargest); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1000, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1000, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(__pyx_v_k);
__Pyx_GIVEREF(__pyx_v_k);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_k);
__Pyx_INCREF(__pyx_v_parsetrees);
__Pyx_GIVEREF(__pyx_v_parsetrees);
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_parsetrees);
__pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1000, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_itemgetter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1000, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__31, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1000, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_key, __pyx_t_5) < 0) __PYX_ERR(0, 1000, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1000, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__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_5)) || PyTuple_CheckExact(__pyx_t_5)) {
  __pyx_t_3 = __pyx_t_5; __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = 0;
  __pyx_t_7 = NULL;
} else {
  __pyx_t_6 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1000, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_7 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1000, __pyx_L1_error)
}
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
for (;;) {
  if (likely(!__pyx_t_7)) {
    if (likely(PyList_CheckExact(__pyx_t_3))) {
      if (__pyx_t_6 >= 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_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1000, __pyx_L1_error)
      #else
      __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1000, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      #endif
    } else {
      if (__pyx_t_6 >= 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_6); __Pyx_INCREF(__pyx_t_5); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(0, 1000, __pyx_L1_error)
      #else
      __pyx_t_5 = PySequence_ITEM(__pyx_t_3, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1000, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      #endif
    }
  } else {
    __pyx_t_5 = __pyx_t_7(__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, 1000, __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 != 3)) {
      if (size > 3) __Pyx_RaiseTooManyValuesError(3);
      else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
      __PYX_ERR(0, 1000, __pyx_L1_error)
    }
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    if (likely(PyTuple_CheckExact(sequence))) {
      __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
      __pyx_t_4 = PyTuple_GET_ITEM(sequence, 2); 
    } else {
      __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
      __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
      __pyx_t_4 = PyList_GET_ITEM(sequence, 2); 
    }
    __Pyx_INCREF(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_1);
    __Pyx_INCREF(__pyx_t_4);
    #else
    __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1000, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1000, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_4 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1000, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    #endif
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  } else {
    Py_ssize_t index = -1;
    __pyx_t_8 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1000, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_9 = Py_TYPE(__pyx_t_8)->tp_iternext;
    index = 0; __pyx_t_2 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_2)) goto __pyx_L5_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_2);
    index = 1; __pyx_t_1 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_1)) goto __pyx_L5_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_1);
    index = 2; __pyx_t_4 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_4)) goto __pyx_L5_unpacking_failed;
    __Pyx_GOTREF(__pyx_t_4);
    if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 3) < 0) __PYX_ERR(0, 1000, __pyx_L1_error)
    __pyx_t_9 = NULL;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    goto __pyx_L6_unpacking_done;
    __pyx_L5_unpacking_failed:;
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __pyx_t_9 = NULL;
    if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
    __PYX_ERR(0, 1000, __pyx_L1_error)
    __pyx_L6_unpacking_done:;
  }
  __Pyx_XDECREF_SET(__pyx_v_derivstr, __pyx_t_2);
  __pyx_t_2 = 0;
  __Pyx_XDECREF_SET(__pyx_v_prob, __pyx_t_1);
  __pyx_t_1 = 0;
  __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_4);
  __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":1001
 * 	cdef list results = []
 * 	for derivstr, prob, _ in nlargest(k, parsetrees, key=itemgetter(1)):
 * 		tmp = _fragments.getctrees(             # <<<<<<<<<<<<<<
 * 				[(addbitsets(derivstr), sent)], vocab=vocab)
 * 		frags = _fragments.extractfragments(
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_fragments); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1001, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_getctrees); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1001, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "discodop/disambiguation.pyx":1002
 * 	for derivstr, prob, _ in nlargest(k, parsetrees, key=itemgetter(1)):
 * 		tmp = _fragments.getctrees(
 * 				[(addbitsets(derivstr), sent)], vocab=vocab)             # <<<<<<<<<<<<<<
 * 		frags = _fragments.extractfragments(
 * 				tmp['trees1'], 0, 0, vocab, trees,
 */
  __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_addbitsets); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1002, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(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_5 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_derivstr); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1002, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_derivstr};
      __pyx_t_5 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1002, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_5);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
      PyObject *__pyx_temp[2] = {__pyx_t_2, __pyx_v_derivstr};
      __pyx_t_5 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1002, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
      __Pyx_GOTREF(__pyx_t_5);
    } else
    #endif
    {
      __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1002, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2); __pyx_t_2 = NULL;
      __Pyx_INCREF(__pyx_v_derivstr);
      __Pyx_GIVEREF(__pyx_v_derivstr);
      PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_v_derivstr);
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_8, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1002, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1002, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __Pyx_INCREF(__pyx_v_sent);
  __Pyx_GIVEREF(__pyx_v_sent);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_sent);
  __pyx_t_5 = 0;
  __pyx_t_5 = PyList_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1002, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_GIVEREF(__pyx_t_1);
  PyList_SET_ITEM(__pyx_t_5, 0, __pyx_t_1);
  __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":1001
 * 	cdef list results = []
 * 	for derivstr, prob, _ in nlargest(k, parsetrees, key=itemgetter(1)):
 * 		tmp = _fragments.getctrees(             # <<<<<<<<<<<<<<
 * 				[(addbitsets(derivstr), sent)], vocab=vocab)
 * 		frags = _fragments.extractfragments(
 */
  __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1001, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5);
  __pyx_t_5 = 0;

  /* "discodop/disambiguation.pyx":1002
 * 	for derivstr, prob, _ in nlargest(k, parsetrees, key=itemgetter(1)):
 * 		tmp = _fragments.getctrees(
 * 				[(addbitsets(derivstr), sent)], vocab=vocab)             # <<<<<<<<<<<<<<
 * 		frags = _fragments.extractfragments(
 * 				tmp['trees1'], 0, 0, vocab, trees,
 */
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1002, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_vocab, __pyx_v_vocab) < 0) __PYX_ERR(0, 1002, __pyx_L1_error)

  /* "discodop/disambiguation.pyx":1001
 * 	cdef list results = []
 * 	for derivstr, prob, _ in nlargest(k, parsetrees, key=itemgetter(1)):
 * 		tmp = _fragments.getctrees(             # <<<<<<<<<<<<<<
 * 				[(addbitsets(derivstr), sent)], vocab=vocab)
 * 		frags = _fragments.extractfragments(
 */
  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1001, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_XDECREF_SET(__pyx_v_tmp, __pyx_t_8);
  __pyx_t_8 = 0;

  /* "discodop/disambiguation.pyx":1003
 * 		tmp = _fragments.getctrees(
 * 				[(addbitsets(derivstr), sent)], vocab=vocab)
 * 		frags = _fragments.extractfragments(             # <<<<<<<<<<<<<<
 * 				tmp['trees1'], 0, 0, vocab, trees,
 * 				disc=True, approx=False)
 */
  __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_fragments); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1003, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_extractfragments); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1003, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

  /* "discodop/disambiguation.pyx":1004
 * 				[(addbitsets(derivstr), sent)], vocab=vocab)
 * 		frags = _fragments.extractfragments(
 * 				tmp['trees1'], 0, 0, vocab, trees,             # <<<<<<<<<<<<<<
 * 				disc=True, approx=False)
 * 		frags = {frag: bitset for frag, bitset in frags.items()
 */
  __pyx_t_8 = PyObject_GetItem(__pyx_v_tmp, __pyx_n_u_trees1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1004, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);

  /* "discodop/disambiguation.pyx":1003
 * 		tmp = _fragments.getctrees(
 * 				[(addbitsets(derivstr), sent)], vocab=vocab)
 * 		frags = _fragments.extractfragments(             # <<<<<<<<<<<<<<
 * 				tmp['trees1'], 0, 0, vocab, trees,
 * 				disc=True, approx=False)
 */
  __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1003, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_0);
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_GIVEREF(__pyx_int_0);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_int_0);
  __Pyx_INCREF(__pyx_v_vocab);
  __Pyx_GIVEREF(__pyx_v_vocab);
  PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_vocab);
  __Pyx_INCREF(__pyx_v_trees);
  __Pyx_GIVEREF(__pyx_v_trees);
  PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_v_trees);
  __pyx_t_8 = 0;

  /* "discodop/disambiguation.pyx":1005
 * 		frags = _fragments.extractfragments(
 * 				tmp['trees1'], 0, 0, vocab, trees,
 * 				disc=True, approx=False)             # <<<<<<<<<<<<<<
 * 		frags = {frag: bitset for frag, bitset in frags.items()
 * 				if frag[0].count('(') > 3}
 */
  __pyx_t_8 = PyDict_New(); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1005, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_disc, Py_True) < 0) __PYX_ERR(0, 1005, __pyx_L1_error)
  if (PyDict_SetItem(__pyx_t_8, __pyx_n_s_approx, Py_False) < 0) __PYX_ERR(0, 1005, __pyx_L1_error)

  /* "discodop/disambiguation.pyx":1003
 * 		tmp = _fragments.getctrees(
 * 				[(addbitsets(derivstr), sent)], vocab=vocab)
 * 		frags = _fragments.extractfragments(             # <<<<<<<<<<<<<<
 * 				tmp['trees1'], 0, 0, vocab, trees,
 * 				disc=True, approx=False)
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1003, __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_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_XDECREF_SET(__pyx_v_frags, __pyx_t_4);
  __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":1006
 * 				tmp['trees1'], 0, 0, vocab, trees,
 * 				disc=True, approx=False)
 * 		frags = {frag: bitset for frag, bitset in frags.items()             # <<<<<<<<<<<<<<
 * 				if frag[0].count('(') > 3}
 * 		indices = _fragments.exactcounts(
 */
  { /* enter inner scope */
    PyObject *__pyx_9genexpr25__pyx_v_frag = NULL;
    PyObject *__pyx_9genexpr25__pyx_v_bitset = NULL;
    __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1006, __pyx_L9_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_10 = 0;
    if (unlikely(__pyx_v_frags == Py_None)) {
      PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%s'", "items");
      __PYX_ERR(0, 1006, __pyx_L9_error)
    }
    __pyx_t_1 = __Pyx_dict_iterator(__pyx_v_frags, 0, __pyx_n_s_items, (&__pyx_t_11), (&__pyx_t_12)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1006, __pyx_L9_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_XDECREF(__pyx_t_8);
    __pyx_t_8 = __pyx_t_1;
    __pyx_t_1 = 0;
    while (1) {
      __pyx_t_13 = __Pyx_dict_iter_next(__pyx_t_8, __pyx_t_11, &__pyx_t_10, &__pyx_t_1, &__pyx_t_5, NULL, __pyx_t_12);
      if (unlikely(__pyx_t_13 == 0)) break;
      if (unlikely(__pyx_t_13 == -1)) __PYX_ERR(0, 1006, __pyx_L9_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_XDECREF_SET(__pyx_9genexpr25__pyx_v_frag, __pyx_t_1);
      __pyx_t_1 = 0;
      __Pyx_XDECREF_SET(__pyx_9genexpr25__pyx_v_bitset, __pyx_t_5);
      __pyx_t_5 = 0;

      /* "discodop/disambiguation.pyx":1007
 * 				disc=True, approx=False)
 * 		frags = {frag: bitset for frag, bitset in frags.items()
 * 				if frag[0].count('(') > 3}             # <<<<<<<<<<<<<<
 * 		indices = _fragments.exactcounts(
 * 				tmp['trees1'], trees, list(frags.values()), indices=True)
 */
      __pyx_t_5 = __Pyx_GetItemInt(__pyx_9genexpr25__pyx_v_frag, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1007, __pyx_L9_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_count); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1007, __pyx_L9_error)
      __Pyx_GOTREF(__pyx_t_1);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__32, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1007, __pyx_L9_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = PyObject_RichCompare(__pyx_t_5, __pyx_int_3, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1007, __pyx_L9_error)
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_14 < 0)) __PYX_ERR(0, 1007, __pyx_L9_error)
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      if (__pyx_t_14) {

        /* "discodop/disambiguation.pyx":1006
 * 				tmp['trees1'], 0, 0, vocab, trees,
 * 				disc=True, approx=False)
 * 		frags = {frag: bitset for frag, bitset in frags.items()             # <<<<<<<<<<<<<<
 * 				if frag[0].count('(') > 3}
 * 		indices = _fragments.exactcounts(
 */
        if (unlikely(PyDict_SetItem(__pyx_t_4, (PyObject*)__pyx_9genexpr25__pyx_v_frag, (PyObject*)__pyx_9genexpr25__pyx_v_bitset))) __PYX_ERR(0, 1006, __pyx_L9_error)

        /* "discodop/disambiguation.pyx":1007
 * 				disc=True, approx=False)
 * 		frags = {frag: bitset for frag, bitset in frags.items()
 * 				if frag[0].count('(') > 3}             # <<<<<<<<<<<<<<
 * 		indices = _fragments.exactcounts(
 * 				tmp['trees1'], trees, list(frags.values()), indices=True)
 */
      }
    }
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    __Pyx_XDECREF(__pyx_9genexpr25__pyx_v_frag);
    __Pyx_XDECREF(__pyx_9genexpr25__pyx_v_bitset);
    goto __pyx_L13_exit_scope;
    __pyx_L9_error:;
    __Pyx_XDECREF(__pyx_9genexpr25__pyx_v_frag);
    __Pyx_XDECREF(__pyx_9genexpr25__pyx_v_bitset);
    goto __pyx_L1_error;
    __pyx_L13_exit_scope:;
  } /* exit inner scope */
  __Pyx_DECREF_SET(__pyx_v_frags, __pyx_t_4);
  __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":1008
 * 		frags = {frag: bitset for frag, bitset in frags.items()
 * 				if frag[0].count('(') > 3}
 * 		indices = _fragments.exactcounts(             # <<<<<<<<<<<<<<
 * 				tmp['trees1'], trees, list(frags.values()), indices=True)
 * 		score = 0
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_fragments); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1008, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_exactcounts); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1008, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":1009
 * 				if frag[0].count('(') > 3}
 * 		indices = _fragments.exactcounts(
 * 				tmp['trees1'], trees, list(frags.values()), indices=True)             # <<<<<<<<<<<<<<
 * 		score = 0
 * 		rev = defaultdict(set)
 */
  __pyx_t_4 = PyObject_GetItem(__pyx_v_tmp, __pyx_n_u_trees1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1009, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_frags, __pyx_n_s_values); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1009, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_2 = NULL;
  if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_2)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_2);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  if (__pyx_t_2) {
    __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1009, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else {
    __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1009, __pyx_L1_error)
  }
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1009, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

  /* "discodop/disambiguation.pyx":1008
 * 		frags = {frag: bitset for frag, bitset in frags.items()
 * 				if frag[0].count('(') > 3}
 * 		indices = _fragments.exactcounts(             # <<<<<<<<<<<<<<
 * 				tmp['trees1'], trees, list(frags.values()), indices=True)
 * 		score = 0
 */
  __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1008, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_GIVEREF(__pyx_t_4);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_4);
  __Pyx_INCREF(__pyx_v_trees);
  __Pyx_GIVEREF(__pyx_v_trees);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_trees);
  __Pyx_GIVEREF(__pyx_t_5);
  PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_5);
  __pyx_t_4 = 0;
  __pyx_t_5 = 0;

  /* "discodop/disambiguation.pyx":1009
 * 				if frag[0].count('(') > 3}
 * 		indices = _fragments.exactcounts(
 * 				tmp['trees1'], trees, list(frags.values()), indices=True)             # <<<<<<<<<<<<<<
 * 		score = 0
 * 		rev = defaultdict(set)
 */
  __pyx_t_5 = PyDict_New(); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1009, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_indices, Py_True) < 0) __PYX_ERR(0, 1009, __pyx_L1_error)

  /* "discodop/disambiguation.pyx":1008
 * 		frags = {frag: bitset for frag, bitset in frags.items()
 * 				if frag[0].count('(') > 3}
 * 		indices = _fragments.exactcounts(             # <<<<<<<<<<<<<<
 * 				tmp['trees1'], trees, list(frags.values()), indices=True)
 * 		score = 0
 */
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_1, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1008, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_XDECREF_SET(__pyx_v_indices, __pyx_t_4);
  __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":1010
 * 		indices = _fragments.exactcounts(
 * 				tmp['trees1'], trees, list(frags.values()), indices=True)
 * 		score = 0             # <<<<<<<<<<<<<<
 * 		rev = defaultdict(set)
 * 		for n, (frag, idx) in enumerate(zip(frags, indices)):
 */
  __Pyx_INCREF(__pyx_int_0);
  __Pyx_XDECREF_SET(__pyx_v_score, __pyx_int_0);

  /* "discodop/disambiguation.pyx":1011
 * 				tmp['trees1'], trees, list(frags.values()), indices=True)
 * 		score = 0
 * 		rev = defaultdict(set)             # <<<<<<<<<<<<<<
 * 		for n, (frag, idx) in enumerate(zip(frags, indices)):
 * 			# from: frag => (tree idx, freq)...
 */
  __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_defaultdict); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1011, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __pyx_t_1 = NULL;
  if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_5))) {
    __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_5);
    if (likely(__pyx_t_1)) {
      PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5);
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(function);
      __Pyx_DECREF_SET(__pyx_t_5, function);
    }
  }
  if (!__pyx_t_1) {
    __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_5, ((PyObject *)(&PySet_Type))); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1011, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
  } else {
    #if CYTHON_FAST_PYCALL
    if (PyFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[2] = {__pyx_t_1, ((PyObject *)(&PySet_Type))};
      __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1011, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_4);
    } else
    #endif
    #if CYTHON_FAST_PYCCALL
    if (__Pyx_PyFastCFunction_Check(__pyx_t_5)) {
      PyObject *__pyx_temp[2] = {__pyx_t_1, ((PyObject *)(&PySet_Type))};
      __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_5, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1011, __pyx_L1_error)
      __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
      __Pyx_GOTREF(__pyx_t_4);
    } else
    #endif
    {
      __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1011, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_1); __pyx_t_1 = NULL;
      __Pyx_INCREF(((PyObject *)(&PySet_Type)));
      __Pyx_GIVEREF(((PyObject *)(&PySet_Type)));
      PyTuple_SET_ITEM(__pyx_t_8, 0+1, ((PyObject *)(&PySet_Type)));
      __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_t_8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1011, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_4);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    }
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_rev);
  __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_rev, __pyx_t_4);
  __Pyx_GIVEREF(__pyx_t_4);
  __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":1012
 * 		score = 0
 * 		rev = defaultdict(set)
 * 		for n, (frag, idx) in enumerate(zip(frags, indices)):             # <<<<<<<<<<<<<<
 * 			# from: frag => (tree idx, freq)...
 * 			# to: tree idx => frags...
 */
  __Pyx_INCREF(__pyx_int_0);
  __pyx_t_4 = __pyx_int_0;
  __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1012, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_v_frags);
  __Pyx_GIVEREF(__pyx_v_frags);
  PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_frags);
  __Pyx_INCREF(__pyx_v_indices);
  __Pyx_GIVEREF(__pyx_v_indices);
  PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_indices);
  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_zip, __pyx_t_5, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1012, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (likely(PyList_CheckExact(__pyx_t_8)) || PyTuple_CheckExact(__pyx_t_8)) {
    __pyx_t_5 = __pyx_t_8; __Pyx_INCREF(__pyx_t_5); __pyx_t_11 = 0;
    __pyx_t_15 = NULL;
  } else {
    __pyx_t_11 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1012, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_15 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1012, __pyx_L1_error)
  }
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  for (;;) {
    if (likely(!__pyx_t_15)) {
      if (likely(PyList_CheckExact(__pyx_t_5))) {
        if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_8 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_11); __Pyx_INCREF(__pyx_t_8); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 1012, __pyx_L1_error)
        #else
        __pyx_t_8 = PySequence_ITEM(__pyx_t_5, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1012, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        #endif
      } else {
        if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_8 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_11); __Pyx_INCREF(__pyx_t_8); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 1012, __pyx_L1_error)
        #else
        __pyx_t_8 = PySequence_ITEM(__pyx_t_5, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1012, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_8);
        #endif
      }
    } else {
      __pyx_t_8 = __pyx_t_15(__pyx_t_5);
      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, 1012, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_8);
    }
    if ((likely(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) {
      PyObject* sequence = __pyx_t_8;
      #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, 1012, __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_2 = PyTuple_GET_ITEM(sequence, 1); 
      } else {
        __pyx_t_1 = PyList_GET_ITEM(sequence, 0); 
        __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
      }
      __Pyx_INCREF(__pyx_t_1);
      __Pyx_INCREF(__pyx_t_2);
      #else
      __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1012, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1012, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_2);
      #endif
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    } else {
      Py_ssize_t index = -1;
      __pyx_t_16 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1012, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_9 = Py_TYPE(__pyx_t_16)->tp_iternext;
      index = 0; __pyx_t_1 = __pyx_t_9(__pyx_t_16); if (unlikely(!__pyx_t_1)) goto __pyx_L16_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_1);
      index = 1; __pyx_t_2 = __pyx_t_9(__pyx_t_16); if (unlikely(!__pyx_t_2)) goto __pyx_L16_unpacking_failed;
      __Pyx_GOTREF(__pyx_t_2);
      if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_16), 2) < 0) __PYX_ERR(0, 1012, __pyx_L1_error)
      __pyx_t_9 = NULL;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      goto __pyx_L17_unpacking_done;
      __pyx_L16_unpacking_failed:;
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __pyx_t_9 = NULL;
      if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
      __PYX_ERR(0, 1012, __pyx_L1_error)
      __pyx_L17_unpacking_done:;
    }
    __Pyx_XDECREF_SET(__pyx_v_frag, __pyx_t_1);
    __pyx_t_1 = 0;
    __Pyx_XDECREF_SET(__pyx_v_idx, __pyx_t_2);
    __pyx_t_2 = 0;
    __Pyx_INCREF(__pyx_t_4);
    __Pyx_XDECREF_SET(__pyx_v_n, __pyx_t_4);
    __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_t_4, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1012, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_8);
    __Pyx_DECREF(__pyx_t_4);
    __pyx_t_4 = __pyx_t_8;
    __pyx_t_8 = 0;

    /* "discodop/disambiguation.pyx":1015
 * 			# from: frag => (tree idx, freq)...
 * 			# to: tree idx => frags...
 * 			for i in idx:             # <<<<<<<<<<<<<<
 * 				rev[i].add(frag)
 * 		for i in rev:
 */
    if (likely(PyList_CheckExact(__pyx_v_idx)) || PyTuple_CheckExact(__pyx_v_idx)) {
      __pyx_t_8 = __pyx_v_idx; __Pyx_INCREF(__pyx_t_8); __pyx_t_10 = 0;
      __pyx_t_17 = NULL;
    } else {
      __pyx_t_10 = -1; __pyx_t_8 = PyObject_GetIter(__pyx_v_idx); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1015, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __pyx_t_17 = Py_TYPE(__pyx_t_8)->tp_iternext; if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 1015, __pyx_L1_error)
    }
    for (;;) {
      if (likely(!__pyx_t_17)) {
        if (likely(PyList_CheckExact(__pyx_t_8))) {
          if (__pyx_t_10 >= PyList_GET_SIZE(__pyx_t_8)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyList_GET_ITEM(__pyx_t_8, __pyx_t_10); __Pyx_INCREF(__pyx_t_2); __pyx_t_10++; if (unlikely(0 < 0)) __PYX_ERR(0, 1015, __pyx_L1_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_8, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1015, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        } else {
          if (__pyx_t_10 >= PyTuple_GET_SIZE(__pyx_t_8)) break;
          #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
          __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_8, __pyx_t_10); __Pyx_INCREF(__pyx_t_2); __pyx_t_10++; if (unlikely(0 < 0)) __PYX_ERR(0, 1015, __pyx_L1_error)
          #else
          __pyx_t_2 = PySequence_ITEM(__pyx_t_8, __pyx_t_10); __pyx_t_10++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1015, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          #endif
        }
      } else {
        __pyx_t_2 = __pyx_t_17(__pyx_t_8);
        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, 1015, __pyx_L1_error)
          }
          break;
        }
        __Pyx_GOTREF(__pyx_t_2);
      }
      __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_i);
      __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_i, __pyx_t_2);
      __Pyx_GIVEREF(__pyx_t_2);
      __pyx_t_2 = 0;

      /* "discodop/disambiguation.pyx":1016
 * 			# to: tree idx => frags...
 * 			for i in idx:
 * 				rev[i].add(frag)             # <<<<<<<<<<<<<<
 * 		for i in rev:
 * 			if len(rev[i]) > 1:
 */
      __pyx_t_1 = PyObject_GetItem(__pyx_cur_scope->__pyx_v_rev, __pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1016, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_1);
      __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_add); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 1016, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_16);
      __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
      __pyx_t_1 = NULL;
      if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_16))) {
        __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_16);
        if (likely(__pyx_t_1)) {
          PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16);
          __Pyx_INCREF(__pyx_t_1);
          __Pyx_INCREF(function);
          __Pyx_DECREF_SET(__pyx_t_16, function);
        }
      }
      if (!__pyx_t_1) {
        __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_t_16, __pyx_v_frag); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1016, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_2);
      } else {
        #if CYTHON_FAST_PYCALL
        if (PyFunction_Check(__pyx_t_16)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_frag};
          __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_16, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1016, __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_16)) {
          PyObject *__pyx_temp[2] = {__pyx_t_1, __pyx_v_frag};
          __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_16, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1016, __pyx_L1_error)
          __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0;
          __Pyx_GOTREF(__pyx_t_2);
        } else
        #endif
        {
          __pyx_t_18 = PyTuple_New(1+1); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 1016, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_18);
          __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_18, 0, __pyx_t_1); __pyx_t_1 = NULL;
          __Pyx_INCREF(__pyx_v_frag);
          __Pyx_GIVEREF(__pyx_v_frag);
          PyTuple_SET_ITEM(__pyx_t_18, 0+1, __pyx_v_frag);
          __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_16, __pyx_t_18, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1016, __pyx_L1_error)
          __Pyx_GOTREF(__pyx_t_2);
          __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0;
        }
      }
      __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0;
      __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

      /* "discodop/disambiguation.pyx":1015
 * 			# from: frag => (tree idx, freq)...
 * 			# to: tree idx => frags...
 * 			for i in idx:             # <<<<<<<<<<<<<<
 * 				rev[i].add(frag)
 * 		for i in rev:
 */
    }
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;

    /* "discodop/disambiguation.pyx":1012
 * 		score = 0
 * 		rev = defaultdict(set)
 * 		for n, (frag, idx) in enumerate(zip(frags, indices)):             # <<<<<<<<<<<<<<
 * 			# from: frag => (tree idx, freq)...
 * 			# to: tree idx => frags...
 */
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":1017
 * 			for i in idx:
 * 				rev[i].add(frag)
 * 		for i in rev:             # <<<<<<<<<<<<<<
 * 			if len(rev[i]) > 1:
 * 				# score is the total number of nodes
 */
  if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_v_rev)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_rev)) {
    __pyx_t_4 = __pyx_cur_scope->__pyx_v_rev; __Pyx_INCREF(__pyx_t_4); __pyx_t_11 = 0;
    __pyx_t_15 = NULL;
  } else {
    __pyx_t_11 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_rev); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1017, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __pyx_t_15 = Py_TYPE(__pyx_t_4)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1017, __pyx_L1_error)
  }
  for (;;) {
    if (likely(!__pyx_t_15)) {
      if (likely(PyList_CheckExact(__pyx_t_4))) {
        if (__pyx_t_11 >= PyList_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_11); __Pyx_INCREF(__pyx_t_5); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 1017, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1017, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      } else {
        if (__pyx_t_11 >= PyTuple_GET_SIZE(__pyx_t_4)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_11); __Pyx_INCREF(__pyx_t_5); __pyx_t_11++; if (unlikely(0 < 0)) __PYX_ERR(0, 1017, __pyx_L1_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_4, __pyx_t_11); __pyx_t_11++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1017, __pyx_L1_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      }
    } else {
      __pyx_t_5 = __pyx_t_15(__pyx_t_4);
      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, 1017, __pyx_L1_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_5);
    }
    __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_i);
    __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_i, __pyx_t_5);
    __Pyx_GIVEREF(__pyx_t_5);
    __pyx_t_5 = 0;

    /* "discodop/disambiguation.pyx":1018
 * 				rev[i].add(frag)
 * 		for i in rev:
 * 			if len(rev[i]) > 1:             # <<<<<<<<<<<<<<
 * 				# score is the total number of nodes
 * 				# of the common fragments consisting of at least 2 parts
 */
    __pyx_t_5 = PyObject_GetItem(__pyx_cur_scope->__pyx_v_rev, __pyx_cur_scope->__pyx_v_i); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1018, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_10 = PyObject_Length(__pyx_t_5); if (unlikely(__pyx_t_10 == -1)) __PYX_ERR(0, 1018, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_14 = ((__pyx_t_10 > 1) != 0);
    if (__pyx_t_14) {

      /* "discodop/disambiguation.pyx":1021
 * 				# score is the total number of nodes
 * 				# of the common fragments consisting of at least 2 parts
 * 				score += sum(frag[0].count('(') for frag in rev[i])             # <<<<<<<<<<<<<<
 * 		# divide by number of nodes in derivation to avoid preferring
 * 		# larger derivations
 */
      __pyx_t_5 = __pyx_pf_8discodop_14disambiguation_8mcrerank_genexpr(((PyObject*)__pyx_cur_scope)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1021, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1021, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_GIVEREF(__pyx_t_5);
      PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_5);
      __pyx_t_5 = 0;
      __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_sum, __pyx_t_8, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1021, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_5);
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      __pyx_t_8 = PyNumber_InPlaceAdd(__pyx_v_score, __pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1021, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_8);
      __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
      __Pyx_DECREF_SET(__pyx_v_score, __pyx_t_8);
      __pyx_t_8 = 0;

      /* "discodop/disambiguation.pyx":1018
 * 				rev[i].add(frag)
 * 		for i in rev:
 * 			if len(rev[i]) > 1:             # <<<<<<<<<<<<<<
 * 				# score is the total number of nodes
 * 				# of the common fragments consisting of at least 2 parts
 */
    }

    /* "discodop/disambiguation.pyx":1017
 * 			for i in idx:
 * 				rev[i].add(frag)
 * 		for i in rev:             # <<<<<<<<<<<<<<
 * 			if len(rev[i]) > 1:
 * 				# score is the total number of nodes
 */
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":1024
 * 		# divide by number of nodes in derivation to avoid preferring
 * 		# larger derivations
 * 		score = float(score) / (derivstr.count('(') + len(sent))             # <<<<<<<<<<<<<<
 * 		results.append((derivstr, (score, prob), None))
 * 	msg = 're-ranked %d parse trees; best tree at %d. ' % (
 */
  __pyx_t_4 = __Pyx_PyNumber_Float(__pyx_v_score); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1024, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_derivstr, __pyx_n_s_count); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1024, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_tuple__33, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1024, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_11 = PyObject_Length(__pyx_v_sent); if (unlikely(__pyx_t_11 == -1)) __PYX_ERR(0, 1024, __pyx_L1_error)
  __pyx_t_8 = PyInt_FromSsize_t(__pyx_t_11); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1024, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __pyx_t_2 = PyNumber_Add(__pyx_t_5, __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1024, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_8 = __Pyx_PyNumber_Divide(__pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1024, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_DECREF_SET(__pyx_v_score, __pyx_t_8);
  __pyx_t_8 = 0;

  /* "discodop/disambiguation.pyx":1025
 * 		# larger derivations
 * 		score = float(score) / (derivstr.count('(') + len(sent))
 * 		results.append((derivstr, (score, prob), None))             # <<<<<<<<<<<<<<
 * 	msg = 're-ranked %d parse trees; best tree at %d. ' % (
 * 			len(results),
 */
  __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1025, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_INCREF(__pyx_v_score);
  __Pyx_GIVEREF(__pyx_v_score);
  PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_score);
  __Pyx_INCREF(__pyx_v_prob);
  __Pyx_GIVEREF(__pyx_v_prob);
  PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_v_prob);
  __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1025, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_v_derivstr);
  __Pyx_GIVEREF(__pyx_v_derivstr);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_derivstr);
  __Pyx_GIVEREF(__pyx_t_8);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_8);
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  PyTuple_SET_ITEM(__pyx_t_2, 2, Py_None);
  __pyx_t_8 = 0;
  __pyx_t_19 = __Pyx_PyList_Append(__pyx_cur_scope->__pyx_v_results, __pyx_t_2); if (unlikely(__pyx_t_19 == -1)) __PYX_ERR(0, 1025, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

  /* "discodop/disambiguation.pyx":1000
 * 	Searches for trees that share multiple fragments (multi component)."""
 * 	cdef list results = []
 * 	for derivstr, prob, _ in nlargest(k, parsetrees, key=itemgetter(1)):             # <<<<<<<<<<<<<<
 * 		tmp = _fragments.getctrees(
 * 				[(addbitsets(derivstr), sent)], vocab=vocab)
 */
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

/* "discodop/disambiguation.pyx":1027
 * 		results.append((derivstr, (score, prob), None))
 * 	msg = 're-ranked %d parse trees; best tree at %d. ' % (
 * 			len(results),             # <<<<<<<<<<<<<<
 * 			max(range(len(results)), key=lambda x: results[x][1]) + 1)
 * 	return results, msg
 */
__pyx_t_3 = __pyx_cur_scope->__pyx_v_results;
__Pyx_INCREF(__pyx_t_3);
if (unlikely(__pyx_t_3 == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
  __PYX_ERR(0, 1027, __pyx_L1_error)
}
__pyx_t_6 = PyList_GET_SIZE(__pyx_t_3); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 1027, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_3 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1027, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);

/* "discodop/disambiguation.pyx":1028
 * 	msg = 're-ranked %d parse trees; best tree at %d. ' % (
 * 			len(results),
 * 			max(range(len(results)), key=lambda x: results[x][1]) + 1)             # <<<<<<<<<<<<<<
 * 	return results, msg
 * 
 */
__pyx_t_2 = __pyx_cur_scope->__pyx_v_results;
__Pyx_INCREF(__pyx_t_2);
if (unlikely(__pyx_t_2 == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()");
  __PYX_ERR(0, 1028, __pyx_L1_error)
}
__pyx_t_6 = PyList_GET_SIZE(__pyx_t_2); if (unlikely(__pyx_t_6 == -1)) __PYX_ERR(0, 1028, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_2 = PyInt_FromSsize_t(__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1028, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1028, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__Pyx_GIVEREF(__pyx_t_2);
PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2);
__pyx_t_2 = 0;
__pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1028, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
__pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1028, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__Pyx_GIVEREF(__pyx_t_2);
PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_2);
__pyx_t_2 = 0;
__pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1028, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_4 = __Pyx_CyFunction_NewEx(&__pyx_mdef_8discodop_14disambiguation_8mcrerank_3lambda2, 0, __pyx_n_s_mcrerank_locals_lambda, ((PyObject*)__pyx_cur_scope), __pyx_n_s_discodop_disambiguation, __pyx_d, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1028, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_key, __pyx_t_4) < 0) __PYX_ERR(0, 1028, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_max, __pyx_t_8, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1028, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_2 = __Pyx_PyInt_AddObjC(__pyx_t_4, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1028, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

/* "discodop/disambiguation.pyx":1027
 * 		results.append((derivstr, (score, prob), None))
 * 	msg = 're-ranked %d parse trees; best tree at %d. ' % (
 * 			len(results),             # <<<<<<<<<<<<<<
 * 			max(range(len(results)), key=lambda x: results[x][1]) + 1)
 * 	return results, msg
 */
__pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1027, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_GIVEREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
__Pyx_GIVEREF(__pyx_t_2);
PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
__pyx_t_3 = 0;
__pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":1026
 * 		score = float(score) / (derivstr.count('(') + len(sent))
 * 		results.append((derivstr, (score, prob), None))
 * 	msg = 're-ranked %d parse trees; best tree at %d. ' % (             # <<<<<<<<<<<<<<
 * 			len(results),
 * 			max(range(len(results)), key=lambda x: results[x][1]) + 1)
 */
__pyx_t_2 = PyUnicode_Format(__pyx_kp_u_re_ranked_d_parse_trees_best_tre, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1026, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_v_msg = ((PyObject*)__pyx_t_2);
__pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":1029
 * 			len(results),
 * 			max(range(len(results)), key=lambda x: results[x][1]) + 1)
 * 	return results, msg             # <<<<<<<<<<<<<<
 * 
 * 
 */
__Pyx_XDECREF(__pyx_r);
__pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1029, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(__pyx_cur_scope->__pyx_v_results);
__Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_results);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_cur_scope->__pyx_v_results);
__Pyx_INCREF(__pyx_v_msg);
__Pyx_GIVEREF(__pyx_v_msg);
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_msg);
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
goto __pyx_L0;

/* "discodop/disambiguation.pyx":995
 * 
 * 
 * def mcrerank(parsetrees, sent, k, trees, vocab):             # <<<<<<<<<<<<<<
 * 	"""Rerank *k*-best trees using tree fragments from training treebank.
 * 
 */

/* 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_5);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_XDECREF(__pyx_t_16);
__Pyx_XDECREF(__pyx_t_18);
__Pyx_AddTraceback("discodop.disambiguation.mcrerank", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_derivstr);
__Pyx_XDECREF(__pyx_v_prob);
__Pyx_XDECREF(__pyx_v__);
__Pyx_XDECREF(__pyx_v_tmp);
__Pyx_XDECREF(__pyx_v_frags);
__Pyx_XDECREF(__pyx_v_indices);
__Pyx_XDECREF(__pyx_v_score);
__Pyx_XDECREF(__pyx_v_n);
__Pyx_XDECREF(__pyx_v_frag);
__Pyx_XDECREF(__pyx_v_idx);
__Pyx_XDECREF(__pyx_v_msg);
__Pyx_DECREF(((PyObject *)__pyx_cur_scope));
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":1032
 * 
 * 
 * cdef str prodrepr(r, yf):             # <<<<<<<<<<<<<<
 * 	"""Produce string repr as in ``Grammar.rulenos[]`` for a rule.
 * 
 */

static PyObject *__pyx_f_8discodop_14disambiguation_prodrepr(PyObject *__pyx_v_r, PyObject *__pyx_v_yf) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
Py_ssize_t __pyx_t_3;
PyObject *(*__pyx_t_4)(PyObject *);
PyObject *__pyx_t_5 = NULL;
PyObject *__pyx_t_6 = NULL;
__Pyx_RefNannySetupContext("prodrepr", 0);
__Pyx_INCREF(__pyx_v_yf);

/* "discodop/disambiguation.pyx":1037
 * 	>>> prodrepr((('X', 'A', '', 'C', 'D'), ((0, 1, 2, 3), )))
 * 	'0123 X A B C D'"""
 * 	yf = ','.join([''.join(map(str, component)) for component in yf])             # <<<<<<<<<<<<<<
 * 	return ' '.join([yf, ' '.join(r)])
 * 
 */
{ /* enter inner scope */
  PyObject *__pyx_9genexpr27__pyx_v_component = NULL;
  __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1037, __pyx_L5_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (likely(PyList_CheckExact(__pyx_v_yf)) || PyTuple_CheckExact(__pyx_v_yf)) {
    __pyx_t_2 = __pyx_v_yf; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = 0;
    __pyx_t_4 = NULL;
  } else {
    __pyx_t_3 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_v_yf); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1037, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_2);
    __pyx_t_4 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1037, __pyx_L5_error)
  }
  for (;;) {
    if (likely(!__pyx_t_4)) {
      if (likely(PyList_CheckExact(__pyx_t_2))) {
        if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 1037, __pyx_L5_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1037, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      } else {
        if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_2)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_5 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_3); __Pyx_INCREF(__pyx_t_5); __pyx_t_3++; if (unlikely(0 < 0)) __PYX_ERR(0, 1037, __pyx_L5_error)
        #else
        __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_3); __pyx_t_3++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1037, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_5);
        #endif
      }
    } else {
      __pyx_t_5 = __pyx_t_4(__pyx_t_2);
      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, 1037, __pyx_L5_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_5);
    }
    __Pyx_XDECREF_SET(__pyx_9genexpr27__pyx_v_component, __pyx_t_5);
    __pyx_t_5 = 0;
    __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1037, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_INCREF(((PyObject *)(&PyUnicode_Type)));
    __Pyx_GIVEREF(((PyObject *)(&PyUnicode_Type)));
    PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)(&PyUnicode_Type)));
    __Pyx_INCREF(__pyx_9genexpr27__pyx_v_component);
    __Pyx_GIVEREF(__pyx_9genexpr27__pyx_v_component);
    PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_9genexpr27__pyx_v_component);
    __pyx_t_6 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_5, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1037, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
    __pyx_t_5 = PyUnicode_Join(__pyx_kp_u__4, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1037, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_5);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_5))) __PYX_ERR(0, 1037, __pyx_L5_error)
    __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  }
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_XDECREF(__pyx_9genexpr27__pyx_v_component);
  goto __pyx_L8_exit_scope;
  __pyx_L5_error:;
  __Pyx_XDECREF(__pyx_9genexpr27__pyx_v_component);
  goto __pyx_L1_error;
  __pyx_L8_exit_scope:;
} /* exit inner scope */
__pyx_t_2 = PyUnicode_Join(__pyx_kp_u__34, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1037, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF_SET(__pyx_v_yf, __pyx_t_2);
__pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":1038
 * 	'0123 X A B C D'"""
 * 	yf = ','.join([''.join(map(str, component)) for component in yf])
 * 	return ' '.join([yf, ' '.join(r)])             # <<<<<<<<<<<<<<
 * 
 * 
 */
__Pyx_XDECREF(__pyx_r);
__pyx_t_2 = PyUnicode_Join(__pyx_kp_u__25, __pyx_v_r); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1038, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_1 = PyList_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1038, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_INCREF(__pyx_v_yf);
__Pyx_GIVEREF(__pyx_v_yf);
PyList_SET_ITEM(__pyx_t_1, 0, __pyx_v_yf);
__Pyx_GIVEREF(__pyx_t_2);
PyList_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
__pyx_t_2 = 0;
__pyx_t_2 = PyUnicode_Join(__pyx_kp_u__25, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1038, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_r = ((PyObject*)__pyx_t_2);
__pyx_t_2 = 0;
goto __pyx_L0;

/* "discodop/disambiguation.pyx":1032
 * 
 * 
 * cdef str prodrepr(r, yf):             # <<<<<<<<<<<<<<
 * 	"""Produce string repr as in ``Grammar.rulenos[]`` for a rule.
 * 
 */

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_AddTraceback("discodop.disambiguation.prodrepr", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_yf);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":1041
 * 
 * 
 * cdef str nodeprod(deriv):             # <<<<<<<<<<<<<<
 * 	"""Produce string repr as in ``Grammar.rulenos[]`` of a non-disc. Tree.
 * 
 */

static PyObject *__pyx_f_8discodop_14disambiguation_nodeprod(PyObject *__pyx_v_deriv) {
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
Py_ssize_t __pyx_t_1;
PyObject *__pyx_t_2 = NULL;
PyObject *__pyx_t_3 = NULL;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
PyObject *(*__pyx_t_6)(PyObject *);
PyObject *__pyx_t_7 = NULL;
__Pyx_RefNannySetupContext("nodeprod", 0);

/* "discodop/disambiguation.pyx":1046
 * 	>>> nodeprod(Tree('(X (A 0) (B 1) (C 2) (D 3))'))
 * 	'0123 X A B C D'"""
 * 	return ('%s %s %s' % (''.join(map(str, range(len(deriv)))),             # <<<<<<<<<<<<<<
 * 			deriv.label, ' '.join([a.label for a in deriv])))
 * 
 */
__Pyx_XDECREF(__pyx_r);
__pyx_t_1 = PyObject_Length(__pyx_v_deriv); if (unlikely(__pyx_t_1 == -1)) __PYX_ERR(0, 1046, __pyx_L1_error)
__pyx_t_2 = PyInt_FromSsize_t(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1046, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1046, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_GIVEREF(__pyx_t_2);
PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_2);
__pyx_t_2 = 0;
__pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_range, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1046, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1046, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_INCREF(((PyObject *)(&PyUnicode_Type)));
__Pyx_GIVEREF(((PyObject *)(&PyUnicode_Type)));
PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)(&PyUnicode_Type)));
__Pyx_GIVEREF(__pyx_t_2);
PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_2);
__pyx_t_2 = 0;
__pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1046, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_3 = PyUnicode_Join(__pyx_kp_u__4, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1046, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":1047
 * 	'0123 X A B C D'"""
 * 	return ('%s %s %s' % (''.join(map(str, range(len(deriv)))),
 * 			deriv.label, ' '.join([a.label for a in deriv])))             # <<<<<<<<<<<<<<
 * 
 * 
 */
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_deriv, __pyx_n_s_label); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1047, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
{ /* enter inner scope */
  PyObject *__pyx_9genexpr28__pyx_v_a = NULL;
  __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1047, __pyx_L5_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (likely(PyList_CheckExact(__pyx_v_deriv)) || PyTuple_CheckExact(__pyx_v_deriv)) {
    __pyx_t_5 = __pyx_v_deriv; __Pyx_INCREF(__pyx_t_5); __pyx_t_1 = 0;
    __pyx_t_6 = NULL;
  } else {
    __pyx_t_1 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_v_deriv); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1047, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_5);
    __pyx_t_6 = Py_TYPE(__pyx_t_5)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1047, __pyx_L5_error)
  }
  for (;;) {
    if (likely(!__pyx_t_6)) {
      if (likely(PyList_CheckExact(__pyx_t_5))) {
        if (__pyx_t_1 >= PyList_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_7 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_1); __Pyx_INCREF(__pyx_t_7); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 1047, __pyx_L5_error)
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_5, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1047, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_7);
        #endif
      } else {
        if (__pyx_t_1 >= PyTuple_GET_SIZE(__pyx_t_5)) break;
        #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
        __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_1); __Pyx_INCREF(__pyx_t_7); __pyx_t_1++; if (unlikely(0 < 0)) __PYX_ERR(0, 1047, __pyx_L5_error)
        #else
        __pyx_t_7 = PySequence_ITEM(__pyx_t_5, __pyx_t_1); __pyx_t_1++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1047, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_7);
        #endif
      }
    } else {
      __pyx_t_7 = __pyx_t_6(__pyx_t_5);
      if (unlikely(!__pyx_t_7)) {
        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, 1047, __pyx_L5_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_7);
    }
    __Pyx_XDECREF_SET(__pyx_9genexpr28__pyx_v_a, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_9genexpr28__pyx_v_a, __pyx_n_s_label); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1047, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_7);
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_t_7))) __PYX_ERR(0, 1047, __pyx_L5_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_XDECREF(__pyx_9genexpr28__pyx_v_a);
  goto __pyx_L8_exit_scope;
  __pyx_L5_error:;
  __Pyx_XDECREF(__pyx_9genexpr28__pyx_v_a);
  goto __pyx_L1_error;
  __pyx_L8_exit_scope:;
} /* exit inner scope */
__pyx_t_5 = PyUnicode_Join(__pyx_kp_u__25, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1047, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

/* "discodop/disambiguation.pyx":1046
 * 	>>> nodeprod(Tree('(X (A 0) (B 1) (C 2) (D 3))'))
 * 	'0123 X A B C D'"""
 * 	return ('%s %s %s' % (''.join(map(str, range(len(deriv)))),             # <<<<<<<<<<<<<<
 * 			deriv.label, ' '.join([a.label for a in deriv])))
 * 
 */
__pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1046, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_GIVEREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3);
__Pyx_GIVEREF(__pyx_t_2);
PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_5);
PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_t_5);
__pyx_t_3 = 0;
__pyx_t_2 = 0;
__pyx_t_5 = 0;
__pyx_t_5 = PyUnicode_Format(__pyx_kp_u_s_s_s_2, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1046, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_r = ((PyObject*)__pyx_t_5);
__pyx_t_5 = 0;
goto __pyx_L0;

/* "discodop/disambiguation.pyx":1041
 * 
 * 
 * cdef str nodeprod(deriv):             # <<<<<<<<<<<<<<
 * 	"""Produce string repr as in ``Grammar.rulenos[]`` of a non-disc. Tree.
 * 
 */

/* function exit code */
__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_7);
__Pyx_AddTraceback("discodop.disambiguation.nodeprod", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":1050
 * 
 * 
 * def test():             # <<<<<<<<<<<<<<
 * 	from .grammar import dopreduction
 * 	from .containers import Grammar
 */

/* Python wrapper */
static PyObject *__pyx_pw_8discodop_14disambiguation_27test(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/
static char __pyx_doc_8discodop_14disambiguation_26test[] = "test()";
static PyMethodDef __pyx_mdef_8discodop_14disambiguation_27test = {"test", (PyCFunction)__pyx_pw_8discodop_14disambiguation_27test, METH_NOARGS, __pyx_doc_8discodop_14disambiguation_26test};
static PyObject *__pyx_pw_8discodop_14disambiguation_27test(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("test (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_14disambiguation_26test(__pyx_self);

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

/* "discodop/disambiguation.pyx":1055
 * 	from . import plcfrs
 * 
 * 	def e(x):             # <<<<<<<<<<<<<<
 * 		a, b, _ = max(x, key=itemgetter(1))
 * 		return (a, (int(abs(b[0])), b[1])) if isinstance(b, tuple) else (
 */

/* Python wrapper */
static PyObject *__pyx_pw_8discodop_14disambiguation_4test_1e(PyObject *__pyx_self, PyObject *__pyx_v_x); /*proto*/
static PyMethodDef __pyx_mdef_8discodop_14disambiguation_4test_1e = {"e", (PyCFunction)__pyx_pw_8discodop_14disambiguation_4test_1e, METH_O, 0};
static PyObject *__pyx_pw_8discodop_14disambiguation_4test_1e(PyObject *__pyx_self, PyObject *__pyx_v_x) {
PyObject *__pyx_r = 0;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("e (wrapper)", 0);
__pyx_r = __pyx_pf_8discodop_14disambiguation_4test_e(__pyx_self, ((PyObject *)__pyx_v_x));

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

static PyObject *__pyx_pf_8discodop_14disambiguation_4test_e(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_x) {
PyObject *__pyx_v_a = NULL;
PyObject *__pyx_v_b = NULL;
CYTHON_UNUSED PyObject *__pyx_v__ = NULL;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
PyObject *__pyx_t_2 = NULL;
PyObject *__pyx_t_3 = NULL;
PyObject *__pyx_t_4 = NULL;
PyObject *__pyx_t_5 = NULL;
PyObject *(*__pyx_t_6)(PyObject *);
int __pyx_t_7;
__Pyx_RefNannySetupContext("e", 0);

/* "discodop/disambiguation.pyx":1056
 * 
 * 	def e(x):
 * 		a, b, _ = max(x, key=itemgetter(1))             # <<<<<<<<<<<<<<
 * 		return (a, (int(abs(b[0])), b[1])) if isinstance(b, tuple) else (
 * 				a, b)
 */
__pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1056, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_INCREF(__pyx_v_x);
__Pyx_GIVEREF(__pyx_v_x);
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_x);
__pyx_t_2 = PyDict_New(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1056, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_itemgetter); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1056, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple__35, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1056, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_key, __pyx_t_4) < 0) __PYX_ERR(0, 1056, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_max, __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1056, __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;
if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) {
  PyObject* sequence = __pyx_t_4;
  #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, 1056, __pyx_L1_error)
  }
  #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
  if (likely(PyTuple_CheckExact(sequence))) {
    __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
    __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
    __pyx_t_3 = PyTuple_GET_ITEM(sequence, 2); 
  } else {
    __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
    __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
    __pyx_t_3 = PyList_GET_ITEM(sequence, 2); 
  }
  __Pyx_INCREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_t_3);
  #else
  __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1056, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1056, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_3 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1056, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  #endif
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
} else {
  Py_ssize_t index = -1;
  __pyx_t_5 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1056, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_6 = Py_TYPE(__pyx_t_5)->tp_iternext;
  index = 0; __pyx_t_2 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_2)) goto __pyx_L3_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_2);
  index = 1; __pyx_t_1 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_1)) goto __pyx_L3_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_1);
  index = 2; __pyx_t_3 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L3_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_3);
  if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_5), 3) < 0) __PYX_ERR(0, 1056, __pyx_L1_error)
  __pyx_t_6 = NULL;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  goto __pyx_L4_unpacking_done;
  __pyx_L3_unpacking_failed:;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_6 = NULL;
  if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
  __PYX_ERR(0, 1056, __pyx_L1_error)
  __pyx_L4_unpacking_done:;
}
__pyx_v_a = __pyx_t_2;
__pyx_t_2 = 0;
__pyx_v_b = __pyx_t_1;
__pyx_t_1 = 0;
__pyx_v__ = __pyx_t_3;
__pyx_t_3 = 0;

/* "discodop/disambiguation.pyx":1057
 * 	def e(x):
 * 		a, b, _ = max(x, key=itemgetter(1))
 * 		return (a, (int(abs(b[0])), b[1])) if isinstance(b, tuple) else (             # <<<<<<<<<<<<<<
 * 				a, b)
 * 
 */
__Pyx_XDECREF(__pyx_r);
__pyx_t_7 = PyTuple_Check(__pyx_v_b); 
if ((__pyx_t_7 != 0)) {
  __pyx_t_3 = __Pyx_GetItemInt(__pyx_v_b, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_1 = PyNumber_Absolute(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_3 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_b, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3);
  __Pyx_GIVEREF(__pyx_t_1);
  PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1);
  __pyx_t_3 = 0;
  __pyx_t_1 = 0;
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1057, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_a);
  __Pyx_GIVEREF(__pyx_v_a);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_a);
  __Pyx_GIVEREF(__pyx_t_2);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2);
  __pyx_t_2 = 0;
  __pyx_t_4 = __pyx_t_1;
  __pyx_t_1 = 0;
} else {

  /* "discodop/disambiguation.pyx":1058
 * 		a, b, _ = max(x, key=itemgetter(1))
 * 		return (a, (int(abs(b[0])), b[1])) if isinstance(b, tuple) else (
 * 				a, b)             # <<<<<<<<<<<<<<
 * 
 * 	trees = [Tree(t) for t in
 */
  __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1058, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_INCREF(__pyx_v_a);
  __Pyx_GIVEREF(__pyx_v_a);
  PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_a);
  __Pyx_INCREF(__pyx_v_b);
  __Pyx_GIVEREF(__pyx_v_b);
  PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_b);
  __pyx_t_4 = __pyx_t_1;
  __pyx_t_1 = 0;
}
__pyx_r = __pyx_t_4;
__pyx_t_4 = 0;
goto __pyx_L0;

/* "discodop/disambiguation.pyx":1055
 * 	from . import plcfrs
 * 
 * 	def e(x):             # <<<<<<<<<<<<<<
 * 		a, b, _ = max(x, key=itemgetter(1))
 * 		return (a, (int(abs(b[0])), b[1])) if isinstance(b, tuple) else (
 */

/* 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_5);
__Pyx_AddTraceback("discodop.disambiguation.test.e", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_a);
__Pyx_XDECREF(__pyx_v_b);
__Pyx_XDECREF(__pyx_v__);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "discodop/disambiguation.pyx":1050
 * 
 * 
 * def test():             # <<<<<<<<<<<<<<
 * 	from .grammar import dopreduction
 * 	from .containers import Grammar
 */

static PyObject *__pyx_pf_8discodop_14disambiguation_26test(CYTHON_UNUSED PyObject *__pyx_self) {
PyObject *__pyx_v_dopreduction = NULL;
PyObject *__pyx_v_Grammar = NULL;
PyObject *__pyx_v_plcfrs = NULL;
PyObject *__pyx_v_e = 0;
PyObject *__pyx_v_trees = NULL;
PyObject *__pyx_v_sents = NULL;
PyObject *__pyx_v_xgrammar = NULL;
PyObject *__pyx_v_altweights = NULL;
PyObject *__pyx_v_grammar = NULL;
PyObject *__pyx_v_sent = NULL;
PyObject *__pyx_v_chart = NULL;
CYTHON_UNUSED PyObject *__pyx_v__ = NULL;
PyObject *__pyx_v_vitderiv = NULL;
PyObject *__pyx_v_vitprob = NULL;
PyObject *__pyx_v_derivations = NULL;
PyObject *__pyx_v_entries = NULL;
PyObject *__pyx_v_mpd = NULL;
PyObject *__pyx_v_mpp = NULL;
PyObject *__pyx_v_mcc = NULL;
PyObject *__pyx_v_sldop_ = NULL;
PyObject *__pyx_v_sldopsimple = NULL;
PyObject *__pyx_v_short = NULL;
PyObject *__pyx_v_mppsampled = 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;
PyObject *__pyx_t_8 = NULL;
int __pyx_t_9;
PyObject *(*__pyx_t_10)(PyObject *);
int __pyx_t_11;
struct __pyx_opt_args_8discodop_14disambiguation_getderivations __pyx_t_12;
PyObject *__pyx_t_13 = NULL;
PyObject *__pyx_t_14 = NULL;
PyObject *__pyx_t_15 = NULL;
__Pyx_RefNannySetupContext("test", 0);

/* "discodop/disambiguation.pyx":1051
 * 
 * def test():
 * 	from .grammar import dopreduction             # <<<<<<<<<<<<<<
 * 	from .containers import Grammar
 * 	from . import plcfrs
 */
__pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1051, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_INCREF(__pyx_n_s_dopreduction);
__Pyx_GIVEREF(__pyx_n_s_dopreduction);
PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_dopreduction);
__pyx_t_2 = __Pyx_Import(__pyx_n_s_grammar, __pyx_t_1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1051, __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_dopreduction); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1051, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_INCREF(__pyx_t_1);
__pyx_v_dopreduction = __pyx_t_1;
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":1052
 * def test():
 * 	from .grammar import dopreduction
 * 	from .containers import Grammar             # <<<<<<<<<<<<<<
 * 	from . import plcfrs
 * 
 */
__pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1052, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(__pyx_n_s_Grammar);
__Pyx_GIVEREF(__pyx_n_s_Grammar);
PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_Grammar);
__pyx_t_1 = __Pyx_Import(__pyx_n_s_containers, __pyx_t_2, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1052, __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_Grammar); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1052, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(__pyx_t_2);
__pyx_v_Grammar = __pyx_t_2;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":1053
 * 	from .grammar import dopreduction
 * 	from .containers import Grammar
 * 	from . import plcfrs             # <<<<<<<<<<<<<<
 * 
 * 	def e(x):
 */
__pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1053, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_INCREF(__pyx_n_s_plcfrs);
__Pyx_GIVEREF(__pyx_n_s_plcfrs);
PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_plcfrs);
__pyx_t_2 = __Pyx_Import(__pyx_n_s__4, __pyx_t_1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1053, __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_plcfrs); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1053, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_INCREF(__pyx_t_1);
__pyx_v_plcfrs = __pyx_t_1;
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":1055
 * 	from . import plcfrs
 * 
 * 	def e(x):             # <<<<<<<<<<<<<<
 * 		a, b, _ = max(x, key=itemgetter(1))
 * 		return (a, (int(abs(b[0])), b[1])) if isinstance(b, tuple) else (
 */
__pyx_t_2 = __Pyx_CyFunction_NewEx(&__pyx_mdef_8discodop_14disambiguation_4test_1e, 0, __pyx_n_s_test_locals_e, NULL, __pyx_n_s_discodop_disambiguation, __pyx_d, ((PyObject *)__pyx_codeobj__38)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1055, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_v_e = __pyx_t_2;
__pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":1060
 * 				a, b)
 * 
 * 	trees = [Tree(t) for t in             # <<<<<<<<<<<<<<
 * 		'''(ROOT (A (A 0) (B 1)) (C 2))
 * 		(ROOT (C 0) (A (A 1) (B 2)))
 */
{ /* enter inner scope */
  PyObject *__pyx_9genexpr29__pyx_v_t = NULL;
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1060, __pyx_L5_error)
  __Pyx_GOTREF(__pyx_t_2);

  /* "discodop/disambiguation.pyx":1064
 * 		(ROOT (C 0) (A (A 1) (B 2)))
 * 		(ROOT (A 0) (C (B 1) (C 2)))
 * 		(ROOT (A 0) (C (B 1) (C 2)))'''.splitlines()             # <<<<<<<<<<<<<<
 * 		+ 14 * ['(ROOT (B (A 0) (B 1)) (C 2))']]
 * 	sents = [a.split() for a in
 */
  __pyx_t_1 = PyUnicode_Splitlines(__pyx_kp_u_ROOT_A_A_0_B_1_C_2_ROOT_C_0_A_A, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1064, __pyx_L5_error)
  __Pyx_GOTREF(__pyx_t_1);

  /* "discodop/disambiguation.pyx":1065
 * 		(ROOT (A 0) (C (B 1) (C 2)))
 * 		(ROOT (A 0) (C (B 1) (C 2)))'''.splitlines()
 * 		+ 14 * ['(ROOT (B (A 0) (B 1)) (C 2))']]             # <<<<<<<<<<<<<<
 * 	sents = [a.split() for a in
 * 		'''d b c\n c a b\n a e f\n a e f\n a e f\n a e f\n d b f\n d b f
 */
  __pyx_t_3 = PyList_New(1 * 14); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1065, __pyx_L5_error)
  __Pyx_GOTREF(__pyx_t_3);
  { Py_ssize_t __pyx_temp;
    for (__pyx_temp=0; __pyx_temp < 14; __pyx_temp++) {
      __Pyx_INCREF(__pyx_kp_u_ROOT_B_A_0_B_1_C_2);
      __Pyx_GIVEREF(__pyx_kp_u_ROOT_B_A_0_B_1_C_2);
      PyList_SET_ITEM(__pyx_t_3, __pyx_temp, __pyx_kp_u_ROOT_B_A_0_B_1_C_2);
    }
  }
  __pyx_t_4 = PyNumber_Add(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1065, __pyx_L5_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

  /* "discodop/disambiguation.pyx":1061
 * 
 * 	trees = [Tree(t) for t in
 * 		'''(ROOT (A (A 0) (B 1)) (C 2))             # <<<<<<<<<<<<<<
 * 		(ROOT (C 0) (A (A 1) (B 2)))
 * 		(ROOT (A 0) (C (B 1) (C 2)))
 */
  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, 1061, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_3);
    __pyx_t_6 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1061, __pyx_L5_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, 1061, __pyx_L5_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1061, __pyx_L5_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, 1061, __pyx_L5_error)
        #else
        __pyx_t_4 = PySequence_ITEM(__pyx_t_3, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1061, __pyx_L5_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, 1061, __pyx_L5_error)
        }
        break;
      }
      __Pyx_GOTREF(__pyx_t_4);
    }
    __Pyx_XDECREF_SET(__pyx_9genexpr29__pyx_v_t, __pyx_t_4);
    __pyx_t_4 = 0;

    /* "discodop/disambiguation.pyx":1060
 * 				a, b)
 * 
 * 	trees = [Tree(t) for t in             # <<<<<<<<<<<<<<
 * 		'''(ROOT (A (A 0) (B 1)) (C 2))
 * 		(ROOT (C 0) (A (A 1) (B 2)))
 */
    __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_Tree); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1060, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_1);
    __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_4 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_9genexpr29__pyx_v_t); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1060, __pyx_L5_error)
      __Pyx_GOTREF(__pyx_t_4);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_9genexpr29__pyx_v_t};
        __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1060, __pyx_L5_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_4);
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
        PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_9genexpr29__pyx_v_t};
        __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1060, __pyx_L5_error)
        __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
        __Pyx_GOTREF(__pyx_t_4);
      } else
      #endif
      {
        __pyx_t_8 = PyTuple_New(1+1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1060, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_8);
        __Pyx_GIVEREF(__pyx_t_7); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __pyx_t_7 = NULL;
        __Pyx_INCREF(__pyx_9genexpr29__pyx_v_t);
        __Pyx_GIVEREF(__pyx_9genexpr29__pyx_v_t);
        PyTuple_SET_ITEM(__pyx_t_8, 0+1, __pyx_9genexpr29__pyx_v_t);
        __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_8, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1060, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_4);
        __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 1060, __pyx_L5_error)
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_XDECREF(__pyx_9genexpr29__pyx_v_t);
  goto __pyx_L8_exit_scope;
  __pyx_L5_error:;
  __Pyx_XDECREF(__pyx_9genexpr29__pyx_v_t);
  goto __pyx_L1_error;
  __pyx_L8_exit_scope:;
} /* exit inner scope */
__pyx_v_trees = ((PyObject*)__pyx_t_2);
__pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":1066
 * 		(ROOT (A 0) (C (B 1) (C 2)))'''.splitlines()
 * 		+ 14 * ['(ROOT (B (A 0) (B 1)) (C 2))']]
 * 	sents = [a.split() for a in             # <<<<<<<<<<<<<<
 * 		'''d b c\n c a b\n a e f\n a e f\n a e f\n a e f\n d b f\n d b f
 * 		d b f\n d b g\n e f c\n e f c\n e f c\n e f c\n e f c\n e f c\n f b c
 */
{ /* enter inner scope */
  PyObject *__pyx_9genexpr30__pyx_v_a = NULL;
  __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1066, __pyx_L11_error)
  __Pyx_GOTREF(__pyx_t_2);

  /* "discodop/disambiguation.pyx":1069
 * 		'''d b c\n c a b\n a e f\n a e f\n a e f\n a e f\n d b f\n d b f
 * 		d b f\n d b g\n e f c\n e f c\n e f c\n e f c\n e f c\n e f c\n f b c
 * 		a d e'''.splitlines()]             # <<<<<<<<<<<<<<
 * 	xgrammar, altweights = dopreduction(trees, sents)
 * 	grammar = Grammar(xgrammar)
 */
  __pyx_t_3 = PyUnicode_Splitlines(__pyx_kp_u_d_b_c_c_a_b_a_e_f_a_e_f_a_e_f_a, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1069, __pyx_L11_error)
  __Pyx_GOTREF(__pyx_t_3);

  /* "discodop/disambiguation.pyx":1067
 * 		+ 14 * ['(ROOT (B (A 0) (B 1)) (C 2))']]
 * 	sents = [a.split() for a in
 * 		'''d b c\n c a b\n a e f\n a e f\n a e f\n a e f\n d b f\n d b f             # <<<<<<<<<<<<<<
 * 		d b f\n d b g\n e f c\n e f c\n e f c\n e f c\n e f c\n e f c\n f b c
 * 		a d e'''.splitlines()]
 */
  __pyx_t_4 = __pyx_t_3; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  for (;;) {
    if (__pyx_t_5 >= 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_5); __Pyx_INCREF(__pyx_t_3); __pyx_t_5++; if (unlikely(0 < 0)) __PYX_ERR(0, 1067, __pyx_L11_error)
    #else
    __pyx_t_3 = PySequence_ITEM(__pyx_t_4, __pyx_t_5); __pyx_t_5++; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1067, __pyx_L11_error)
    __Pyx_GOTREF(__pyx_t_3);
    #endif
    __Pyx_XDECREF_SET(__pyx_9genexpr30__pyx_v_a, __pyx_t_3);
    __pyx_t_3 = 0;

    /* "discodop/disambiguation.pyx":1066
 * 		(ROOT (A 0) (C (B 1) (C 2)))'''.splitlines()
 * 		+ 14 * ['(ROOT (B (A 0) (B 1)) (C 2))']]
 * 	sents = [a.split() for a in             # <<<<<<<<<<<<<<
 * 		'''d b c\n c a b\n a e f\n a e f\n a e f\n a e f\n d b f\n d b f
 * 		d b f\n d b g\n e f c\n e f c\n e f c\n e f c\n e f c\n e f c\n f b c
 */
    __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_9genexpr30__pyx_v_a, __pyx_n_s_split); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1066, __pyx_L11_error)
    __Pyx_GOTREF(__pyx_t_1);
    __pyx_t_8 = NULL;
    if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_1))) {
      __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_1);
      if (likely(__pyx_t_8)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1);
        __Pyx_INCREF(__pyx_t_8);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_1, function);
      }
    }
    if (__pyx_t_8) {
      __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1066, __pyx_L11_error)
      __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    } else {
      __pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1066, __pyx_L11_error)
    }
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_3))) __PYX_ERR(0, 1066, __pyx_L11_error)
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_XDECREF(__pyx_9genexpr30__pyx_v_a);
  goto __pyx_L14_exit_scope;
  __pyx_L11_error:;
  __Pyx_XDECREF(__pyx_9genexpr30__pyx_v_a);
  goto __pyx_L1_error;
  __pyx_L14_exit_scope:;
} /* exit inner scope */
__pyx_v_sents = ((PyObject*)__pyx_t_2);
__pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":1070
 * 		d b f\n d b g\n e f c\n e f c\n e f c\n e f c\n e f c\n e f c\n f b c
 * 		a d e'''.splitlines()]
 * 	xgrammar, altweights = dopreduction(trees, sents)             # <<<<<<<<<<<<<<
 * 	grammar = Grammar(xgrammar)
 * 	grammar.register(u'shortest', altweights['shortest'])
 */
__Pyx_INCREF(__pyx_v_dopreduction);
__pyx_t_4 = __pyx_v_dopreduction; __pyx_t_3 = NULL;
__pyx_t_9 = 0;
if (CYTHON_UNPACK_METHODS && unlikely(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);
    __pyx_t_9 = 1;
  }
}
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_4)) {
  PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_trees, __pyx_v_sents};
  __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1070, __pyx_L1_error)
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_GOTREF(__pyx_t_2);
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
  PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_v_trees, __pyx_v_sents};
  __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1070, __pyx_L1_error)
  __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_GOTREF(__pyx_t_2);
} else
#endif
{
  __pyx_t_1 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__pyx_t_3) {
    __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); __pyx_t_3 = NULL;
  }
  __Pyx_INCREF(__pyx_v_trees);
  __Pyx_GIVEREF(__pyx_v_trees);
  PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_9, __pyx_v_trees);
  __Pyx_INCREF(__pyx_v_sents);
  __Pyx_GIVEREF(__pyx_v_sents);
  PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_9, __pyx_v_sents);
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
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, 1070, __pyx_L1_error)
  }
  #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
  if (likely(PyTuple_CheckExact(sequence))) {
    __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); 
    __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); 
  } else {
    __pyx_t_4 = PyList_GET_ITEM(sequence, 0); 
    __pyx_t_1 = PyList_GET_ITEM(sequence, 1); 
  }
  __Pyx_INCREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_t_1);
  #else
  __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  #endif
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
} else {
  Py_ssize_t index = -1;
  __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1070, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_10 = Py_TYPE(__pyx_t_3)->tp_iternext;
  index = 0; __pyx_t_4 = __pyx_t_10(__pyx_t_3); if (unlikely(!__pyx_t_4)) goto __pyx_L15_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_4);
  index = 1; __pyx_t_1 = __pyx_t_10(__pyx_t_3); if (unlikely(!__pyx_t_1)) goto __pyx_L15_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_1);
  if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_3), 2) < 0) __PYX_ERR(0, 1070, __pyx_L1_error)
  __pyx_t_10 = NULL;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  goto __pyx_L16_unpacking_done;
  __pyx_L15_unpacking_failed:;
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_t_10 = NULL;
  if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
  __PYX_ERR(0, 1070, __pyx_L1_error)
  __pyx_L16_unpacking_done:;
}
__pyx_v_xgrammar = __pyx_t_4;
__pyx_t_4 = 0;
__pyx_v_altweights = __pyx_t_1;
__pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":1071
 * 		a d e'''.splitlines()]
 * 	xgrammar, altweights = dopreduction(trees, sents)
 * 	grammar = Grammar(xgrammar)             # <<<<<<<<<<<<<<
 * 	grammar.register(u'shortest', altweights['shortest'])
 * 	print(grammar)
 */
__Pyx_INCREF(__pyx_v_Grammar);
__pyx_t_1 = __pyx_v_Grammar; __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_v_xgrammar); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1071, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
} else {
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_xgrammar};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1071, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_2);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_v_xgrammar};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1071, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_2);
  } else
  #endif
  {
    __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1071, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = NULL;
    __Pyx_INCREF(__pyx_v_xgrammar);
    __Pyx_GIVEREF(__pyx_v_xgrammar);
    PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_v_xgrammar);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1071, __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_v_grammar = __pyx_t_2;
__pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":1072
 * 	xgrammar, altweights = dopreduction(trees, sents)
 * 	grammar = Grammar(xgrammar)
 * 	grammar.register(u'shortest', altweights['shortest'])             # <<<<<<<<<<<<<<
 * 	print(grammar)
 * 	sent = 'a b c'.split()
 */
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_grammar, __pyx_n_s_register); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1072, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_3 = PyObject_GetItem(__pyx_v_altweights, __pyx_n_u_shortest); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1072, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_4 = NULL;
__pyx_t_9 = 0;
if (CYTHON_UNPACK_METHODS && likely(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);
    __pyx_t_9 = 1;
  }
}
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_1)) {
  PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_shortest, __pyx_t_3};
  __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1072, __pyx_L1_error)
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 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_1)) {
  PyObject *__pyx_temp[3] = {__pyx_t_4, __pyx_n_u_shortest, __pyx_t_3};
  __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1072, __pyx_L1_error)
  __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
} else
#endif
{
  __pyx_t_8 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1072, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  if (__pyx_t_4) {
    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_4); __pyx_t_4 = NULL;
  }
  __Pyx_INCREF(__pyx_n_u_shortest);
  __Pyx_GIVEREF(__pyx_n_u_shortest);
  PyTuple_SET_ITEM(__pyx_t_8, 0+__pyx_t_9, __pyx_n_u_shortest);
  __Pyx_GIVEREF(__pyx_t_3);
  PyTuple_SET_ITEM(__pyx_t_8, 1+__pyx_t_9, __pyx_t_3);
  __pyx_t_3 = 0;
  __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_8, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1072, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":1073
 * 	grammar = Grammar(xgrammar)
 * 	grammar.register(u'shortest', altweights['shortest'])
 * 	print(grammar)             # <<<<<<<<<<<<<<
 * 	sent = 'a b c'.split()
 * 	chart, _ = plcfrs.parse(sent, grammar, None, True)
 */
__pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1073, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(__pyx_v_grammar);
__Pyx_GIVEREF(__pyx_v_grammar);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_grammar);
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_t_2, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1073, __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;

/* "discodop/disambiguation.pyx":1074
 * 	grammar.register(u'shortest', altweights['shortest'])
 * 	print(grammar)
 * 	sent = 'a b c'.split()             # <<<<<<<<<<<<<<
 * 	chart, _ = plcfrs.parse(sent, grammar, None, True)
 * 	assert chart
 */
__pyx_t_1 = PyUnicode_Split(__pyx_kp_u_a_b_c, ((PyObject *)NULL), -1L); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1074, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_sent = __pyx_t_1;
__pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":1075
 * 	print(grammar)
 * 	sent = 'a b c'.split()
 * 	chart, _ = plcfrs.parse(sent, grammar, None, True)             # <<<<<<<<<<<<<<
 * 	assert chart
 * 	vitderiv, vitprob = viterbiderivation(chart)
 */
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_plcfrs, __pyx_n_s_parse); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1075, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_8 = NULL;
__pyx_t_9 = 0;
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);
    __pyx_t_9 = 1;
  }
}
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_2)) {
  PyObject *__pyx_temp[5] = {__pyx_t_8, __pyx_v_sent, __pyx_v_grammar, Py_None, Py_True};
  __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_9, 4+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1075, __pyx_L1_error)
  __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_GOTREF(__pyx_t_1);
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
  PyObject *__pyx_temp[5] = {__pyx_t_8, __pyx_v_sent, __pyx_v_grammar, Py_None, Py_True};
  __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-__pyx_t_9, 4+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1075, __pyx_L1_error)
  __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
  __Pyx_GOTREF(__pyx_t_1);
} else
#endif
{
  __pyx_t_3 = PyTuple_New(4+__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1075, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (__pyx_t_8) {
    __Pyx_GIVEREF(__pyx_t_8); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_8); __pyx_t_8 = NULL;
  }
  __Pyx_INCREF(__pyx_v_sent);
  __Pyx_GIVEREF(__pyx_v_sent);
  PyTuple_SET_ITEM(__pyx_t_3, 0+__pyx_t_9, __pyx_v_sent);
  __Pyx_INCREF(__pyx_v_grammar);
  __Pyx_GIVEREF(__pyx_v_grammar);
  PyTuple_SET_ITEM(__pyx_t_3, 1+__pyx_t_9, __pyx_v_grammar);
  __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(Py_None);
  PyTuple_SET_ITEM(__pyx_t_3, 2+__pyx_t_9, Py_None);
  __Pyx_INCREF(Py_True);
  __Pyx_GIVEREF(Py_True);
  PyTuple_SET_ITEM(__pyx_t_3, 3+__pyx_t_9, Py_True);
  __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1075, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
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, 1075, __pyx_L1_error)
  }
  #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
  if (likely(PyTuple_CheckExact(sequence))) {
    __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
    __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
  } else {
    __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
    __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
  }
  __Pyx_INCREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_t_3);
  #else
  __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1075, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1075, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  #endif
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
} else {
  Py_ssize_t index = -1;
  __pyx_t_8 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1075, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_10 = Py_TYPE(__pyx_t_8)->tp_iternext;
  index = 0; __pyx_t_2 = __pyx_t_10(__pyx_t_8); if (unlikely(!__pyx_t_2)) goto __pyx_L17_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_2);
  index = 1; __pyx_t_3 = __pyx_t_10(__pyx_t_8); if (unlikely(!__pyx_t_3)) goto __pyx_L17_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_3);
  if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_8), 2) < 0) __PYX_ERR(0, 1075, __pyx_L1_error)
  __pyx_t_10 = NULL;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  goto __pyx_L18_unpacking_done;
  __pyx_L17_unpacking_failed:;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_10 = NULL;
  if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
  __PYX_ERR(0, 1075, __pyx_L1_error)
  __pyx_L18_unpacking_done:;
}
__pyx_v_chart = __pyx_t_2;
__pyx_t_2 = 0;
__pyx_v__ = __pyx_t_3;
__pyx_t_3 = 0;

/* "discodop/disambiguation.pyx":1076
 * 	sent = 'a b c'.split()
 * 	chart, _ = plcfrs.parse(sent, grammar, None, True)
 * 	assert chart             # <<<<<<<<<<<<<<
 * 	vitderiv, vitprob = viterbiderivation(chart)
 * 	derivations, entries = getderivations(chart, 1000, True, False, True)
 */
#ifndef CYTHON_WITHOUT_ASSERTIONS
if (unlikely(!Py_OptimizeFlag)) {
  __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_chart); if (unlikely(__pyx_t_11 < 0)) __PYX_ERR(0, 1076, __pyx_L1_error)
  if (unlikely(!__pyx_t_11)) {
    PyErr_SetNone(PyExc_AssertionError);
    __PYX_ERR(0, 1076, __pyx_L1_error)
  }
}
#endif

/* "discodop/disambiguation.pyx":1077
 * 	chart, _ = plcfrs.parse(sent, grammar, None, True)
 * 	assert chart
 * 	vitderiv, vitprob = viterbiderivation(chart)             # <<<<<<<<<<<<<<
 * 	derivations, entries = getderivations(chart, 1000, True, False, True)
 * 	mpd, _ = marginalize('mpd', derivations, entries, chart)
 */
if (!(likely(((__pyx_v_chart) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_chart, __pyx_ptype_8discodop_10containers_Chart))))) __PYX_ERR(0, 1077, __pyx_L1_error)
__pyx_t_1 = __pyx_f_8discodop_14disambiguation_viterbiderivation(((struct __pyx_obj_8discodop_10containers_Chart *)__pyx_v_chart), 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1077, __pyx_L1_error)
__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, 1077, __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_2 = PyTuple_GET_ITEM(sequence, 1); 
  } else {
    __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
    __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
  }
  __Pyx_INCREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_t_2);
  #else
  __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1077, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1077, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  #endif
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
} else {
  Py_ssize_t index = -1;
  __pyx_t_8 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1077, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_10 = Py_TYPE(__pyx_t_8)->tp_iternext;
  index = 0; __pyx_t_3 = __pyx_t_10(__pyx_t_8); if (unlikely(!__pyx_t_3)) goto __pyx_L19_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_3);
  index = 1; __pyx_t_2 = __pyx_t_10(__pyx_t_8); if (unlikely(!__pyx_t_2)) goto __pyx_L19_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_8), 2) < 0) __PYX_ERR(0, 1077, __pyx_L1_error)
  __pyx_t_10 = NULL;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  goto __pyx_L20_unpacking_done;
  __pyx_L19_unpacking_failed:;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_10 = NULL;
  if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
  __PYX_ERR(0, 1077, __pyx_L1_error)
  __pyx_L20_unpacking_done:;
}
__pyx_v_vitderiv = __pyx_t_3;
__pyx_t_3 = 0;
__pyx_v_vitprob = __pyx_t_2;
__pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":1078
 * 	assert chart
 * 	vitderiv, vitprob = viterbiderivation(chart)
 * 	derivations, entries = getderivations(chart, 1000, True, False, True)             # <<<<<<<<<<<<<<
 * 	mpd, _ = marginalize('mpd', derivations, entries, chart)
 * 	mpp, _ = marginalize('mpp', derivations, entries, chart)
 */
if (!(likely(((__pyx_v_chart) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_chart, __pyx_ptype_8discodop_10containers_Chart))))) __PYX_ERR(0, 1078, __pyx_L1_error)
__pyx_t_12.__pyx_n = 3;
__pyx_t_12.kbest = 1;
__pyx_t_12.sample = 0;
__pyx_t_12.derivstrings = Py_True;
__pyx_t_1 = __pyx_f_8discodop_14disambiguation_getderivations(((struct __pyx_obj_8discodop_10containers_Chart *)__pyx_v_chart), 0x3E8, 0, &__pyx_t_12); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1078, __pyx_L1_error)
__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, 1078, __pyx_L1_error)
  }
  #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
  if (likely(PyTuple_CheckExact(sequence))) {
    __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
    __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
  } else {
    __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
    __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
  }
  __Pyx_INCREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_t_3);
  #else
  __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1078, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1078, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  #endif
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
} else {
  Py_ssize_t index = -1;
  __pyx_t_8 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1078, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_10 = Py_TYPE(__pyx_t_8)->tp_iternext;
  index = 0; __pyx_t_2 = __pyx_t_10(__pyx_t_8); if (unlikely(!__pyx_t_2)) goto __pyx_L21_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_2);
  index = 1; __pyx_t_3 = __pyx_t_10(__pyx_t_8); if (unlikely(!__pyx_t_3)) goto __pyx_L21_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_3);
  if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_8), 2) < 0) __PYX_ERR(0, 1078, __pyx_L1_error)
  __pyx_t_10 = NULL;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  goto __pyx_L22_unpacking_done;
  __pyx_L21_unpacking_failed:;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_10 = NULL;
  if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
  __PYX_ERR(0, 1078, __pyx_L1_error)
  __pyx_L22_unpacking_done:;
}
__pyx_v_derivations = __pyx_t_2;
__pyx_t_2 = 0;
__pyx_v_entries = __pyx_t_3;
__pyx_t_3 = 0;

/* "discodop/disambiguation.pyx":1079
 * 	vitderiv, vitprob = viterbiderivation(chart)
 * 	derivations, entries = getderivations(chart, 1000, True, False, True)
 * 	mpd, _ = marginalize('mpd', derivations, entries, chart)             # <<<<<<<<<<<<<<
 * 	mpp, _ = marginalize('mpp', derivations, entries, chart)
 * 	mcc, _ = marginalize('mcc', derivations, entries, chart)
 */
if (!(likely(PyList_CheckExact(__pyx_v_derivations))||((__pyx_v_derivations) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_derivations)->tp_name), 0))) __PYX_ERR(0, 1079, __pyx_L1_error)
if (!(likely(PyList_CheckExact(__pyx_v_entries))||((__pyx_v_entries) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_entries)->tp_name), 0))) __PYX_ERR(0, 1079, __pyx_L1_error)
if (!(likely(((__pyx_v_chart) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_chart, __pyx_ptype_8discodop_10containers_Chart))))) __PYX_ERR(0, 1079, __pyx_L1_error)
__pyx_t_1 = __pyx_f_8discodop_14disambiguation_marginalize(__pyx_n_u_mpd, ((PyObject*)__pyx_v_derivations), ((PyObject*)__pyx_v_entries), ((struct __pyx_obj_8discodop_10containers_Chart *)__pyx_v_chart), 0, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1079, __pyx_L1_error)
__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, 1079, __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_2 = PyTuple_GET_ITEM(sequence, 1); 
  } else {
    __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
    __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
  }
  __Pyx_INCREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_t_2);
  #else
  __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1079, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1079, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  #endif
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
} else {
  Py_ssize_t index = -1;
  __pyx_t_8 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1079, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_10 = Py_TYPE(__pyx_t_8)->tp_iternext;
  index = 0; __pyx_t_3 = __pyx_t_10(__pyx_t_8); if (unlikely(!__pyx_t_3)) goto __pyx_L23_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_3);
  index = 1; __pyx_t_2 = __pyx_t_10(__pyx_t_8); if (unlikely(!__pyx_t_2)) goto __pyx_L23_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_8), 2) < 0) __PYX_ERR(0, 1079, __pyx_L1_error)
  __pyx_t_10 = NULL;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  goto __pyx_L24_unpacking_done;
  __pyx_L23_unpacking_failed:;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_10 = NULL;
  if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
  __PYX_ERR(0, 1079, __pyx_L1_error)
  __pyx_L24_unpacking_done:;
}
__pyx_v_mpd = __pyx_t_3;
__pyx_t_3 = 0;
__Pyx_DECREF_SET(__pyx_v__, __pyx_t_2);
__pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":1080
 * 	derivations, entries = getderivations(chart, 1000, True, False, True)
 * 	mpd, _ = marginalize('mpd', derivations, entries, chart)
 * 	mpp, _ = marginalize('mpp', derivations, entries, chart)             # <<<<<<<<<<<<<<
 * 	mcc, _ = marginalize('mcc', derivations, entries, chart)
 * 	sldop_, _ = marginalize('sl-dop', derivations, entries, chart, k=1000,
 */
if (!(likely(PyList_CheckExact(__pyx_v_derivations))||((__pyx_v_derivations) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_derivations)->tp_name), 0))) __PYX_ERR(0, 1080, __pyx_L1_error)
if (!(likely(PyList_CheckExact(__pyx_v_entries))||((__pyx_v_entries) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_entries)->tp_name), 0))) __PYX_ERR(0, 1080, __pyx_L1_error)
if (!(likely(((__pyx_v_chart) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_chart, __pyx_ptype_8discodop_10containers_Chart))))) __PYX_ERR(0, 1080, __pyx_L1_error)
__pyx_t_1 = __pyx_f_8discodop_14disambiguation_marginalize(__pyx_n_u_mpp, ((PyObject*)__pyx_v_derivations), ((PyObject*)__pyx_v_entries), ((struct __pyx_obj_8discodop_10containers_Chart *)__pyx_v_chart), 0, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1080, __pyx_L1_error)
__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, 1080, __pyx_L1_error)
  }
  #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
  if (likely(PyTuple_CheckExact(sequence))) {
    __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
    __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
  } else {
    __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
    __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
  }
  __Pyx_INCREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_t_3);
  #else
  __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1080, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1080, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  #endif
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
} else {
  Py_ssize_t index = -1;
  __pyx_t_8 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1080, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_10 = Py_TYPE(__pyx_t_8)->tp_iternext;
  index = 0; __pyx_t_2 = __pyx_t_10(__pyx_t_8); if (unlikely(!__pyx_t_2)) goto __pyx_L25_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_2);
  index = 1; __pyx_t_3 = __pyx_t_10(__pyx_t_8); if (unlikely(!__pyx_t_3)) goto __pyx_L25_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_3);
  if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_8), 2) < 0) __PYX_ERR(0, 1080, __pyx_L1_error)
  __pyx_t_10 = NULL;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  goto __pyx_L26_unpacking_done;
  __pyx_L25_unpacking_failed:;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_10 = NULL;
  if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
  __PYX_ERR(0, 1080, __pyx_L1_error)
  __pyx_L26_unpacking_done:;
}
__pyx_v_mpp = __pyx_t_2;
__pyx_t_2 = 0;
__Pyx_DECREF_SET(__pyx_v__, __pyx_t_3);
__pyx_t_3 = 0;

/* "discodop/disambiguation.pyx":1081
 * 	mpd, _ = marginalize('mpd', derivations, entries, chart)
 * 	mpp, _ = marginalize('mpp', derivations, entries, chart)
 * 	mcc, _ = marginalize('mcc', derivations, entries, chart)             # <<<<<<<<<<<<<<
 * 	sldop_, _ = marginalize('sl-dop', derivations, entries, chart, k=1000,
 * 			sldop_n=7, sent=sent)
 */
if (!(likely(PyList_CheckExact(__pyx_v_derivations))||((__pyx_v_derivations) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_derivations)->tp_name), 0))) __PYX_ERR(0, 1081, __pyx_L1_error)
if (!(likely(PyList_CheckExact(__pyx_v_entries))||((__pyx_v_entries) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_entries)->tp_name), 0))) __PYX_ERR(0, 1081, __pyx_L1_error)
if (!(likely(((__pyx_v_chart) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_chart, __pyx_ptype_8discodop_10containers_Chart))))) __PYX_ERR(0, 1081, __pyx_L1_error)
__pyx_t_1 = __pyx_f_8discodop_14disambiguation_marginalize(__pyx_n_u_mcc, ((PyObject*)__pyx_v_derivations), ((PyObject*)__pyx_v_entries), ((struct __pyx_obj_8discodop_10containers_Chart *)__pyx_v_chart), 0, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1081, __pyx_L1_error)
__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, 1081, __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_2 = PyTuple_GET_ITEM(sequence, 1); 
  } else {
    __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
    __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
  }
  __Pyx_INCREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_t_2);
  #else
  __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1081, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1081, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  #endif
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
} else {
  Py_ssize_t index = -1;
  __pyx_t_8 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1081, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_10 = Py_TYPE(__pyx_t_8)->tp_iternext;
  index = 0; __pyx_t_3 = __pyx_t_10(__pyx_t_8); if (unlikely(!__pyx_t_3)) goto __pyx_L27_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_3);
  index = 1; __pyx_t_2 = __pyx_t_10(__pyx_t_8); if (unlikely(!__pyx_t_2)) goto __pyx_L27_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_8), 2) < 0) __PYX_ERR(0, 1081, __pyx_L1_error)
  __pyx_t_10 = NULL;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  goto __pyx_L28_unpacking_done;
  __pyx_L27_unpacking_failed:;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_10 = NULL;
  if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
  __PYX_ERR(0, 1081, __pyx_L1_error)
  __pyx_L28_unpacking_done:;
}
__pyx_v_mcc = __pyx_t_3;
__pyx_t_3 = 0;
__Pyx_DECREF_SET(__pyx_v__, __pyx_t_2);
__pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":1082
 * 	mpp, _ = marginalize('mpp', derivations, entries, chart)
 * 	mcc, _ = marginalize('mcc', derivations, entries, chart)
 * 	sldop_, _ = marginalize('sl-dop', derivations, entries, chart, k=1000,             # <<<<<<<<<<<<<<
 * 			sldop_n=7, sent=sent)
 * 	sldopsimple, _ = marginalize('sl-dop-simple', derivations, entries,
 */
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_marginalize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1082, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1082, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(__pyx_kp_u_sl_dop);
__Pyx_GIVEREF(__pyx_kp_u_sl_dop);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_u_sl_dop);
__Pyx_INCREF(__pyx_v_derivations);
__Pyx_GIVEREF(__pyx_v_derivations);
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_derivations);
__Pyx_INCREF(__pyx_v_entries);
__Pyx_GIVEREF(__pyx_v_entries);
PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_entries);
__Pyx_INCREF(__pyx_v_chart);
__Pyx_GIVEREF(__pyx_v_chart);
PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_v_chart);
__pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1082, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_k, __pyx_int_1000) < 0) __PYX_ERR(0, 1082, __pyx_L1_error)
if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_sldop_n, __pyx_int_7) < 0) __PYX_ERR(0, 1082, __pyx_L1_error)

/* "discodop/disambiguation.pyx":1083
 * 	mcc, _ = marginalize('mcc', derivations, entries, chart)
 * 	sldop_, _ = marginalize('sl-dop', derivations, entries, chart, k=1000,
 * 			sldop_n=7, sent=sent)             # <<<<<<<<<<<<<<
 * 	sldopsimple, _ = marginalize('sl-dop-simple', derivations, entries,
 * 			chart, k=1000, sldop_n=7, sent=sent)
 */
if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_sent, __pyx_v_sent) < 0) __PYX_ERR(0, 1082, __pyx_L1_error)

/* "discodop/disambiguation.pyx":1082
 * 	mpp, _ = marginalize('mpp', derivations, entries, chart)
 * 	mcc, _ = marginalize('mcc', derivations, entries, chart)
 * 	sldop_, _ = marginalize('sl-dop', derivations, entries, chart, k=1000,             # <<<<<<<<<<<<<<
 * 			sldop_n=7, sent=sent)
 * 	sldopsimple, _ = marginalize('sl-dop-simple', derivations, entries,
 */
__pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1082, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__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(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) {
  PyObject* sequence = __pyx_t_8;
  #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, 1082, __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_2 = PyTuple_GET_ITEM(sequence, 1); 
  } else {
    __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
    __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
  }
  __Pyx_INCREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_t_2);
  #else
  __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1082, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1082, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  #endif
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
} else {
  Py_ssize_t index = -1;
  __pyx_t_1 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1082, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_10 = Py_TYPE(__pyx_t_1)->tp_iternext;
  index = 0; __pyx_t_3 = __pyx_t_10(__pyx_t_1); if (unlikely(!__pyx_t_3)) goto __pyx_L29_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_3);
  index = 1; __pyx_t_2 = __pyx_t_10(__pyx_t_1); if (unlikely(!__pyx_t_2)) goto __pyx_L29_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_1), 2) < 0) __PYX_ERR(0, 1082, __pyx_L1_error)
  __pyx_t_10 = NULL;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  goto __pyx_L30_unpacking_done;
  __pyx_L29_unpacking_failed:;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_10 = NULL;
  if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
  __PYX_ERR(0, 1082, __pyx_L1_error)
  __pyx_L30_unpacking_done:;
}
__pyx_v_sldop_ = __pyx_t_3;
__pyx_t_3 = 0;
__Pyx_DECREF_SET(__pyx_v__, __pyx_t_2);
__pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":1084
 * 	sldop_, _ = marginalize('sl-dop', derivations, entries, chart, k=1000,
 * 			sldop_n=7, sent=sent)
 * 	sldopsimple, _ = marginalize('sl-dop-simple', derivations, entries,             # <<<<<<<<<<<<<<
 * 			chart, k=1000, sldop_n=7, sent=sent)
 * 	short, _ = marginalize('shortest', derivations, entries, chart, sent=sent)
 */
__pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_marginalize); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1084, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);

/* "discodop/disambiguation.pyx":1085
 * 			sldop_n=7, sent=sent)
 * 	sldopsimple, _ = marginalize('sl-dop-simple', derivations, entries,
 * 			chart, k=1000, sldop_n=7, sent=sent)             # <<<<<<<<<<<<<<
 * 	short, _ = marginalize('shortest', derivations, entries, chart, sent=sent)
 * 	derivations, entries = getderivations(chart, 1000, False, True, True)
 */
__pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1084, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(__pyx_kp_u_sl_dop_simple);
__Pyx_GIVEREF(__pyx_kp_u_sl_dop_simple);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_u_sl_dop_simple);
__Pyx_INCREF(__pyx_v_derivations);
__Pyx_GIVEREF(__pyx_v_derivations);
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_derivations);
__Pyx_INCREF(__pyx_v_entries);
__Pyx_GIVEREF(__pyx_v_entries);
PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_entries);
__Pyx_INCREF(__pyx_v_chart);
__Pyx_GIVEREF(__pyx_v_chart);
PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_v_chart);
__pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1085, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_k, __pyx_int_1000) < 0) __PYX_ERR(0, 1085, __pyx_L1_error)
if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_sldop_n, __pyx_int_7) < 0) __PYX_ERR(0, 1085, __pyx_L1_error)
if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_sent, __pyx_v_sent) < 0) __PYX_ERR(0, 1085, __pyx_L1_error)

/* "discodop/disambiguation.pyx":1084
 * 	sldop_, _ = marginalize('sl-dop', derivations, entries, chart, k=1000,
 * 			sldop_n=7, sent=sent)
 * 	sldopsimple, _ = marginalize('sl-dop-simple', derivations, entries,             # <<<<<<<<<<<<<<
 * 			chart, k=1000, sldop_n=7, sent=sent)
 * 	short, _ = marginalize('shortest', derivations, entries, chart, sent=sent)
 */
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1084, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
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, 1084, __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_2 = PyTuple_GET_ITEM(sequence, 1); 
  } else {
    __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
    __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
  }
  __Pyx_INCREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_t_2);
  #else
  __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1084, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1084, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  #endif
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
} else {
  Py_ssize_t index = -1;
  __pyx_t_8 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1084, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_10 = Py_TYPE(__pyx_t_8)->tp_iternext;
  index = 0; __pyx_t_3 = __pyx_t_10(__pyx_t_8); if (unlikely(!__pyx_t_3)) goto __pyx_L31_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_3);
  index = 1; __pyx_t_2 = __pyx_t_10(__pyx_t_8); if (unlikely(!__pyx_t_2)) goto __pyx_L31_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_8), 2) < 0) __PYX_ERR(0, 1084, __pyx_L1_error)
  __pyx_t_10 = NULL;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  goto __pyx_L32_unpacking_done;
  __pyx_L31_unpacking_failed:;
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_10 = NULL;
  if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
  __PYX_ERR(0, 1084, __pyx_L1_error)
  __pyx_L32_unpacking_done:;
}
__pyx_v_sldopsimple = __pyx_t_3;
__pyx_t_3 = 0;
__Pyx_DECREF_SET(__pyx_v__, __pyx_t_2);
__pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":1086
 * 	sldopsimple, _ = marginalize('sl-dop-simple', derivations, entries,
 * 			chart, k=1000, sldop_n=7, sent=sent)
 * 	short, _ = marginalize('shortest', derivations, entries, chart, sent=sent)             # <<<<<<<<<<<<<<
 * 	derivations, entries = getderivations(chart, 1000, False, True, True)
 * 	mppsampled, _ = marginalize('mpp', derivations, entries, chart)
 */
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_marginalize); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1086, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1086, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_INCREF(__pyx_n_u_shortest);
__Pyx_GIVEREF(__pyx_n_u_shortest);
PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_n_u_shortest);
__Pyx_INCREF(__pyx_v_derivations);
__Pyx_GIVEREF(__pyx_v_derivations);
PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_derivations);
__Pyx_INCREF(__pyx_v_entries);
__Pyx_GIVEREF(__pyx_v_entries);
PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_entries);
__Pyx_INCREF(__pyx_v_chart);
__Pyx_GIVEREF(__pyx_v_chart);
PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_v_chart);
__pyx_t_3 = PyDict_New(); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1086, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_sent, __pyx_v_sent) < 0) __PYX_ERR(0, 1086, __pyx_L1_error)
__pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1086, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__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(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) {
  PyObject* sequence = __pyx_t_8;
  #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, 1086, __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_2 = PyTuple_GET_ITEM(sequence, 1); 
  } else {
    __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
    __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
  }
  __Pyx_INCREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_t_2);
  #else
  __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1086, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1086, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  #endif
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
} else {
  Py_ssize_t index = -1;
  __pyx_t_1 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1086, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_10 = Py_TYPE(__pyx_t_1)->tp_iternext;
  index = 0; __pyx_t_3 = __pyx_t_10(__pyx_t_1); if (unlikely(!__pyx_t_3)) goto __pyx_L33_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_3);
  index = 1; __pyx_t_2 = __pyx_t_10(__pyx_t_1); if (unlikely(!__pyx_t_2)) goto __pyx_L33_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_1), 2) < 0) __PYX_ERR(0, 1086, __pyx_L1_error)
  __pyx_t_10 = NULL;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  goto __pyx_L34_unpacking_done;
  __pyx_L33_unpacking_failed:;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_10 = NULL;
  if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
  __PYX_ERR(0, 1086, __pyx_L1_error)
  __pyx_L34_unpacking_done:;
}
__pyx_v_short = __pyx_t_3;
__pyx_t_3 = 0;
__Pyx_DECREF_SET(__pyx_v__, __pyx_t_2);
__pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":1087
 * 			chart, k=1000, sldop_n=7, sent=sent)
 * 	short, _ = marginalize('shortest', derivations, entries, chart, sent=sent)
 * 	derivations, entries = getderivations(chart, 1000, False, True, True)             # <<<<<<<<<<<<<<
 * 	mppsampled, _ = marginalize('mpp', derivations, entries, chart)
 * 	print('\nvit:\t\t%s %r' % (REMOVEIDS.sub('', vitderiv),
 */
if (!(likely(((__pyx_v_chart) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_chart, __pyx_ptype_8discodop_10containers_Chart))))) __PYX_ERR(0, 1087, __pyx_L1_error)
__pyx_t_12.__pyx_n = 3;
__pyx_t_12.kbest = 0;
__pyx_t_12.sample = 1;
__pyx_t_12.derivstrings = Py_True;
__pyx_t_8 = __pyx_f_8discodop_14disambiguation_getderivations(((struct __pyx_obj_8discodop_10containers_Chart *)__pyx_v_chart), 0x3E8, 0, &__pyx_t_12); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1087, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
if ((likely(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) {
  PyObject* sequence = __pyx_t_8;
  #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, 1087, __pyx_L1_error)
  }
  #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
  if (likely(PyTuple_CheckExact(sequence))) {
    __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); 
    __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); 
  } else {
    __pyx_t_2 = PyList_GET_ITEM(sequence, 0); 
    __pyx_t_3 = PyList_GET_ITEM(sequence, 1); 
  }
  __Pyx_INCREF(__pyx_t_2);
  __Pyx_INCREF(__pyx_t_3);
  #else
  __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1087, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1087, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  #endif
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
} else {
  Py_ssize_t index = -1;
  __pyx_t_1 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1087, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_10 = Py_TYPE(__pyx_t_1)->tp_iternext;
  index = 0; __pyx_t_2 = __pyx_t_10(__pyx_t_1); if (unlikely(!__pyx_t_2)) goto __pyx_L35_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_2);
  index = 1; __pyx_t_3 = __pyx_t_10(__pyx_t_1); if (unlikely(!__pyx_t_3)) goto __pyx_L35_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_3);
  if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_1), 2) < 0) __PYX_ERR(0, 1087, __pyx_L1_error)
  __pyx_t_10 = NULL;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  goto __pyx_L36_unpacking_done;
  __pyx_L35_unpacking_failed:;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_10 = NULL;
  if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
  __PYX_ERR(0, 1087, __pyx_L1_error)
  __pyx_L36_unpacking_done:;
}
__Pyx_DECREF_SET(__pyx_v_derivations, __pyx_t_2);
__pyx_t_2 = 0;
__Pyx_DECREF_SET(__pyx_v_entries, __pyx_t_3);
__pyx_t_3 = 0;

/* "discodop/disambiguation.pyx":1088
 * 	short, _ = marginalize('shortest', derivations, entries, chart, sent=sent)
 * 	derivations, entries = getderivations(chart, 1000, False, True, True)
 * 	mppsampled, _ = marginalize('mpp', derivations, entries, chart)             # <<<<<<<<<<<<<<
 * 	print('\nvit:\t\t%s %r' % (REMOVEIDS.sub('', vitderiv),
 * 			exp(-vitprob)),
 */
if (!(likely(PyList_CheckExact(__pyx_v_derivations))||((__pyx_v_derivations) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_derivations)->tp_name), 0))) __PYX_ERR(0, 1088, __pyx_L1_error)
if (!(likely(PyList_CheckExact(__pyx_v_entries))||((__pyx_v_entries) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_v_entries)->tp_name), 0))) __PYX_ERR(0, 1088, __pyx_L1_error)
if (!(likely(((__pyx_v_chart) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_chart, __pyx_ptype_8discodop_10containers_Chart))))) __PYX_ERR(0, 1088, __pyx_L1_error)
__pyx_t_8 = __pyx_f_8discodop_14disambiguation_marginalize(__pyx_n_u_mpp, ((PyObject*)__pyx_v_derivations), ((PyObject*)__pyx_v_entries), ((struct __pyx_obj_8discodop_10containers_Chart *)__pyx_v_chart), 0, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1088, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
if ((likely(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) {
  PyObject* sequence = __pyx_t_8;
  #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, 1088, __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_2 = PyTuple_GET_ITEM(sequence, 1); 
  } else {
    __pyx_t_3 = PyList_GET_ITEM(sequence, 0); 
    __pyx_t_2 = PyList_GET_ITEM(sequence, 1); 
  }
  __Pyx_INCREF(__pyx_t_3);
  __Pyx_INCREF(__pyx_t_2);
  #else
  __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1088, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1088, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
  #endif
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
} else {
  Py_ssize_t index = -1;
  __pyx_t_1 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1088, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
  __pyx_t_10 = Py_TYPE(__pyx_t_1)->tp_iternext;
  index = 0; __pyx_t_3 = __pyx_t_10(__pyx_t_1); if (unlikely(!__pyx_t_3)) goto __pyx_L37_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_3);
  index = 1; __pyx_t_2 = __pyx_t_10(__pyx_t_1); if (unlikely(!__pyx_t_2)) goto __pyx_L37_unpacking_failed;
  __Pyx_GOTREF(__pyx_t_2);
  if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_1), 2) < 0) __PYX_ERR(0, 1088, __pyx_L1_error)
  __pyx_t_10 = NULL;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  goto __pyx_L38_unpacking_done;
  __pyx_L37_unpacking_failed:;
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  __pyx_t_10 = NULL;
  if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
  __PYX_ERR(0, 1088, __pyx_L1_error)
  __pyx_L38_unpacking_done:;
}
__pyx_v_mppsampled = __pyx_t_3;
__pyx_t_3 = 0;
__Pyx_DECREF_SET(__pyx_v__, __pyx_t_2);
__pyx_t_2 = 0;

/* "discodop/disambiguation.pyx":1089
 * 	derivations, entries = getderivations(chart, 1000, False, True, True)
 * 	mppsampled, _ = marginalize('mpp', derivations, entries, chart)
 * 	print('\nvit:\t\t%s %r' % (REMOVEIDS.sub('', vitderiv),             # <<<<<<<<<<<<<<
 * 			exp(-vitprob)),
 * 		'MPD:\t\t%s %r' % e(mpd), 'MCC:\t\t%s %r' % e(mcc),
 */
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_REMOVEIDS); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1089, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_sub); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1089, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_2 = NULL;
__pyx_t_9 = 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_9 = 1;
  }
}
#if CYTHON_FAST_PYCALL
if (PyFunction_Check(__pyx_t_3)) {
  PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_kp_u__4, __pyx_v_vitderiv};
  __pyx_t_8 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1089, __pyx_L1_error)
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GOTREF(__pyx_t_8);
} else
#endif
#if CYTHON_FAST_PYCCALL
if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
  PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_kp_u__4, __pyx_v_vitderiv};
  __pyx_t_8 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_9, 2+__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1089, __pyx_L1_error)
  __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GOTREF(__pyx_t_8);
} else
#endif
{
  __pyx_t_1 = PyTuple_New(2+__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1089, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_1);
  if (__pyx_t_2) {
    __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); __pyx_t_2 = NULL;
  }
  __Pyx_INCREF(__pyx_kp_u__4);
  __Pyx_GIVEREF(__pyx_kp_u__4);
  PyTuple_SET_ITEM(__pyx_t_1, 0+__pyx_t_9, __pyx_kp_u__4);
  __Pyx_INCREF(__pyx_v_vitderiv);
  __Pyx_GIVEREF(__pyx_v_vitderiv);
  PyTuple_SET_ITEM(__pyx_t_1, 1+__pyx_t_9, __pyx_v_vitderiv);
  __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_1, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1089, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_8);
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;

/* "discodop/disambiguation.pyx":1090
 * 	mppsampled, _ = marginalize('mpp', derivations, entries, chart)
 * 	print('\nvit:\t\t%s %r' % (REMOVEIDS.sub('', vitderiv),
 * 			exp(-vitprob)),             # <<<<<<<<<<<<<<
 * 		'MPD:\t\t%s %r' % e(mpd), 'MCC:\t\t%s %r' % e(mcc),
 * 		'MPP:\t\t%s %r' % e(mpp), 'MPP sampled:\t%s %r' % e(mppsampled),
 */
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_exp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1090, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyNumber_Negative(__pyx_v_vitprob); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1090, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__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_3 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1090, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __Pyx_GOTREF(__pyx_t_3);
} else {
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_2};
    __pyx_t_3 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1090, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[2] = {__pyx_t_4, __pyx_t_2};
    __pyx_t_3 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1090, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  } else
  #endif
  {
    __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1090, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_4); __pyx_t_4 = NULL;
    __Pyx_GIVEREF(__pyx_t_2);
    PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_2);
    __pyx_t_2 = 0;
    __pyx_t_3 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_7, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1090, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":1089
 * 	derivations, entries = getderivations(chart, 1000, False, True, True)
 * 	mppsampled, _ = marginalize('mpp', derivations, entries, chart)
 * 	print('\nvit:\t\t%s %r' % (REMOVEIDS.sub('', vitderiv),             # <<<<<<<<<<<<<<
 * 			exp(-vitprob)),
 * 		'MPD:\t\t%s %r' % e(mpd), 'MCC:\t\t%s %r' % e(mcc),
 */
__pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1089, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_GIVEREF(__pyx_t_8);
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8);
__Pyx_GIVEREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3);
__pyx_t_8 = 0;
__pyx_t_3 = 0;
__pyx_t_3 = PyUnicode_Format(__pyx_kp_u_vit_s_r, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1089, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":1091
 * 	print('\nvit:\t\t%s %r' % (REMOVEIDS.sub('', vitderiv),
 * 			exp(-vitprob)),
 * 		'MPD:\t\t%s %r' % e(mpd), 'MCC:\t\t%s %r' % e(mcc),             # <<<<<<<<<<<<<<
 * 		'MPP:\t\t%s %r' % e(mpp), 'MPP sampled:\t%s %r' % e(mppsampled),
 * 		'SL-DOP n=7:\t%s %r' % e(sldop_),
 */
__pyx_t_1 = __pyx_pf_8discodop_14disambiguation_4test_e(__pyx_v_e, __pyx_v_mpd); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1091, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_8 = PyUnicode_Format(__pyx_kp_u_MPD_s_r, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1091, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = __pyx_pf_8discodop_14disambiguation_4test_e(__pyx_v_e, __pyx_v_mcc); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1091, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_7 = PyUnicode_Format(__pyx_kp_u_MCC_s_r, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1091, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":1092
 * 			exp(-vitprob)),
 * 		'MPD:\t\t%s %r' % e(mpd), 'MCC:\t\t%s %r' % e(mcc),
 * 		'MPP:\t\t%s %r' % e(mpp), 'MPP sampled:\t%s %r' % e(mppsampled),             # <<<<<<<<<<<<<<
 * 		'SL-DOP n=7:\t%s %r' % e(sldop_),
 * 		'simple SL-DOP:\t%s %r' % e(sldopsimple),
 */
__pyx_t_1 = __pyx_pf_8discodop_14disambiguation_4test_e(__pyx_v_e, __pyx_v_mpp); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1092, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyUnicode_Format(__pyx_kp_u_MPP_s_r, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1092, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_1 = __pyx_pf_8discodop_14disambiguation_4test_e(__pyx_v_e, __pyx_v_mppsampled); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1092, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_4 = PyUnicode_Format(__pyx_kp_u_MPP_sampled_s_r, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1092, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":1093
 * 		'MPD:\t\t%s %r' % e(mpd), 'MCC:\t\t%s %r' % e(mcc),
 * 		'MPP:\t\t%s %r' % e(mpp), 'MPP sampled:\t%s %r' % e(mppsampled),
 * 		'SL-DOP n=7:\t%s %r' % e(sldop_),             # <<<<<<<<<<<<<<
 * 		'simple SL-DOP:\t%s %r' % e(sldopsimple),
 * 		'shortest:\t%s %r' % e(short), sep='\n')
 */
__pyx_t_1 = __pyx_pf_8discodop_14disambiguation_4test_e(__pyx_v_e, __pyx_v_sldop_); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1093, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_13 = PyUnicode_Format(__pyx_kp_u_SL_DOP_n_7_s_r, __pyx_t_1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1093, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_13);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":1094
 * 		'MPP:\t\t%s %r' % e(mpp), 'MPP sampled:\t%s %r' % e(mppsampled),
 * 		'SL-DOP n=7:\t%s %r' % e(sldop_),
 * 		'simple SL-DOP:\t%s %r' % e(sldopsimple),             # <<<<<<<<<<<<<<
 * 		'shortest:\t%s %r' % e(short), sep='\n')
 * 
 */
__pyx_t_1 = __pyx_pf_8discodop_14disambiguation_4test_e(__pyx_v_e, __pyx_v_sldopsimple); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1094, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_14 = PyUnicode_Format(__pyx_kp_u_simple_SL_DOP_s_r, __pyx_t_1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1094, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_14);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":1095
 * 		'SL-DOP n=7:\t%s %r' % e(sldop_),
 * 		'simple SL-DOP:\t%s %r' % e(sldopsimple),
 * 		'shortest:\t%s %r' % e(short), sep='\n')             # <<<<<<<<<<<<<<
 * 
 * __all__ = ['getderivations', 'marginalize', 'gettree', 'recoverfragments',
 */
__pyx_t_1 = __pyx_pf_8discodop_14disambiguation_4test_e(__pyx_v_e, __pyx_v_short); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1095, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_15 = PyUnicode_Format(__pyx_kp_u_shortest_s_r, __pyx_t_1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1095, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_15);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

/* "discodop/disambiguation.pyx":1089
 * 	derivations, entries = getderivations(chart, 1000, False, True, True)
 * 	mppsampled, _ = marginalize('mpp', derivations, entries, chart)
 * 	print('\nvit:\t\t%s %r' % (REMOVEIDS.sub('', vitderiv),             # <<<<<<<<<<<<<<
 * 			exp(-vitprob)),
 * 		'MPD:\t\t%s %r' % e(mpd), 'MCC:\t\t%s %r' % e(mcc),
 */
__pyx_t_1 = PyTuple_New(8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1089, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_GIVEREF(__pyx_t_3);
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3);
__Pyx_GIVEREF(__pyx_t_8);
PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_8);
__Pyx_GIVEREF(__pyx_t_7);
PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_7);
__Pyx_GIVEREF(__pyx_t_2);
PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_2);
__Pyx_GIVEREF(__pyx_t_4);
PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_t_4);
__Pyx_GIVEREF(__pyx_t_13);
PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_t_13);
__Pyx_GIVEREF(__pyx_t_14);
PyTuple_SET_ITEM(__pyx_t_1, 6, __pyx_t_14);
__Pyx_GIVEREF(__pyx_t_15);
PyTuple_SET_ITEM(__pyx_t_1, 7, __pyx_t_15);
__pyx_t_3 = 0;
__pyx_t_8 = 0;
__pyx_t_7 = 0;
__pyx_t_2 = 0;
__pyx_t_4 = 0;
__pyx_t_13 = 0;
__pyx_t_14 = 0;
__pyx_t_15 = 0;

/* "discodop/disambiguation.pyx":1095
 * 		'SL-DOP n=7:\t%s %r' % e(sldop_),
 * 		'simple SL-DOP:\t%s %r' % e(sldopsimple),
 * 		'shortest:\t%s %r' % e(short), sep='\n')             # <<<<<<<<<<<<<<
 * 
 * __all__ = ['getderivations', 'marginalize', 'gettree', 'recoverfragments',
 */
__pyx_t_15 = PyDict_New(); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 1095, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_15);
if (PyDict_SetItem(__pyx_t_15, __pyx_n_s_sep, __pyx_kp_u__39) < 0) __PYX_ERR(0, 1095, __pyx_L1_error)

/* "discodop/disambiguation.pyx":1089
 * 	derivations, entries = getderivations(chart, 1000, False, True, True)
 * 	mppsampled, _ = marginalize('mpp', derivations, entries, chart)
 * 	print('\nvit:\t\t%s %r' % (REMOVEIDS.sub('', vitderiv),             # <<<<<<<<<<<<<<
 * 			exp(-vitprob)),
 * 		'MPD:\t\t%s %r' % e(mpd), 'MCC:\t\t%s %r' % e(mcc),
 */
__pyx_t_14 = __Pyx_PyObject_Call(__pyx_builtin_print, __pyx_t_1, __pyx_t_15); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 1089, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_14);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
__Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;

/* "discodop/disambiguation.pyx":1050
 * 
 * 
 * def test():             # <<<<<<<<<<<<<<
 * 	from .grammar import dopreduction
 * 	from .containers import Grammar
 */

/* 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_7);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_XDECREF(__pyx_t_13);
__Pyx_XDECREF(__pyx_t_14);
__Pyx_XDECREF(__pyx_t_15);
__Pyx_AddTraceback("discodop.disambiguation.test", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = NULL;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_dopreduction);
__Pyx_XDECREF(__pyx_v_Grammar);
__Pyx_XDECREF(__pyx_v_plcfrs);
__Pyx_XDECREF(__pyx_v_e);
__Pyx_XDECREF(__pyx_v_trees);
__Pyx_XDECREF(__pyx_v_sents);
__Pyx_XDECREF(__pyx_v_xgrammar);
__Pyx_XDECREF(__pyx_v_altweights);
__Pyx_XDECREF(__pyx_v_grammar);
__Pyx_XDECREF(__pyx_v_sent);
__Pyx_XDECREF(__pyx_v_chart);
__Pyx_XDECREF(__pyx_v__);
__Pyx_XDECREF(__pyx_v_vitderiv);
__Pyx_XDECREF(__pyx_v_vitprob);
__Pyx_XDECREF(__pyx_v_derivations);
__Pyx_XDECREF(__pyx_v_entries);
__Pyx_XDECREF(__pyx_v_mpd);
__Pyx_XDECREF(__pyx_v_mpp);
__Pyx_XDECREF(__pyx_v_mcc);
__Pyx_XDECREF(__pyx_v_sldop_);
__Pyx_XDECREF(__pyx_v_sldopsimple);
__Pyx_XDECREF(__pyx_v_short);
__Pyx_XDECREF(__pyx_v_mppsampled);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "containers.pxd":292
 * 
 * 
 * cdef inline FatChartItem new_FatChartItem(uint32_t label):             # <<<<<<<<<<<<<<
 * 	cdef FatChartItem item = FatChartItem.__new__(FatChartItem)
 * 	item.label = label
 */

static CYTHON_INLINE struct __pyx_obj_8discodop_10containers_FatChartItem *__pyx_f_8discodop_10containers_new_FatChartItem(uint32_t __pyx_v_label) {
struct __pyx_obj_8discodop_10containers_FatChartItem *__pyx_v_item = 0;
struct __pyx_obj_8discodop_10containers_FatChartItem *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
__Pyx_RefNannySetupContext("new_FatChartItem", 0);

/* "containers.pxd":293
 * 
 * cdef inline FatChartItem new_FatChartItem(uint32_t label):
 * 	cdef FatChartItem item = FatChartItem.__new__(FatChartItem)             # <<<<<<<<<<<<<<
 * 	item.label = label
 * 	# NB: since item.vec is a static array, its elements are initialized to 0.
 */
__pyx_t_1 = __Pyx_tp_new(((PyObject *)__pyx_ptype_8discodop_10containers_FatChartItem), __pyx_empty_tuple); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 293, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8discodop_10containers_FatChartItem)))) __PYX_ERR(1, 293, __pyx_L1_error)
__pyx_v_item = ((struct __pyx_obj_8discodop_10containers_FatChartItem *)__pyx_t_1);
__pyx_t_1 = 0;

/* "containers.pxd":294
 * cdef inline FatChartItem new_FatChartItem(uint32_t label):
 * 	cdef FatChartItem item = FatChartItem.__new__(FatChartItem)
 * 	item.label = label             # <<<<<<<<<<<<<<
 * 	# NB: since item.vec is a static array, its elements are initialized to 0.
 * 	return item
 */
__pyx_v_item->__pyx_base.label = __pyx_v_label;

/* "containers.pxd":296
 * 	item.label = label
 * 	# NB: since item.vec is a static array, its elements are initialized to 0.
 * 	return item             # <<<<<<<<<<<<<<
 * 
 * 
 */
__Pyx_XDECREF(((PyObject *)__pyx_r));
__Pyx_INCREF(((PyObject *)__pyx_v_item));
__pyx_r = __pyx_v_item;
goto __pyx_L0;

/* "containers.pxd":292
 * 
 * 
 * cdef inline FatChartItem new_FatChartItem(uint32_t label):             # <<<<<<<<<<<<<<
 * 	cdef FatChartItem item = FatChartItem.__new__(FatChartItem)
 * 	item.label = label
 */

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("discodop.containers.new_FatChartItem", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_item);
__Pyx_XGIVEREF((PyObject *)__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "containers.pxd":299
 * 
 * 
 * cdef inline SmallChartItem new_SmallChartItem(uint32_t label, uint64_t vec):             # <<<<<<<<<<<<<<
 * 	cdef SmallChartItem item = SmallChartItem.__new__(SmallChartItem)
 * 	item.label = label
 */

static CYTHON_INLINE struct __pyx_obj_8discodop_10containers_SmallChartItem *__pyx_f_8discodop_10containers_new_SmallChartItem(uint32_t __pyx_v_label, uint64_t __pyx_v_vec) {
struct __pyx_obj_8discodop_10containers_SmallChartItem *__pyx_v_item = 0;
struct __pyx_obj_8discodop_10containers_SmallChartItem *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
__Pyx_RefNannySetupContext("new_SmallChartItem", 0);

/* "containers.pxd":300
 * 
 * cdef inline SmallChartItem new_SmallChartItem(uint32_t label, uint64_t vec):
 * 	cdef SmallChartItem item = SmallChartItem.__new__(SmallChartItem)             # <<<<<<<<<<<<<<
 * 	item.label = label
 * 	item.vec = vec
 */
__pyx_t_1 = __Pyx_tp_new(((PyObject *)__pyx_ptype_8discodop_10containers_SmallChartItem), __pyx_empty_tuple); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 300, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8discodop_10containers_SmallChartItem)))) __PYX_ERR(1, 300, __pyx_L1_error)
__pyx_v_item = ((struct __pyx_obj_8discodop_10containers_SmallChartItem *)__pyx_t_1);
__pyx_t_1 = 0;

/* "containers.pxd":301
 * cdef inline SmallChartItem new_SmallChartItem(uint32_t label, uint64_t vec):
 * 	cdef SmallChartItem item = SmallChartItem.__new__(SmallChartItem)
 * 	item.label = label             # <<<<<<<<<<<<<<
 * 	item.vec = vec
 * 	return item
 */
__pyx_v_item->__pyx_base.label = __pyx_v_label;

/* "containers.pxd":302
 * 	cdef SmallChartItem item = SmallChartItem.__new__(SmallChartItem)
 * 	item.label = label
 * 	item.vec = vec             # <<<<<<<<<<<<<<
 * 	return item
 * 
 */
__pyx_v_item->vec = __pyx_v_vec;

/* "containers.pxd":303
 * 	item.label = label
 * 	item.vec = vec
 * 	return item             # <<<<<<<<<<<<<<
 * 
 * 
 */
__Pyx_XDECREF(((PyObject *)__pyx_r));
__Pyx_INCREF(((PyObject *)__pyx_v_item));
__pyx_r = __pyx_v_item;
goto __pyx_L0;

/* "containers.pxd":299
 * 
 * 
 * cdef inline SmallChartItem new_SmallChartItem(uint32_t label, uint64_t vec):             # <<<<<<<<<<<<<<
 * 	cdef SmallChartItem item = SmallChartItem.__new__(SmallChartItem)
 * 	item.label = label
 */

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("discodop.containers.new_SmallChartItem", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_item);
__Pyx_XGIVEREF((PyObject *)__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "containers.pxd":306
 * 
 * 
 * cdef inline RankedEdge new_RankedEdge(             # <<<<<<<<<<<<<<
 * 		object head, Edge *edge, int left, int right):
 * 	cdef RankedEdge rankededge = RankedEdge.__new__(RankedEdge)
 */

static CYTHON_INLINE struct __pyx_obj_8discodop_10containers_RankedEdge *__pyx_f_8discodop_10containers_new_RankedEdge(PyObject *__pyx_v_head, struct __pyx_t_8discodop_10containers_Edge *__pyx_v_edge, int __pyx_v_left, int __pyx_v_right) {
struct __pyx_obj_8discodop_10containers_RankedEdge *__pyx_v_rankededge = 0;
struct __pyx_obj_8discodop_10containers_RankedEdge *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
__Pyx_RefNannySetupContext("new_RankedEdge", 0);

/* "containers.pxd":308
 * cdef inline RankedEdge new_RankedEdge(
 * 		object head, Edge *edge, int left, int right):
 * 	cdef RankedEdge rankededge = RankedEdge.__new__(RankedEdge)             # <<<<<<<<<<<<<<
 * 	rankededge.head = head
 * 	rankededge.edge = edge
 */
__pyx_t_1 = __Pyx_tp_new(((PyObject *)__pyx_ptype_8discodop_10containers_RankedEdge), __pyx_empty_tuple); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 308, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8discodop_10containers_RankedEdge)))) __PYX_ERR(1, 308, __pyx_L1_error)
__pyx_v_rankededge = ((struct __pyx_obj_8discodop_10containers_RankedEdge *)__pyx_t_1);
__pyx_t_1 = 0;

/* "containers.pxd":309
 * 		object head, Edge *edge, int left, int right):
 * 	cdef RankedEdge rankededge = RankedEdge.__new__(RankedEdge)
 * 	rankededge.head = head             # <<<<<<<<<<<<<<
 * 	rankededge.edge = edge
 * 	rankededge.left = left
 */
__Pyx_INCREF(__pyx_v_head);
__Pyx_GIVEREF(__pyx_v_head);
__Pyx_GOTREF(__pyx_v_rankededge->head);
__Pyx_DECREF(__pyx_v_rankededge->head);
__pyx_v_rankededge->head = __pyx_v_head;

/* "containers.pxd":310
 * 	cdef RankedEdge rankededge = RankedEdge.__new__(RankedEdge)
 * 	rankededge.head = head
 * 	rankededge.edge = edge             # <<<<<<<<<<<<<<
 * 	rankededge.left = left
 * 	rankededge.right = right
 */
__pyx_v_rankededge->edge = __pyx_v_edge;

/* "containers.pxd":311
 * 	rankededge.head = head
 * 	rankededge.edge = edge
 * 	rankededge.left = left             # <<<<<<<<<<<<<<
 * 	rankededge.right = right
 * 	return rankededge
 */
__pyx_v_rankededge->left = __pyx_v_left;

/* "containers.pxd":312
 * 	rankededge.edge = edge
 * 	rankededge.left = left
 * 	rankededge.right = right             # <<<<<<<<<<<<<<
 * 	return rankededge
 * 
 */
__pyx_v_rankededge->right = __pyx_v_right;

/* "containers.pxd":313
 * 	rankededge.left = left
 * 	rankededge.right = right
 * 	return rankededge             # <<<<<<<<<<<<<<
 * 
 * 
 */
__Pyx_XDECREF(((PyObject *)__pyx_r));
__Pyx_INCREF(((PyObject *)__pyx_v_rankededge));
__pyx_r = __pyx_v_rankededge;
goto __pyx_L0;

/* "containers.pxd":306
 * 
 * 
 * cdef inline RankedEdge new_RankedEdge(             # <<<<<<<<<<<<<<
 * 		object head, Edge *edge, int left, int right):
 * 	cdef RankedEdge rankededge = RankedEdge.__new__(RankedEdge)
 */

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("discodop.containers.new_RankedEdge", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_rankededge);
__Pyx_XGIVEREF((PyObject *)__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "containers.pxd":317
 * 
 * # defined here because circular import.
 * cdef inline size_t cellidx(short start, short end, short lensent,             # <<<<<<<<<<<<<<
 * 		uint32_t nonterminals):
 * 	"""Return an index for a regular three dimensional array.
 */

static CYTHON_INLINE size_t __pyx_f_8discodop_10containers_cellidx(short __pyx_v_start, short __pyx_v_end, short __pyx_v_lensent, uint32_t __pyx_v_nonterminals) {
size_t __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("cellidx", 0);

/* "containers.pxd":322
 * 
 * 	``chart[start][end][0] => chart[idx]`` """
 * 	return (start * lensent + (end - 1)) * nonterminals             # <<<<<<<<<<<<<<
 * 
 * 
 */
__pyx_r = (((__pyx_v_start * __pyx_v_lensent) + (__pyx_v_end - 1)) * __pyx_v_nonterminals);
goto __pyx_L0;

/* "containers.pxd":317
 * 
 * # defined here because circular import.
 * cdef inline size_t cellidx(short start, short end, short lensent,             # <<<<<<<<<<<<<<
 * 		uint32_t nonterminals):
 * 	"""Return an index for a regular three dimensional array.
 */

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

/* "containers.pxd":325
 * 
 * 
 * cdef inline size_t compactcellidx(short start, short end, short lensent,             # <<<<<<<<<<<<<<
 * 		uint32_t nonterminals):
 * 	"""Return an index to a triangular array, given start < end.
 */

static CYTHON_INLINE size_t __pyx_f_8discodop_10containers_compactcellidx(short __pyx_v_start, short __pyx_v_end, short __pyx_v_lensent, uint32_t __pyx_v_nonterminals) {
size_t __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("compactcellidx", 0);

/* "containers.pxd":329
 * 	"""Return an index to a triangular array, given start < end.
 * 	The result of this function is the index to chart[start][end][0]."""
 * 	return nonterminals * (lensent * start             # <<<<<<<<<<<<<<
 * 			- ((start - 1) * start / 2) + end - start - 1)
 * 
 */
__pyx_r = (__pyx_v_nonterminals * (((((__pyx_v_lensent * __pyx_v_start) - (((__pyx_v_start - 1) * __pyx_v_start) / 2)) + __pyx_v_end) - __pyx_v_start) - 1));
goto __pyx_L0;

/* "containers.pxd":325
 * 
 * 
 * cdef inline size_t compactcellidx(short start, short end, short lensent,             # <<<<<<<<<<<<<<
 * 		uint32_t nonterminals):
 * 	"""Return an index to a triangular array, given start < end.
 */

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

/* "containers.pxd":336
 * 
 * 
 * cdef inline logprobadd(x, y):             # <<<<<<<<<<<<<<
 * 	""" Add two log probabilities in log space.
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_8discodop_10containers_logprobadd(PyObject *__pyx_v_x, PyObject *__pyx_v_y) {
PyObject *__pyx_v_diff = 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;
int __pyx_t_5;
PyObject *__pyx_t_6 = NULL;
PyObject *__pyx_t_7 = NULL;
__Pyx_RefNannySetupContext("logprobadd", 0);

/* "containers.pxd":346
 * 	:source: https://facwiki.cs.byu.edu/nlp/index.php/Log_Domain_Computations
 * 	"""
 * 	if isinf(x):             # <<<<<<<<<<<<<<
 * 		return y
 * 	elif isinf(y):
 */
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_isinf); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 346, __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_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 346, __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_x};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 346, __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_x};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 346, __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(1, 346, __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_x);
    __Pyx_GIVEREF(__pyx_v_x);
    PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_x);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 346, __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_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(1, 346, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (__pyx_t_5) {

  /* "containers.pxd":347
 * 	"""
 * 	if isinf(x):
 * 		return y             # <<<<<<<<<<<<<<
 * 	elif isinf(y):
 * 		return x
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_y);
  __pyx_r = __pyx_v_y;
  goto __pyx_L0;

  /* "containers.pxd":346
 * 	:source: https://facwiki.cs.byu.edu/nlp/index.php/Log_Domain_Computations
 * 	"""
 * 	if isinf(x):             # <<<<<<<<<<<<<<
 * 		return y
 * 	elif isinf(y):
 */
}

/* "containers.pxd":348
 * 	if isinf(x):
 * 		return y
 * 	elif isinf(y):             # <<<<<<<<<<<<<<
 * 		return x
 * 	# If one value is much smaller than the other, keep the larger value.
 */
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_isinf); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 348, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_4 = NULL;
if (CYTHON_UNPACK_METHODS && unlikely(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_v_y); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 348, __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_4, __pyx_v_y};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 348, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 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_4, __pyx_v_y};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 348, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
    __Pyx_GOTREF(__pyx_t_1);
  } else
  #endif
  {
    __pyx_t_3 = PyTuple_New(1+1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 348, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_3);
    __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_4); __pyx_t_4 = NULL;
    __Pyx_INCREF(__pyx_v_y);
    __Pyx_GIVEREF(__pyx_v_y);
    PyTuple_SET_ITEM(__pyx_t_3, 0+1, __pyx_v_y);
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 348, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  }
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(1, 348, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (__pyx_t_5) {

  /* "containers.pxd":349
 * 		return y
 * 	elif isinf(y):
 * 		return x             # <<<<<<<<<<<<<<
 * 	# If one value is much smaller than the other, keep the larger value.
 * 	elif x < (y - 460):  # log(1e200)
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_x);
  __pyx_r = __pyx_v_x;
  goto __pyx_L0;

  /* "containers.pxd":348
 * 	if isinf(x):
 * 		return y
 * 	elif isinf(y):             # <<<<<<<<<<<<<<
 * 		return x
 * 	# If one value is much smaller than the other, keep the larger value.
 */
}

/* "containers.pxd":351
 * 		return x
 * 	# If one value is much smaller than the other, keep the larger value.
 * 	elif x < (y - 460):  # log(1e200)             # <<<<<<<<<<<<<<
 * 		return y
 * 	elif y < (x - 460):  # log(1e200)
 */
__pyx_t_1 = __Pyx_PyInt_SubtractObjC(__pyx_v_y, __pyx_int_460, 0x1CC, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 351, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_2 = PyObject_RichCompare(__pyx_v_x, __pyx_t_1, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 351, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(1, 351, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_5) {

  /* "containers.pxd":352
 * 	# If one value is much smaller than the other, keep the larger value.
 * 	elif x < (y - 460):  # log(1e200)
 * 		return y             # <<<<<<<<<<<<<<
 * 	elif y < (x - 460):  # log(1e200)
 * 		return x
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_y);
  __pyx_r = __pyx_v_y;
  goto __pyx_L0;

  /* "containers.pxd":351
 * 		return x
 * 	# If one value is much smaller than the other, keep the larger value.
 * 	elif x < (y - 460):  # log(1e200)             # <<<<<<<<<<<<<<
 * 		return y
 * 	elif y < (x - 460):  # log(1e200)
 */
}

/* "containers.pxd":353
 * 	elif x < (y - 460):  # log(1e200)
 * 		return y
 * 	elif y < (x - 460):  # log(1e200)             # <<<<<<<<<<<<<<
 * 		return x
 * 	diff = y - x
 */
__pyx_t_2 = __Pyx_PyInt_SubtractObjC(__pyx_v_x, __pyx_int_460, 0x1CC, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 353, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_1 = PyObject_RichCompare(__pyx_v_y, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 353, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(1, 353, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (__pyx_t_5) {

  /* "containers.pxd":354
 * 		return y
 * 	elif y < (x - 460):  # log(1e200)
 * 		return x             # <<<<<<<<<<<<<<
 * 	diff = y - x
 * 	assert not isinf(diff)
 */
  __Pyx_XDECREF(__pyx_r);
  __Pyx_INCREF(__pyx_v_x);
  __pyx_r = __pyx_v_x;
  goto __pyx_L0;

  /* "containers.pxd":353
 * 	elif x < (y - 460):  # log(1e200)
 * 		return y
 * 	elif y < (x - 460):  # log(1e200)             # <<<<<<<<<<<<<<
 * 		return x
 * 	diff = y - x
 */
}

/* "containers.pxd":355
 * 	elif y < (x - 460):  # log(1e200)
 * 		return x
 * 	diff = y - x             # <<<<<<<<<<<<<<
 * 	assert not isinf(diff)
 * 	if isinf(exp(diff)):  # difference is too large
 */
__pyx_t_1 = PyNumber_Subtract(__pyx_v_y, __pyx_v_x); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 355, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_diff = __pyx_t_1;
__pyx_t_1 = 0;

/* "containers.pxd":356
 * 		return x
 * 	diff = y - x
 * 	assert not isinf(diff)             # <<<<<<<<<<<<<<
 * 	if isinf(exp(diff)):  # difference is too large
 * 		return x if x > y else y
 */
#ifndef CYTHON_WITHOUT_ASSERTIONS
if (unlikely(!Py_OptimizeFlag)) {
  __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_isinf); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 356, __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_diff); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 356, __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_diff};
      __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 356, __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_diff};
      __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 356, __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(1, 356, __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_diff);
      __Pyx_GIVEREF(__pyx_v_diff);
      PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_diff);
      __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 356, __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_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(1, 356, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  if (unlikely(!((!__pyx_t_5) != 0))) {
    PyErr_SetNone(PyExc_AssertionError);
    __PYX_ERR(1, 356, __pyx_L1_error)
  }
}
#endif

/* "containers.pxd":357
 * 	diff = y - x
 * 	assert not isinf(diff)
 * 	if isinf(exp(diff)):  # difference is too large             # <<<<<<<<<<<<<<
 * 		return x if x > y else y
 * 	# otherwise return the sum.
 */
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_isinf); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 357, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = __Pyx_GetModuleGlobalName(__pyx_n_s_exp); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 357, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__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_4 = __Pyx_PyObject_CallOneArg(__pyx_t_3, __pyx_v_diff); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 357, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
} else {
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_diff};
    __pyx_t_4 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 357, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_4);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) {
    PyObject *__pyx_temp[2] = {__pyx_t_6, __pyx_v_diff};
    __pyx_t_4 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 357, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
    __Pyx_GOTREF(__pyx_t_4);
  } else
  #endif
  {
    __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 357, __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_INCREF(__pyx_v_diff);
    __Pyx_GIVEREF(__pyx_v_diff);
    PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_v_diff);
    __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 357, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_4);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
}
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__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_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 357, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_GOTREF(__pyx_t_1);
} else {
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_4};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 357, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_t_4};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 357, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __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(1, 357, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3); __pyx_t_3 = NULL;
    __Pyx_GIVEREF(__pyx_t_4);
    PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 357, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(1, 357, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
if (__pyx_t_5) {

  /* "containers.pxd":358
 * 	assert not isinf(diff)
 * 	if isinf(exp(diff)):  # difference is too large
 * 		return x if x > y else y             # <<<<<<<<<<<<<<
 * 	# otherwise return the sum.
 * 	return x + log(1.0 + exp(diff))
 */
  __Pyx_XDECREF(__pyx_r);
  __pyx_t_2 = PyObject_RichCompare(__pyx_v_x, __pyx_v_y, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 358, __pyx_L1_error)
  __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(1, 358, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  if (__pyx_t_5) {
    __Pyx_INCREF(__pyx_v_x);
    __pyx_t_1 = __pyx_v_x;
  } else {
    __Pyx_INCREF(__pyx_v_y);
    __pyx_t_1 = __pyx_v_y;
  }
  __pyx_r = __pyx_t_1;
  __pyx_t_1 = 0;
  goto __pyx_L0;

  /* "containers.pxd":357
 * 	diff = y - x
 * 	assert not isinf(diff)
 * 	if isinf(exp(diff)):  # difference is too large             # <<<<<<<<<<<<<<
 * 		return x if x > y else y
 * 	# otherwise return the sum.
 */
}

/* "containers.pxd":360
 * 		return x if x > y else y
 * 	# otherwise return the sum.
 * 	return x + log(1.0 + exp(diff))             # <<<<<<<<<<<<<<
 * 
 * 
 */
__Pyx_XDECREF(__pyx_r);
__pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_log); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 360, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_exp); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 360, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_3 = NULL;
if (CYTHON_UNPACK_METHODS && unlikely(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_7 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_v_diff); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 360, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_7);
} else {
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_diff};
    __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 360, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_7);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_diff};
    __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 360, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_7);
  } else
  #endif
  {
    __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 360, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_6);
    __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_3); __pyx_t_3 = NULL;
    __Pyx_INCREF(__pyx_v_diff);
    __Pyx_GIVEREF(__pyx_v_diff);
    PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_v_diff);
    __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_6, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 360, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = __Pyx_PyFloat_AddCObj(__pyx_float_1_0, __pyx_t_7, 1.0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 360, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_7 = NULL;
if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_2))) {
  __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_2);
  if (likely(__pyx_t_7)) {
    PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2);
    __Pyx_INCREF(__pyx_t_7);
    __Pyx_INCREF(function);
    __Pyx_DECREF_SET(__pyx_t_2, function);
  }
}
if (!__pyx_t_7) {
  __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 360, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_GOTREF(__pyx_t_1);
} else {
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_4};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 360, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_2)) {
    PyObject *__pyx_temp[2] = {__pyx_t_7, __pyx_t_4};
    __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_2, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 360, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  } else
  #endif
  {
    __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 360, __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_4);
    PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_4);
    __pyx_t_4 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 360, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
  }
}
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_2 = PyNumber_Add(__pyx_v_x, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 360, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_r = __pyx_t_2;
__pyx_t_2 = 0;
goto __pyx_L0;

/* "containers.pxd":336
 * 
 * 
 * cdef inline logprobadd(x, y):             # <<<<<<<<<<<<<<
 * 	""" Add two log probabilities in log space.
 * 
 */

/* 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_6);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_AddTraceback("discodop.containers.logprobadd", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_diff);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "containers.pxd":363
 * 
 * 
 * cdef inline double logprobsum(list logprobs):             # <<<<<<<<<<<<<<
 * 	"""Sum a list of log probabilities producing a normal probability.
 * 
 */

static CYTHON_INLINE double __pyx_f_8discodop_10containers_logprobsum(PyObject *__pyx_v_logprobs) {
PyObject *__pyx_v_maxprob = NULL;
double __pyx_r;
__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;
Py_ssize_t __pyx_t_6;
PyObject *__pyx_t_7 = NULL;
PyObject *__pyx_t_8 = NULL;
PyObject *__pyx_t_9 = NULL;
PyObject *__pyx_t_10 = NULL;
PyObject *__pyx_t_11 = NULL;
double __pyx_t_12;
__Pyx_RefNannySetupContext("logprobsum", 0);

/* "containers.pxd":377
 * 	Comparison of different methods: https://gist.github.com/andreasvc/6204982
 * 	"""
 * 	maxprob = max(logprobs)             # <<<<<<<<<<<<<<
 * 	return exp(maxprob) * fsum([exp(prob - maxprob) for prob in logprobs])
 * 
 */
__pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 377, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_INCREF(__pyx_v_logprobs);
__Pyx_GIVEREF(__pyx_v_logprobs);
PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_logprobs);
__pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_max, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 377, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_maxprob = __pyx_t_2;
__pyx_t_2 = 0;

/* "containers.pxd":378
 * 	"""
 * 	maxprob = max(logprobs)
 * 	return exp(maxprob) * fsum([exp(prob - maxprob) for prob in logprobs])             # <<<<<<<<<<<<<<
 * 
 * 
 */
__pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_exp); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 378, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_3 = NULL;
if (CYTHON_UNPACK_METHODS && unlikely(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_2 = __Pyx_PyObject_CallOneArg(__pyx_t_1, __pyx_v_maxprob); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 378, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_2);
} else {
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_maxprob};
    __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 378, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_2);
  } else
  #endif
  #if CYTHON_FAST_PYCCALL
  if (__Pyx_PyFastCFunction_Check(__pyx_t_1)) {
    PyObject *__pyx_temp[2] = {__pyx_t_3, __pyx_v_maxprob};
    __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_1, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 378, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
    __Pyx_GOTREF(__pyx_t_2);
  } else
  #endif
  {
    __pyx_t_4 = PyTuple_New(1+1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 378, __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_maxprob);
    __Pyx_GIVEREF(__pyx_v_maxprob);
    PyTuple_SET_ITEM(__pyx_t_4, 0+1, __pyx_v_maxprob);
    __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 378, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_2);
    __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  }
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_fsum); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 378, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
{ /* enter inner scope */
  PyObject *__pyx_7genexpr__pyx_v_prob = NULL;
  __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 378, __pyx_L5_error)
  __Pyx_GOTREF(__pyx_t_3);
  if (unlikely(__pyx_v_logprobs == Py_None)) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
    __PYX_ERR(1, 378, __pyx_L5_error)
  }
  __pyx_t_5 = __pyx_v_logprobs; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0;
  for (;;) {
    if (__pyx_t_6 >= PyList_GET_SIZE(__pyx_t_5)) break;
    #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
    __pyx_t_7 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_6); __Pyx_INCREF(__pyx_t_7); __pyx_t_6++; if (unlikely(0 < 0)) __PYX_ERR(1, 378, __pyx_L5_error)
    #else
    __pyx_t_7 = PySequence_ITEM(__pyx_t_5, __pyx_t_6); __pyx_t_6++; if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 378, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_7);
    #endif
    __Pyx_XDECREF_SET(__pyx_7genexpr__pyx_v_prob, __pyx_t_7);
    __pyx_t_7 = 0;
    __pyx_t_8 = __Pyx_GetModuleGlobalName(__pyx_n_s_exp); if (unlikely(!__pyx_t_8)) __PYX_ERR(1, 378, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_8);
    __pyx_t_9 = PyNumber_Subtract(__pyx_7genexpr__pyx_v_prob, __pyx_v_maxprob); if (unlikely(!__pyx_t_9)) __PYX_ERR(1, 378, __pyx_L5_error)
    __Pyx_GOTREF(__pyx_t_9);
    __pyx_t_10 = NULL;
    if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_8))) {
      __pyx_t_10 = PyMethod_GET_SELF(__pyx_t_8);
      if (likely(__pyx_t_10)) {
        PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8);
        __Pyx_INCREF(__pyx_t_10);
        __Pyx_INCREF(function);
        __Pyx_DECREF_SET(__pyx_t_8, function);
      }
    }
    if (!__pyx_t_10) {
      __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 378, __pyx_L5_error)
      __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      __Pyx_GOTREF(__pyx_t_7);
    } else {
      #if CYTHON_FAST_PYCALL
      if (PyFunction_Check(__pyx_t_8)) {
        PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_9};
        __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 378, __pyx_L5_error)
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      } else
      #endif
      #if CYTHON_FAST_PYCCALL
      if (__Pyx_PyFastCFunction_Check(__pyx_t_8)) {
        PyObject *__pyx_temp[2] = {__pyx_t_10, __pyx_t_9};
        __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_8, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 378, __pyx_L5_error)
        __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0;
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
      } else
      #endif
      {
        __pyx_t_11 = PyTuple_New(1+1); if (unlikely(!__pyx_t_11)) __PYX_ERR(1, 378, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_11);
        __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_11, 0, __pyx_t_10); __pyx_t_10 = NULL;
        __Pyx_GIVEREF(__pyx_t_9);
        PyTuple_SET_ITEM(__pyx_t_11, 0+1, __pyx_t_9);
        __pyx_t_9 = 0;
        __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_8, __pyx_t_11, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 378, __pyx_L5_error)
        __Pyx_GOTREF(__pyx_t_7);
        __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0;
      }
    }
    __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
    if (unlikely(__Pyx_ListComp_Append(__pyx_t_3, (PyObject*)__pyx_t_7))) __PYX_ERR(1, 378, __pyx_L5_error)
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_XDECREF(__pyx_7genexpr__pyx_v_prob);
  goto __pyx_L8_exit_scope;
  __pyx_L5_error:;
  __Pyx_XDECREF(__pyx_7genexpr__pyx_v_prob);
  goto __pyx_L1_error;
  __pyx_L8_exit_scope:;
} /* exit inner scope */
__pyx_t_5 = NULL;
if (CYTHON_UNPACK_METHODS && unlikely(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_1 = __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 378, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __Pyx_GOTREF(__pyx_t_1);
} else {
  #if CYTHON_FAST_PYCALL
  if (PyFunction_Check(__pyx_t_4)) {
    PyObject *__pyx_temp[2] = {__pyx_t_5, __pyx_t_3};
    __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 378, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __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_1 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 378, __pyx_L1_error)
    __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  } else
  #endif
  {
    __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 378, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_7);
    __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL;
    __Pyx_GIVEREF(__pyx_t_3);
    PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_3);
    __pyx_t_3 = 0;
    __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 378, __pyx_L1_error)
    __Pyx_GOTREF(__pyx_t_1);
    __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
  }
}
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = PyNumber_Multiply(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(1, 378, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_12 = __pyx_PyFloat_AsDouble(__pyx_t_4); if (unlikely((__pyx_t_12 == (double)-1) && PyErr_Occurred())) __PYX_ERR(1, 378, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_r = __pyx_t_12;
goto __pyx_L0;

/* "containers.pxd":363
 * 
 * 
 * cdef inline double logprobsum(list logprobs):             # <<<<<<<<<<<<<<
 * 	"""Sum a list of log probabilities producing a normal probability.
 * 
 */

/* 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_5);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_XDECREF(__pyx_t_9);
__Pyx_XDECREF(__pyx_t_10);
__Pyx_XDECREF(__pyx_t_11);
__Pyx_WriteUnraisable("discodop.containers.logprobsum", __pyx_clineno, __pyx_lineno, __pyx_filename, 0, 0);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_maxprob);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "containers.pxd":381
 * 
 * 
 * cdef inline str yieldranges(list leaves):             # <<<<<<<<<<<<<<
 * 	"""Convert a sorted list of indices into a string with intervals.
 * 
 */

static CYTHON_INLINE PyObject *__pyx_f_8discodop_10containers_yieldranges(PyObject *__pyx_v_leaves) {
PyObject *__pyx_v_yields = 0;
int __pyx_v_a;
int __pyx_v_start;
int __pyx_v_prev;
PyObject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
Py_ssize_t __pyx_t_2;
PyObject *__pyx_t_3 = NULL;
int __pyx_t_4;
int __pyx_t_5;
PyObject *__pyx_t_6 = NULL;
PyObject *__pyx_t_7 = NULL;
int __pyx_t_8;
__Pyx_RefNannySetupContext("yieldranges", 0);

/* "containers.pxd":389
 * 	>>> yieldranges([0, 1, 2, 3, 4])
 * 	'0:1= 2:4='"""
 * 	cdef list yields = []             # <<<<<<<<<<<<<<
 * 	cdef int a, start = -2, prev = -2
 * 	for a in leaves:
 */
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 389, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_yields = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;

/* "containers.pxd":390
 * 	'0:1= 2:4='"""
 * 	cdef list yields = []
 * 	cdef int a, start = -2, prev = -2             # <<<<<<<<<<<<<<
 * 	for a in leaves:
 * 		if a - 1 != prev:
 */
__pyx_v_start = -2;
__pyx_v_prev = -2;

/* "containers.pxd":391
 * 	cdef list yields = []
 * 	cdef int a, start = -2, prev = -2
 * 	for a in leaves:             # <<<<<<<<<<<<<<
 * 		if a - 1 != prev:
 * 			if prev != -2:
 */
if (unlikely(__pyx_v_leaves == Py_None)) {
  PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
  __PYX_ERR(1, 391, __pyx_L1_error)
}
__pyx_t_1 = __pyx_v_leaves; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = 0;
for (;;) {
  if (__pyx_t_2 >= PyList_GET_SIZE(__pyx_t_1)) break;
  #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
  __pyx_t_3 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_2); __Pyx_INCREF(__pyx_t_3); __pyx_t_2++; if (unlikely(0 < 0)) __PYX_ERR(1, 391, __pyx_L1_error)
  #else
  __pyx_t_3 = PySequence_ITEM(__pyx_t_1, __pyx_t_2); __pyx_t_2++; if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 391, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_3);
  #endif
  __pyx_t_4 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 391, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  __pyx_v_a = __pyx_t_4;

  /* "containers.pxd":392
 * 	cdef int a, start = -2, prev = -2
 * 	for a in leaves:
 * 		if a - 1 != prev:             # <<<<<<<<<<<<<<
 * 			if prev != -2:
 * 				yields.append('%d:%d' % (start, prev))
 */
  __pyx_t_5 = (((__pyx_v_a - 1) != __pyx_v_prev) != 0);
  if (__pyx_t_5) {

    /* "containers.pxd":393
 * 	for a in leaves:
 * 		if a - 1 != prev:
 * 			if prev != -2:             # <<<<<<<<<<<<<<
 * 				yields.append('%d:%d' % (start, prev))
 * 			start = a
 */
    __pyx_t_5 = ((__pyx_v_prev != -2L) != 0);
    if (__pyx_t_5) {

      /* "containers.pxd":394
 * 		if a - 1 != prev:
 * 			if prev != -2:
 * 				yields.append('%d:%d' % (start, prev))             # <<<<<<<<<<<<<<
 * 			start = a
 * 		prev = a
 */
      __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_start); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 394, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_3);
      __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_prev); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 394, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 394, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_7);
      __Pyx_GIVEREF(__pyx_t_3);
      PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_3);
      __Pyx_GIVEREF(__pyx_t_6);
      PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
      __pyx_t_3 = 0;
      __pyx_t_6 = 0;
      __pyx_t_6 = PyUnicode_Format(__pyx_kp_u_d_d, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 394, __pyx_L1_error)
      __Pyx_GOTREF(__pyx_t_6);
      __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
      __pyx_t_8 = __Pyx_PyList_Append(__pyx_v_yields, __pyx_t_6); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(1, 394, __pyx_L1_error)
      __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

      /* "containers.pxd":393
 * 	for a in leaves:
 * 		if a - 1 != prev:
 * 			if prev != -2:             # <<<<<<<<<<<<<<
 * 				yields.append('%d:%d' % (start, prev))
 * 			start = a
 */
    }

    /* "containers.pxd":395
 * 			if prev != -2:
 * 				yields.append('%d:%d' % (start, prev))
 * 			start = a             # <<<<<<<<<<<<<<
 * 		prev = a
 * 	yields.append('%d:%d' % (start, prev))
 */
    __pyx_v_start = __pyx_v_a;

    /* "containers.pxd":392
 * 	cdef int a, start = -2, prev = -2
 * 	for a in leaves:
 * 		if a - 1 != prev:             # <<<<<<<<<<<<<<
 * 			if prev != -2:
 * 				yields.append('%d:%d' % (start, prev))
 */
  }

  /* "containers.pxd":396
 * 				yields.append('%d:%d' % (start, prev))
 * 			start = a
 * 		prev = a             # <<<<<<<<<<<<<<
 * 	yields.append('%d:%d' % (start, prev))
 * 	return ' '.join(yields)
 */
  __pyx_v_prev = __pyx_v_a;

  /* "containers.pxd":391
 * 	cdef list yields = []
 * 	cdef int a, start = -2, prev = -2
 * 	for a in leaves:             # <<<<<<<<<<<<<<
 * 		if a - 1 != prev:
 * 			if prev != -2:
 */
}
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;

/* "containers.pxd":397
 * 			start = a
 * 		prev = a
 * 	yields.append('%d:%d' % (start, prev))             # <<<<<<<<<<<<<<
 * 	return ' '.join(yields)
 * 
 */
__pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_start); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 397, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_prev); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 397, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(1, 397, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_GIVEREF(__pyx_t_1);
PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1);
__Pyx_GIVEREF(__pyx_t_6);
PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_6);
__pyx_t_1 = 0;
__pyx_t_6 = 0;
__pyx_t_6 = PyUnicode_Format(__pyx_kp_u_d_d, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 397, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_8 = __Pyx_PyList_Append(__pyx_v_yields, __pyx_t_6); if (unlikely(__pyx_t_8 == -1)) __PYX_ERR(1, 397, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;

/* "containers.pxd":398
 * 		prev = a
 * 	yields.append('%d:%d' % (start, prev))
 * 	return ' '.join(yields)             # <<<<<<<<<<<<<<
 * 
 * 
 */
__Pyx_XDECREF(__pyx_r);
__pyx_t_6 = PyUnicode_Join(__pyx_kp_u__25, __pyx_v_yields); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 398, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_r = ((PyObject*)__pyx_t_6);
__pyx_t_6 = 0;
goto __pyx_L0;

/* "containers.pxd":381
 * 
 * 
 * cdef inline str yieldranges(list leaves):             # <<<<<<<<<<<<<<
 * 	"""Convert a sorted list of indices into a string with intervals.
 * 
 */

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_AddTraceback("discodop.containers.yieldranges", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_yields);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "containers.pxd":401
 * 
 * 
 * cdef inline short termidx(short x):             # <<<<<<<<<<<<<<
 * 	"""Translate representation for terminal indices."""
 * 	return -x - 1
 */

static CYTHON_INLINE short __pyx_f_8discodop_10containers_termidx(short __pyx_v_x) {
short __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("termidx", 0);

/* "containers.pxd":403
 * cdef inline short termidx(short x):
 * 	"""Translate representation for terminal indices."""
 * 	return -x - 1             # <<<<<<<<<<<<<<
 */
__pyx_r = ((-__pyx_v_x) - 1);
goto __pyx_L0;

/* "containers.pxd":401
 * 
 * 
 * cdef inline short termidx(short x):             # <<<<<<<<<<<<<<
 * 	"""Translate representation for terminal indices."""
 * 	return -x - 1
 */

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

/* "cpython/array.pxd":91
 *             __data_union data
 * 
 *         def __getbuffer__(self, Py_buffer* info, int flags):             # <<<<<<<<<<<<<<
 *             # This implementation of getbuffer is geared towards Cython
 *             # requirements, and does not yet fullfill the PEP.
 */

/* Python wrapper */
static CYTHON_UNUSED int __pyx_pw_7cpython_5array_5array_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags); /*proto*/
static CYTHON_UNUSED int __pyx_pw_7cpython_5array_5array_1__getbuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info, int __pyx_v_flags) {
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__getbuffer__ (wrapper)", 0);
__pyx_r = __pyx_pf_7cpython_5array_5array___getbuffer__(((arrayobject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info), ((int)__pyx_v_flags));

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

static int __pyx_pf_7cpython_5array_5array___getbuffer__(arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info, CYTHON_UNUSED int __pyx_v_flags) {
PyObject *__pyx_v_item_count = NULL;
int __pyx_r;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
char *__pyx_t_2;
int __pyx_t_3;
PyObject *__pyx_t_4 = NULL;
Py_ssize_t __pyx_t_5;
int __pyx_t_6;
__Pyx_RefNannySetupContext("__getbuffer__", 0);
if (__pyx_v_info != NULL) {
  __pyx_v_info->obj = Py_None; __Pyx_INCREF(Py_None);
  __Pyx_GIVEREF(__pyx_v_info->obj);
}

/* "cpython/array.pxd":96
 *             # In particular strided access is always provided regardless
 *             # of flags
 *             item_count = Py_SIZE(self)             # <<<<<<<<<<<<<<
 * 
 *             info.suboffsets = NULL
 */
__pyx_t_1 = PyInt_FromSsize_t(Py_SIZE(((PyObject *)__pyx_v_self))); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 96, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_item_count = __pyx_t_1;
__pyx_t_1 = 0;

/* "cpython/array.pxd":98
 *             item_count = Py_SIZE(self)
 * 
 *             info.suboffsets = NULL             # <<<<<<<<<<<<<<
 *             info.buf = self.data.as_chars
 *             info.readonly = 0
 */
__pyx_v_info->suboffsets = NULL;

/* "cpython/array.pxd":99
 * 
 *             info.suboffsets = NULL
 *             info.buf = self.data.as_chars             # <<<<<<<<<<<<<<
 *             info.readonly = 0
 *             info.ndim = 1
 */
__pyx_t_2 = __pyx_v_self->data.as_chars;
__pyx_v_info->buf = __pyx_t_2;

/* "cpython/array.pxd":100
 *             info.suboffsets = NULL
 *             info.buf = self.data.as_chars
 *             info.readonly = 0             # <<<<<<<<<<<<<<
 *             info.ndim = 1
 *             info.itemsize = self.ob_descr.itemsize   # e.g. sizeof(float)
 */
__pyx_v_info->readonly = 0;

/* "cpython/array.pxd":101
 *             info.buf = self.data.as_chars
 *             info.readonly = 0
 *             info.ndim = 1             # <<<<<<<<<<<<<<
 *             info.itemsize = self.ob_descr.itemsize   # e.g. sizeof(float)
 *             info.len = info.itemsize * item_count
 */
__pyx_v_info->ndim = 1;

/* "cpython/array.pxd":102
 *             info.readonly = 0
 *             info.ndim = 1
 *             info.itemsize = self.ob_descr.itemsize   # e.g. sizeof(float)             # <<<<<<<<<<<<<<
 *             info.len = info.itemsize * item_count
 * 
 */
__pyx_t_3 = __pyx_v_self->ob_descr->itemsize;
__pyx_v_info->itemsize = __pyx_t_3;

/* "cpython/array.pxd":103
 *             info.ndim = 1
 *             info.itemsize = self.ob_descr.itemsize   # e.g. sizeof(float)
 *             info.len = info.itemsize * item_count             # <<<<<<<<<<<<<<
 * 
 *             info.shape = <Py_ssize_t*> PyObject_Malloc(sizeof(Py_ssize_t) + 2)
 */
__pyx_t_1 = PyInt_FromSsize_t(__pyx_v_info->itemsize); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 103, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_4 = PyNumber_Multiply(__pyx_t_1, __pyx_v_item_count); if (unlikely(!__pyx_t_4)) __PYX_ERR(2, 103, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_t_4); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 103, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_v_info->len = __pyx_t_5;

/* "cpython/array.pxd":105
 *             info.len = info.itemsize * item_count
 * 
 *             info.shape = <Py_ssize_t*> PyObject_Malloc(sizeof(Py_ssize_t) + 2)             # <<<<<<<<<<<<<<
 *             if not info.shape:
 *                 raise MemoryError()
 */
__pyx_v_info->shape = ((Py_ssize_t *)PyObject_Malloc(((sizeof(Py_ssize_t)) + 2)));

/* "cpython/array.pxd":106
 * 
 *             info.shape = <Py_ssize_t*> PyObject_Malloc(sizeof(Py_ssize_t) + 2)
 *             if not info.shape:             # <<<<<<<<<<<<<<
 *                 raise MemoryError()
 *             info.shape[0] = item_count      # constant regardless of resizing
 */
__pyx_t_6 = ((!(__pyx_v_info->shape != 0)) != 0);
if (__pyx_t_6) {

  /* "cpython/array.pxd":107
 *             info.shape = <Py_ssize_t*> PyObject_Malloc(sizeof(Py_ssize_t) + 2)
 *             if not info.shape:
 *                 raise MemoryError()             # <<<<<<<<<<<<<<
 *             info.shape[0] = item_count      # constant regardless of resizing
 *             info.strides = &info.itemsize
 */
  PyErr_NoMemory(); __PYX_ERR(2, 107, __pyx_L1_error)

  /* "cpython/array.pxd":106
 * 
 *             info.shape = <Py_ssize_t*> PyObject_Malloc(sizeof(Py_ssize_t) + 2)
 *             if not info.shape:             # <<<<<<<<<<<<<<
 *                 raise MemoryError()
 *             info.shape[0] = item_count      # constant regardless of resizing
 */
}

/* "cpython/array.pxd":108
 *             if not info.shape:
 *                 raise MemoryError()
 *             info.shape[0] = item_count      # constant regardless of resizing             # <<<<<<<<<<<<<<
 *             info.strides = &info.itemsize
 * 
 */
__pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_v_item_count); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(2, 108, __pyx_L1_error)
(__pyx_v_info->shape[0]) = __pyx_t_5;

/* "cpython/array.pxd":109
 *                 raise MemoryError()
 *             info.shape[0] = item_count      # constant regardless of resizing
 *             info.strides = &info.itemsize             # <<<<<<<<<<<<<<
 * 
 *             info.format = <char*> (info.shape + 1)
 */
__pyx_v_info->strides = (&__pyx_v_info->itemsize);

/* "cpython/array.pxd":111
 *             info.strides = &info.itemsize
 * 
 *             info.format = <char*> (info.shape + 1)             # <<<<<<<<<<<<<<
 *             info.format[0] = self.ob_descr.typecode
 *             info.format[1] = 0
 */
__pyx_v_info->format = ((char *)(__pyx_v_info->shape + 1));

/* "cpython/array.pxd":112
 * 
 *             info.format = <char*> (info.shape + 1)
 *             info.format[0] = self.ob_descr.typecode             # <<<<<<<<<<<<<<
 *             info.format[1] = 0
 *             info.obj = self
 */
__pyx_t_3 = __pyx_v_self->ob_descr->typecode;
(__pyx_v_info->format[0]) = __pyx_t_3;

/* "cpython/array.pxd":113
 *             info.format = <char*> (info.shape + 1)
 *             info.format[0] = self.ob_descr.typecode
 *             info.format[1] = 0             # <<<<<<<<<<<<<<
 *             info.obj = self
 * 
 */
(__pyx_v_info->format[1]) = 0;

/* "cpython/array.pxd":114
 *             info.format[0] = self.ob_descr.typecode
 *             info.format[1] = 0
 *             info.obj = self             # <<<<<<<<<<<<<<
 * 
 *         def __releasebuffer__(self, Py_buffer* info):
 */
__Pyx_INCREF(((PyObject *)__pyx_v_self));
__Pyx_GIVEREF(((PyObject *)__pyx_v_self));
__Pyx_GOTREF(__pyx_v_info->obj);
__Pyx_DECREF(__pyx_v_info->obj);
__pyx_v_info->obj = ((PyObject *)__pyx_v_self);

/* "cpython/array.pxd":91
 *             __data_union data
 * 
 *         def __getbuffer__(self, Py_buffer* info, int flags):             # <<<<<<<<<<<<<<
 *             # This implementation of getbuffer is geared towards Cython
 *             # requirements, and does not yet fullfill the PEP.
 */

/* function exit code */
__pyx_r = 0;
goto __pyx_L0;
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_4);
__Pyx_AddTraceback("cpython.array.array.__getbuffer__", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = -1;
if (__pyx_v_info != NULL && __pyx_v_info->obj != NULL) {
  __Pyx_GOTREF(__pyx_v_info->obj);
  __Pyx_DECREF(__pyx_v_info->obj); __pyx_v_info->obj = NULL;
}
goto __pyx_L2;
__pyx_L0:;
if (__pyx_v_info != NULL && __pyx_v_info->obj == Py_None) {
  __Pyx_GOTREF(Py_None);
  __Pyx_DECREF(Py_None); __pyx_v_info->obj = NULL;
}
__pyx_L2:;
__Pyx_XDECREF(__pyx_v_item_count);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "cpython/array.pxd":116
 *             info.obj = self
 * 
 *         def __releasebuffer__(self, Py_buffer* info):             # <<<<<<<<<<<<<<
 *             PyObject_Free(info.shape)
 * 
 */

/* Python wrapper */
static CYTHON_UNUSED void __pyx_pw_7cpython_5array_5array_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info); /*proto*/
static CYTHON_UNUSED void __pyx_pw_7cpython_5array_5array_3__releasebuffer__(PyObject *__pyx_v_self, Py_buffer *__pyx_v_info) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__releasebuffer__ (wrapper)", 0);
__pyx_pf_7cpython_5array_5array_2__releasebuffer__(((arrayobject *)__pyx_v_self), ((Py_buffer *)__pyx_v_info));

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

static void __pyx_pf_7cpython_5array_5array_2__releasebuffer__(CYTHON_UNUSED arrayobject *__pyx_v_self, Py_buffer *__pyx_v_info) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__releasebuffer__", 0);

/* "cpython/array.pxd":117
 * 
 *         def __releasebuffer__(self, Py_buffer* info):
 *             PyObject_Free(info.shape)             # <<<<<<<<<<<<<<
 * 
 *     array newarrayobject(PyTypeObject* type, Py_ssize_t size, arraydescr *descr)
 */
PyObject_Free(__pyx_v_info->shape);

/* "cpython/array.pxd":116
 *             info.obj = self
 * 
 *         def __releasebuffer__(self, Py_buffer* info):             # <<<<<<<<<<<<<<
 *             PyObject_Free(info.shape)
 * 
 */

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

/* "cpython/array.pxd":128
 * 
 * 
 * cdef inline array clone(array template, Py_ssize_t length, bint zero):             # <<<<<<<<<<<<<<
 *     """ fast creation of a new array, given a template array.
 *     type will be same as template.
 */

static CYTHON_INLINE arrayobject *__pyx_f_7cpython_5array_clone(arrayobject *__pyx_v_template, Py_ssize_t __pyx_v_length, int __pyx_v_zero) {
arrayobject *__pyx_v_op = NULL;
arrayobject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
int __pyx_t_2;
int __pyx_t_3;
int __pyx_t_4;
__Pyx_RefNannySetupContext("clone", 0);

/* "cpython/array.pxd":132
 *     type will be same as template.
 *     if zero is true, new array will be initialized with zeroes."""
 *     op = newarrayobject(Py_TYPE(template), length, template.ob_descr)             # <<<<<<<<<<<<<<
 *     if zero and op is not None:
 *         memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)
 */
__pyx_t_1 = ((PyObject *)newarrayobject(Py_TYPE(((PyObject *)__pyx_v_template)), __pyx_v_length, __pyx_v_template->ob_descr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 132, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_op = ((arrayobject *)__pyx_t_1);
__pyx_t_1 = 0;

/* "cpython/array.pxd":133
 *     if zero is true, new array will be initialized with zeroes."""
 *     op = newarrayobject(Py_TYPE(template), length, template.ob_descr)
 *     if zero and op is not None:             # <<<<<<<<<<<<<<
 *         memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)
 *     return op
 */
__pyx_t_3 = (__pyx_v_zero != 0);
if (__pyx_t_3) {
} else {
  __pyx_t_2 = __pyx_t_3;
  goto __pyx_L4_bool_binop_done;
}
__pyx_t_3 = (((PyObject *)__pyx_v_op) != Py_None);
__pyx_t_4 = (__pyx_t_3 != 0);
__pyx_t_2 = __pyx_t_4;
__pyx_L4_bool_binop_done:;
if (__pyx_t_2) {

  /* "cpython/array.pxd":134
 *     op = newarrayobject(Py_TYPE(template), length, template.ob_descr)
 *     if zero and op is not None:
 *         memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)             # <<<<<<<<<<<<<<
 *     return op
 * 
 */
  memset(__pyx_v_op->data.as_chars, 0, (__pyx_v_length * __pyx_v_op->ob_descr->itemsize));

  /* "cpython/array.pxd":133
 *     if zero is true, new array will be initialized with zeroes."""
 *     op = newarrayobject(Py_TYPE(template), length, template.ob_descr)
 *     if zero and op is not None:             # <<<<<<<<<<<<<<
 *         memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)
 *     return op
 */
}

/* "cpython/array.pxd":135
 *     if zero and op is not None:
 *         memset(op.data.as_chars, 0, length * op.ob_descr.itemsize)
 *     return op             # <<<<<<<<<<<<<<
 * 
 * cdef inline array copy(array self):
 */
__Pyx_XDECREF(((PyObject *)__pyx_r));
__Pyx_INCREF(((PyObject *)__pyx_v_op));
__pyx_r = __pyx_v_op;
goto __pyx_L0;

/* "cpython/array.pxd":128
 * 
 * 
 * cdef inline array clone(array template, Py_ssize_t length, bint zero):             # <<<<<<<<<<<<<<
 *     """ fast creation of a new array, given a template array.
 *     type will be same as template.
 */

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("cpython.array.clone", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_op);
__Pyx_XGIVEREF((PyObject *)__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "cpython/array.pxd":137
 *     return op
 * 
 * cdef inline array copy(array self):             # <<<<<<<<<<<<<<
 *     """ make a copy of an array. """
 *     op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)
 */

static CYTHON_INLINE arrayobject *__pyx_f_7cpython_5array_copy(arrayobject *__pyx_v_self) {
arrayobject *__pyx_v_op = NULL;
arrayobject *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
__Pyx_RefNannySetupContext("copy", 0);

/* "cpython/array.pxd":139
 * cdef inline array copy(array self):
 *     """ make a copy of an array. """
 *     op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)             # <<<<<<<<<<<<<<
 *     memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize)
 *     return op
 */
__pyx_t_1 = ((PyObject *)newarrayobject(Py_TYPE(((PyObject *)__pyx_v_self)), Py_SIZE(((PyObject *)__pyx_v_self)), __pyx_v_self->ob_descr)); if (unlikely(!__pyx_t_1)) __PYX_ERR(2, 139, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_v_op = ((arrayobject *)__pyx_t_1);
__pyx_t_1 = 0;

/* "cpython/array.pxd":140
 *     """ make a copy of an array. """
 *     op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)
 *     memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize)             # <<<<<<<<<<<<<<
 *     return op
 * 
 */
memcpy(__pyx_v_op->data.as_chars, __pyx_v_self->data.as_chars, (Py_SIZE(((PyObject *)__pyx_v_op)) * __pyx_v_op->ob_descr->itemsize));

/* "cpython/array.pxd":141
 *     op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)
 *     memcpy(op.data.as_chars, self.data.as_chars, Py_SIZE(op) * op.ob_descr.itemsize)
 *     return op             # <<<<<<<<<<<<<<
 * 
 * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1:
 */
__Pyx_XDECREF(((PyObject *)__pyx_r));
__Pyx_INCREF(((PyObject *)__pyx_v_op));
__pyx_r = __pyx_v_op;
goto __pyx_L0;

/* "cpython/array.pxd":137
 *     return op
 * 
 * cdef inline array copy(array self):             # <<<<<<<<<<<<<<
 *     """ make a copy of an array. """
 *     op = newarrayobject(Py_TYPE(self), Py_SIZE(self), self.ob_descr)
 */

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("cpython.array.copy", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_op);
__Pyx_XGIVEREF((PyObject *)__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "cpython/array.pxd":143
 *     return op
 * 
 * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1:             # <<<<<<<<<<<<<<
 *     """ efficent appending of new stuff of same type
 *     (e.g. of same array type)
 */

static CYTHON_INLINE int __pyx_f_7cpython_5array_extend_buffer(arrayobject *__pyx_v_self, char *__pyx_v_stuff, Py_ssize_t __pyx_v_n) {
Py_ssize_t __pyx_v_itemsize;
Py_ssize_t __pyx_v_origsize;
int __pyx_r;
__Pyx_RefNannyDeclarations
int __pyx_t_1;
__Pyx_RefNannySetupContext("extend_buffer", 0);

/* "cpython/array.pxd":147
 *     (e.g. of same array type)
 *     n: number of elements (not number of bytes!) """
 *     cdef Py_ssize_t itemsize = self.ob_descr.itemsize             # <<<<<<<<<<<<<<
 *     cdef Py_ssize_t origsize = Py_SIZE(self)
 *     resize_smart(self, origsize + n)
 */
__pyx_t_1 = __pyx_v_self->ob_descr->itemsize;
__pyx_v_itemsize = __pyx_t_1;

/* "cpython/array.pxd":148
 *     n: number of elements (not number of bytes!) """
 *     cdef Py_ssize_t itemsize = self.ob_descr.itemsize
 *     cdef Py_ssize_t origsize = Py_SIZE(self)             # <<<<<<<<<<<<<<
 *     resize_smart(self, origsize + n)
 *     memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize)
 */
__pyx_v_origsize = Py_SIZE(((PyObject *)__pyx_v_self));

/* "cpython/array.pxd":149
 *     cdef Py_ssize_t itemsize = self.ob_descr.itemsize
 *     cdef Py_ssize_t origsize = Py_SIZE(self)
 *     resize_smart(self, origsize + n)             # <<<<<<<<<<<<<<
 *     memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize)
 *     return 0
 */
__pyx_t_1 = resize_smart(__pyx_v_self, (__pyx_v_origsize + __pyx_v_n)); if (unlikely(__pyx_t_1 == -1)) __PYX_ERR(2, 149, __pyx_L1_error)

/* "cpython/array.pxd":150
 *     cdef Py_ssize_t origsize = Py_SIZE(self)
 *     resize_smart(self, origsize + n)
 *     memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize)             # <<<<<<<<<<<<<<
 *     return 0
 * 
 */
memcpy((__pyx_v_self->data.as_chars + (__pyx_v_origsize * __pyx_v_itemsize)), __pyx_v_stuff, (__pyx_v_n * __pyx_v_itemsize));

/* "cpython/array.pxd":151
 *     resize_smart(self, origsize + n)
 *     memcpy(self.data.as_chars + origsize * itemsize, stuff, n * itemsize)
 *     return 0             # <<<<<<<<<<<<<<
 * 
 * cdef inline int extend(array self, array other) except -1:
 */
__pyx_r = 0;
goto __pyx_L0;

/* "cpython/array.pxd":143
 *     return op
 * 
 * cdef inline int extend_buffer(array self, char* stuff, Py_ssize_t n) except -1:             # <<<<<<<<<<<<<<
 *     """ efficent appending of new stuff of same type
 *     (e.g. of same array type)
 */

/* function exit code */
__pyx_L1_error:;
__Pyx_AddTraceback("cpython.array.extend_buffer", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = -1;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "cpython/array.pxd":153
 *     return 0
 * 
 * cdef inline int extend(array self, array other) except -1:             # <<<<<<<<<<<<<<
 *     """ extend array with data from another array; types must match. """
 *     if self.ob_descr.typecode != other.ob_descr.typecode:
 */

static CYTHON_INLINE int __pyx_f_7cpython_5array_extend(arrayobject *__pyx_v_self, arrayobject *__pyx_v_other) {
int __pyx_r;
__Pyx_RefNannyDeclarations
int __pyx_t_1;
int __pyx_t_2;
__Pyx_RefNannySetupContext("extend", 0);

/* "cpython/array.pxd":155
 * cdef inline int extend(array self, array other) except -1:
 *     """ extend array with data from another array; types must match. """
 *     if self.ob_descr.typecode != other.ob_descr.typecode:             # <<<<<<<<<<<<<<
 *         PyErr_BadArgument()
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 */
__pyx_t_1 = ((__pyx_v_self->ob_descr->typecode != __pyx_v_other->ob_descr->typecode) != 0);
if (__pyx_t_1) {

  /* "cpython/array.pxd":156
 *     """ extend array with data from another array; types must match. """
 *     if self.ob_descr.typecode != other.ob_descr.typecode:
 *         PyErr_BadArgument()             # <<<<<<<<<<<<<<
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 * 
 */
  __pyx_t_2 = PyErr_BadArgument(); if (unlikely(__pyx_t_2 == 0)) __PYX_ERR(2, 156, __pyx_L1_error)

  /* "cpython/array.pxd":155
 * cdef inline int extend(array self, array other) except -1:
 *     """ extend array with data from another array; types must match. """
 *     if self.ob_descr.typecode != other.ob_descr.typecode:             # <<<<<<<<<<<<<<
 *         PyErr_BadArgument()
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 */
}

/* "cpython/array.pxd":157
 *     if self.ob_descr.typecode != other.ob_descr.typecode:
 *         PyErr_BadArgument()
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))             # <<<<<<<<<<<<<<
 * 
 * cdef inline void zero(array self):
 */
__pyx_t_2 = __pyx_f_7cpython_5array_extend_buffer(__pyx_v_self, __pyx_v_other->data.as_chars, Py_SIZE(((PyObject *)__pyx_v_other))); if (unlikely(__pyx_t_2 == -1)) __PYX_ERR(2, 157, __pyx_L1_error)
__pyx_r = __pyx_t_2;
goto __pyx_L0;

/* "cpython/array.pxd":153
 *     return 0
 * 
 * cdef inline int extend(array self, array other) except -1:             # <<<<<<<<<<<<<<
 *     """ extend array with data from another array; types must match. """
 *     if self.ob_descr.typecode != other.ob_descr.typecode:
 */

/* function exit code */
__pyx_L1_error:;
__Pyx_AddTraceback("cpython.array.extend", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = -1;
__pyx_L0:;
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "cpython/array.pxd":159
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 * 
 * cdef inline void zero(array self):             # <<<<<<<<<<<<<<
 *     """ set all elements of array to zero. """
 *     memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize)
 */

static CYTHON_INLINE void __pyx_f_7cpython_5array_zero(arrayobject *__pyx_v_self) {
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("zero", 0);

/* "cpython/array.pxd":161
 * cdef inline void zero(array self):
 *     """ set all elements of array to zero. """
 *     memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize)             # <<<<<<<<<<<<<<
 */
memset(__pyx_v_self->data.as_chars, 0, (Py_SIZE(((PyObject *)__pyx_v_self)) * __pyx_v_self->ob_descr->itemsize));

/* "cpython/array.pxd":159
 *     return extend_buffer(self, other.data.as_chars, Py_SIZE(other))
 * 
 * cdef inline void zero(array self):             # <<<<<<<<<<<<<<
 *     """ set all elements of array to zero. """
 *     memset(self.data.as_chars, 0, Py_SIZE(self) * self.ob_descr.itemsize)
 */

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

/* "bit.pxd":60
 * 
 * 
 * cdef inline bint testbit(unsigned_fused vec, uint32_t pos):             # <<<<<<<<<<<<<<
 * 	"""Mask a particular bit, return nonzero if set.
 * 
 */

static CYTHON_INLINE int __pyx_fuse_0__pyx_f_8discodop_3bit_testbit(uint8_t __pyx_v_vec, uint32_t __pyx_v_pos) {
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__pyx_fuse_0testbit", 0);

/* "bit.pxd":73
 * 			or unsigned_fused is uint16_t
 * 			or unsigned_fused is uint32_t):
 * 		return vec & (1U << pos)             # <<<<<<<<<<<<<<
 * 	else:
 * 		return vec & ((<unsigned_fused>1U) << pos) != 0
 */
__pyx_r = (__pyx_v_vec & (1U << __pyx_v_pos));
goto __pyx_L0;

/* "bit.pxd":60
 * 
 * 
 * cdef inline bint testbit(unsigned_fused vec, uint32_t pos):             # <<<<<<<<<<<<<<
 * 	"""Mask a particular bit, return nonzero if set.
 * 
 */

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

static CYTHON_INLINE int __pyx_fuse_1__pyx_f_8discodop_3bit_testbit(uint16_t __pyx_v_vec, uint32_t __pyx_v_pos) {
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__pyx_fuse_1testbit", 0);

/* "bit.pxd":73
 * 			or unsigned_fused is uint16_t
 * 			or unsigned_fused is uint32_t):
 * 		return vec & (1U << pos)             # <<<<<<<<<<<<<<
 * 	else:
 * 		return vec & ((<unsigned_fused>1U) << pos) != 0
 */
__pyx_r = (__pyx_v_vec & (1U << __pyx_v_pos));
goto __pyx_L0;

/* "bit.pxd":60
 * 
 * 
 * cdef inline bint testbit(unsigned_fused vec, uint32_t pos):             # <<<<<<<<<<<<<<
 * 	"""Mask a particular bit, return nonzero if set.
 * 
 */

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

static CYTHON_INLINE int __pyx_fuse_2__pyx_f_8discodop_3bit_testbit(uint32_t __pyx_v_vec, uint32_t __pyx_v_pos) {
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__pyx_fuse_2testbit", 0);

/* "bit.pxd":73
 * 			or unsigned_fused is uint16_t
 * 			or unsigned_fused is uint32_t):
 * 		return vec & (1U << pos)             # <<<<<<<<<<<<<<
 * 	else:
 * 		return vec & ((<unsigned_fused>1U) << pos) != 0
 */
__pyx_r = (__pyx_v_vec & (1U << __pyx_v_pos));
goto __pyx_L0;

/* "bit.pxd":60
 * 
 * 
 * cdef inline bint testbit(unsigned_fused vec, uint32_t pos):             # <<<<<<<<<<<<<<
 * 	"""Mask a particular bit, return nonzero if set.
 * 
 */

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

static CYTHON_INLINE int __pyx_fuse_3__pyx_f_8discodop_3bit_testbit(uint64_t __pyx_v_vec, uint32_t __pyx_v_pos) {
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__pyx_fuse_3testbit", 0);

/* "bit.pxd":75
 * 		return vec & (1U << pos)
 * 	else:
 * 		return vec & ((<unsigned_fused>1U) << pos) != 0             # <<<<<<<<<<<<<<
 * 
 * 
 */
__pyx_r = ((__pyx_v_vec & (((uint64_t)1U) << __pyx_v_pos)) != 0);
goto __pyx_L0;

/* "bit.pxd":60
 * 
 * 
 * cdef inline bint testbit(unsigned_fused vec, uint32_t pos):             # <<<<<<<<<<<<<<
 * 	"""Mask a particular bit, return nonzero if set.
 * 
 */

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

/* "bit.pxd":78
 * 
 * 
 * cdef inline int nextset(uint64_t vec, uint32_t pos):             # <<<<<<<<<<<<<<
 * 	""" Return next set bit starting from pos, -1 if there is none.
 * 
 */

static CYTHON_INLINE int __pyx_f_8discodop_3bit_nextset(uint64_t __pyx_v_vec, uint32_t __pyx_v_pos) {
int __pyx_r;
__Pyx_RefNannyDeclarations
uint32_t __pyx_t_1;
__Pyx_RefNannySetupContext("nextset", 0);

/* "bit.pxd":84
 * 	2
 * 	"""
 * 	return (pos + bit_ctz(vec >> pos)) if (vec >> pos) else -1             # <<<<<<<<<<<<<<
 * 	# mask instead of shift:
 * 	# return __builtin_ffsl(vec & (~0UL << pos)) - 1
 */
if (((__pyx_v_vec >> __pyx_v_pos) != 0)) {
  __pyx_t_1 = (__pyx_v_pos + bit_ctz((__pyx_v_vec >> __pyx_v_pos)));
} else {
  __pyx_t_1 = -1;
}
__pyx_r = __pyx_t_1;
goto __pyx_L0;

/* "bit.pxd":78
 * 
 * 
 * cdef inline int nextset(uint64_t vec, uint32_t pos):             # <<<<<<<<<<<<<<
 * 	""" Return next set bit starting from pos, -1 if there is none.
 * 
 */

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

/* "bit.pxd":93
 * 
 * 
 * cdef inline int nextunset(uint64_t vec, uint32_t pos):             # <<<<<<<<<<<<<<
 * 	""" Return next unset bit starting from pos.
 * 
 */

static CYTHON_INLINE int __pyx_f_8discodop_3bit_nextunset(uint64_t __pyx_v_vec, uint32_t __pyx_v_pos) {
uint64_t __pyx_v_x;
int __pyx_r;
__Pyx_RefNannyDeclarations
size_t __pyx_t_1;
__Pyx_RefNannySetupContext("nextunset", 0);

/* "bit.pxd":101
 * 	64
 * 	"""
 * 	cdef uint64_t x = ~vec & (~0UL << pos)             # <<<<<<<<<<<<<<
 * 	return bit_ctz(x) if x else (sizeof(uint64_t) * 8)
 * 
 */
__pyx_v_x = ((~__pyx_v_vec) & ((~0UL) << __pyx_v_pos));

/* "bit.pxd":102
 * 	"""
 * 	cdef uint64_t x = ~vec & (~0UL << pos)
 * 	return bit_ctz(x) if x else (sizeof(uint64_t) * 8)             # <<<<<<<<<<<<<<
 * 
 * 
 */
if ((__pyx_v_x != 0)) {
  __pyx_t_1 = bit_ctz(__pyx_v_x);
} else {
  __pyx_t_1 = ((sizeof(uint64_t)) * 8);
}
__pyx_r = __pyx_t_1;
goto __pyx_L0;

/* "bit.pxd":93
 * 
 * 
 * cdef inline int nextunset(uint64_t vec, uint32_t pos):             # <<<<<<<<<<<<<<
 * 	""" Return next unset bit starting from pos.
 * 
 */

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

/* "bit.pxd":105
 * 
 * 
 * cdef inline int bitlength(uint64_t vec):             # <<<<<<<<<<<<<<
 * 	"""Return number of bits needed to represent vector.
 * 
 */

static CYTHON_INLINE int __pyx_f_8discodop_3bit_bitlength(uint64_t __pyx_v_vec) {
int __pyx_r;
__Pyx_RefNannyDeclarations
size_t __pyx_t_1;
__Pyx_RefNannySetupContext("bitlength", 0);

/* "bit.pxd":112
 * 	>>> bitlength(0b0011101)
 * 	5"""
 * 	return sizeof(vec) * 8 - bit_clz(vec) if vec else 0             # <<<<<<<<<<<<<<
 * 
 * 
 */
if ((__pyx_v_vec != 0)) {
  __pyx_t_1 = (((sizeof(__pyx_v_vec)) * 8) - bit_clz(__pyx_v_vec));
} else {
  __pyx_t_1 = 0;
}
__pyx_r = __pyx_t_1;
goto __pyx_L0;

/* "bit.pxd":105
 * 
 * 
 * cdef inline int bitlength(uint64_t vec):             # <<<<<<<<<<<<<<
 * 	"""Return number of bits needed to represent vector.
 * 
 */

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

/* "bit.pxd":115
 * 
 * 
 * cdef inline int abitcount(uint64_t *vec, int slots):             # <<<<<<<<<<<<<<
 * 	""" Return number of set bits in variable length bitvector """
 * 	cdef int a
 */

static CYTHON_INLINE int __pyx_f_8discodop_3bit_abitcount(uint64_t *__pyx_v_vec, int __pyx_v_slots) {
int __pyx_v_a;
int __pyx_v_result;
int __pyx_r;
__Pyx_RefNannyDeclarations
int __pyx_t_1;
int __pyx_t_2;
__Pyx_RefNannySetupContext("abitcount", 0);

/* "bit.pxd":118
 * 	""" Return number of set bits in variable length bitvector """
 * 	cdef int a
 * 	cdef int result = 0             # <<<<<<<<<<<<<<
 * 	for a in range(slots):
 * 		result += bit_popcount(vec[a])
 */
__pyx_v_result = 0;

/* "bit.pxd":119
 * 	cdef int a
 * 	cdef int result = 0
 * 	for a in range(slots):             # <<<<<<<<<<<<<<
 * 		result += bit_popcount(vec[a])
 * 	return result
 */
__pyx_t_1 = __pyx_v_slots;
for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {
  __pyx_v_a = __pyx_t_2;

  /* "bit.pxd":120
 * 	cdef int result = 0
 * 	for a in range(slots):
 * 		result += bit_popcount(vec[a])             # <<<<<<<<<<<<<<
 * 	return result
 * 
 */
  __pyx_v_result = (__pyx_v_result + bit_popcount((__pyx_v_vec[__pyx_v_a])));
}

/* "bit.pxd":121
 * 	for a in range(slots):
 * 		result += bit_popcount(vec[a])
 * 	return result             # <<<<<<<<<<<<<<
 * 
 * 
 */
__pyx_r = __pyx_v_result;
goto __pyx_L0;

/* "bit.pxd":115
 * 
 * 
 * cdef inline int abitcount(uint64_t *vec, int slots):             # <<<<<<<<<<<<<<
 * 	""" Return number of set bits in variable length bitvector """
 * 	cdef int a
 */

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

/* "bit.pxd":124
 * 
 * 
 * cdef inline int abitlength(uint64_t *vec, int slots):             # <<<<<<<<<<<<<<
 * 	"""Return number of bits needed to represent vector.
 * 
 */

static CYTHON_INLINE int __pyx_f_8discodop_3bit_abitlength(uint64_t *__pyx_v_vec, int __pyx_v_slots) {
int __pyx_v_a;
int __pyx_r;
__Pyx_RefNannyDeclarations
int __pyx_t_1;
__Pyx_RefNannySetupContext("abitlength", 0);

/* "bit.pxd":128
 * 
 * 	(equivalently: index of most significant set bit, plus one)."""
 * 	cdef int a = slots - 1             # <<<<<<<<<<<<<<
 * 	while not vec[a]:
 * 		a -= 1
 */
__pyx_v_a = (__pyx_v_slots - 1);

/* "bit.pxd":129
 * 	(equivalently: index of most significant set bit, plus one)."""
 * 	cdef int a = slots - 1
 * 	while not vec[a]:             # <<<<<<<<<<<<<<
 * 		a -= 1
 * 		if a < 0:
 */
while (1) {
  __pyx_t_1 = ((!((__pyx_v_vec[__pyx_v_a]) != 0)) != 0);
  if (!__pyx_t_1) break;

  /* "bit.pxd":130
 * 	cdef int a = slots - 1
 * 	while not vec[a]:
 * 		a -= 1             # <<<<<<<<<<<<<<
 * 		if a < 0:
 * 			return 0
 */
  __pyx_v_a = (__pyx_v_a - 1);

  /* "bit.pxd":131
 * 	while not vec[a]:
 * 		a -= 1
 * 		if a < 0:             # <<<<<<<<<<<<<<
 * 			return 0
 * 	return (a + 1) * sizeof(uint64_t) * 8 - bit_clz(vec[a])
 */
  __pyx_t_1 = ((__pyx_v_a < 0) != 0);
  if (__pyx_t_1) {

    /* "bit.pxd":132
 * 		a -= 1
 * 		if a < 0:
 * 			return 0             # <<<<<<<<<<<<<<
 * 	return (a + 1) * sizeof(uint64_t) * 8 - bit_clz(vec[a])
 * 
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "bit.pxd":131
 * 	while not vec[a]:
 * 		a -= 1
 * 		if a < 0:             # <<<<<<<<<<<<<<
 * 			return 0
 * 	return (a + 1) * sizeof(uint64_t) * 8 - bit_clz(vec[a])
 */
  }
}

/* "bit.pxd":133
 * 		if a < 0:
 * 			return 0
 * 	return (a + 1) * sizeof(uint64_t) * 8 - bit_clz(vec[a])             # <<<<<<<<<<<<<<
 * 
 * 
 */
__pyx_r = ((((__pyx_v_a + 1) * (sizeof(uint64_t))) * 8) - bit_clz((__pyx_v_vec[__pyx_v_a])));
goto __pyx_L0;

/* "bit.pxd":124
 * 
 * 
 * cdef inline int abitlength(uint64_t *vec, int slots):             # <<<<<<<<<<<<<<
 * 	"""Return number of bits needed to represent vector.
 * 
 */

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

/* "bit.pxd":136
 * 
 * 
 * cdef inline int anextset(uint64_t *vec, uint32_t pos, int slots):             # <<<<<<<<<<<<<<
 * 	""" Return next set bit starting from pos, -1 if there is none. """
 * 	cdef int a = BITSLOT(pos)
 */

static CYTHON_INLINE int __pyx_f_8discodop_3bit_anextset(uint64_t *__pyx_v_vec, uint32_t __pyx_v_pos, int __pyx_v_slots) {
int __pyx_v_a;
uint64_t __pyx_v_x;
int __pyx_r;
__Pyx_RefNannyDeclarations
int __pyx_t_1;
__Pyx_RefNannySetupContext("anextset", 0);

/* "bit.pxd":138
 * cdef inline int anextset(uint64_t *vec, uint32_t pos, int slots):
 * 	""" Return next set bit starting from pos, -1 if there is none. """
 * 	cdef int a = BITSLOT(pos)             # <<<<<<<<<<<<<<
 * 	cdef uint64_t x
 * 	if a >= slots:
 */
__pyx_v_a = BITSLOT(__pyx_v_pos);

/* "bit.pxd":140
 * 	cdef int a = BITSLOT(pos)
 * 	cdef uint64_t x
 * 	if a >= slots:             # <<<<<<<<<<<<<<
 * 		return -1
 * 	x = vec[a] & (~0UL << (pos % BITSIZE))
 */
__pyx_t_1 = ((__pyx_v_a >= __pyx_v_slots) != 0);
if (__pyx_t_1) {

  /* "bit.pxd":141
 * 	cdef uint64_t x
 * 	if a >= slots:
 * 		return -1             # <<<<<<<<<<<<<<
 * 	x = vec[a] & (~0UL << (pos % BITSIZE))
 * 	while x == 0UL:
 */
  __pyx_r = -1;
  goto __pyx_L0;

  /* "bit.pxd":140
 * 	cdef int a = BITSLOT(pos)
 * 	cdef uint64_t x
 * 	if a >= slots:             # <<<<<<<<<<<<<<
 * 		return -1
 * 	x = vec[a] & (~0UL << (pos % BITSIZE))
 */
}

/* "bit.pxd":142
 * 	if a >= slots:
 * 		return -1
 * 	x = vec[a] & (~0UL << (pos % BITSIZE))             # <<<<<<<<<<<<<<
 * 	while x == 0UL:
 * 		a += 1
 */
__pyx_v_x = ((__pyx_v_vec[__pyx_v_a]) & ((~0UL) << (__pyx_v_pos % BITSIZE)));

/* "bit.pxd":143
 * 		return -1
 * 	x = vec[a] & (~0UL << (pos % BITSIZE))
 * 	while x == 0UL:             # <<<<<<<<<<<<<<
 * 		a += 1
 * 		if a == slots:
 */
while (1) {
  __pyx_t_1 = ((__pyx_v_x == 0UL) != 0);
  if (!__pyx_t_1) break;

  /* "bit.pxd":144
 * 	x = vec[a] & (~0UL << (pos % BITSIZE))
 * 	while x == 0UL:
 * 		a += 1             # <<<<<<<<<<<<<<
 * 		if a == slots:
 * 			return -1
 */
  __pyx_v_a = (__pyx_v_a + 1);

  /* "bit.pxd":145
 * 	while x == 0UL:
 * 		a += 1
 * 		if a == slots:             # <<<<<<<<<<<<<<
 * 			return -1
 * 		x = vec[a]
 */
  __pyx_t_1 = ((__pyx_v_a == __pyx_v_slots) != 0);
  if (__pyx_t_1) {

    /* "bit.pxd":146
 * 		a += 1
 * 		if a == slots:
 * 			return -1             # <<<<<<<<<<<<<<
 * 		x = vec[a]
 * 	return a * BITSIZE + bit_ctz(x)
 */
    __pyx_r = -1;
    goto __pyx_L0;

    /* "bit.pxd":145
 * 	while x == 0UL:
 * 		a += 1
 * 		if a == slots:             # <<<<<<<<<<<<<<
 * 			return -1
 * 		x = vec[a]
 */
  }

  /* "bit.pxd":147
 * 		if a == slots:
 * 			return -1
 * 		x = vec[a]             # <<<<<<<<<<<<<<
 * 	return a * BITSIZE + bit_ctz(x)
 * 
 */
  __pyx_v_x = (__pyx_v_vec[__pyx_v_a]);
}

/* "bit.pxd":148
 * 			return -1
 * 		x = vec[a]
 * 	return a * BITSIZE + bit_ctz(x)             # <<<<<<<<<<<<<<
 * 
 * 
 */
__pyx_r = ((__pyx_v_a * BITSIZE) + bit_ctz(__pyx_v_x));
goto __pyx_L0;

/* "bit.pxd":136
 * 
 * 
 * cdef inline int anextset(uint64_t *vec, uint32_t pos, int slots):             # <<<<<<<<<<<<<<
 * 	""" Return next set bit starting from pos, -1 if there is none. """
 * 	cdef int a = BITSLOT(pos)
 */

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

/* "bit.pxd":151
 * 
 * 
 * cdef inline int anextunset(uint64_t *vec, uint32_t pos, int slots):             # <<<<<<<<<<<<<<
 * 	""" Return next unset bit starting from pos. """
 * 	cdef int a = BITSLOT(pos)
 */

static CYTHON_INLINE int __pyx_f_8discodop_3bit_anextunset(uint64_t *__pyx_v_vec, uint32_t __pyx_v_pos, int __pyx_v_slots) {
int __pyx_v_a;
uint64_t __pyx_v_x;
int __pyx_r;
__Pyx_RefNannyDeclarations
int __pyx_t_1;
__Pyx_RefNannySetupContext("anextunset", 0);

/* "bit.pxd":153
 * cdef inline int anextunset(uint64_t *vec, uint32_t pos, int slots):
 * 	""" Return next unset bit starting from pos. """
 * 	cdef int a = BITSLOT(pos)             # <<<<<<<<<<<<<<
 * 	cdef uint64_t x
 * 	if a >= slots:
 */
__pyx_v_a = BITSLOT(__pyx_v_pos);

/* "bit.pxd":155
 * 	cdef int a = BITSLOT(pos)
 * 	cdef uint64_t x
 * 	if a >= slots:             # <<<<<<<<<<<<<<
 * 		return a * BITSIZE
 * 	x = vec[a] | (BITMASK(pos) - 1)
 */
__pyx_t_1 = ((__pyx_v_a >= __pyx_v_slots) != 0);
if (__pyx_t_1) {

  /* "bit.pxd":156
 * 	cdef uint64_t x
 * 	if a >= slots:
 * 		return a * BITSIZE             # <<<<<<<<<<<<<<
 * 	x = vec[a] | (BITMASK(pos) - 1)
 * 	while x == ~0UL:
 */
  __pyx_r = (__pyx_v_a * BITSIZE);
  goto __pyx_L0;

  /* "bit.pxd":155
 * 	cdef int a = BITSLOT(pos)
 * 	cdef uint64_t x
 * 	if a >= slots:             # <<<<<<<<<<<<<<
 * 		return a * BITSIZE
 * 	x = vec[a] | (BITMASK(pos) - 1)
 */
}

/* "bit.pxd":157
 * 	if a >= slots:
 * 		return a * BITSIZE
 * 	x = vec[a] | (BITMASK(pos) - 1)             # <<<<<<<<<<<<<<
 * 	while x == ~0UL:
 * 		a += 1
 */
__pyx_v_x = ((__pyx_v_vec[__pyx_v_a]) | (BITMASK(__pyx_v_pos) - 1));

/* "bit.pxd":158
 * 		return a * BITSIZE
 * 	x = vec[a] | (BITMASK(pos) - 1)
 * 	while x == ~0UL:             # <<<<<<<<<<<<<<
 * 		a += 1
 * 		if a == slots:
 */
while (1) {
  __pyx_t_1 = ((__pyx_v_x == (~0UL)) != 0);
  if (!__pyx_t_1) break;

  /* "bit.pxd":159
 * 	x = vec[a] | (BITMASK(pos) - 1)
 * 	while x == ~0UL:
 * 		a += 1             # <<<<<<<<<<<<<<
 * 		if a == slots:
 * 			return a * BITSIZE
 */
  __pyx_v_a = (__pyx_v_a + 1);

  /* "bit.pxd":160
 * 	while x == ~0UL:
 * 		a += 1
 * 		if a == slots:             # <<<<<<<<<<<<<<
 * 			return a * BITSIZE
 * 		x = vec[a]
 */
  __pyx_t_1 = ((__pyx_v_a == __pyx_v_slots) != 0);
  if (__pyx_t_1) {

    /* "bit.pxd":161
 * 		a += 1
 * 		if a == slots:
 * 			return a * BITSIZE             # <<<<<<<<<<<<<<
 * 		x = vec[a]
 * 	return a * BITSIZE + bit_ctz(~x)
 */
    __pyx_r = (__pyx_v_a * BITSIZE);
    goto __pyx_L0;

    /* "bit.pxd":160
 * 	while x == ~0UL:
 * 		a += 1
 * 		if a == slots:             # <<<<<<<<<<<<<<
 * 			return a * BITSIZE
 * 		x = vec[a]
 */
  }

  /* "bit.pxd":162
 * 		if a == slots:
 * 			return a * BITSIZE
 * 		x = vec[a]             # <<<<<<<<<<<<<<
 * 	return a * BITSIZE + bit_ctz(~x)
 * 
 */
  __pyx_v_x = (__pyx_v_vec[__pyx_v_a]);
}

/* "bit.pxd":163
 * 			return a * BITSIZE
 * 		x = vec[a]
 * 	return a * BITSIZE + bit_ctz(~x)             # <<<<<<<<<<<<<<
 * 
 * 
 */
__pyx_r = ((__pyx_v_a * BITSIZE) + bit_ctz((~__pyx_v_x)));
goto __pyx_L0;

/* "bit.pxd":151
 * 
 * 
 * cdef inline int anextunset(uint64_t *vec, uint32_t pos, int slots):             # <<<<<<<<<<<<<<
 * 	""" Return next unset bit starting from pos. """
 * 	cdef int a = BITSLOT(pos)
 */

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

/* "bit.pxd":166
 * 
 * 
 * cdef inline int iteratesetbits(uint64_t *vec, int slots,             # <<<<<<<<<<<<<<
 * 		uint64_t *cur, int *idx):
 * 	"""Iterate over set bits in an array of unsigned long.
 */

static CYTHON_INLINE int __pyx_f_8discodop_3bit_iteratesetbits(uint64_t *__pyx_v_vec, int __pyx_v_slots, uint64_t *__pyx_v_cur, int *__pyx_v_idx) {
int __pyx_v_tmp;
int __pyx_r;
__Pyx_RefNannyDeclarations
int __pyx_t_1;
long __pyx_t_2;
__Pyx_RefNannySetupContext("iteratesetbits", 0);

/* "bit.pxd":187
 * 	"""
 * 	cdef int tmp
 * 	while not cur[0]:             # <<<<<<<<<<<<<<
 * 		idx[0] += 1
 * 		if idx[0] >= slots:
 */
while (1) {
  __pyx_t_1 = ((!((__pyx_v_cur[0]) != 0)) != 0);
  if (!__pyx_t_1) break;

  /* "bit.pxd":188
 * 	cdef int tmp
 * 	while not cur[0]:
 * 		idx[0] += 1             # <<<<<<<<<<<<<<
 * 		if idx[0] >= slots:
 * 			return -1
 */
  __pyx_t_2 = 0;
  (__pyx_v_idx[__pyx_t_2]) = ((__pyx_v_idx[__pyx_t_2]) + 1);

  /* "bit.pxd":189
 * 	while not cur[0]:
 * 		idx[0] += 1
 * 		if idx[0] >= slots:             # <<<<<<<<<<<<<<
 * 			return -1
 * 		cur[0] = vec[idx[0]]
 */
  __pyx_t_1 = (((__pyx_v_idx[0]) >= __pyx_v_slots) != 0);
  if (__pyx_t_1) {

    /* "bit.pxd":190
 * 		idx[0] += 1
 * 		if idx[0] >= slots:
 * 			return -1             # <<<<<<<<<<<<<<
 * 		cur[0] = vec[idx[0]]
 * 	tmp = bit_ctz(cur[0])  # index of bit in current slot
 */
    __pyx_r = -1;
    goto __pyx_L0;

    /* "bit.pxd":189
 * 	while not cur[0]:
 * 		idx[0] += 1
 * 		if idx[0] >= slots:             # <<<<<<<<<<<<<<
 * 			return -1
 * 		cur[0] = vec[idx[0]]
 */
  }

  /* "bit.pxd":191
 * 		if idx[0] >= slots:
 * 			return -1
 * 		cur[0] = vec[idx[0]]             # <<<<<<<<<<<<<<
 * 	tmp = bit_ctz(cur[0])  # index of bit in current slot
 * 	cur[0] ^= 1UL << tmp  # TOGGLEBIT(cur, tmp)
 */
  (__pyx_v_cur[0]) = (__pyx_v_vec[(__pyx_v_idx[0])]);
}

/* "bit.pxd":192
 * 			return -1
 * 		cur[0] = vec[idx[0]]
 * 	tmp = bit_ctz(cur[0])  # index of bit in current slot             # <<<<<<<<<<<<<<
 * 	cur[0] ^= 1UL << tmp  # TOGGLEBIT(cur, tmp)
 * 	return idx[0] * BITSIZE + tmp
 */
__pyx_v_tmp = bit_ctz((__pyx_v_cur[0]));

/* "bit.pxd":193
 * 		cur[0] = vec[idx[0]]
 * 	tmp = bit_ctz(cur[0])  # index of bit in current slot
 * 	cur[0] ^= 1UL << tmp  # TOGGLEBIT(cur, tmp)             # <<<<<<<<<<<<<<
 * 	return idx[0] * BITSIZE + tmp
 * 
 */
__pyx_t_2 = 0;
(__pyx_v_cur[__pyx_t_2]) = ((__pyx_v_cur[__pyx_t_2]) ^ (1UL << __pyx_v_tmp));

/* "bit.pxd":194
 * 	tmp = bit_ctz(cur[0])  # index of bit in current slot
 * 	cur[0] ^= 1UL << tmp  # TOGGLEBIT(cur, tmp)
 * 	return idx[0] * BITSIZE + tmp             # <<<<<<<<<<<<<<
 * 
 * 
 */
__pyx_r = (((__pyx_v_idx[0]) * BITSIZE) + __pyx_v_tmp);
goto __pyx_L0;

/* "bit.pxd":166
 * 
 * 
 * cdef inline int iteratesetbits(uint64_t *vec, int slots,             # <<<<<<<<<<<<<<
 * 		uint64_t *cur, int *idx):
 * 	"""Iterate over set bits in an array of unsigned long.
 */

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

/* "bit.pxd":197
 * 
 * 
 * cdef inline int iterateunsetbits(uint64_t *vec, int slots,             # <<<<<<<<<<<<<<
 * 		uint64_t *cur, int *idx):
 * 	"""Like ``iteratesetbits``, but return indices of zero bits.
 */

static CYTHON_INLINE int __pyx_f_8discodop_3bit_iterateunsetbits(uint64_t *__pyx_v_vec, int __pyx_v_slots, uint64_t *__pyx_v_cur, int *__pyx_v_idx) {
int __pyx_v_tmp;
int __pyx_r;
__Pyx_RefNannyDeclarations
int __pyx_t_1;
long __pyx_t_2;
__Pyx_RefNannySetupContext("iterateunsetbits", 0);

/* "bit.pxd":203
 * 	:param cur: should be initialized as: ``cur = ~vec[idx]``."""
 * 	cdef int tmp
 * 	while not cur[0]:             # <<<<<<<<<<<<<<
 * 		idx[0] += 1
 * 		if idx[0] >= slots:
 */
while (1) {
  __pyx_t_1 = ((!((__pyx_v_cur[0]) != 0)) != 0);
  if (!__pyx_t_1) break;

  /* "bit.pxd":204
 * 	cdef int tmp
 * 	while not cur[0]:
 * 		idx[0] += 1             # <<<<<<<<<<<<<<
 * 		if idx[0] >= slots:
 * 			return -1
 */
  __pyx_t_2 = 0;
  (__pyx_v_idx[__pyx_t_2]) = ((__pyx_v_idx[__pyx_t_2]) + 1);

  /* "bit.pxd":205
 * 	while not cur[0]:
 * 		idx[0] += 1
 * 		if idx[0] >= slots:             # <<<<<<<<<<<<<<
 * 			return -1
 * 		cur[0] = ~vec[idx[0]]
 */
  __pyx_t_1 = (((__pyx_v_idx[0]) >= __pyx_v_slots) != 0);
  if (__pyx_t_1) {

    /* "bit.pxd":206
 * 		idx[0] += 1
 * 		if idx[0] >= slots:
 * 			return -1             # <<<<<<<<<<<<<<
 * 		cur[0] = ~vec[idx[0]]
 * 	tmp = bit_ctz(cur[0])  # index of bit in current slot
 */
    __pyx_r = -1;
    goto __pyx_L0;

    /* "bit.pxd":205
 * 	while not cur[0]:
 * 		idx[0] += 1
 * 		if idx[0] >= slots:             # <<<<<<<<<<<<<<
 * 			return -1
 * 		cur[0] = ~vec[idx[0]]
 */
  }

  /* "bit.pxd":207
 * 		if idx[0] >= slots:
 * 			return -1
 * 		cur[0] = ~vec[idx[0]]             # <<<<<<<<<<<<<<
 * 	tmp = bit_ctz(cur[0])  # index of bit in current slot
 * 	cur[0] ^= 1UL << tmp  # TOGGLEBIT(cur, tmp)
 */
  (__pyx_v_cur[0]) = (~(__pyx_v_vec[(__pyx_v_idx[0])]));
}

/* "bit.pxd":208
 * 			return -1
 * 		cur[0] = ~vec[idx[0]]
 * 	tmp = bit_ctz(cur[0])  # index of bit in current slot             # <<<<<<<<<<<<<<
 * 	cur[0] ^= 1UL << tmp  # TOGGLEBIT(cur, tmp)
 * 	return idx[0] * BITSIZE + tmp
 */
__pyx_v_tmp = bit_ctz((__pyx_v_cur[0]));

/* "bit.pxd":209
 * 		cur[0] = ~vec[idx[0]]
 * 	tmp = bit_ctz(cur[0])  # index of bit in current slot
 * 	cur[0] ^= 1UL << tmp  # TOGGLEBIT(cur, tmp)             # <<<<<<<<<<<<<<
 * 	return idx[0] * BITSIZE + tmp
 * 
 */
__pyx_t_2 = 0;
(__pyx_v_cur[__pyx_t_2]) = ((__pyx_v_cur[__pyx_t_2]) ^ (1UL << __pyx_v_tmp));

/* "bit.pxd":210
 * 	tmp = bit_ctz(cur[0])  # index of bit in current slot
 * 	cur[0] ^= 1UL << tmp  # TOGGLEBIT(cur, tmp)
 * 	return idx[0] * BITSIZE + tmp             # <<<<<<<<<<<<<<
 * 
 * 
 */
__pyx_r = (((__pyx_v_idx[0]) * BITSIZE) + __pyx_v_tmp);
goto __pyx_L0;

/* "bit.pxd":197
 * 
 * 
 * cdef inline int iterateunsetbits(uint64_t *vec, int slots,             # <<<<<<<<<<<<<<
 * 		uint64_t *cur, int *idx):
 * 	"""Like ``iteratesetbits``, but return indices of zero bits.
 */

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

/* "bit.pxd":213
 * 
 * 
 * cdef inline void setintersectinplace(uint64_t *dest, uint64_t *src, int slots):             # <<<<<<<<<<<<<<
 * 	"""dest gets the intersection of dest and src.
 * 
 */

static CYTHON_INLINE void __pyx_f_8discodop_3bit_setintersectinplace(uint64_t *__pyx_v_dest, uint64_t *__pyx_v_src, int __pyx_v_slots) {
int __pyx_v_a;
__Pyx_RefNannyDeclarations
int __pyx_t_1;
int __pyx_t_2;
int __pyx_t_3;
__Pyx_RefNannySetupContext("setintersectinplace", 0);

/* "bit.pxd":218
 * 	both operands must have at least `slots' slots."""
 * 	cdef int a
 * 	for a in range(slots):             # <<<<<<<<<<<<<<
 * 		dest[a] &= src[a]
 * 
 */
__pyx_t_1 = __pyx_v_slots;
for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {
  __pyx_v_a = __pyx_t_2;

  /* "bit.pxd":219
 * 	cdef int a
 * 	for a in range(slots):
 * 		dest[a] &= src[a]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __pyx_v_a;
  (__pyx_v_dest[__pyx_t_3]) = ((__pyx_v_dest[__pyx_t_3]) & (__pyx_v_src[__pyx_v_a]));
}

/* "bit.pxd":213
 * 
 * 
 * cdef inline void setintersectinplace(uint64_t *dest, uint64_t *src, int slots):             # <<<<<<<<<<<<<<
 * 	"""dest gets the intersection of dest and src.
 * 
 */

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

/* "bit.pxd":222
 * 
 * 
 * cdef inline void setunioninplace(uint64_t *dest, uint64_t *src, int slots):             # <<<<<<<<<<<<<<
 * 	"""dest gets the union of dest and src.
 * 
 */

static CYTHON_INLINE void __pyx_f_8discodop_3bit_setunioninplace(uint64_t *__pyx_v_dest, uint64_t *__pyx_v_src, int __pyx_v_slots) {
int __pyx_v_a;
__Pyx_RefNannyDeclarations
int __pyx_t_1;
int __pyx_t_2;
int __pyx_t_3;
__Pyx_RefNannySetupContext("setunioninplace", 0);

/* "bit.pxd":227
 * 	Both operands must have at least ``slots`` slots."""
 * 	cdef int a
 * 	for a in range(slots):             # <<<<<<<<<<<<<<
 * 		dest[a] |= src[a]
 * 
 */
__pyx_t_1 = __pyx_v_slots;
for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {
  __pyx_v_a = __pyx_t_2;

  /* "bit.pxd":228
 * 	cdef int a
 * 	for a in range(slots):
 * 		dest[a] |= src[a]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  __pyx_t_3 = __pyx_v_a;
  (__pyx_v_dest[__pyx_t_3]) = ((__pyx_v_dest[__pyx_t_3]) | (__pyx_v_src[__pyx_v_a]));
}

/* "bit.pxd":222
 * 
 * 
 * cdef inline void setunioninplace(uint64_t *dest, uint64_t *src, int slots):             # <<<<<<<<<<<<<<
 * 	"""dest gets the union of dest and src.
 * 
 */

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

/* "bit.pxd":231
 * 
 * 
 * cdef inline void setintersect(uint64_t *dest, uint64_t *src1, uint64_t *src2,             # <<<<<<<<<<<<<<
 * 		int slots):
 * 	"""dest gets the intersection of src1 and src2.
 */

static CYTHON_INLINE void __pyx_f_8discodop_3bit_setintersect(uint64_t *__pyx_v_dest, uint64_t *__pyx_v_src1, uint64_t *__pyx_v_src2, int __pyx_v_slots) {
int __pyx_v_a;
__Pyx_RefNannyDeclarations
int __pyx_t_1;
int __pyx_t_2;
__Pyx_RefNannySetupContext("setintersect", 0);

/* "bit.pxd":237
 * 	operands must have at least ``slots`` slots."""
 * 	cdef int a
 * 	for a in range(slots):             # <<<<<<<<<<<<<<
 * 		dest[a] = src1[a] & src2[a]
 * 
 */
__pyx_t_1 = __pyx_v_slots;
for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {
  __pyx_v_a = __pyx_t_2;

  /* "bit.pxd":238
 * 	cdef int a
 * 	for a in range(slots):
 * 		dest[a] = src1[a] & src2[a]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  (__pyx_v_dest[__pyx_v_a]) = ((__pyx_v_src1[__pyx_v_a]) & (__pyx_v_src2[__pyx_v_a]));
}

/* "bit.pxd":231
 * 
 * 
 * cdef inline void setintersect(uint64_t *dest, uint64_t *src1, uint64_t *src2,             # <<<<<<<<<<<<<<
 * 		int slots):
 * 	"""dest gets the intersection of src1 and src2.
 */

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

/* "bit.pxd":241
 * 
 * 
 * cdef inline void setunion(uint64_t *dest, uint64_t *src1, uint64_t *src2,             # <<<<<<<<<<<<<<
 * 		int slots):
 * 	"""dest gets the union of src1 and src2.
 */

static CYTHON_INLINE void __pyx_f_8discodop_3bit_setunion(uint64_t *__pyx_v_dest, uint64_t *__pyx_v_src1, uint64_t *__pyx_v_src2, int __pyx_v_slots) {
int __pyx_v_a;
__Pyx_RefNannyDeclarations
int __pyx_t_1;
int __pyx_t_2;
__Pyx_RefNannySetupContext("setunion", 0);

/* "bit.pxd":247
 * 	operands must have at least ``slots`` slots."""
 * 	cdef int a
 * 	for a in range(slots):             # <<<<<<<<<<<<<<
 * 		dest[a] = src1[a] | src2[a]
 * 
 */
__pyx_t_1 = __pyx_v_slots;
for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {
  __pyx_v_a = __pyx_t_2;

  /* "bit.pxd":248
 * 	cdef int a
 * 	for a in range(slots):
 * 		dest[a] = src1[a] | src2[a]             # <<<<<<<<<<<<<<
 * 
 * 
 */
  (__pyx_v_dest[__pyx_v_a]) = ((__pyx_v_src1[__pyx_v_a]) | (__pyx_v_src2[__pyx_v_a]));
}

/* "bit.pxd":241
 * 
 * 
 * cdef inline void setunion(uint64_t *dest, uint64_t *src1, uint64_t *src2,             # <<<<<<<<<<<<<<
 * 		int slots):
 * 	"""dest gets the union of src1 and src2.
 */

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

/* "bit.pxd":251
 * 
 * 
 * cdef inline bint subset(uint64_t *vec1, uint64_t *vec2, int slots):             # <<<<<<<<<<<<<<
 * 	"""Test whether vec1 is a subset of vec2.
 * 
 */

static CYTHON_INLINE int __pyx_f_8discodop_3bit_subset(uint64_t *__pyx_v_vec1, uint64_t *__pyx_v_vec2, int __pyx_v_slots) {
int __pyx_v_a;
int __pyx_r;
__Pyx_RefNannyDeclarations
int __pyx_t_1;
int __pyx_t_2;
int __pyx_t_3;
__Pyx_RefNannySetupContext("subset", 0);

/* "bit.pxd":256
 * 	i.e., all set bits of vec1 should be set in vec2."""
 * 	cdef int a
 * 	for a in range(slots):             # <<<<<<<<<<<<<<
 * 		if (vec1[a] & vec2[a]) != vec1[a]:
 * 			return False
 */
__pyx_t_1 = __pyx_v_slots;
for (__pyx_t_2 = 0; __pyx_t_2 < __pyx_t_1; __pyx_t_2+=1) {
  __pyx_v_a = __pyx_t_2;

  /* "bit.pxd":257
 * 	cdef int a
 * 	for a in range(slots):
 * 		if (vec1[a] & vec2[a]) != vec1[a]:             # <<<<<<<<<<<<<<
 * 			return False
 * 	return True
 */
  __pyx_t_3 = ((((__pyx_v_vec1[__pyx_v_a]) & (__pyx_v_vec2[__pyx_v_a])) != (__pyx_v_vec1[__pyx_v_a])) != 0);
  if (__pyx_t_3) {

    /* "bit.pxd":258
 * 	for a in range(slots):
 * 		if (vec1[a] & vec2[a]) != vec1[a]:
 * 			return False             # <<<<<<<<<<<<<<
 * 	return True
 */
    __pyx_r = 0;
    goto __pyx_L0;

    /* "bit.pxd":257
 * 	cdef int a
 * 	for a in range(slots):
 * 		if (vec1[a] & vec2[a]) != vec1[a]:             # <<<<<<<<<<<<<<
 * 			return False
 * 	return True
 */
  }
}

/* "bit.pxd":259
 * 		if (vec1[a] & vec2[a]) != vec1[a]:
 * 			return False
 * 	return True             # <<<<<<<<<<<<<<
 */
__pyx_r = 1;
goto __pyx_L0;

/* "bit.pxd":251
 * 
 * 
 * cdef inline bint subset(uint64_t *vec1, uint64_t *vec2, int slots):             # <<<<<<<<<<<<<<
 * 	"""Test whether vec1 is a subset of vec2.
 * 
 */

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

/* "plcfrs.pxd":74
 * 
 * 
 * cdef inline Entry new_Entry(object k, object v, uint64_t c):             # <<<<<<<<<<<<<<
 * 	cdef Entry entry = Entry.__new__(Entry)
 * 	entry.key = k
 */

static CYTHON_INLINE struct __pyx_obj_8discodop_6plcfrs_Entry *__pyx_f_8discodop_6plcfrs_new_Entry(PyObject *__pyx_v_k, PyObject *__pyx_v_v, uint64_t __pyx_v_c) {
struct __pyx_obj_8discodop_6plcfrs_Entry *__pyx_v_entry = 0;
struct __pyx_obj_8discodop_6plcfrs_Entry *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
__Pyx_RefNannySetupContext("new_Entry", 0);

/* "plcfrs.pxd":75
 * 
 * cdef inline Entry new_Entry(object k, object v, uint64_t c):
 * 	cdef Entry entry = Entry.__new__(Entry)             # <<<<<<<<<<<<<<
 * 	entry.key = k
 * 	entry.value = v
 */
__pyx_t_1 = __Pyx_tp_new(((PyObject *)__pyx_ptype_8discodop_6plcfrs_Entry), __pyx_empty_tuple); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 75, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8discodop_6plcfrs_Entry)))) __PYX_ERR(3, 75, __pyx_L1_error)
__pyx_v_entry = ((struct __pyx_obj_8discodop_6plcfrs_Entry *)__pyx_t_1);
__pyx_t_1 = 0;

/* "plcfrs.pxd":76
 * cdef inline Entry new_Entry(object k, object v, uint64_t c):
 * 	cdef Entry entry = Entry.__new__(Entry)
 * 	entry.key = k             # <<<<<<<<<<<<<<
 * 	entry.value = v
 * 	entry.count = c
 */
__Pyx_INCREF(__pyx_v_k);
__Pyx_GIVEREF(__pyx_v_k);
__Pyx_GOTREF(__pyx_v_entry->key);
__Pyx_DECREF(__pyx_v_entry->key);
__pyx_v_entry->key = __pyx_v_k;

/* "plcfrs.pxd":77
 * 	cdef Entry entry = Entry.__new__(Entry)
 * 	entry.key = k
 * 	entry.value = v             # <<<<<<<<<<<<<<
 * 	entry.count = c
 * 	return entry
 */
__Pyx_INCREF(__pyx_v_v);
__Pyx_GIVEREF(__pyx_v_v);
__Pyx_GOTREF(__pyx_v_entry->value);
__Pyx_DECREF(__pyx_v_entry->value);
__pyx_v_entry->value = __pyx_v_v;

/* "plcfrs.pxd":78
 * 	entry.key = k
 * 	entry.value = v
 * 	entry.count = c             # <<<<<<<<<<<<<<
 * 	return entry
 * 
 */
__pyx_v_entry->count = __pyx_v_c;

/* "plcfrs.pxd":79
 * 	entry.value = v
 * 	entry.count = c
 * 	return entry             # <<<<<<<<<<<<<<
 * 
 * 
 */
__Pyx_XDECREF(((PyObject *)__pyx_r));
__Pyx_INCREF(((PyObject *)__pyx_v_entry));
__pyx_r = __pyx_v_entry;
goto __pyx_L0;

/* "plcfrs.pxd":74
 * 
 * 
 * cdef inline Entry new_Entry(object k, object v, uint64_t c):             # <<<<<<<<<<<<<<
 * 	cdef Entry entry = Entry.__new__(Entry)
 * 	entry.key = k
 */

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("discodop.plcfrs.new_Entry", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_entry);
__Pyx_XGIVEREF((PyObject *)__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

/* "plcfrs.pxd":82
 * 
 * 
 * cdef inline DoubleEntry new_DoubleEntry(object k, double v, uint64_t c):             # <<<<<<<<<<<<<<
 * 	cdef DoubleEntry entry = DoubleEntry.__new__(DoubleEntry)
 * 	entry.key = k
 */

static CYTHON_INLINE struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *__pyx_f_8discodop_6plcfrs_new_DoubleEntry(PyObject *__pyx_v_k, double __pyx_v_v, uint64_t __pyx_v_c) {
struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *__pyx_v_entry = 0;
struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *__pyx_r = NULL;
__Pyx_RefNannyDeclarations
PyObject *__pyx_t_1 = NULL;
__Pyx_RefNannySetupContext("new_DoubleEntry", 0);

/* "plcfrs.pxd":83
 * 
 * cdef inline DoubleEntry new_DoubleEntry(object k, double v, uint64_t c):
 * 	cdef DoubleEntry entry = DoubleEntry.__new__(DoubleEntry)             # <<<<<<<<<<<<<<
 * 	entry.key = k
 * 	entry.value = v
 */
__pyx_t_1 = __Pyx_tp_new(((PyObject *)__pyx_ptype_8discodop_6plcfrs_DoubleEntry), __pyx_empty_tuple); if (unlikely(!__pyx_t_1)) __PYX_ERR(3, 83, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (!(likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_8discodop_6plcfrs_DoubleEntry)))) __PYX_ERR(3, 83, __pyx_L1_error)
__pyx_v_entry = ((struct __pyx_obj_8discodop_6plcfrs_DoubleEntry *)__pyx_t_1);
__pyx_t_1 = 0;

/* "plcfrs.pxd":84
 * cdef inline DoubleEntry new_DoubleEntry(object k, double v, uint64_t c):
 * 	cdef DoubleEntry entry = DoubleEntry.__new__(DoubleEntry)
 * 	entry.key = k             # <<<<<<<<<<<<<<
 * 	entry.value = v
 * 	entry.count = c
 */
__Pyx_INCREF(__pyx_v_k);
__Pyx_GIVEREF(__pyx_v_k);
__Pyx_GOTREF(__pyx_v_entry->key);
__Pyx_DECREF(__pyx_v_entry->key);
__pyx_v_entry->key = __pyx_v_k;

/* "plcfrs.pxd":85
 * 	cdef DoubleEntry entry = DoubleEntry.__new__(DoubleEntry)
 * 	entry.key = k
 * 	entry.value = v             # <<<<<<<<<<<<<<
 * 	entry.count = c
 * 	return entry
 */
__pyx_v_entry->value = __pyx_v_v;

/* "plcfrs.pxd":86
 * 	entry.key = k
 * 	entry.value = v
 * 	entry.count = c             # <<<<<<<<<<<<<<
 * 	return entry
 * 
 */
__pyx_v_entry->count = __pyx_v_c;

/* "plcfrs.pxd":87
 * 	entry.value = v
 * 	entry.count = c
 * 	return entry             # <<<<<<<<<<<<<<
 * 
 * 
 */
__Pyx_XDECREF(((PyObject *)__pyx_r));
__Pyx_INCREF(((PyObject *)__pyx_v_entry));
__pyx_r = __pyx_v_entry;
goto __pyx_L0;

/* "plcfrs.pxd":82
 * 
 * 
 * cdef inline DoubleEntry new_DoubleEntry(object k, double v, uint64_t c):             # <<<<<<<<<<<<<<
 * 	cdef DoubleEntry entry = DoubleEntry.__new__(DoubleEntry)
 * 	entry.key = k
 */

/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_AddTraceback("discodop.plcfrs.new_DoubleEntry", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XDECREF((PyObject *)__pyx_v_entry);
__Pyx_XGIVEREF((PyObject *)__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}

static struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct__doprerank *__pyx_freelist_8discodop_14disambiguation___pyx_scope_struct__doprerank[8];
static int __pyx_freecount_8discodop_14disambiguation___pyx_scope_struct__doprerank = 0;

static PyObject *__pyx_tp_new_8discodop_14disambiguation___pyx_scope_struct__doprerank(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
PyObject *o;
if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_8discodop_14disambiguation___pyx_scope_struct__doprerank > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct__doprerank)))) {
  o = (PyObject*)__pyx_freelist_8discodop_14disambiguation___pyx_scope_struct__doprerank[--__pyx_freecount_8discodop_14disambiguation___pyx_scope_struct__doprerank];
  memset(o, 0, sizeof(struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct__doprerank));
  (void) PyObject_INIT(o, t);
  PyObject_GC_Track(o);
} else {
  o = (*t->tp_alloc)(t, 0);
  if (unlikely(!o)) return 0;
}
return o;
}

static void __pyx_tp_dealloc_8discodop_14disambiguation___pyx_scope_struct__doprerank(PyObject *o) {
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct__doprerank *p = (struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct__doprerank *)o;
PyObject_GC_UnTrack(o);
Py_CLEAR(p->__pyx_v_results);
if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_8discodop_14disambiguation___pyx_scope_struct__doprerank < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct__doprerank)))) {
  __pyx_freelist_8discodop_14disambiguation___pyx_scope_struct__doprerank[__pyx_freecount_8discodop_14disambiguation___pyx_scope_struct__doprerank++] = ((struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct__doprerank *)o);
} else {
  (*Py_TYPE(o)->tp_free)(o);
}
}

static int __pyx_tp_traverse_8discodop_14disambiguation___pyx_scope_struct__doprerank(PyObject *o, visitproc v, void *a) {
int e;
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct__doprerank *p = (struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct__doprerank *)o;
if (p->__pyx_v_results) {
  e = (*v)(p->__pyx_v_results, a); if (e) return e;
}
return 0;
}

static int __pyx_tp_clear_8discodop_14disambiguation___pyx_scope_struct__doprerank(PyObject *o) {
PyObject* tmp;
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct__doprerank *p = (struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct__doprerank *)o;
tmp = ((PyObject*)p->__pyx_v_results);
p->__pyx_v_results = ((PyObject*)Py_None); Py_INCREF(Py_None);
Py_XDECREF(tmp);
return 0;
}

static PyTypeObject __pyx_type_8discodop_14disambiguation___pyx_scope_struct__doprerank = {
PyVarObject_HEAD_INIT(0, 0)
"discodop.disambiguation.__pyx_scope_struct__doprerank", /*tp_name*/
sizeof(struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct__doprerank), /*tp_basicsize*/
0, /*tp_itemsize*/
__pyx_tp_dealloc_8discodop_14disambiguation___pyx_scope_struct__doprerank, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
#if PY_MAJOR_VERSION < 3
0, /*tp_compare*/
#endif
#if PY_MAJOR_VERSION >= 3
0, /*tp_as_async*/
#endif
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
0, /*tp_doc*/
__pyx_tp_traverse_8discodop_14disambiguation___pyx_scope_struct__doprerank, /*tp_traverse*/
__pyx_tp_clear_8discodop_14disambiguation___pyx_scope_struct__doprerank, /*tp_clear*/
0, /*tp_richcompare*/
0, /*tp_weaklistoffset*/
0, /*tp_iter*/
0, /*tp_iternext*/
0, /*tp_methods*/
0, /*tp_members*/
0, /*tp_getset*/
0, /*tp_base*/
0, /*tp_dict*/
0, /*tp_descr_get*/
0, /*tp_descr_set*/
0, /*tp_dictoffset*/
0, /*tp_init*/
0, /*tp_alloc*/
__pyx_tp_new_8discodop_14disambiguation___pyx_scope_struct__doprerank, /*tp_new*/
0, /*tp_free*/
0, /*tp_is_gc*/
0, /*tp_bases*/
0, /*tp_mro*/
0, /*tp_cache*/
0, /*tp_subclasses*/
0, /*tp_weaklist*/
0, /*tp_del*/
0, /*tp_version_tag*/
#if PY_VERSION_HEX >= 0x030400a1
0, /*tp_finalize*/
#endif
};

static struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank *__pyx_freelist_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank[8];
static int __pyx_freecount_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank = 0;

static PyObject *__pyx_tp_new_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
PyObject *o;
if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank)))) {
  o = (PyObject*)__pyx_freelist_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank[--__pyx_freecount_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank];
  memset(o, 0, sizeof(struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank));
  (void) PyObject_INIT(o, t);
  PyObject_GC_Track(o);
} else {
  o = (*t->tp_alloc)(t, 0);
  if (unlikely(!o)) return 0;
}
return o;
}

static void __pyx_tp_dealloc_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank(PyObject *o) {
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank *p = (struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank *)o;
PyObject_GC_UnTrack(o);
Py_CLEAR(p->__pyx_v_i);
Py_CLEAR(p->__pyx_v_results);
Py_CLEAR(p->__pyx_v_rev);
if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank)))) {
  __pyx_freelist_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank[__pyx_freecount_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank++] = ((struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank *)o);
} else {
  (*Py_TYPE(o)->tp_free)(o);
}
}

static int __pyx_tp_traverse_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank(PyObject *o, visitproc v, void *a) {
int e;
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank *p = (struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank *)o;
if (p->__pyx_v_i) {
  e = (*v)(p->__pyx_v_i, a); if (e) return e;
}
if (p->__pyx_v_results) {
  e = (*v)(p->__pyx_v_results, a); if (e) return e;
}
if (p->__pyx_v_rev) {
  e = (*v)(p->__pyx_v_rev, a); if (e) return e;
}
return 0;
}

static int __pyx_tp_clear_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank(PyObject *o) {
PyObject* tmp;
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank *p = (struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank *)o;
tmp = ((PyObject*)p->__pyx_v_i);
p->__pyx_v_i = Py_None; Py_INCREF(Py_None);
Py_XDECREF(tmp);
tmp = ((PyObject*)p->__pyx_v_results);
p->__pyx_v_results = ((PyObject*)Py_None); Py_INCREF(Py_None);
Py_XDECREF(tmp);
tmp = ((PyObject*)p->__pyx_v_rev);
p->__pyx_v_rev = Py_None; Py_INCREF(Py_None);
Py_XDECREF(tmp);
return 0;
}

static PyTypeObject __pyx_type_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank = {
PyVarObject_HEAD_INIT(0, 0)
"discodop.disambiguation.__pyx_scope_struct_1_mcrerank", /*tp_name*/
sizeof(struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank), /*tp_basicsize*/
0, /*tp_itemsize*/
__pyx_tp_dealloc_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
#if PY_MAJOR_VERSION < 3
0, /*tp_compare*/
#endif
#if PY_MAJOR_VERSION >= 3
0, /*tp_as_async*/
#endif
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
0, /*tp_doc*/
__pyx_tp_traverse_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank, /*tp_traverse*/
__pyx_tp_clear_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank, /*tp_clear*/
0, /*tp_richcompare*/
0, /*tp_weaklistoffset*/
0, /*tp_iter*/
0, /*tp_iternext*/
0, /*tp_methods*/
0, /*tp_members*/
0, /*tp_getset*/
0, /*tp_base*/
0, /*tp_dict*/
0, /*tp_descr_get*/
0, /*tp_descr_set*/
0, /*tp_dictoffset*/
0, /*tp_init*/
0, /*tp_alloc*/
__pyx_tp_new_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank, /*tp_new*/
0, /*tp_free*/
0, /*tp_is_gc*/
0, /*tp_bases*/
0, /*tp_mro*/
0, /*tp_cache*/
0, /*tp_subclasses*/
0, /*tp_weaklist*/
0, /*tp_del*/
0, /*tp_version_tag*/
#if PY_VERSION_HEX >= 0x030400a1
0, /*tp_finalize*/
#endif
};

static struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_2_genexpr *__pyx_freelist_8discodop_14disambiguation___pyx_scope_struct_2_genexpr[8];
static int __pyx_freecount_8discodop_14disambiguation___pyx_scope_struct_2_genexpr = 0;

static PyObject *__pyx_tp_new_8discodop_14disambiguation___pyx_scope_struct_2_genexpr(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) {
PyObject *o;
if (CYTHON_COMPILING_IN_CPYTHON && likely((__pyx_freecount_8discodop_14disambiguation___pyx_scope_struct_2_genexpr > 0) & (t->tp_basicsize == sizeof(struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_2_genexpr)))) {
  o = (PyObject*)__pyx_freelist_8discodop_14disambiguation___pyx_scope_struct_2_genexpr[--__pyx_freecount_8discodop_14disambiguation___pyx_scope_struct_2_genexpr];
  memset(o, 0, sizeof(struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_2_genexpr));
  (void) PyObject_INIT(o, t);
  PyObject_GC_Track(o);
} else {
  o = (*t->tp_alloc)(t, 0);
  if (unlikely(!o)) return 0;
}
return o;
}

static void __pyx_tp_dealloc_8discodop_14disambiguation___pyx_scope_struct_2_genexpr(PyObject *o) {
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_2_genexpr *p = (struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_2_genexpr *)o;
PyObject_GC_UnTrack(o);
Py_CLEAR(p->__pyx_outer_scope);
Py_CLEAR(p->__pyx_v_frag);
Py_CLEAR(p->__pyx_t_0);
if (CYTHON_COMPILING_IN_CPYTHON && ((__pyx_freecount_8discodop_14disambiguation___pyx_scope_struct_2_genexpr < 8) & (Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_2_genexpr)))) {
  __pyx_freelist_8discodop_14disambiguation___pyx_scope_struct_2_genexpr[__pyx_freecount_8discodop_14disambiguation___pyx_scope_struct_2_genexpr++] = ((struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_2_genexpr *)o);
} else {
  (*Py_TYPE(o)->tp_free)(o);
}
}

static int __pyx_tp_traverse_8discodop_14disambiguation___pyx_scope_struct_2_genexpr(PyObject *o, visitproc v, void *a) {
int e;
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_2_genexpr *p = (struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_2_genexpr *)o;
if (p->__pyx_outer_scope) {
  e = (*v)(((PyObject*)p->__pyx_outer_scope), a); if (e) return e;
}
if (p->__pyx_v_frag) {
  e = (*v)(p->__pyx_v_frag, a); if (e) return e;
}
if (p->__pyx_t_0) {
  e = (*v)(p->__pyx_t_0, a); if (e) return e;
}
return 0;
}

static int __pyx_tp_clear_8discodop_14disambiguation___pyx_scope_struct_2_genexpr(PyObject *o) {
PyObject* tmp;
struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_2_genexpr *p = (struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_2_genexpr *)o;
tmp = ((PyObject*)p->__pyx_outer_scope);
p->__pyx_outer_scope = ((struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank *)Py_None); Py_INCREF(Py_None);
Py_XDECREF(tmp);
tmp = ((PyObject*)p->__pyx_v_frag);
p->__pyx_v_frag = Py_None; Py_INCREF(Py_None);
Py_XDECREF(tmp);
tmp = ((PyObject*)p->__pyx_t_0);
p->__pyx_t_0 = Py_None; Py_INCREF(Py_None);
Py_XDECREF(tmp);
return 0;
}

static PyTypeObject __pyx_type_8discodop_14disambiguation___pyx_scope_struct_2_genexpr = {
PyVarObject_HEAD_INIT(0, 0)
"discodop.disambiguation.__pyx_scope_struct_2_genexpr", /*tp_name*/
sizeof(struct __pyx_obj_8discodop_14disambiguation___pyx_scope_struct_2_genexpr), /*tp_basicsize*/
0, /*tp_itemsize*/
__pyx_tp_dealloc_8discodop_14disambiguation___pyx_scope_struct_2_genexpr, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
#if PY_MAJOR_VERSION < 3
0, /*tp_compare*/
#endif
#if PY_MAJOR_VERSION >= 3
0, /*tp_as_async*/
#endif
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
0, /*tp_doc*/
__pyx_tp_traverse_8discodop_14disambiguation___pyx_scope_struct_2_genexpr, /*tp_traverse*/
__pyx_tp_clear_8discodop_14disambiguation___pyx_scope_struct_2_genexpr, /*tp_clear*/
0, /*tp_richcompare*/
0, /*tp_weaklistoffset*/
0, /*tp_iter*/
0, /*tp_iternext*/
0, /*tp_methods*/
0, /*tp_members*/
0, /*tp_getset*/
0, /*tp_base*/
0, /*tp_dict*/
0, /*tp_descr_get*/
0, /*tp_descr_set*/
0, /*tp_dictoffset*/
0, /*tp_init*/
0, /*tp_alloc*/
__pyx_tp_new_8discodop_14disambiguation___pyx_scope_struct_2_genexpr, /*tp_new*/
0, /*tp_free*/
0, /*tp_is_gc*/
0, /*tp_bases*/
0, /*tp_mro*/
0, /*tp_cache*/
0, /*tp_subclasses*/
0, /*tp_weaklist*/
0, /*tp_del*/
0, /*tp_version_tag*/
#if PY_VERSION_HEX >= 0x030400a1
0, /*tp_finalize*/
#endif
};

static PyMethodDef __pyx_methods[] = {
{"getderivations", (PyCFunction)__pyx_pw_8discodop_14disambiguation_1getderivations, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8discodop_14disambiguation_getderivations},
{"marginalize", (PyCFunction)__pyx_pw_8discodop_14disambiguation_3marginalize, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8discodop_14disambiguation_2marginalize},
{"recoverfragments", (PyCFunction)__pyx_pw_8discodop_14disambiguation_7recoverfragments, METH_VARARGS|METH_KEYWORDS, __pyx_doc_8discodop_14disambiguation_6recoverfragments},
{"viterbiderivation", (PyCFunction)__pyx_pw_8discodop_14disambiguation_17viterbiderivation, METH_O, __pyx_doc_8discodop_14disambiguation_16viterbiderivation},
{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
  "disambiguation",
  __pyx_k_Disambiguate_parse_forests_with, /* 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_u_0_9, __pyx_k_0_9, sizeof(__pyx_k_0_9), 0, 1, 0, 0},
  {&__pyx_kp_u_1, __pyx_k_1, sizeof(__pyx_k_1), 0, 1, 0, 0},
  {&__pyx_n_s_AttributeError, __pyx_k_AttributeError, sizeof(__pyx_k_AttributeError), 0, 0, 1, 1},
  {&__pyx_n_s_Grammar, __pyx_k_Grammar, sizeof(__pyx_k_Grammar), 0, 0, 1, 1},
  {&__pyx_kp_u_Grammar_should_have_log_probabil, __pyx_k_Grammar_should_have_log_probabil, sizeof(__pyx_k_Grammar_should_have_log_probabil), 0, 1, 0, 0},
  {&__pyx_n_s_KeyError, __pyx_k_KeyError, sizeof(__pyx_k_KeyError), 0, 0, 1, 1},
  {&__pyx_kp_u_MCC_failed_s, __pyx_k_MCC_failed_s, sizeof(__pyx_k_MCC_failed_s), 0, 1, 0, 0},
  {&__pyx_kp_u_MCC_s_r, __pyx_k_MCC_s_r, sizeof(__pyx_k_MCC_s_r), 0, 1, 0, 0},
  {&__pyx_kp_u_MCC_span_not_in_cell_r, __pyx_k_MCC_span_not_in_cell_r, sizeof(__pyx_k_MCC_span_not_in_cell_r), 0, 1, 0, 0},
  {&__pyx_kp_u_MPD_s_r, __pyx_k_MPD_s_r, sizeof(__pyx_k_MPD_s_r), 0, 1, 0, 0},
  {&__pyx_kp_u_MPP_s_r, __pyx_k_MPP_s_r, sizeof(__pyx_k_MPP_s_r), 0, 1, 0, 0},
  {&__pyx_kp_u_MPP_sampled_s_r, __pyx_k_MPP_sampled_s_r, sizeof(__pyx_k_MPP_sampled_s_r), 0, 1, 0, 0},
  {&__pyx_n_s_MemoryError, __pyx_k_MemoryError, sizeof(__pyx_k_MemoryError), 0, 0, 1, 1},
  {&__pyx_n_u_NONE, __pyx_k_NONE, sizeof(__pyx_k_NONE), 0, 1, 0, 1},
  {&__pyx_n_s_REMOVEIDS, __pyx_k_REMOVEIDS, sizeof(__pyx_k_REMOVEIDS), 0, 0, 1, 1},
  {&__pyx_n_s_REMOVEWORDTAGS, __pyx_k_REMOVEWORDTAGS, sizeof(__pyx_k_REMOVEWORDTAGS), 0, 0, 1, 1},
  {&__pyx_kp_u_ROOT_A_A_0_B_1_C_2_ROOT_C_0_A_A, __pyx_k_ROOT_A_A_0_B_1_C_2_ROOT_C_0_A_A, sizeof(__pyx_k_ROOT_A_A_0_B_1_C_2_ROOT_C_0_A_A), 0, 1, 0, 0},
  {&__pyx_kp_u_ROOT_B_A_0_B_1_C_2, __pyx_k_ROOT_B_A_0_B_1_C_2, sizeof(__pyx_k_ROOT_B_A_0_B_1_C_2), 0, 1, 0, 0},
  {&__pyx_kp_u_SL_DOP_couldn_t_find_parse_for_t, __pyx_k_SL_DOP_couldn_t_find_parse_for_t, sizeof(__pyx_k_SL_DOP_couldn_t_find_parse_for_t), 0, 1, 0, 0},
  {&__pyx_kp_u_SL_DOP_n_7_s_r, __pyx_k_SL_DOP_n_7_s_r, sizeof(__pyx_k_SL_DOP_n_7_s_r), 0, 1, 0, 0},
  {&__pyx_n_s_Tree, __pyx_k_Tree, sizeof(__pyx_k_Tree), 0, 0, 1, 1},
  {&__pyx_n_s_ValueError, __pyx_k_ValueError, sizeof(__pyx_k_ValueError), 0, 0, 1, 1},
  {&__pyx_kp_u__13, __pyx_k__13, sizeof(__pyx_k__13), 0, 1, 0, 0},
  {&__pyx_kp_u__14, __pyx_k__14, sizeof(__pyx_k__14), 0, 1, 0, 0},
  {&__pyx_kp_u__16, __pyx_k__16, sizeof(__pyx_k__16), 0, 1, 0, 0},
  {&__pyx_kp_u__25, __pyx_k__25, sizeof(__pyx_k__25), 0, 1, 0, 0},
  {&__pyx_kp_u__34, __pyx_k__34, sizeof(__pyx_k__34), 0, 1, 0, 0},
  {&__pyx_n_s__36, __pyx_k__36, sizeof(__pyx_k__36), 0, 0, 1, 1},
  {&__pyx_kp_u__39, __pyx_k__39, sizeof(__pyx_k__39), 0, 1, 0, 0},
  {&__pyx_n_s__4, __pyx_k__4, sizeof(__pyx_k__4), 0, 0, 1, 1},
  {&__pyx_kp_u__4, __pyx_k__4, sizeof(__pyx_k__4), 0, 1, 0, 0},
  {&__pyx_kp_u__41, __pyx_k__41, sizeof(__pyx_k__41), 0, 1, 0, 0},
  {&__pyx_kp_u__43, __pyx_k__43, sizeof(__pyx_k__43), 0, 1, 0, 0},
  {&__pyx_kp_u__7, __pyx_k__7, sizeof(__pyx_k__7), 0, 1, 0, 0},
  {&__pyx_kp_u__8, __pyx_k__8, sizeof(__pyx_k__8), 0, 1, 0, 0},
  {&__pyx_kp_u__9, __pyx_k__9, sizeof(__pyx_k__9), 0, 1, 0, 0},
  {&__pyx_n_s_a, __pyx_k_a, sizeof(__pyx_k_a), 0, 0, 1, 1},
  {&__pyx_kp_u_a_b_c, __pyx_k_a_b_c, sizeof(__pyx_k_a_b_c), 0, 1, 0, 0},
  {&__pyx_n_s_add, __pyx_k_add, sizeof(__pyx_k_add), 0, 0, 1, 1},
  {&__pyx_n_s_addbitsets, __pyx_k_addbitsets, sizeof(__pyx_k_addbitsets), 0, 0, 1, 1},
  {&__pyx_n_s_all, __pyx_k_all, sizeof(__pyx_k_all), 0, 0, 1, 1},
  {&__pyx_n_s_altweights, __pyx_k_altweights, sizeof(__pyx_k_altweights), 0, 0, 1, 1},
  {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1},
  {&__pyx_n_s_approx, __pyx_k_approx, sizeof(__pyx_k_approx), 0, 0, 1, 1},
  {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1},
  {&__pyx_kp_u_at_least_one_of_kbest_or_sample, __pyx_k_at_least_one_of_kbest_or_sample, sizeof(__pyx_k_at_least_one_of_kbest_or_sample), 0, 1, 0, 0},
  {&__pyx_n_s_attrgetter, __pyx_k_attrgetter, sizeof(__pyx_k_attrgetter), 0, 0, 1, 1},
  {&__pyx_n_s_b, __pyx_k_b, sizeof(__pyx_k_b), 0, 0, 1, 1},
  {&__pyx_n_s_backtransform, __pyx_k_backtransform, sizeof(__pyx_k_backtransform), 0, 0, 1, 1},
  {&__pyx_n_s_bin, __pyx_k_bin, sizeof(__pyx_k_bin), 0, 0, 1, 1},
  {&__pyx_n_s_binarize, __pyx_k_binarize, sizeof(__pyx_k_binarize), 0, 0, 1, 1},
  {&__pyx_n_s_bisect, __pyx_k_bisect, sizeof(__pyx_k_bisect), 0, 0, 1, 1},
  {&__pyx_n_s_bisect_right, __pyx_k_bisect_right, sizeof(__pyx_k_bisect_right), 0, 0, 1, 1},
  {&__pyx_n_s_bit, __pyx_k_bit, sizeof(__pyx_k_bit), 0, 0, 1, 1},
  {&__pyx_n_s_bitpar, __pyx_k_bitpar, sizeof(__pyx_k_bitpar), 0, 0, 1, 1},
  {&__pyx_n_s_bitset, __pyx_k_bitset, sizeof(__pyx_k_bitset), 0, 0, 1, 1},
  {&__pyx_n_s_canonicalize, __pyx_k_canonicalize, sizeof(__pyx_k_canonicalize), 0, 0, 1, 1},
  {&__pyx_n_s_cell, __pyx_k_cell, sizeof(__pyx_k_cell), 0, 0, 1, 1},
  {&__pyx_n_s_cells, __pyx_k_cells, sizeof(__pyx_k_cells), 0, 0, 1, 1},
  {&__pyx_n_s_chart, __pyx_k_chart, sizeof(__pyx_k_chart), 0, 0, 1, 1},
  {&__pyx_n_s_chartidx, __pyx_k_chartidx, sizeof(__pyx_k_chartidx), 0, 0, 1, 1},
  {&__pyx_n_s_child, __pyx_k_child, sizeof(__pyx_k_child), 0, 0, 1, 1},
  {&__pyx_n_s_childchar, __pyx_k_childchar, sizeof(__pyx_k_childchar), 0, 0, 1, 1},
  {&__pyx_n_s_children, __pyx_k_children, sizeof(__pyx_k_children), 0, 0, 1, 1},
  {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1},
  {&__pyx_n_s_coarse, __pyx_k_coarse, sizeof(__pyx_k_coarse), 0, 0, 1, 1},
  {&__pyx_n_s_collapseunary, __pyx_k_collapseunary, sizeof(__pyx_k_collapseunary), 0, 0, 1, 1},
  {&__pyx_n_s_collections, __pyx_k_collections, sizeof(__pyx_k_collections), 0, 0, 1, 1},
  {&__pyx_n_s_compile, __pyx_k_compile, sizeof(__pyx_k_compile), 0, 0, 1, 1},
  {&__pyx_n_s_containers, __pyx_k_containers, sizeof(__pyx_k_containers), 0, 0, 1, 1},
  {&__pyx_n_s_count, __pyx_k_count, sizeof(__pyx_k_count), 0, 0, 1, 1},
  {&__pyx_kp_u_d_b_c_c_a_b_a_e_f_a_e_f_a_e_f_a, __pyx_k_d_b_c_c_a_b_a_e_f_a_e_f_a_e_f_a, sizeof(__pyx_k_d_b_c_c_a_b_a_e_f_a_e_f_a_e_f_a), 0, 1, 0, 0},
  {&__pyx_kp_u_d_d, __pyx_k_d_d, sizeof(__pyx_k_d_d), 0, 1, 0, 0},
  {&__pyx_kp_u_d_derivations_d_of_d_parsetrees, __pyx_k_d_derivations_d_of_d_parsetrees, sizeof(__pyx_k_d_derivations_d_of_d_parsetrees), 0, 1, 0, 0},
  {&__pyx_kp_u_d_derivations_d_parsetrees, __pyx_k_d_derivations_d_parsetrees, sizeof(__pyx_k_d_derivations_d_parsetrees), 0, 1, 0, 0},
  {&__pyx_kp_u_d_s, __pyx_k_d_s, sizeof(__pyx_k_d_s), 0, 1, 0, 0},
  {&__pyx_kp_s_datastore_avcrane1_disco_dop_di, __pyx_k_datastore_avcrane1_disco_dop_di, sizeof(__pyx_k_datastore_avcrane1_disco_dop_di), 0, 0, 1, 0},
  {&__pyx_n_s_debin, __pyx_k_debin, sizeof(__pyx_k_debin), 0, 0, 1, 1},
  {&__pyx_n_s_defaultdict, __pyx_k_defaultdict, sizeof(__pyx_k_defaultdict), 0, 0, 1, 1},
  {&__pyx_n_s_deriv, __pyx_k_deriv, sizeof(__pyx_k_deriv), 0, 0, 1, 1},
  {&__pyx_kp_u_deriv_should_be_a_RankedEdge_or, __pyx_k_deriv_should_be_a_RankedEdge_or, sizeof(__pyx_k_deriv_should_be_a_RankedEdge_or), 0, 1, 0, 0},
  {&__pyx_kp_u_derivation_has_unexpected_type_r, __pyx_k_derivation_has_unexpected_type_r, sizeof(__pyx_k_derivation_has_unexpected_type_r), 0, 1, 0, 0},
  {&__pyx_n_s_derivations, __pyx_k_derivations, sizeof(__pyx_k_derivations), 0, 0, 1, 1},
  {&__pyx_n_s_derivs, __pyx_k_derivs, sizeof(__pyx_k_derivs), 0, 0, 1, 1},
  {&__pyx_n_s_derivstr, __pyx_k_derivstr, sizeof(__pyx_k_derivstr), 0, 0, 1, 1},
  {&__pyx_n_s_derivstrings, __pyx_k_derivstrings, sizeof(__pyx_k_derivstrings), 0, 0, 1, 1},
  {&__pyx_n_s_disc, __pyx_k_disc, sizeof(__pyx_k_disc), 0, 0, 1, 1},
  {&__pyx_n_s_discodop_disambiguation, __pyx_k_discodop_disambiguation, sizeof(__pyx_k_discodop_disambiguation), 0, 0, 1, 1},
  {&__pyx_n_s_dopparseprob, __pyx_k_dopparseprob, sizeof(__pyx_k_dopparseprob), 0, 0, 1, 1},
  {&__pyx_n_u_dopparseprob, __pyx_k_dopparseprob, sizeof(__pyx_k_dopparseprob), 0, 1, 0, 1},
  {&__pyx_n_s_dopreduction, __pyx_k_dopreduction, sizeof(__pyx_k_dopreduction), 0, 0, 1, 1},
  {&__pyx_n_s_doprerank, __pyx_k_doprerank, sizeof(__pyx_k_doprerank), 0, 0, 1, 1},
  {&__pyx_n_u_doprerank, __pyx_k_doprerank, sizeof(__pyx_k_doprerank), 0, 1, 0, 1},
  {&__pyx_n_s_doprerank_locals_lambda, __pyx_k_doprerank_locals_lambda, sizeof(__pyx_k_doprerank_locals_lambda), 0, 0, 1, 1},
  {&__pyx_n_s_e, __pyx_k_e, sizeof(__pyx_k_e), 0, 0, 1, 1},
  {&__pyx_n_s_edge, __pyx_k_edge, sizeof(__pyx_k_edge), 0, 0, 1, 1},
  {&__pyx_n_s_edgelist, __pyx_k_edgelist, sizeof(__pyx_k_edgelist), 0, 0, 1, 1},
  {&__pyx_n_s_edges, __pyx_k_edges, sizeof(__pyx_k_edges), 0, 0, 1, 1},
  {&__pyx_n_s_entries, __pyx_k_entries, sizeof(__pyx_k_entries), 0, 0, 1, 1},
  {&__pyx_n_s_enumerate, __pyx_k_enumerate, sizeof(__pyx_k_enumerate), 0, 0, 1, 1},
  {&__pyx_n_s_exactcounts, __pyx_k_exactcounts, sizeof(__pyx_k_exactcounts), 0, 0, 1, 1},
  {&__pyx_n_s_exp, __pyx_k_exp, sizeof(__pyx_k_exp), 0, 0, 1, 1},
  {&__pyx_n_s_expandunary, __pyx_k_expandunary, sizeof(__pyx_k_expandunary), 0, 0, 1, 1},
  {&__pyx_kp_u_expected_binarized_tree, __pyx_k_expected_binarized_tree, sizeof(__pyx_k_expected_binarized_tree), 0, 1, 0, 0},
  {&__pyx_kp_u_expected_binary_tree_without_emp, __pyx_k_expected_binary_tree_without_emp, sizeof(__pyx_k_expected_binary_tree_without_emp), 0, 1, 0, 0},
  {&__pyx_n_s_extractfragments, __pyx_k_extractfragments, sizeof(__pyx_k_extractfragments), 0, 0, 1, 1},
  {&__pyx_n_s_fine, __pyx_k_fine, sizeof(__pyx_k_fine), 0, 0, 1, 1},
  {&__pyx_n_s_fitem, __pyx_k_fitem, sizeof(__pyx_k_fitem), 0, 0, 1, 1},
  {&__pyx_n_s_format, __pyx_k_format, sizeof(__pyx_k_format), 0, 0, 1, 1},
  {&__pyx_n_s_frag, __pyx_k_frag, sizeof(__pyx_k_frag), 0, 0, 1, 1},
  {&__pyx_n_s_fragments, __pyx_k_fragments, sizeof(__pyx_k_fragments), 0, 0, 1, 1},
  {&__pyx_n_s_fragmentsinderiv, __pyx_k_fragmentsinderiv, sizeof(__pyx_k_fragmentsinderiv), 0, 0, 1, 1},
  {&__pyx_n_u_fragmentsinderiv, __pyx_k_fragmentsinderiv, sizeof(__pyx_k_fragmentsinderiv), 0, 1, 0, 1},
  {&__pyx_n_s_frags, __pyx_k_frags, sizeof(__pyx_k_frags), 0, 0, 1, 1},
  {&__pyx_n_s_frontiernt, __pyx_k_frontiernt, sizeof(__pyx_k_frontiernt), 0, 0, 1, 1},
  {&__pyx_n_u_frontiernt, __pyx_k_frontiernt, sizeof(__pyx_k_frontiernt), 0, 1, 0, 1},
  {&__pyx_n_s_fsum, __pyx_k_fsum, sizeof(__pyx_k_fsum), 0, 0, 1, 1},
  {&__pyx_n_s_functools, __pyx_k_functools, sizeof(__pyx_k_functools), 0, 0, 1, 1},
  {&__pyx_n_s_genexpr, __pyx_k_genexpr, sizeof(__pyx_k_genexpr), 0, 0, 1, 1},
  {&__pyx_n_s_get, __pyx_k_get, sizeof(__pyx_k_get), 0, 0, 1, 1},
  {&__pyx_n_s_getctrees, __pyx_k_getctrees, sizeof(__pyx_k_getctrees), 0, 0, 1, 1},
  {&__pyx_n_s_getderiv, __pyx_k_getderiv, sizeof(__pyx_k_getderiv), 0, 0, 1, 1},
  {&__pyx_n_u_getderivations, __pyx_k_getderivations, sizeof(__pyx_k_getderivations), 0, 1, 0, 1},
  {&__pyx_n_s_getitems, __pyx_k_getitems, sizeof(__pyx_k_getitems), 0, 0, 1, 1},
  {&__pyx_n_s_getsamples, __pyx_k_getsamples, sizeof(__pyx_k_getsamples), 0, 0, 1, 1},
  {&__pyx_n_u_getsamples, __pyx_k_getsamples, sizeof(__pyx_k_getsamples), 0, 1, 0, 1},
  {&__pyx_n_s_gettree, __pyx_k_gettree, sizeof(__pyx_k_gettree), 0, 0, 1, 1},
  {&__pyx_n_u_gettree, __pyx_k_gettree, sizeof(__pyx_k_gettree), 0, 1, 0, 1},
  {&__pyx_n_s_grammar, __pyx_k_grammar, sizeof(__pyx_k_grammar), 0, 0, 1, 1},
  {&__pyx_n_s_heapq, __pyx_k_heapq, sizeof(__pyx_k_heapq), 0, 0, 1, 1},
  {&__pyx_n_s_i, __pyx_k_i, sizeof(__pyx_k_i), 0, 0, 1, 1},
  {&__pyx_n_s_idx, __pyx_k_idx, sizeof(__pyx_k_idx), 0, 0, 1, 1},
  {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1},
  {&__pyx_n_s_indices, __pyx_k_indices, sizeof(__pyx_k_indices), 0, 0, 1, 1},
  {&__pyx_kp_u_inf, __pyx_k_inf, sizeof(__pyx_k_inf), 0, 1, 0, 0},
  {&__pyx_n_s_isinf, __pyx_k_isinf, sizeof(__pyx_k_isinf), 0, 0, 1, 1},
  {&__pyx_n_s_item, __pyx_k_item, sizeof(__pyx_k_item), 0, 0, 1, 1},
  {&__pyx_n_s_itemgetter, __pyx_k_itemgetter, sizeof(__pyx_k_itemgetter), 0, 0, 1, 1},
  {&__pyx_n_s_items, __pyx_k_items, sizeof(__pyx_k_items), 0, 0, 1, 1},
  {&__pyx_n_s_itertools, __pyx_k_itertools, sizeof(__pyx_k_itertools), 0, 0, 1, 1},
  {&__pyx_n_s_joinchar, __pyx_k_joinchar, sizeof(__pyx_k_joinchar), 0, 0, 1, 1},
  {&__pyx_n_s_k, __pyx_k_k, sizeof(__pyx_k_k), 0, 0, 1, 1},
  {&__pyx_n_s_kbest, __pyx_k_kbest, sizeof(__pyx_k_kbest), 0, 0, 1, 1},
  {&__pyx_n_s_key, __pyx_k_key, sizeof(__pyx_k_key), 0, 0, 1, 1},
  {&__pyx_n_s_keys, __pyx_k_keys, sizeof(__pyx_k_keys), 0, 0, 1, 1},
  {&__pyx_n_s_label, __pyx_k_label, sizeof(__pyx_k_label), 0, 0, 1, 1},
  {&__pyx_n_s_lazykbest, __pyx_k_lazykbest, sizeof(__pyx_k_lazykbest), 0, 0, 1, 1},
  {&__pyx_n_s_lcfrsproductions, __pyx_k_lcfrsproductions, sizeof(__pyx_k_lcfrsproductions), 0, 0, 1, 1},
  {&__pyx_n_s_leaves, __pyx_k_leaves, sizeof(__pyx_k_leaves), 0, 0, 1, 1},
  {&__pyx_n_s_leftcell, __pyx_k_leftcell, sizeof(__pyx_k_leftcell), 0, 0, 1, 1},
  {&__pyx_n_s_leftmostunary, __pyx_k_leftmostunary, sizeof(__pyx_k_leftmostunary), 0, 0, 1, 1},
  {&__pyx_n_s_leftspan, __pyx_k_leftspan, sizeof(__pyx_k_leftspan), 0, 0, 1, 1},
  {&__pyx_n_s_lensent, __pyx_k_lensent, sizeof(__pyx_k_lensent), 0, 0, 1, 1},
  {&__pyx_n_s_lexrule, __pyx_k_lexrule, sizeof(__pyx_k_lexrule), 0, 0, 1, 1},
  {&__pyx_n_s_log, __pyx_k_log, sizeof(__pyx_k_log), 0, 0, 1, 1},
  {&__pyx_n_s_logprob, __pyx_k_logprob, sizeof(__pyx_k_logprob), 0, 0, 1, 1},
  {&__pyx_n_s_m, __pyx_k_m, sizeof(__pyx_k_m), 0, 0, 1, 1},
  {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1},
  {&__pyx_n_s_map, __pyx_k_map, sizeof(__pyx_k_map), 0, 0, 1, 1},
  {&__pyx_n_s_marginalize, __pyx_k_marginalize, sizeof(__pyx_k_marginalize), 0, 0, 1, 1},
  {&__pyx_n_u_marginalize, __pyx_k_marginalize, sizeof(__pyx_k_marginalize), 0, 1, 0, 1},
  {&__pyx_n_s_maskrules, __pyx_k_maskrules, sizeof(__pyx_k_maskrules), 0, 0, 1, 1},
  {&__pyx_n_s_math, __pyx_k_math, sizeof(__pyx_k_math), 0, 0, 1, 1},
  {&__pyx_n_s_max, __pyx_k_max, sizeof(__pyx_k_max), 0, 0, 1, 1},
  {&__pyx_n_s_mcc, __pyx_k_mcc, sizeof(__pyx_k_mcc), 0, 0, 1, 1},
  {&__pyx_n_u_mcc, __pyx_k_mcc, sizeof(__pyx_k_mcc), 0, 1, 0, 1},
  {&__pyx_n_s_mcc_labda, __pyx_k_mcc_labda, sizeof(__pyx_k_mcc_labda), 0, 0, 1, 1},
  {&__pyx_n_s_mcc_labels, __pyx_k_mcc_labels, sizeof(__pyx_k_mcc_labels), 0, 0, 1, 1},
  {&__pyx_n_s_mcrerank, __pyx_k_mcrerank, sizeof(__pyx_k_mcrerank), 0, 0, 1, 1},
  {&__pyx_n_s_mcrerank_locals_genexpr, __pyx_k_mcrerank_locals_genexpr, sizeof(__pyx_k_mcrerank_locals_genexpr), 0, 0, 1, 1},
  {&__pyx_n_s_mcrerank_locals_lambda, __pyx_k_mcrerank_locals_lambda, sizeof(__pyx_k_mcrerank_locals_lambda), 0, 0, 1, 1},
  {&__pyx_n_s_mergediscnodes, __pyx_k_mergediscnodes, sizeof(__pyx_k_mergediscnodes), 0, 0, 1, 1},
  {&__pyx_n_s_method, __pyx_k_method, sizeof(__pyx_k_method), 0, 0, 1, 1},
  {&__pyx_n_s_min, __pyx_k_min, sizeof(__pyx_k_min), 0, 0, 1, 1},
  {&__pyx_n_s_mpd, __pyx_k_mpd, sizeof(__pyx_k_mpd), 0, 0, 1, 1},
  {&__pyx_n_u_mpd, __pyx_k_mpd, sizeof(__pyx_k_mpd), 0, 1, 0, 1},
  {&__pyx_n_s_mpp, __pyx_k_mpp, sizeof(__pyx_k_mpp), 0, 0, 1, 1},
  {&__pyx_n_u_mpp, __pyx_k_mpp, sizeof(__pyx_k_mpp), 0, 1, 0, 1},
  {&__pyx_n_s_mppsampled, __pyx_k_mppsampled, sizeof(__pyx_k_mppsampled), 0, 0, 1, 1},
  {&__pyx_n_s_msg, __pyx_k_msg, sizeof(__pyx_k_msg), 0, 0, 1, 1},
  {&__pyx_n_s_n, __pyx_k_n, sizeof(__pyx_k_n), 0, 0, 1, 1},
  {&__pyx_n_s_newprob, __pyx_k_newprob, sizeof(__pyx_k_newprob), 0, 0, 1, 1},
  {&__pyx_n_s_nlargest, __pyx_k_nlargest, sizeof(__pyx_k_nlargest), 0, 0, 1, 1},
  {&__pyx_kp_u_no_matching_derivation_found, __pyx_k_no_matching_derivation_found, sizeof(__pyx_k_no_matching_derivation_found), 0, 1, 0, 0},
  {&__pyx_n_s_node, __pyx_k_node, sizeof(__pyx_k_node), 0, 0, 1, 1},
  {&__pyx_n_s_operator, __pyx_k_operator, sizeof(__pyx_k_operator), 0, 0, 1, 1},
  {&__pyx_n_s_parse, __pyx_k_parse, sizeof(__pyx_k_parse), 0, 0, 1, 1},
  {&__pyx_n_s_parsetrees, __pyx_k_parsetrees, sizeof(__pyx_k_parsetrees), 0, 0, 1, 1},
  {&__pyx_n_s_partial, __pyx_k_partial, sizeof(__pyx_k_partial), 0, 0, 1, 1},
  {&__pyx_n_s_plcfrs, __pyx_k_plcfrs, sizeof(__pyx_k_plcfrs), 0, 0, 1, 1},
  {&__pyx_n_s_pos, __pyx_k_pos, sizeof(__pyx_k_pos), 0, 0, 1, 1},
  {&__pyx_n_s_prev, __pyx_k_prev, sizeof(__pyx_k_prev), 0, 0, 1, 1},
  {&__pyx_n_s_print, __pyx_k_print, sizeof(__pyx_k_print), 0, 0, 1, 1},
  {&__pyx_n_s_prob, __pyx_k_prob, sizeof(__pyx_k_prob), 0, 0, 1, 1},
  {&__pyx_n_s_prod, __pyx_k_prod, sizeof(__pyx_k_prod), 0, 0, 1, 1},
  {&__pyx_n_s_pygetsent, __pyx_k_pygetsent, sizeof(__pyx_k_pygetsent), 0, 0, 1, 1},
  {&__pyx_n_s_pyintbitcount, __pyx_k_pyintbitcount, sizeof(__pyx_k_pyintbitcount), 0, 0, 1, 1},
  {&__pyx_n_s_pyintnextset, __pyx_k_pyintnextset, sizeof(__pyx_k_pyintnextset), 0, 0, 1, 1},
  {&__pyx_n_s_pyx_vtable, __pyx_k_pyx_vtable, sizeof(__pyx_k_pyx_vtable), 0, 0, 1, 1},
  {&__pyx_n_s_r, __pyx_k_r, sizeof(__pyx_k_r), 0, 0, 1, 1},
  {&__pyx_n_s_random, __pyx_k_random, sizeof(__pyx_k_random), 0, 0, 1, 1},
  {&__pyx_n_s_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1},
  {&__pyx_n_s_rankededges, __pyx_k_rankededges, sizeof(__pyx_k_rankededges), 0, 0, 1, 1},
  {&__pyx_n_s_re, __pyx_k_re, sizeof(__pyx_k_re), 0, 0, 1, 1},
  {&__pyx_kp_u_re_ranked_d_parse_trees_best_tre, __pyx_k_re_ranked_d_parse_trees_best_tre, sizeof(__pyx_k_re_ranked_d_parse_trees_best_tre), 0, 1, 0, 0},
  {&__pyx_n_u_recoverfragments, __pyx_k_recoverfragments, sizeof(__pyx_k_recoverfragments), 0, 1, 0, 1},
  {&__pyx_n_s_register, __pyx_k_register, sizeof(__pyx_k_register), 0, 0, 1, 1},
  {&__pyx_n_s_result, __pyx_k_result, sizeof(__pyx_k_result), 0, 0, 1, 1},
  {&__pyx_n_s_results, __pyx_k_results, sizeof(__pyx_k_results), 0, 0, 1, 1},
  {&__pyx_n_s_rev, __pyx_k_rev, sizeof(__pyx_k_rev), 0, 0, 1, 1},
  {&__pyx_n_s_reversed, __pyx_k_reversed, sizeof(__pyx_k_reversed), 0, 0, 1, 1},
  {&__pyx_n_s_rightcell, __pyx_k_rightcell, sizeof(__pyx_k_rightcell), 0, 0, 1, 1},
  {&__pyx_n_s_rightspan, __pyx_k_rightspan, sizeof(__pyx_k_rightspan), 0, 0, 1, 1},
  {&__pyx_n_s_root, __pyx_k_root, sizeof(__pyx_k_root), 0, 0, 1, 1},
  {&__pyx_n_s_rstrip, __pyx_k_rstrip, sizeof(__pyx_k_rstrip), 0, 0, 1, 1},
  {&__pyx_n_s_rule, __pyx_k_rule, sizeof(__pyx_k_rule), 0, 0, 1, 1},
  {&__pyx_n_s_ruleno, __pyx_k_ruleno, sizeof(__pyx_k_ruleno), 0, 0, 1, 1},
  {&__pyx_kp_u_s_d, __pyx_k_s_d, sizeof(__pyx_k_s_d), 0, 1, 0, 0},
  {&__pyx_kp_u_s_d_s, __pyx_k_s_d_s, sizeof(__pyx_k_s_d_s), 0, 1, 0, 0},
  {&__pyx_kp_u_s_not_in_grammar, __pyx_k_s_not_in_grammar, sizeof(__pyx_k_s_not_in_grammar), 0, 1, 0, 0},
  {&__pyx_kp_u_s_s, __pyx_k_s_s, sizeof(__pyx_k_s_s), 0, 1, 0, 0},
  {&__pyx_kp_u_s_s_2, __pyx_k_s_s_2, sizeof(__pyx_k_s_s_2), 0, 1, 0, 0},
  {&__pyx_kp_u_s_s_s, __pyx_k_s_s_s, sizeof(__pyx_k_s_s_s), 0, 1, 0, 0},
  {&__pyx_kp_u_s_s_s_2, __pyx_k_s_s_s_2, sizeof(__pyx_k_s_s_s_2), 0, 1, 0, 0},
  {&__pyx_n_s_sample, __pyx_k_sample, sizeof(__pyx_k_sample), 0, 0, 1, 1},
  {&__pyx_n_s_score, __pyx_k_score, sizeof(__pyx_k_score), 0, 0, 1, 1},
  {&__pyx_n_s_send, __pyx_k_send, sizeof(__pyx_k_send), 0, 0, 1, 1},
  {&__pyx_n_s_sent, __pyx_k_sent, sizeof(__pyx_k_sent), 0, 0, 1, 1},
  {&__pyx_kp_u_sentprob_g, __pyx_k_sentprob_g, sizeof(__pyx_k_sentprob_g), 0, 1, 0, 0},
  {&__pyx_n_s_sents, __pyx_k_sents, sizeof(__pyx_k_sents), 0, 0, 1, 1},
  {&__pyx_n_s_sep, __pyx_k_sep, sizeof(__pyx_k_sep), 0, 0, 1, 1},
  {&__pyx_n_s_setdefault, __pyx_k_setdefault, sizeof(__pyx_k_setdefault), 0, 0, 1, 1},
  {&__pyx_n_s_setmask, __pyx_k_setmask, sizeof(__pyx_k_setmask), 0, 0, 1, 1},
  {&__pyx_n_s_short, __pyx_k_short, sizeof(__pyx_k_short), 0, 0, 1, 1},
  {&__pyx_n_u_shortest, __pyx_k_shortest, sizeof(__pyx_k_shortest), 0, 1, 0, 1},
  {&__pyx_kp_u_shortest_s_r, __pyx_k_shortest_s_r, sizeof(__pyx_k_shortest_s_r), 0, 1, 0, 0},
  {&__pyx_kp_u_simple_SL_DOP_s_r, __pyx_k_simple_SL_DOP_s_r, sizeof(__pyx_k_simple_SL_DOP_s_r), 0, 1, 0, 0},
  {&__pyx_kp_u_sl_dop, __pyx_k_sl_dop, sizeof(__pyx_k_sl_dop), 0, 1, 0, 0},
  {&__pyx_kp_u_sl_dop_simple, __pyx_k_sl_dop_simple, sizeof(__pyx_k_sl_dop_simple), 0, 1, 0, 0},
  {&__pyx_n_s_sldop, __pyx_k_sldop, sizeof(__pyx_k_sldop), 0, 0, 1, 1},
  {&__pyx_n_s_sldop_n, __pyx_k_sldop_n, sizeof(__pyx_k_sldop_n), 0, 0, 1, 1},
  {&__pyx_n_s_sldopsimple, __pyx_k_sldopsimple, sizeof(__pyx_k_sldopsimple), 0, 0, 1, 1},
  {&__pyx_n_s_sort, __pyx_k_sort, sizeof(__pyx_k_sort), 0, 0, 1, 1},
  {&__pyx_n_s_span, __pyx_k_span, sizeof(__pyx_k_span), 0, 0, 1, 1},
  {&__pyx_n_s_split, __pyx_k_split, sizeof(__pyx_k_split), 0, 0, 1, 1},
  {&__pyx_n_s_splitfrag, __pyx_k_splitfrag, sizeof(__pyx_k_splitfrag), 0, 0, 1, 1},
  {&__pyx_n_u_splitfrag, __pyx_k_splitfrag, sizeof(__pyx_k_splitfrag), 0, 1, 0, 1},
  {&__pyx_n_s_startswith, __pyx_k_startswith, sizeof(__pyx_k_startswith), 0, 0, 1, 1},
  {&__pyx_n_s_sub, __pyx_k_sub, sizeof(__pyx_k_sub), 0, 0, 1, 1},
  {&__pyx_n_s_subtrees, __pyx_k_subtrees, sizeof(__pyx_k_subtrees), 0, 0, 1, 1},
  {&__pyx_n_s_sum, __pyx_k_sum, sizeof(__pyx_k_sum), 0, 0, 1, 1},
  {&__pyx_n_s_switch, __pyx_k_switch, sizeof(__pyx_k_switch), 0, 0, 1, 1},
  {&__pyx_n_s_tables, __pyx_k_tables, sizeof(__pyx_k_tables), 0, 0, 1, 1},
  {&__pyx_n_s_tags, __pyx_k_tags, sizeof(__pyx_k_tags), 0, 0, 1, 1},
  {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1},
  {&__pyx_n_s_test_2, __pyx_k_test_2, sizeof(__pyx_k_test_2), 0, 0, 1, 1},
  {&__pyx_n_s_test_locals_e, __pyx_k_test_locals_e, sizeof(__pyx_k_test_locals_e), 0, 0, 1, 1},
  {&__pyx_n_s_throw, __pyx_k_throw, sizeof(__pyx_k_throw), 0, 0, 1, 1},
  {&__pyx_n_s_tmp, __pyx_k_tmp, sizeof(__pyx_k_tmp), 0, 0, 1, 1},
  {&__pyx_n_s_tree, __pyx_k_tree, sizeof(__pyx_k_tree), 0, 0, 1, 1},
  {&__pyx_kp_u_tree_parsing_failed, __pyx_k_tree_parsing_failed, sizeof(__pyx_k_tree_parsing_failed), 0, 1, 0, 0},
  {&__pyx_n_s_treeparsing, __pyx_k_treeparsing, sizeof(__pyx_k_treeparsing), 0, 0, 1, 1},
  {&__pyx_n_u_treeparsing, __pyx_k_treeparsing, sizeof(__pyx_k_treeparsing), 0, 1, 0, 1},
  {&__pyx_n_s_trees, __pyx_k_trees, sizeof(__pyx_k_trees), 0, 0, 1, 1},
  {&__pyx_n_u_trees1, __pyx_k_trees1, sizeof(__pyx_k_trees1), 0, 1, 0, 1},
  {&__pyx_n_s_treestr, __pyx_k_treestr, sizeof(__pyx_k_treestr), 0, 0, 1, 1},
  {&__pyx_n_s_treetransforms, __pyx_k_treetransforms, sizeof(__pyx_k_treetransforms), 0, 0, 1, 1},
  {&__pyx_n_s_unarychar, __pyx_k_unarychar, sizeof(__pyx_k_unarychar), 0, 0, 1, 1},
  {&__pyx_n_s_unbinarize, __pyx_k_unbinarize, sizeof(__pyx_k_unbinarize), 0, 0, 1, 1},
  {&__pyx_n_s_unused_score, __pyx_k_unused_score, sizeof(__pyx_k_unused_score), 0, 0, 1, 1},
  {&__pyx_n_s_values, __pyx_k_values, sizeof(__pyx_k_values), 0, 0, 1, 1},
  {&__pyx_kp_u_vit_s_r, __pyx_k_vit_s_r, sizeof(__pyx_k_vit_s_r), 0, 1, 0, 0},
  {&__pyx_n_s_vitderiv, __pyx_k_vitderiv, sizeof(__pyx_k_vitderiv), 0, 0, 1, 1},
  {&__pyx_n_u_viterbiderivation, __pyx_k_viterbiderivation, sizeof(__pyx_k_viterbiderivation), 0, 1, 0, 1},
  {&__pyx_n_s_vitprob, __pyx_k_vitprob, sizeof(__pyx_k_vitprob), 0, 0, 1, 1},
  {&__pyx_n_s_vocab, __pyx_k_vocab, sizeof(__pyx_k_vocab), 0, 0, 1, 1},
  {&__pyx_n_s_whitelist, __pyx_k_whitelist, sizeof(__pyx_k_whitelist), 0, 0, 1, 1},
  {&__pyx_n_s_word, __pyx_k_word, sizeof(__pyx_k_word), 0, 0, 1, 1},
  {&__pyx_n_s_writediscbrackettree, __pyx_k_writediscbrackettree, sizeof(__pyx_k_writediscbrackettree), 0, 0, 1, 1},
  {&__pyx_n_s_x, __pyx_k_x, sizeof(__pyx_k_x), 0, 0, 1, 1},
  {&__pyx_n_s_xgrammar, __pyx_k_xgrammar, sizeof(__pyx_k_xgrammar), 0, 0, 1, 1},
  {&__pyx_n_s_yf, __pyx_k_yf, sizeof(__pyx_k_yf), 0, 0, 1, 1},
  {&__pyx_n_s_zip, __pyx_k_zip, sizeof(__pyx_k_zip), 0, 0, 1, 1},
  {0, 0, 0, 0, 0, 0, 0}
};
static int __Pyx_InitCachedBuiltins(void) {
  __pyx_builtin_ValueError = __Pyx_GetBuiltinName(__pyx_n_s_ValueError); if (!__pyx_builtin_ValueError) __PYX_ERR(0, 64, __pyx_L1_error)
  __pyx_builtin_zip = __Pyx_GetBuiltinName(__pyx_n_s_zip); if (!__pyx_builtin_zip) __PYX_ERR(0, 74, __pyx_L1_error)
  __pyx_builtin_min = __Pyx_GetBuiltinName(__pyx_n_s_min); if (!__pyx_builtin_min) __PYX_ERR(0, 141, __pyx_L1_error)
  __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(0, 199, __pyx_L1_error)
  __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 296, __pyx_L1_error)
  __pyx_builtin_enumerate = __Pyx_GetBuiltinName(__pyx_n_s_enumerate); if (!__pyx_builtin_enumerate) __PYX_ERR(0, 297, __pyx_L1_error)
  __pyx_builtin_max = __Pyx_GetBuiltinName(__pyx_n_s_max); if (!__pyx_builtin_max) __PYX_ERR(0, 303, __pyx_L1_error)
  __pyx_builtin_AttributeError = __Pyx_GetBuiltinName(__pyx_n_s_AttributeError); if (!__pyx_builtin_AttributeError) __PYX_ERR(0, 336, __pyx_L1_error)
  __pyx_builtin_bin = __Pyx_GetBuiltinName(__pyx_n_s_bin); if (!__pyx_builtin_bin) __PYX_ERR(0, 347, __pyx_L1_error)
  __pyx_builtin_reversed = __Pyx_GetBuiltinName(__pyx_n_s_reversed); if (!__pyx_builtin_reversed) __PYX_ERR(0, 540, __pyx_L1_error)
  __pyx_builtin_sum = __Pyx_GetBuiltinName(__pyx_n_s_sum); if (!__pyx_builtin_sum) __PYX_ERR(0, 746, __pyx_L1_error)
  __pyx_builtin_map = __Pyx_GetBuiltinName(__pyx_n_s_map); if (!__pyx_builtin_map) __PYX_ERR(0, 1037, __pyx_L1_error)
  __pyx_builtin_print = __Pyx_GetBuiltinName(__pyx_n_s_print); if (!__pyx_builtin_print) __PYX_ERR(0, 1073, __pyx_L1_error)
  __pyx_builtin_MemoryError = __Pyx_GetBuiltinName(__pyx_n_s_MemoryError); if (!__pyx_builtin_MemoryError) __PYX_ERR(2, 107, __pyx_L1_error)
  return 0;
  __pyx_L1_error:;
  return -1;
}

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

  /* "discodop/disambiguation.pyx":64
 * 	cdef list derivations = [], entries = []
 * 	if not (kbest or sample):
 * 		raise ValueError('at least one of kbest or sample needs to be True.')             # <<<<<<<<<<<<<<
 * 	chart.rankededges = {}
 * 	if kbest:
 */
  __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_u_at_least_one_of_kbest_or_sample); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 64, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple_);
  __Pyx_GIVEREF(__pyx_tuple_);

  /* "discodop/disambiguation.pyx":144
 * 			entries = [entry for entry in entries if entry.value == maxprob]
 * 		elif derivations:
 * 			_, maxprob = min(derivations, key=itemgetter(1))             # <<<<<<<<<<<<<<
 * 			derivations = [(deriv, prob) for deriv, prob in derivations
 * 					if prob == maxprob]
 */
  __pyx_tuple__2 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 144, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__2);
  __Pyx_GIVEREF(__pyx_tuple__2);

  /* "discodop/disambiguation.pyx":162
 * 				# probability in a different model.
 * 				newprob = exp(-getderivprob(entry.key, chart, sent))
 * 				score = (int(prob / log(0.5)), newprob)             # <<<<<<<<<<<<<<
 * 				if treestr not in parsetrees or score > parsetrees[treestr]:
 * 					parsetrees[treestr] = score
 */
  __pyx_tuple__3 = PyTuple_Pack(1, __pyx_float_0_5); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 162, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__3);
  __Pyx_GIVEREF(__pyx_tuple__3);

  /* "discodop/disambiguation.pyx":190
 * 						if isinstance(t[0], Tree):
 * 							if not 1 <= len(t) <= 2:
 * 								raise ValueError('expected binarized tree.')             # <<<<<<<<<<<<<<
 * 							m = chart.grammar.rulenos[nodeprod(t)]
 * 							newprob += chart.grammar.bylhs[0][
 */
  __pyx_tuple__5 = PyTuple_Pack(1, __pyx_kp_u_expected_binarized_tree); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 190, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__5);
  __Pyx_GIVEREF(__pyx_tuple__5);

  /* "discodop/disambiguation.pyx":205
 * 				else:
 * 					newprob = getderivprob(entry.key, chart, sent)
 * 				score = (int(prob / log(0.5)), exp(-newprob))             # <<<<<<<<<<<<<<
 * 				if treestr not in parsetrees or (not dopreduction
 * 						and score > parsetrees[treestr]):
 */
  __pyx_tuple__6 = PyTuple_Pack(1, __pyx_float_0_5); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 205, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__6);
  __Pyx_GIVEREF(__pyx_tuple__6);

  /* "discodop/disambiguation.pyx":304
 * 				if tablecell:
 * 					maxlabel, maxscore = max(tablecell.items(),
 * 							key=itemgetter(1))             # <<<<<<<<<<<<<<
 * 				maxcombscore = 0.0
 * 				maxleft = None
 */
  __pyx_tuple__10 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 304, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__10);
  __Pyx_GIVEREF(__pyx_tuple__10);

  /* "discodop/disambiguation.pyx":396
 * 
 * 	model = chart.grammar.modelnames[chart.grammar.currentmodel]
 * 	chart.grammar.switch(u'shortest', logprob=True)             # <<<<<<<<<<<<<<
 * 	shortestderivations, unused_explored, chart2 = treeparsing(
 * 			nmostlikelytrees, sent, chart.grammar, m, backtransform, tags)
 */
  __pyx_tuple__11 = PyTuple_Pack(1, __pyx_n_u_shortest); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 396, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__11);
  __Pyx_GIVEREF(__pyx_tuple__11);

  /* "discodop/disambiguation.pyx":411
 * 					chart2, backtransform)
 * 		if treestr in nmostlikelytrees and treestr not in result:
 * 			result[treestr] = (-abs(int(s / log(0.5))), parsetreeprob[treestr])             # <<<<<<<<<<<<<<
 * 			derivs[treestr] = fragmentsinderiv(
 * 					deriv if bitpar or backtransform is None
 */
  __pyx_tuple__12 = PyTuple_Pack(1, __pyx_float_0_5); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(0, 411, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__12);
  __Pyx_GIVEREF(__pyx_tuple__12);

  /* "discodop/disambiguation.pyx":465
 * 	result = {}
 * 	for tree in selectedtrees:
 * 		score, deriv = min([(deriv.count('(') -             # <<<<<<<<<<<<<<
 * 				len([a for a in deriv.split() if '@' in a or '}<' in a]),
 * 				deriv)
 */
  __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_u__14); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 465, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__15);
  __Pyx_GIVEREF(__pyx_tuple__15);

  /* "discodop/disambiguation.pyx":573
 * 		while '}<' in deriv[0].label:
 * 			# one of the right children
 * 			children.extend(reversed(deriv[1:]))             # <<<<<<<<<<<<<<
 * 			# move on to next node in this binarized constituent
 * 			deriv = deriv[0]
 */
  __pyx_slice__17 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__17)) __PYX_ERR(0, 573, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__17);
  __Pyx_GIVEREF(__pyx_slice__17);

  /* "discodop/disambiguation.pyx":577
 * 			deriv = deriv[0]
 * 		# last right child
 * 		children.extend(reversed(deriv[1:]))             # <<<<<<<<<<<<<<
 * 	elif '}<' in deriv[0].label:
 * 		deriv = deriv[0]
 */
  __pyx_slice__18 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__18)) __PYX_ERR(0, 577, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__18);
  __Pyx_GIVEREF(__pyx_slice__18);

  /* "discodop/disambiguation.pyx":612
 * 		fragmentsinderiv_str(deriv, chart, backtransform, result)
 * 	else:
 * 		raise ValueError('deriv should be a RankedEdge or a string.')             # <<<<<<<<<<<<<<
 * 	return [_fragments.pygetsent(frag) for frag in result]
 * 
 */
  __pyx_tuple__19 = PyTuple_Pack(1, __pyx_kp_u_deriv_should_be_a_RankedEdge_or); if (unlikely(!__pyx_tuple__19)) __PYX_ERR(0, 612, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__19);
  __Pyx_GIVEREF(__pyx_tuple__19);

  /* "discodop/disambiguation.pyx":646
 * 
 * 	result.append(frag.format(*['(%s %s)' % (
 * 				chart.grammar.tolabel[chart.label(deriv.head)].split('@')[0],             # <<<<<<<<<<<<<<
 * 				('%d=%s' % (chart.lexidx(deriv.edge),
 * 					chart.sent[chart.lexidx(deriv.edge)])
 */
  __pyx_tuple__20 = PyTuple_Pack(1, __pyx_kp_u__16); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 646, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__20);
  __Pyx_GIVEREF(__pyx_tuple__20);

  /* "discodop/disambiguation.pyx":674
 * 		while '}<' in deriv[0].label:
 * 			# one of the right children
 * 			children.extend(reversed(deriv[1:]))             # <<<<<<<<<<<<<<
 * 			# move on to next node in this binarized constituent
 * 			deriv = deriv[0]
 */
  __pyx_slice__21 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__21)) __PYX_ERR(0, 674, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__21);
  __Pyx_GIVEREF(__pyx_slice__21);

  /* "discodop/disambiguation.pyx":678
 * 			deriv = deriv[0]
 * 		# last right child
 * 		children.extend(reversed(deriv[1:]))             # <<<<<<<<<<<<<<
 * 	elif '}<' in deriv[0].label:
 * 		deriv = deriv[0]
 */
  __pyx_slice__22 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__22)) __PYX_ERR(0, 678, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__22);
  __Pyx_GIVEREF(__pyx_slice__22);

  /* "discodop/disambiguation.pyx":685
 * 
 * 	result.append(frag.format(*['(%s %s)' % (
 * 			child.label.split('@')[0],             # <<<<<<<<<<<<<<
 * 			('%d=%s' % (child[0], chart.sent[child[0]]) if '@' in child.label
 * 				else yieldranges(sorted(child.leaves()))))
 */
  __pyx_tuple__23 = PyTuple_Pack(1, __pyx_kp_u__16); if (unlikely(!__pyx_tuple__23)) __PYX_ERR(0, 685, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__23);
  __Pyx_GIVEREF(__pyx_tuple__23);

  /* "discodop/disambiguation.pyx":748
 * 				item = SmallChartItem(0, sum([1L << n for n in leaves]))
 * 			else:
 * 				fitem = item = FatChartItem(0)             # <<<<<<<<<<<<<<
 * 				for n in leaves:
 * 					SETBIT(fitem.vec, n)
 */
  __pyx_tuple__24 = PyTuple_Pack(1, __pyx_int_0); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 748, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__24);
  __Pyx_GIVEREF(__pyx_tuple__24);

  /* "discodop/disambiguation.pyx":904
 * 	cf. ``dopparseprob()``."""
 * 	cdef list results = []
 * 	for derivstr, _, _ in nlargest(k, parsetrees, key=itemgetter(1)):             # <<<<<<<<<<<<<<
 * 		deriv = addbitsets(derivstr)
 * 		results.append((derivstr, exp(dopparseprob(deriv, sent, coarse, fine)),
 */
  __pyx_tuple__26 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 904, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__26);
  __Pyx_GIVEREF(__pyx_tuple__26);

  /* "discodop/disambiguation.pyx":943
 * 	cdef str pos
 * 	if not fine.logprob:
 * 		raise ValueError('Grammar should have log probabilities.')             # <<<<<<<<<<<<<<
 * 	# Log probabilities are not ideal here because we do lots of additions,
 * 	# but the probabilities are very small.
 */
  __pyx_tuple__27 = PyTuple_Pack(1, __pyx_kp_u_Grammar_should_have_log_probabil); if (unlikely(!__pyx_tuple__27)) __PYX_ERR(0, 943, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__27);
  __Pyx_GIVEREF(__pyx_tuple__27);

  /* "discodop/disambiguation.pyx":962
 * 	# do post-order traversal (bottom-up)
 * 	for node, (r, yf) in list(zip(tree.subtrees(),
 * 			lcfrsproductions(tree, sent)))[::-1]:             # <<<<<<<<<<<<<<
 * 		if not isinstance(node[0], Tree):
 * 			continue
 */
  __pyx_slice__28 = PySlice_New(Py_None, Py_None, __pyx_int_neg_1); if (unlikely(!__pyx_slice__28)) __PYX_ERR(0, 962, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_slice__28);
  __Pyx_GIVEREF(__pyx_slice__28);

  /* "discodop/disambiguation.pyx":991
 * 						cell[rule.lhs] = newprob
 * 		else:
 * 			raise ValueError('expected binary tree without empty nodes.')             # <<<<<<<<<<<<<<
 * 	return chart[tree.bitset].get(fine.toid[tree.label], float('-inf'))
 * 
 */
  __pyx_tuple__29 = PyTuple_Pack(1, __pyx_kp_u_expected_binary_tree_without_emp); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 991, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__29);
  __Pyx_GIVEREF(__pyx_tuple__29);

  /* "discodop/disambiguation.pyx":1021
 * 				# score is the total number of nodes
 * 				# of the common fragments consisting of at least 2 parts
 * 				score += sum(frag[0].count('(') for frag in rev[i])             # <<<<<<<<<<<<<<
 * 		# divide by number of nodes in derivation to avoid preferring
 * 		# larger derivations
 */
  __pyx_tuple__30 = PyTuple_Pack(1, __pyx_kp_u__14); if (unlikely(!__pyx_tuple__30)) __PYX_ERR(0, 1021, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__30);
  __Pyx_GIVEREF(__pyx_tuple__30);

  /* "discodop/disambiguation.pyx":1000
 * 	Searches for trees that share multiple fragments (multi component)."""
 * 	cdef list results = []
 * 	for derivstr, prob, _ in nlargest(k, parsetrees, key=itemgetter(1)):             # <<<<<<<<<<<<<<
 * 		tmp = _fragments.getctrees(
 * 				[(addbitsets(derivstr), sent)], vocab=vocab)
 */
  __pyx_tuple__31 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 1000, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__31);
  __Pyx_GIVEREF(__pyx_tuple__31);

  /* "discodop/disambiguation.pyx":1007
 * 				disc=True, approx=False)
 * 		frags = {frag: bitset for frag, bitset in frags.items()
 * 				if frag[0].count('(') > 3}             # <<<<<<<<<<<<<<
 * 		indices = _fragments.exactcounts(
 * 				tmp['trees1'], trees, list(frags.values()), indices=True)
 */
  __pyx_tuple__32 = PyTuple_Pack(1, __pyx_kp_u__14); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 1007, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__32);
  __Pyx_GIVEREF(__pyx_tuple__32);

  /* "discodop/disambiguation.pyx":1024
 * 		# divide by number of nodes in derivation to avoid preferring
 * 		# larger derivations
 * 		score = float(score) / (derivstr.count('(') + len(sent))             # <<<<<<<<<<<<<<
 * 		results.append((derivstr, (score, prob), None))
 * 	msg = 're-ranked %d parse trees; best tree at %d. ' % (
 */
  __pyx_tuple__33 = PyTuple_Pack(1, __pyx_kp_u__14); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(0, 1024, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__33);
  __Pyx_GIVEREF(__pyx_tuple__33);

  /* "discodop/disambiguation.pyx":1056
 * 
 * 	def e(x):
 * 		a, b, _ = max(x, key=itemgetter(1))             # <<<<<<<<<<<<<<
 * 		return (a, (int(abs(b[0])), b[1])) if isinstance(b, tuple) else (
 * 				a, b)
 */
  __pyx_tuple__35 = PyTuple_Pack(1, __pyx_int_1); if (unlikely(!__pyx_tuple__35)) __PYX_ERR(0, 1056, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__35);
  __Pyx_GIVEREF(__pyx_tuple__35);

  /* "discodop/disambiguation.pyx":1055
 * 	from . import plcfrs
 * 
 * 	def e(x):             # <<<<<<<<<<<<<<
 * 		a, b, _ = max(x, key=itemgetter(1))
 * 		return (a, (int(abs(b[0])), b[1])) if isinstance(b, tuple) else (
 */
  __pyx_tuple__37 = PyTuple_Pack(4, __pyx_n_s_x, __pyx_n_s_a, __pyx_n_s_b, __pyx_n_s__36); if (unlikely(!__pyx_tuple__37)) __PYX_ERR(0, 1055, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__37);
  __Pyx_GIVEREF(__pyx_tuple__37);
  __pyx_codeobj__38 = (PyObject*)__Pyx_PyCode_New(1, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__37, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_datastore_avcrane1_disco_dop_di, __pyx_n_s_e, 1055, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__38)) __PYX_ERR(0, 1055, __pyx_L1_error)

  /* "discodop/disambiguation.pyx":43
 * include "constants.pxi"
 * 
 * REMOVEIDS = re.compile('@[-0-9]+')             # <<<<<<<<<<<<<<
 * REMOVEWORDTAGS = re.compile('@[^ )]+')
 * cdef str NONCONSTLABEL = ''
 */
  __pyx_tuple__40 = PyTuple_Pack(1, __pyx_kp_u_0_9); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__40);
  __Pyx_GIVEREF(__pyx_tuple__40);

  /* "discodop/disambiguation.pyx":44
 * 
 * REMOVEIDS = re.compile('@[-0-9]+')
 * REMOVEWORDTAGS = re.compile('@[^ )]+')             # <<<<<<<<<<<<<<
 * cdef str NONCONSTLABEL = ''
 * cdef str NEGATIVECONSTLABEL = '-#-'
 */
  __pyx_tuple__42 = PyTuple_Pack(1, __pyx_kp_u__41); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__42);
  __Pyx_GIVEREF(__pyx_tuple__42);

  /* "discodop/disambiguation.pyx":344
 * 
 * 
 * def gettree(cells, span):             # <<<<<<<<<<<<<<
 * 	"""Extract parse tree from most constituents correct table."""
 * 	if span not in cells:
 */
  __pyx_tuple__44 = PyTuple_Pack(6, __pyx_n_s_cells, __pyx_n_s_span, __pyx_n_s_label, __pyx_n_s_unused_score, __pyx_n_s_leftspan, __pyx_n_s_rightspan); if (unlikely(!__pyx_tuple__44)) __PYX_ERR(0, 344, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__44);
  __Pyx_GIVEREF(__pyx_tuple__44);
  __pyx_codeobj__45 = (PyObject*)__Pyx_PyCode_New(2, 0, 6, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__44, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_datastore_avcrane1_disco_dop_di, __pyx_n_s_gettree, 344, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__45)) __PYX_ERR(0, 344, __pyx_L1_error)

  /* "discodop/disambiguation.pyx":593
 * 
 * 
 * def fragmentsinderiv(deriv, chart, list backtransform):             # <<<<<<<<<<<<<<
 * 	"""Extract the list of fragments that were used in a given derivation.
 * 
 */
  __pyx_tuple__46 = PyTuple_Pack(4, __pyx_n_s_deriv, __pyx_n_s_chart, __pyx_n_s_backtransform, __pyx_n_s_result); if (unlikely(!__pyx_tuple__46)) __PYX_ERR(0, 593, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__46);
  __Pyx_GIVEREF(__pyx_tuple__46);
  __pyx_codeobj__47 = (PyObject*)__Pyx_PyCode_New(3, 0, 4, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__46, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_datastore_avcrane1_disco_dop_di, __pyx_n_s_fragmentsinderiv, 593, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__47)) __PYX_ERR(0, 593, __pyx_L1_error)

  /* "discodop/disambiguation.pyx":698
 * 
 * 
 * def frontiernt(node):             # <<<<<<<<<<<<<<
 * 	"""Test whether node from a DOP derivation is a frontier nonterminal."""
 * 	return '@' not in node.label
 */
  __pyx_tuple__48 = PyTuple_Pack(1, __pyx_n_s_node); if (unlikely(!__pyx_tuple__48)) __PYX_ERR(0, 698, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__48);
  __Pyx_GIVEREF(__pyx_tuple__48);
  __pyx_codeobj__49 = (PyObject*)__Pyx_PyCode_New(1, 0, 1, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__48, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_datastore_avcrane1_disco_dop_di, __pyx_n_s_frontiernt, 698, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__49)) __PYX_ERR(0, 698, __pyx_L1_error)

  /* "discodop/disambiguation.pyx":703
 * 
 * 
 * def splitfrag(node):             # <<<<<<<<<<<<<<
 * 	"""Return a copy of a tree with subtrees labeled without '@' removed."""
 * 	children = []
 */
  __pyx_tuple__50 = PyTuple_Pack(3, __pyx_n_s_node, __pyx_n_s_children, __pyx_n_s_child); if (unlikely(!__pyx_tuple__50)) __PYX_ERR(0, 703, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__50);
  __Pyx_GIVEREF(__pyx_tuple__50);
  __pyx_codeobj__51 = (PyObject*)__Pyx_PyCode_New(1, 0, 3, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__50, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_datastore_avcrane1_disco_dop_di, __pyx_n_s_splitfrag, 703, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__51)) __PYX_ERR(0, 703, __pyx_L1_error)

  /* "discodop/disambiguation.pyx":718
 * 
 * 
 * def treeparsing(trees, sent, Grammar grammar, int m, backtransform, tags=None,             # <<<<<<<<<<<<<<
 * 		maskrules=False):
 * 	"""Assign probabilities to a sequence of trees with a DOP grammar.
 */
  __pyx_tuple__52 = PyTuple_Pack(22, __pyx_n_s_trees, __pyx_n_s_sent, __pyx_n_s_grammar, __pyx_n_s_m, __pyx_n_s_backtransform, __pyx_n_s_tags, __pyx_n_s_maskrules, __pyx_n_s_fitem, __pyx_n_s_n, __pyx_n_s_lensent, __pyx_n_s_whitelist, __pyx_n_s_treestr, __pyx_n_s_tree, __pyx_n_s_node, __pyx_n_s_r, __pyx_n_s_yf, __pyx_n_s_leaves, __pyx_n_s_item, __pyx_n_s_ruleno, __pyx_n_s_label, __pyx_n_s_chart, __pyx_n_s__36); if (unlikely(!__pyx_tuple__52)) __PYX_ERR(0, 718, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__52);
  __Pyx_GIVEREF(__pyx_tuple__52);
  __pyx_codeobj__53 = (PyObject*)__Pyx_PyCode_New(7, 0, 22, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__52, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_datastore_avcrane1_disco_dop_di, __pyx_n_s_treeparsing, 718, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__53)) __PYX_ERR(0, 718, __pyx_L1_error)

  /* "discodop/disambiguation.pyx":814
 * 
 * 
 * def getsamples(Chart chart, k, debin=None):             # <<<<<<<<<<<<<<
 * 	"""Samples *k* derivations from a chart."""
 * 	cdef dict tables = {}
 */
  __pyx_tuple__54 = PyTuple_Pack(14, __pyx_n_s_chart, __pyx_n_s_k, __pyx_n_s_debin, __pyx_n_s_tables, __pyx_n_s_edge, __pyx_n_s_edges, __pyx_n_s_edgelist, __pyx_n_s_prob, __pyx_n_s_prev, __pyx_n_s_n, __pyx_n_s_chartidx, __pyx_n_s_item, __pyx_n_s__36, __pyx_n_s_result); if (unlikely(!__pyx_tuple__54)) __PYX_ERR(0, 814, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__54);
  __Pyx_GIVEREF(__pyx_tuple__54);
  __pyx_codeobj__55 = (PyObject*)__Pyx_PyCode_New(3, 0, 14, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__54, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_datastore_avcrane1_disco_dop_di, __pyx_n_s_getsamples, 814, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__55)) __PYX_ERR(0, 814, __pyx_L1_error)

  /* "discodop/disambiguation.pyx":899
 * 
 * 
 * def doprerank(parsetrees, sent, k, Grammar coarse, Grammar fine):             # <<<<<<<<<<<<<<
 * 	"""Rerank *k*-best coarse trees w/parse probabilities of DOP reduction.
 * 
 */
  __pyx_tuple__56 = PyTuple_Pack(10, __pyx_n_s_parsetrees, __pyx_n_s_sent, __pyx_n_s_k, __pyx_n_s_coarse, __pyx_n_s_fine, __pyx_n_s_results, __pyx_n_s_derivstr, __pyx_n_s__36, __pyx_n_s_deriv, __pyx_n_s_msg); if (unlikely(!__pyx_tuple__56)) __PYX_ERR(0, 899, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__56);
  __Pyx_GIVEREF(__pyx_tuple__56);
  __pyx_codeobj__57 = (PyObject*)__Pyx_PyCode_New(5, 0, 10, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__56, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_datastore_avcrane1_disco_dop_di, __pyx_n_s_doprerank, 899, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__57)) __PYX_ERR(0, 899, __pyx_L1_error)

  /* "discodop/disambiguation.pyx":914
 * 
 * 
 * def dopparseprob(tree, sent, Grammar coarse, Grammar fine):             # <<<<<<<<<<<<<<
 * 	"""Compute the exact DOP parse probability of a Tree in a DOP reduction.
 * 
 */
  __pyx_tuple__58 = PyTuple_Pack(19, __pyx_n_s_tree, __pyx_n_s_sent, __pyx_n_s_coarse, __pyx_n_s_fine, __pyx_n_s_chart, __pyx_n_s_cell, __pyx_n_s_rule, __pyx_n_s_lexrule, __pyx_n_s_n, __pyx_n_s_pos, __pyx_n_s_word, __pyx_n_s_node, __pyx_n_s_r, __pyx_n_s_yf, __pyx_n_s_prod, __pyx_n_s_ruleno, __pyx_n_s_leftcell, __pyx_n_s_rightcell, __pyx_n_s_newprob); if (unlikely(!__pyx_tuple__58)) __PYX_ERR(0, 914, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__58);
  __Pyx_GIVEREF(__pyx_tuple__58);
  __pyx_codeobj__59 = (PyObject*)__Pyx_PyCode_New(4, 0, 19, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__58, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_datastore_avcrane1_disco_dop_di, __pyx_n_s_dopparseprob, 914, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__59)) __PYX_ERR(0, 914, __pyx_L1_error)

  /* "discodop/disambiguation.pyx":995
 * 
 * 
 * def mcrerank(parsetrees, sent, k, trees, vocab):             # <<<<<<<<<<<<<<
 * 	"""Rerank *k*-best trees using tree fragments from training treebank.
 * 
 */
  __pyx_tuple__60 = PyTuple_Pack(21, __pyx_n_s_parsetrees, __pyx_n_s_sent, __pyx_n_s_k, __pyx_n_s_trees, __pyx_n_s_vocab, __pyx_n_s_results, __pyx_n_s_derivstr, __pyx_n_s_prob, __pyx_n_s__36, __pyx_n_s_tmp, __pyx_n_s_frags, __pyx_n_s_indices, __pyx_n_s_score, __pyx_n_s_rev, __pyx_n_s_n, __pyx_n_s_frag, __pyx_n_s_idx, __pyx_n_s_i, __pyx_n_s_msg, __pyx_n_s_genexpr, __pyx_n_s_genexpr); if (unlikely(!__pyx_tuple__60)) __PYX_ERR(0, 995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__60);
  __Pyx_GIVEREF(__pyx_tuple__60);
  __pyx_codeobj__61 = (PyObject*)__Pyx_PyCode_New(5, 0, 21, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__60, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_datastore_avcrane1_disco_dop_di, __pyx_n_s_mcrerank, 995, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__61)) __PYX_ERR(0, 995, __pyx_L1_error)

  /* "discodop/disambiguation.pyx":1050
 * 
 * 
 * def test():             # <<<<<<<<<<<<<<
 * 	from .grammar import dopreduction
 * 	from .containers import Grammar
 */
  __pyx_tuple__62 = PyTuple_Pack(24, __pyx_n_s_dopreduction, __pyx_n_s_Grammar, __pyx_n_s_plcfrs, __pyx_n_s_e, __pyx_n_s_e, __pyx_n_s_trees, __pyx_n_s_sents, __pyx_n_s_xgrammar, __pyx_n_s_altweights, __pyx_n_s_grammar, __pyx_n_s_sent, __pyx_n_s_chart, __pyx_n_s__36, __pyx_n_s_vitderiv, __pyx_n_s_vitprob, __pyx_n_s_derivations, __pyx_n_s_entries, __pyx_n_s_mpd, __pyx_n_s_mpp, __pyx_n_s_mcc, __pyx_n_s_sldop, __pyx_n_s_sldopsimple, __pyx_n_s_short, __pyx_n_s_mppsampled); if (unlikely(!__pyx_tuple__62)) __PYX_ERR(0, 1050, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_tuple__62);
  __Pyx_GIVEREF(__pyx_tuple__62);
  __pyx_codeobj__63 = (PyObject*)__Pyx_PyCode_New(0, 0, 24, 0, 0, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__62, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_datastore_avcrane1_disco_dop_di, __pyx_n_s_test, 1050, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__63)) __PYX_ERR(0, 1050, __pyx_L1_error)
  __Pyx_RefNannyFinishContext();
  return 0;
  __pyx_L1_error:;
  __Pyx_RefNannyFinishContext();
  return -1;
}

static int __Pyx_InitGlobals(void) {
  __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_0 = PyFloat_FromDouble(0.0); if (unlikely(!__pyx_float_0_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_float_30_0 = PyFloat_FromDouble(30.0); if (unlikely(!__pyx_float_30_0)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_float_neg_0_0 = PyFloat_FromDouble(-0.0); if (unlikely(!__pyx_float_neg_0_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_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_7 = PyInt_FromLong(7); if (unlikely(!__pyx_int_7)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_10 = PyInt_FromLong(10); if (unlikely(!__pyx_int_10)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_460 = PyInt_FromLong(460); if (unlikely(!__pyx_int_460)) __PYX_ERR(0, 1, __pyx_L1_error)
  __pyx_int_1000 = PyInt_FromLong(1000); if (unlikely(!__pyx_int_1000)) __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 initdisambiguation(void); /*proto*/
PyMODINIT_FUNC initdisambiguation(void)
#else
PyMODINIT_FUNC PyInit_disambiguation(void); /*proto*/
PyMODINIT_FUNC PyInit_disambiguation(void)
#endif
{
  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;
  __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_disambiguation(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("disambiguation", __pyx_methods, __pyx_k_Disambiguate_parse_forests_with, 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)
  #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_discodop__disambiguation) {
    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, "discodop.disambiguation")) {
      if (unlikely(PyDict_SetItemString(modules, "discodop.disambiguation", __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 ---*/
  __pyx_v_8discodop_14disambiguation_NONCONSTLABEL = ((PyObject*)Py_None); Py_INCREF(Py_None);
  __pyx_v_8discodop_14disambiguation_NEGATIVECONSTLABEL = ((PyObject*)Py_None); Py_INCREF(Py_None);
  /*--- Variable export code ---*/
  /*--- Function export code ---*/
  /*--- Type init code ---*/
  if (PyType_Ready(&__pyx_type_8discodop_14disambiguation___pyx_scope_struct__doprerank) < 0) __PYX_ERR(0, 899, __pyx_L1_error)
  __pyx_type_8discodop_14disambiguation___pyx_scope_struct__doprerank.tp_print = 0;
  __pyx_ptype_8discodop_14disambiguation___pyx_scope_struct__doprerank = &__pyx_type_8discodop_14disambiguation___pyx_scope_struct__doprerank;
  if (PyType_Ready(&__pyx_type_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank) < 0) __PYX_ERR(0, 995, __pyx_L1_error)
  __pyx_type_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank.tp_print = 0;
  __pyx_ptype_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank = &__pyx_type_8discodop_14disambiguation___pyx_scope_struct_1_mcrerank;
  if (PyType_Ready(&__pyx_type_8discodop_14disambiguation___pyx_scope_struct_2_genexpr) < 0) __PYX_ERR(0, 1021, __pyx_L1_error)
  __pyx_type_8discodop_14disambiguation___pyx_scope_struct_2_genexpr.tp_print = 0;
  __pyx_ptype_8discodop_14disambiguation___pyx_scope_struct_2_genexpr = &__pyx_type_8discodop_14disambiguation___pyx_scope_struct_2_genexpr;
  /*--- Type import code ---*/
  __pyx_ptype_7cpython_4type_type = __Pyx_ImportType(__Pyx_BUILTIN_MODULE_NAME, "type", 
  #if CYTHON_COMPILING_IN_PYPY
  sizeof(PyTypeObject),
  #else
  sizeof(PyHeapTypeObject),
  #endif
  0); if (unlikely(!__pyx_ptype_7cpython_4type_type)) __PYX_ERR(4, 9, __pyx_L1_error)
  __pyx_ptype_7cpython_5array_array = __Pyx_ImportType("array", "array", sizeof(arrayobject), 0); if (unlikely(!__pyx_ptype_7cpython_5array_array)) __PYX_ERR(2, 58, __pyx_L1_error)
  __pyx_ptype_8discodop_10containers_Grammar = __Pyx_ImportType("discodop.containers", "Grammar", sizeof(struct __pyx_obj_8discodop_10containers_Grammar), 1); if (unlikely(!__pyx_ptype_8discodop_10containers_Grammar)) __PYX_ERR(1, 29, __pyx_L1_error)
  __pyx_vtabptr_8discodop_10containers_Grammar = (struct __pyx_vtabstruct_8discodop_10containers_Grammar*)__Pyx_GetVtable(__pyx_ptype_8discodop_10containers_Grammar->tp_dict); if (unlikely(!__pyx_vtabptr_8discodop_10containers_Grammar)) __PYX_ERR(1, 29, __pyx_L1_error)
  __pyx_ptype_8discodop_10containers_Chart = __Pyx_ImportType("discodop.containers", "Chart", sizeof(struct __pyx_obj_8discodop_10containers_Chart), 1); if (unlikely(!__pyx_ptype_8discodop_10containers_Chart)) __PYX_ERR(1, 78, __pyx_L1_error)
  __pyx_vtabptr_8discodop_10containers_Chart = (struct __pyx_vtabstruct_8discodop_10containers_Chart*)__Pyx_GetVtable(__pyx_ptype_8discodop_10containers_Chart->tp_dict); if (unlikely(!__pyx_vtabptr_8discodop_10containers_Chart)) __PYX_ERR(1, 78, __pyx_L1_error)
  __pyx_ptype_8discodop_10containers_LexicalRule = __Pyx_ImportType("discodop.containers", "LexicalRule", sizeof(struct __pyx_obj_8discodop_10containers_LexicalRule), 1); if (unlikely(!__pyx_ptype_8discodop_10containers_LexicalRule)) __PYX_ERR(1, 114, __pyx_L1_error)
  __pyx_ptype_8discodop_10containers_ChartItem = __Pyx_ImportType("discodop.containers", "ChartItem", sizeof(struct __pyx_obj_8discodop_10containers_ChartItem), 1); if (unlikely(!__pyx_ptype_8discodop_10containers_ChartItem)) __PYX_ERR(1, 121, __pyx_L1_error)
  __pyx_ptype_8discodop_10containers_SmallChartItem = __Pyx_ImportType("discodop.containers", "SmallChartItem", sizeof(struct __pyx_obj_8discodop_10containers_SmallChartItem), 1); if (unlikely(!__pyx_ptype_8discodop_10containers_SmallChartItem)) __PYX_ERR(1, 127, __pyx_L1_error)
  __pyx_vtabptr_8discodop_10containers_SmallChartItem = (struct __pyx_vtabstruct_8discodop_10containers_SmallChartItem*)__Pyx_GetVtable(__pyx_ptype_8discodop_10containers_SmallChartItem->tp_dict); if (unlikely(!__pyx_vtabptr_8discodop_10containers_SmallChartItem)) __PYX_ERR(1, 127, __pyx_L1_error)
  __pyx_ptype_8discodop_10containers_FatChartItem = __Pyx_ImportType("discodop.containers", "FatChartItem", sizeof(struct __pyx_obj_8discodop_10containers_FatChartItem), 1); if (unlikely(!__pyx_ptype_8discodop_10containers_FatChartItem)) __PYX_ERR(1, 133, __pyx_L1_error)
  __pyx_vtabptr_8discodop_10containers_FatChartItem = (struct __pyx_vtabstruct_8discodop_10containers_FatChartItem*)__Pyx_GetVtable(__pyx_ptype_8discodop_10containers_FatChartItem->tp_dict); if (unlikely(!__pyx_vtabptr_8discodop_10containers_FatChartItem)) __PYX_ERR(1, 133, __pyx_L1_error)
  __pyx_ptype_8discodop_10containers_Edges = __Pyx_ImportType("discodop.containers", "Edges", sizeof(struct __pyx_obj_8discodop_10containers_Edges), 1); if (unlikely(!__pyx_ptype_8discodop_10containers_Edges)) __PYX_ERR(1, 155, __pyx_L1_error)
  __pyx_ptype_8discodop_10containers_RankedEdge = __Pyx_ImportType("discodop.containers", "RankedEdge", sizeof(struct __pyx_obj_8discodop_10containers_RankedEdge), 1); if (unlikely(!__pyx_ptype_8discodop_10containers_RankedEdge)) __PYX_ERR(1, 173, __pyx_L1_error)
  __pyx_ptype_8discodop_10containers_Ctrees = __Pyx_ImportType("discodop.containers", "Ctrees", sizeof(struct __pyx_obj_8discodop_10containers_Ctrees), 1); if (unlikely(!__pyx_ptype_8discodop_10containers_Ctrees)) __PYX_ERR(1, 232, __pyx_L1_error)
  __pyx_vtabptr_8discodop_10containers_Ctrees = (struct __pyx_vtabstruct_8discodop_10containers_Ctrees*)__Pyx_GetVtable(__pyx_ptype_8discodop_10containers_Ctrees->tp_dict); if (unlikely(!__pyx_vtabptr_8discodop_10containers_Ctrees)) __PYX_ERR(1, 232, __pyx_L1_error)
  __pyx_ptype_8discodop_10containers_Vocabulary = __Pyx_ImportType("discodop.containers", "Vocabulary", sizeof(struct __pyx_obj_8discodop_10containers_Vocabulary), 1); if (unlikely(!__pyx_ptype_8discodop_10containers_Vocabulary)) __PYX_ERR(1, 263, __pyx_L1_error)
  __pyx_vtabptr_8discodop_10containers_Vocabulary = (struct __pyx_vtabstruct_8discodop_10containers_Vocabulary*)__Pyx_GetVtable(__pyx_ptype_8discodop_10containers_Vocabulary->tp_dict); if (unlikely(!__pyx_vtabptr_8discodop_10containers_Vocabulary)) __PYX_ERR(1, 263, __pyx_L1_error)
  __pyx_ptype_8discodop_10containers_FixedVocabulary = __Pyx_ImportType("discodop.containers", "FixedVocabulary", sizeof(struct __pyx_obj_8discodop_10containers_FixedVocabulary), 1); if (unlikely(!__pyx_ptype_8discodop_10containers_FixedVocabulary)) __PYX_ERR(1, 280, __pyx_L1_error)
  __pyx_vtabptr_8discodop_10containers_FixedVocabulary = (struct __pyx_vtabstruct_8discodop_10containers_FixedVocabulary*)__Pyx_GetVtable(__pyx_ptype_8discodop_10containers_FixedVocabulary->tp_dict); if (unlikely(!__pyx_vtabptr_8discodop_10containers_FixedVocabulary)) __PYX_ERR(1, 280, __pyx_L1_error)
  __pyx_ptype_8discodop_6plcfrs_LCFRSChart = __Pyx_ImportType("discodop.plcfrs", "LCFRSChart", sizeof(struct __pyx_obj_8discodop_6plcfrs_LCFRSChart), 1); if (unlikely(!__pyx_ptype_8discodop_6plcfrs_LCFRSChart)) __PYX_ERR(3, 30, __pyx_L1_error)
  __pyx_vtabptr_8discodop_6plcfrs_LCFRSChart = (struct __pyx_vtabstruct_8discodop_6plcfrs_LCFRSChart*)__Pyx_GetVtable(__pyx_ptype_8discodop_6plcfrs_LCFRSChart->tp_dict); if (unlikely(!__pyx_vtabptr_8discodop_6plcfrs_LCFRSChart)) __PYX_ERR(3, 30, __pyx_L1_error)
  __pyx_ptype_8discodop_6plcfrs_SmallLCFRSChart = __Pyx_ImportType("discodop.plcfrs", "SmallLCFRSChart", sizeof(struct __pyx_obj_8discodop_6plcfrs_SmallLCFRSChart), 1); if (unlikely(!__pyx_ptype_8discodop_6plcfrs_SmallLCFRSChart)) __PYX_ERR(3, 41, __pyx_L1_error)
  __pyx_vtabptr_8discodop_6plcfrs_SmallLCFRSChart = (struct __pyx_vtabstruct_8discodop_6plcfrs_SmallLCFRSChart*)__Pyx_GetVtable(__pyx_ptype_8discodop_6plcfrs_SmallLCFRSChart->tp_dict); if (unlikely(!__pyx_vtabptr_8discodop_6plcfrs_SmallLCFRSChart)) __PYX_ERR(3, 41, __pyx_L1_error)
  __pyx_ptype_8discodop_6plcfrs_FatLCFRSChart = __Pyx_ImportType("discodop.plcfrs", "FatLCFRSChart", sizeof(struct __pyx_obj_8discodop_6plcfrs_FatLCFRSChart), 1); if (unlikely(!__pyx_ptype_8discodop_6plcfrs_FatLCFRSChart)) __PYX_ERR(3, 48, __pyx_L1_error)
  __pyx_vtabptr_8discodop_6plcfrs_FatLCFRSChart = (struct __pyx_vtabstruct_8discodop_6plcfrs_FatLCFRSChart*)__Pyx_GetVtable(__pyx_ptype_8discodop_6plcfrs_FatLCFRSChart->tp_dict); if (unlikely(!__pyx_vtabptr_8discodop_6plcfrs_FatLCFRSChart)) __PYX_ERR(3, 48, __pyx_L1_error)
  __pyx_ptype_8discodop_6plcfrs_Entry = __Pyx_ImportType("discodop.plcfrs", "Entry", sizeof(struct __pyx_obj_8discodop_6plcfrs_Entry), 1); if (unlikely(!__pyx_ptype_8discodop_6plcfrs_Entry)) __PYX_ERR(3, 56, __pyx_L1_error)
  __pyx_ptype_8discodop_6plcfrs_DoubleEntry = __Pyx_ImportType("discodop.plcfrs", "DoubleEntry", sizeof(struct __pyx_obj_8discodop_6plcfrs_DoubleEntry), 1); if (unlikely(!__pyx_ptype_8discodop_6plcfrs_DoubleEntry)) __PYX_ERR(3, 63, __pyx_L1_error)
  __pyx_ptype_8discodop_6plcfrs_Agenda = __Pyx_ImportType("discodop.plcfrs", "Agenda", sizeof(struct __pyx_obj_8discodop_6plcfrs_Agenda), 1); if (unlikely(!__pyx_ptype_8discodop_6plcfrs_Agenda)) __PYX_ERR(3, 90, __pyx_L1_error)
  __pyx_ptype_8discodop_6plcfrs_DoubleAgenda = __Pyx_ImportType("discodop.plcfrs", "DoubleAgenda", sizeof(struct __pyx_obj_8discodop_6plcfrs_DoubleAgenda), 1); if (unlikely(!__pyx_ptype_8discodop_6plcfrs_DoubleAgenda)) __PYX_ERR(3, 97, __pyx_L1_error)
  __pyx_vtabptr_8discodop_6plcfrs_DoubleAgenda = (struct __pyx_vtabstruct_8discodop_6plcfrs_DoubleAgenda*)__Pyx_GetVtable(__pyx_ptype_8discodop_6plcfrs_DoubleAgenda->tp_dict); if (unlikely(!__pyx_vtabptr_8discodop_6plcfrs_DoubleAgenda)) __PYX_ERR(3, 97, __pyx_L1_error)
  /*--- Variable import code ---*/
  __pyx_t_1 = __Pyx_ImportModule("discodop.containers"); if (!__pyx_t_1) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportVoidPtr(__pyx_t_1, "log1e200", (void **)&__pyx_vp_8discodop_10containers_log1e200, "PyObject *") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_DECREF(__pyx_t_1); __pyx_t_1 = 0;
  /*--- Function import code ---*/
  __pyx_t_2 = __Pyx_ImportModule("discodop.bit"); if (!__pyx_t_2) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportFunction(__pyx_t_2, "bitcount", (void (**)(void))&__pyx_f_8discodop_3bit_bitcount, "int (uint64_t, int __pyx_skip_dispatch)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_DECREF(__pyx_t_2); __pyx_t_2 = 0;
  __pyx_t_3 = __Pyx_ImportModule("discodop.containers"); if (!__pyx_t_3) __PYX_ERR(0, 1, __pyx_L1_error)
  if (__Pyx_ImportFunction(__pyx_t_3, "CFGtoFatChartItem", (void (**)(void))&__pyx_f_8discodop_10containers_CFGtoFatChartItem, "struct __pyx_obj_8discodop_10containers_FatChartItem *(uint32_t, __pyx_t_8discodop_10containers_Idx, __pyx_t_8discodop_10containers_Idx)") < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  Py_DECREF(__pyx_t_3); __pyx_t_3 = 0;
  /*--- Execution code ---*/
  #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
  if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  #endif

  /* "discodop/disambiguation.pyx":10
 * 
 * from __future__ import print_function
 * import re             # <<<<<<<<<<<<<<
 * from heapq import nlargest
 * from math import exp, log, isinf, fsum
 */
  __pyx_t_4 = __Pyx_Import(__pyx_n_s_re, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 10, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_re, __pyx_t_4) < 0) __PYX_ERR(0, 10, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":11
 * from __future__ import print_function
 * import re
 * from heapq import nlargest             # <<<<<<<<<<<<<<
 * from math import exp, log, isinf, fsum
 * from random import random
 */
  __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 11, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_n_s_nlargest);
  __Pyx_GIVEREF(__pyx_n_s_nlargest);
  PyList_SET_ITEM(__pyx_t_4, 0, __pyx_n_s_nlargest);
  __pyx_t_5 = __Pyx_Import(__pyx_n_s_heapq, __pyx_t_4, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 11, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_ImportFrom(__pyx_t_5, __pyx_n_s_nlargest); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 11, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_nlargest, __pyx_t_4) < 0) __PYX_ERR(0, 11, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "discodop/disambiguation.pyx":12
 * import re
 * from heapq import nlargest
 * from math import exp, log, isinf, fsum             # <<<<<<<<<<<<<<
 * from random import random
 * from bisect import bisect_right
 */
  __pyx_t_5 = PyList_New(4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_n_s_exp);
  __Pyx_GIVEREF(__pyx_n_s_exp);
  PyList_SET_ITEM(__pyx_t_5, 0, __pyx_n_s_exp);
  __Pyx_INCREF(__pyx_n_s_log);
  __Pyx_GIVEREF(__pyx_n_s_log);
  PyList_SET_ITEM(__pyx_t_5, 1, __pyx_n_s_log);
  __Pyx_INCREF(__pyx_n_s_isinf);
  __Pyx_GIVEREF(__pyx_n_s_isinf);
  PyList_SET_ITEM(__pyx_t_5, 2, __pyx_n_s_isinf);
  __Pyx_INCREF(__pyx_n_s_fsum);
  __Pyx_GIVEREF(__pyx_n_s_fsum);
  PyList_SET_ITEM(__pyx_t_5, 3, __pyx_n_s_fsum);
  __pyx_t_4 = __Pyx_Import(__pyx_n_s_math, __pyx_t_5, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_ImportFrom(__pyx_t_4, __pyx_n_s_exp); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_exp, __pyx_t_5) < 0) __PYX_ERR(0, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_ImportFrom(__pyx_t_4, __pyx_n_s_log); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_log, __pyx_t_5) < 0) __PYX_ERR(0, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_ImportFrom(__pyx_t_4, __pyx_n_s_isinf); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_isinf, __pyx_t_5) < 0) __PYX_ERR(0, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_ImportFrom(__pyx_t_4, __pyx_n_s_fsum); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 12, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fsum, __pyx_t_5) < 0) __PYX_ERR(0, 12, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":13
 * from heapq import nlargest
 * from math import exp, log, isinf, fsum
 * from random import random             # <<<<<<<<<<<<<<
 * from bisect import bisect_right
 * from operator import itemgetter, attrgetter
 */
  __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 13, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_n_s_random);
  __Pyx_GIVEREF(__pyx_n_s_random);
  PyList_SET_ITEM(__pyx_t_4, 0, __pyx_n_s_random);
  __pyx_t_5 = __Pyx_Import(__pyx_n_s_random, __pyx_t_4, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 13, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_ImportFrom(__pyx_t_5, __pyx_n_s_random); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 13, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_random, __pyx_t_4) < 0) __PYX_ERR(0, 13, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "discodop/disambiguation.pyx":14
 * from math import exp, log, isinf, fsum
 * from random import random
 * from bisect import bisect_right             # <<<<<<<<<<<<<<
 * from operator import itemgetter, attrgetter
 * from itertools import count
 */
  __pyx_t_5 = PyList_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 14, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_n_s_bisect_right);
  __Pyx_GIVEREF(__pyx_n_s_bisect_right);
  PyList_SET_ITEM(__pyx_t_5, 0, __pyx_n_s_bisect_right);
  __pyx_t_4 = __Pyx_Import(__pyx_n_s_bisect, __pyx_t_5, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 14, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_ImportFrom(__pyx_t_4, __pyx_n_s_bisect_right); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 14, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_bisect_right, __pyx_t_5) < 0) __PYX_ERR(0, 14, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":15
 * from random import random
 * from bisect import bisect_right
 * from operator import itemgetter, attrgetter             # <<<<<<<<<<<<<<
 * from itertools import count
 * from functools import partial
 */
  __pyx_t_4 = PyList_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 15, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_n_s_itemgetter);
  __Pyx_GIVEREF(__pyx_n_s_itemgetter);
  PyList_SET_ITEM(__pyx_t_4, 0, __pyx_n_s_itemgetter);
  __Pyx_INCREF(__pyx_n_s_attrgetter);
  __Pyx_GIVEREF(__pyx_n_s_attrgetter);
  PyList_SET_ITEM(__pyx_t_4, 1, __pyx_n_s_attrgetter);
  __pyx_t_5 = __Pyx_Import(__pyx_n_s_operator, __pyx_t_4, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 15, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_ImportFrom(__pyx_t_5, __pyx_n_s_itemgetter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 15, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_itemgetter, __pyx_t_4) < 0) __PYX_ERR(0, 15, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_ImportFrom(__pyx_t_5, __pyx_n_s_attrgetter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 15, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_attrgetter, __pyx_t_4) < 0) __PYX_ERR(0, 15, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "discodop/disambiguation.pyx":16
 * from bisect import bisect_right
 * from operator import itemgetter, attrgetter
 * from itertools import count             # <<<<<<<<<<<<<<
 * from functools import partial
 * from collections import defaultdict
 */
  __pyx_t_5 = PyList_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 16, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_n_s_count);
  __Pyx_GIVEREF(__pyx_n_s_count);
  PyList_SET_ITEM(__pyx_t_5, 0, __pyx_n_s_count);
  __pyx_t_4 = __Pyx_Import(__pyx_n_s_itertools, __pyx_t_5, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 16, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_ImportFrom(__pyx_t_4, __pyx_n_s_count); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 16, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_count, __pyx_t_5) < 0) __PYX_ERR(0, 16, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":17
 * from operator import itemgetter, attrgetter
 * from itertools import count
 * from functools import partial             # <<<<<<<<<<<<<<
 * from collections import defaultdict
 * from . import plcfrs, _fragments
 */
  __pyx_t_4 = PyList_New(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 17, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_n_s_partial);
  __Pyx_GIVEREF(__pyx_n_s_partial);
  PyList_SET_ITEM(__pyx_t_4, 0, __pyx_n_s_partial);
  __pyx_t_5 = __Pyx_Import(__pyx_n_s_functools, __pyx_t_4, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 17, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_ImportFrom(__pyx_t_5, __pyx_n_s_partial); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 17, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_partial, __pyx_t_4) < 0) __PYX_ERR(0, 17, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "discodop/disambiguation.pyx":18
 * from itertools import count
 * from functools import partial
 * from collections import defaultdict             # <<<<<<<<<<<<<<
 * from . import plcfrs, _fragments
 * from .tree import Tree, writediscbrackettree
 */
  __pyx_t_5 = PyList_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 18, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_n_s_defaultdict);
  __Pyx_GIVEREF(__pyx_n_s_defaultdict);
  PyList_SET_ITEM(__pyx_t_5, 0, __pyx_n_s_defaultdict);
  __pyx_t_4 = __Pyx_Import(__pyx_n_s_collections, __pyx_t_5, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 18, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_ImportFrom(__pyx_t_4, __pyx_n_s_defaultdict); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 18, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_defaultdict, __pyx_t_5) < 0) __PYX_ERR(0, 18, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":19
 * from functools import partial
 * from collections import defaultdict
 * from . import plcfrs, _fragments             # <<<<<<<<<<<<<<
 * from .tree import Tree, writediscbrackettree
 * from .kbest import lazykbest, getderiv
 */
  __pyx_t_4 = PyList_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 19, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_n_s_plcfrs);
  __Pyx_GIVEREF(__pyx_n_s_plcfrs);
  PyList_SET_ITEM(__pyx_t_4, 0, __pyx_n_s_plcfrs);
  __Pyx_INCREF(__pyx_n_s_fragments);
  __Pyx_GIVEREF(__pyx_n_s_fragments);
  PyList_SET_ITEM(__pyx_t_4, 1, __pyx_n_s_fragments);
  __pyx_t_5 = __Pyx_Import(__pyx_n_s__4, __pyx_t_4, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 19, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_ImportFrom(__pyx_t_5, __pyx_n_s_plcfrs); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 19, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_plcfrs, __pyx_t_4) < 0) __PYX_ERR(0, 19, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_ImportFrom(__pyx_t_5, __pyx_n_s_fragments); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 19, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fragments, __pyx_t_4) < 0) __PYX_ERR(0, 19, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "discodop/disambiguation.pyx":20
 * from collections import defaultdict
 * from . import plcfrs, _fragments
 * from .tree import Tree, writediscbrackettree             # <<<<<<<<<<<<<<
 * from .kbest import lazykbest, getderiv
 * from .grammar import lcfrsproductions
 */
  __pyx_t_5 = PyList_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 20, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_n_s_Tree);
  __Pyx_GIVEREF(__pyx_n_s_Tree);
  PyList_SET_ITEM(__pyx_t_5, 0, __pyx_n_s_Tree);
  __Pyx_INCREF(__pyx_n_s_writediscbrackettree);
  __Pyx_GIVEREF(__pyx_n_s_writediscbrackettree);
  PyList_SET_ITEM(__pyx_t_5, 1, __pyx_n_s_writediscbrackettree);
  __pyx_t_4 = __Pyx_Import(__pyx_n_s_tree, __pyx_t_5, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 20, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_ImportFrom(__pyx_t_4, __pyx_n_s_Tree); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 20, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_Tree, __pyx_t_5) < 0) __PYX_ERR(0, 20, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_ImportFrom(__pyx_t_4, __pyx_n_s_writediscbrackettree); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 20, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_writediscbrackettree, __pyx_t_5) < 0) __PYX_ERR(0, 20, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":21
 * from . import plcfrs, _fragments
 * from .tree import Tree, writediscbrackettree
 * from .kbest import lazykbest, getderiv             # <<<<<<<<<<<<<<
 * from .grammar import lcfrsproductions
 * from .treetransforms import addbitsets, unbinarize, canonicalize, \
 */
  __pyx_t_4 = PyList_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 21, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_n_s_lazykbest);
  __Pyx_GIVEREF(__pyx_n_s_lazykbest);
  PyList_SET_ITEM(__pyx_t_4, 0, __pyx_n_s_lazykbest);
  __Pyx_INCREF(__pyx_n_s_getderiv);
  __Pyx_GIVEREF(__pyx_n_s_getderiv);
  PyList_SET_ITEM(__pyx_t_4, 1, __pyx_n_s_getderiv);
  __pyx_t_5 = __Pyx_Import(__pyx_n_s_kbest, __pyx_t_4, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 21, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_ImportFrom(__pyx_t_5, __pyx_n_s_lazykbest); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 21, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_lazykbest, __pyx_t_4) < 0) __PYX_ERR(0, 21, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_ImportFrom(__pyx_t_5, __pyx_n_s_getderiv); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 21, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_getderiv, __pyx_t_4) < 0) __PYX_ERR(0, 21, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "discodop/disambiguation.pyx":22
 * from .tree import Tree, writediscbrackettree
 * from .kbest import lazykbest, getderiv
 * from .grammar import lcfrsproductions             # <<<<<<<<<<<<<<
 * from .treetransforms import addbitsets, unbinarize, canonicalize, \
 * 		collapseunary, mergediscnodes, binarize
 */
  __pyx_t_5 = PyList_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 22, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_n_s_lcfrsproductions);
  __Pyx_GIVEREF(__pyx_n_s_lcfrsproductions);
  PyList_SET_ITEM(__pyx_t_5, 0, __pyx_n_s_lcfrsproductions);
  __pyx_t_4 = __Pyx_Import(__pyx_n_s_grammar, __pyx_t_5, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 22, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_ImportFrom(__pyx_t_4, __pyx_n_s_lcfrsproductions); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 22, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_lcfrsproductions, __pyx_t_5) < 0) __PYX_ERR(0, 22, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":23
 * from .kbest import lazykbest, getderiv
 * from .grammar import lcfrsproductions
 * from .treetransforms import addbitsets, unbinarize, canonicalize, \             # <<<<<<<<<<<<<<
 * 		collapseunary, mergediscnodes, binarize
 * from .bit import pyintnextset, pyintbitcount
 */
  __pyx_t_4 = PyList_New(6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 23, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_n_s_addbitsets);
  __Pyx_GIVEREF(__pyx_n_s_addbitsets);
  PyList_SET_ITEM(__pyx_t_4, 0, __pyx_n_s_addbitsets);
  __Pyx_INCREF(__pyx_n_s_unbinarize);
  __Pyx_GIVEREF(__pyx_n_s_unbinarize);
  PyList_SET_ITEM(__pyx_t_4, 1, __pyx_n_s_unbinarize);
  __Pyx_INCREF(__pyx_n_s_canonicalize);
  __Pyx_GIVEREF(__pyx_n_s_canonicalize);
  PyList_SET_ITEM(__pyx_t_4, 2, __pyx_n_s_canonicalize);
  __Pyx_INCREF(__pyx_n_s_collapseunary);
  __Pyx_GIVEREF(__pyx_n_s_collapseunary);
  PyList_SET_ITEM(__pyx_t_4, 3, __pyx_n_s_collapseunary);
  __Pyx_INCREF(__pyx_n_s_mergediscnodes);
  __Pyx_GIVEREF(__pyx_n_s_mergediscnodes);
  PyList_SET_ITEM(__pyx_t_4, 4, __pyx_n_s_mergediscnodes);
  __Pyx_INCREF(__pyx_n_s_binarize);
  __Pyx_GIVEREF(__pyx_n_s_binarize);
  PyList_SET_ITEM(__pyx_t_4, 5, __pyx_n_s_binarize);
  __pyx_t_5 = __Pyx_Import(__pyx_n_s_treetransforms, __pyx_t_4, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 23, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_ImportFrom(__pyx_t_5, __pyx_n_s_addbitsets); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 23, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_addbitsets, __pyx_t_4) < 0) __PYX_ERR(0, 23, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_ImportFrom(__pyx_t_5, __pyx_n_s_unbinarize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 23, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_unbinarize, __pyx_t_4) < 0) __PYX_ERR(0, 23, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_ImportFrom(__pyx_t_5, __pyx_n_s_canonicalize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 23, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_canonicalize, __pyx_t_4) < 0) __PYX_ERR(0, 23, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_ImportFrom(__pyx_t_5, __pyx_n_s_collapseunary); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 23, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_collapseunary, __pyx_t_4) < 0) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_ImportFrom(__pyx_t_5, __pyx_n_s_mergediscnodes); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 23, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_mergediscnodes, __pyx_t_4) < 0) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_ImportFrom(__pyx_t_5, __pyx_n_s_binarize); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 23, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_binarize, __pyx_t_4) < 0) __PYX_ERR(0, 24, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;

  /* "discodop/disambiguation.pyx":25
 * from .treetransforms import addbitsets, unbinarize, canonicalize, \
 * 		collapseunary, mergediscnodes, binarize
 * from .bit import pyintnextset, pyintbitcount             # <<<<<<<<<<<<<<
 * from libc.stdint cimport uint8_t, uint32_t, uint64_t, intptr_t
 * from .bit cimport abitcount
 */
  __pyx_t_5 = PyList_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_INCREF(__pyx_n_s_pyintnextset);
  __Pyx_GIVEREF(__pyx_n_s_pyintnextset);
  PyList_SET_ITEM(__pyx_t_5, 0, __pyx_n_s_pyintnextset);
  __Pyx_INCREF(__pyx_n_s_pyintbitcount);
  __Pyx_GIVEREF(__pyx_n_s_pyintbitcount);
  PyList_SET_ITEM(__pyx_t_5, 1, __pyx_n_s_pyintbitcount);
  __pyx_t_4 = __Pyx_Import(__pyx_n_s_bit, __pyx_t_5, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_ImportFrom(__pyx_t_4, __pyx_n_s_pyintnextset); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyintnextset, __pyx_t_5) < 0) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __pyx_t_5 = __Pyx_ImportFrom(__pyx_t_4, __pyx_n_s_pyintbitcount); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyintbitcount, __pyx_t_5) < 0) __PYX_ERR(0, 25, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":43
 * include "constants.pxi"
 * 
 * REMOVEIDS = re.compile('@[-0-9]+')             # <<<<<<<<<<<<<<
 * REMOVEWORDTAGS = re.compile('@[^ )]+')
 * cdef str NONCONSTLABEL = ''
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_re); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_compile); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__40, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_REMOVEIDS, __pyx_t_4) < 0) __PYX_ERR(0, 43, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":44
 * 
 * REMOVEIDS = re.compile('@[-0-9]+')
 * REMOVEWORDTAGS = re.compile('@[^ )]+')             # <<<<<<<<<<<<<<
 * cdef str NONCONSTLABEL = ''
 * cdef str NEGATIVECONSTLABEL = '-#-'
 */
  __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_re); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_compile); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_5);
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
  __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_tuple__42, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_REMOVEWORDTAGS, __pyx_t_4) < 0) __PYX_ERR(0, 44, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":45
 * REMOVEIDS = re.compile('@[-0-9]+')
 * REMOVEWORDTAGS = re.compile('@[^ )]+')
 * cdef str NONCONSTLABEL = ''             # <<<<<<<<<<<<<<
 * cdef str NEGATIVECONSTLABEL = '-#-'
 * 
 */
  __Pyx_INCREF(__pyx_kp_u__4);
  __Pyx_XGOTREF(__pyx_v_8discodop_14disambiguation_NONCONSTLABEL);
  __Pyx_DECREF_SET(__pyx_v_8discodop_14disambiguation_NONCONSTLABEL, __pyx_kp_u__4);
  __Pyx_GIVEREF(__pyx_kp_u__4);

  /* "discodop/disambiguation.pyx":46
 * REMOVEWORDTAGS = re.compile('@[^ )]+')
 * cdef str NONCONSTLABEL = ''
 * cdef str NEGATIVECONSTLABEL = '-#-'             # <<<<<<<<<<<<<<
 * 
 * cpdef getderivations(Chart chart, int k, bint kbest=True, bint sample=False,
 */
  __Pyx_INCREF(__pyx_kp_u__43);
  __Pyx_XGOTREF(__pyx_v_8discodop_14disambiguation_NEGATIVECONSTLABEL);
  __Pyx_DECREF_SET(__pyx_v_8discodop_14disambiguation_NEGATIVECONSTLABEL, __pyx_kp_u__43);
  __Pyx_GIVEREF(__pyx_kp_u__43);

  /* "discodop/disambiguation.pyx":344
 * 
 * 
 * def gettree(cells, span):             # <<<<<<<<<<<<<<
 * 	"""Extract parse tree from most constituents correct table."""
 * 	if span not in cells:
 */
  __pyx_t_4 = PyCFunction_NewEx(&__pyx_mdef_8discodop_14disambiguation_5gettree, NULL, __pyx_n_s_discodop_disambiguation); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 344, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_gettree, __pyx_t_4) < 0) __PYX_ERR(0, 344, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":593
 * 
 * 
 * def fragmentsinderiv(deriv, chart, list backtransform):             # <<<<<<<<<<<<<<
 * 	"""Extract the list of fragments that were used in a given derivation.
 * 
 */
  __pyx_t_4 = PyCFunction_NewEx(&__pyx_mdef_8discodop_14disambiguation_9fragmentsinderiv, NULL, __pyx_n_s_discodop_disambiguation); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 593, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_fragmentsinderiv, __pyx_t_4) < 0) __PYX_ERR(0, 593, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":698
 * 
 * 
 * def frontiernt(node):             # <<<<<<<<<<<<<<
 * 	"""Test whether node from a DOP derivation is a frontier nonterminal."""
 * 	return '@' not in node.label
 */
  __pyx_t_4 = PyCFunction_NewEx(&__pyx_mdef_8discodop_14disambiguation_11frontiernt, NULL, __pyx_n_s_discodop_disambiguation); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 698, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_frontiernt, __pyx_t_4) < 0) __PYX_ERR(0, 698, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":703
 * 
 * 
 * def splitfrag(node):             # <<<<<<<<<<<<<<
 * 	"""Return a copy of a tree with subtrees labeled without '@' removed."""
 * 	children = []
 */
  __pyx_t_4 = PyCFunction_NewEx(&__pyx_mdef_8discodop_14disambiguation_13splitfrag, NULL, __pyx_n_s_discodop_disambiguation); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 703, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_splitfrag, __pyx_t_4) < 0) __PYX_ERR(0, 703, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":718
 * 
 * 
 * def treeparsing(trees, sent, Grammar grammar, int m, backtransform, tags=None,             # <<<<<<<<<<<<<<
 * 		maskrules=False):
 * 	"""Assign probabilities to a sequence of trees with a DOP grammar.
 */
  __pyx_t_4 = PyCFunction_NewEx(&__pyx_mdef_8discodop_14disambiguation_15treeparsing, NULL, __pyx_n_s_discodop_disambiguation); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 718, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_treeparsing, __pyx_t_4) < 0) __PYX_ERR(0, 718, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":814
 * 
 * 
 * def getsamples(Chart chart, k, debin=None):             # <<<<<<<<<<<<<<
 * 	"""Samples *k* derivations from a chart."""
 * 	cdef dict tables = {}
 */
  __pyx_t_4 = PyCFunction_NewEx(&__pyx_mdef_8discodop_14disambiguation_19getsamples, NULL, __pyx_n_s_discodop_disambiguation); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 814, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_getsamples, __pyx_t_4) < 0) __PYX_ERR(0, 814, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":899
 * 
 * 
 * def doprerank(parsetrees, sent, k, Grammar coarse, Grammar fine):             # <<<<<<<<<<<<<<
 * 	"""Rerank *k*-best coarse trees w/parse probabilities of DOP reduction.
 * 
 */
  __pyx_t_4 = PyCFunction_NewEx(&__pyx_mdef_8discodop_14disambiguation_21doprerank, NULL, __pyx_n_s_discodop_disambiguation); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 899, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_doprerank, __pyx_t_4) < 0) __PYX_ERR(0, 899, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":914
 * 
 * 
 * def dopparseprob(tree, sent, Grammar coarse, Grammar fine):             # <<<<<<<<<<<<<<
 * 	"""Compute the exact DOP parse probability of a Tree in a DOP reduction.
 * 
 */
  __pyx_t_4 = PyCFunction_NewEx(&__pyx_mdef_8discodop_14disambiguation_23dopparseprob, NULL, __pyx_n_s_discodop_disambiguation); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 914, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_dopparseprob, __pyx_t_4) < 0) __PYX_ERR(0, 914, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":995
 * 
 * 
 * def mcrerank(parsetrees, sent, k, trees, vocab):             # <<<<<<<<<<<<<<
 * 	"""Rerank *k*-best trees using tree fragments from training treebank.
 * 
 */
  __pyx_t_4 = PyCFunction_NewEx(&__pyx_mdef_8discodop_14disambiguation_25mcrerank, NULL, __pyx_n_s_discodop_disambiguation); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 995, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_mcrerank, __pyx_t_4) < 0) __PYX_ERR(0, 995, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":1050
 * 
 * 
 * def test():             # <<<<<<<<<<<<<<
 * 	from .grammar import dopreduction
 * 	from .containers import Grammar
 */
  __pyx_t_4 = PyCFunction_NewEx(&__pyx_mdef_8discodop_14disambiguation_27test, NULL, __pyx_n_s_discodop_disambiguation); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1050, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_4) < 0) __PYX_ERR(0, 1050, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":1097
 * 		'shortest:\t%s %r' % e(short), sep='\n')
 * 
 * __all__ = ['getderivations', 'marginalize', 'gettree', 'recoverfragments',             # <<<<<<<<<<<<<<
 * 		'fragmentsinderiv', 'treeparsing', 'viterbiderivation', 'getsamples',
 * 		'doprerank', 'dopparseprob', 'frontiernt', 'splitfrag']
 */
  __pyx_t_4 = PyList_New(12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1097, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  __Pyx_INCREF(__pyx_n_u_getderivations);
  __Pyx_GIVEREF(__pyx_n_u_getderivations);
  PyList_SET_ITEM(__pyx_t_4, 0, __pyx_n_u_getderivations);
  __Pyx_INCREF(__pyx_n_u_marginalize);
  __Pyx_GIVEREF(__pyx_n_u_marginalize);
  PyList_SET_ITEM(__pyx_t_4, 1, __pyx_n_u_marginalize);
  __Pyx_INCREF(__pyx_n_u_gettree);
  __Pyx_GIVEREF(__pyx_n_u_gettree);
  PyList_SET_ITEM(__pyx_t_4, 2, __pyx_n_u_gettree);
  __Pyx_INCREF(__pyx_n_u_recoverfragments);
  __Pyx_GIVEREF(__pyx_n_u_recoverfragments);
  PyList_SET_ITEM(__pyx_t_4, 3, __pyx_n_u_recoverfragments);
  __Pyx_INCREF(__pyx_n_u_fragmentsinderiv);
  __Pyx_GIVEREF(__pyx_n_u_fragmentsinderiv);
  PyList_SET_ITEM(__pyx_t_4, 4, __pyx_n_u_fragmentsinderiv);
  __Pyx_INCREF(__pyx_n_u_treeparsing);
  __Pyx_GIVEREF(__pyx_n_u_treeparsing);
  PyList_SET_ITEM(__pyx_t_4, 5, __pyx_n_u_treeparsing);
  __Pyx_INCREF(__pyx_n_u_viterbiderivation);
  __Pyx_GIVEREF(__pyx_n_u_viterbiderivation);
  PyList_SET_ITEM(__pyx_t_4, 6, __pyx_n_u_viterbiderivation);
  __Pyx_INCREF(__pyx_n_u_getsamples);
  __Pyx_GIVEREF(__pyx_n_u_getsamples);
  PyList_SET_ITEM(__pyx_t_4, 7, __pyx_n_u_getsamples);
  __Pyx_INCREF(__pyx_n_u_doprerank);
  __Pyx_GIVEREF(__pyx_n_u_doprerank);
  PyList_SET_ITEM(__pyx_t_4, 8, __pyx_n_u_doprerank);
  __Pyx_INCREF(__pyx_n_u_dopparseprob);
  __Pyx_GIVEREF(__pyx_n_u_dopparseprob);
  PyList_SET_ITEM(__pyx_t_4, 9, __pyx_n_u_dopparseprob);
  __Pyx_INCREF(__pyx_n_u_frontiernt);
  __Pyx_GIVEREF(__pyx_n_u_frontiernt);
  PyList_SET_ITEM(__pyx_t_4, 10, __pyx_n_u_frontiernt);
  __Pyx_INCREF(__pyx_n_u_splitfrag);
  __Pyx_GIVEREF(__pyx_n_u_splitfrag);
  PyList_SET_ITEM(__pyx_t_4, 11, __pyx_n_u_splitfrag);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_4) < 0) __PYX_ERR(0, 1097, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "discodop/disambiguation.pyx":1
 * """Disambiguate parse forests with various methods for parse selection.             # <<<<<<<<<<<<<<
 * 
 * Use as follows:
 */
  __pyx_t_4 = PyDict_New(); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_GOTREF(__pyx_t_4);
  if (PyDict_SetItem(__pyx_d, __pyx_n_s_test_2, __pyx_t_4) < 0) __PYX_ERR(0, 1, __pyx_L1_error)
  __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;

  /* "plcfrs.pxd":82
 * 
 * 
 * cdef inline DoubleEntry new_DoubleEntry(object k, double v, uint64_t c):             # <<<<<<<<<<<<<<
 * 	cdef DoubleEntry entry = DoubleEntry.__new__(DoubleEntry)
 * 	entry.key = k
 */

  /*--- Wrapped vars code ---*/

  goto __pyx_L0;
  __pyx_L1_error:;
  __Pyx_XDECREF(__pyx_t_1);
  __Pyx_XDECREF(__pyx_t_2);
  __Pyx_XDECREF(__pyx_t_3);
  __Pyx_XDECREF(__pyx_t_4);
  __Pyx_XDECREF(__pyx_t_5);
  if (__pyx_m) {
    if (__pyx_d) {
      __Pyx_AddTraceback("init discodop.disambiguation", __pyx_clineno, __pyx_lineno, __pyx_filename);
    }
    Py_DECREF(__pyx_m); __pyx_m = 0;
  } else if (!PyErr_Occurred()) {
    PyErr_SetString(PyExc_ImportError, "init discodop.disambiguation");
  }
  __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;
}

/* 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

/* 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

/* RaiseException */
#if PY_MAJOR_VERSION < 3
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb,
                        CYTHON_UNUSED PyObject *cause) {
    __Pyx_PyThreadState_declare
    Py_XINCREF(type);
    if (!value || value == Py_None)
        value = NULL;
    else
        Py_INCREF(value);
    if (!tb || tb == Py_None)
        tb = NULL;
    else {
        Py_INCREF(tb);
        if (!PyTraceBack_Check(tb)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: arg 3 must be a traceback or None");
            goto raise_error;
        }
    }
    if (PyType_Check(type)) {
#if CYTHON_COMPILING_IN_PYPY
        if (!value) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#endif
        PyErr_NormalizeException(&type, &value, &tb);
    } else {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        value = type;
        type = (PyObject*) Py_TYPE(type);
        Py_INCREF(type);
        if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
            PyErr_SetString(PyExc_TypeError,
                "raise: exception class must be a subclass of BaseException");
            goto raise_error;
        }
    }
    __Pyx_PyThreadState_assign
    __Pyx_ErrRestore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}
#else
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) {
    PyObject* owned_instance = NULL;
    if (tb == Py_None) {
        tb = 0;
    } else if (tb && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto bad;
    }
    if (value == Py_None)
        value = 0;
    if (PyExceptionInstance_Check(type)) {
        if (value) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto bad;
        }
        value = type;
        type = (PyObject*) Py_TYPE(value);
    } else if (PyExceptionClass_Check(type)) {
        PyObject *instance_class = NULL;
        if (value && PyExceptionInstance_Check(value)) {
            instance_class = (PyObject*) Py_TYPE(value);
            if (instance_class != type) {
                int is_subclass = PyObject_IsSubclass(instance_class, type);
                if (!is_subclass) {
                    instance_class = NULL;
                } else if (unlikely(is_subclass == -1)) {
                    goto bad;
                } else {
                    type = instance_class;
                }
            }
        }
        if (!instance_class) {
            PyObject *args;
            if (!value)
                args = PyTuple_New(0);
            else if (PyTuple_Check(value)) {
                Py_INCREF(value);
                args = value;
            } else
                args = PyTuple_Pack(1, value);
            if (!args)
                goto bad;
            owned_instance = PyObject_Call(type, args, NULL);
            Py_DECREF(args);
            if (!owned_instance)
                goto bad;
            value = owned_instance;
            if (!PyExceptionInstance_Check(value)) {
                PyErr_Format(PyExc_TypeError,
                             "calling %R should have returned an instance of "
                             "BaseException, not %R",
                             type, Py_TYPE(value));
                goto bad;
            }
        }
    } else {
        PyErr_SetString(PyExc_TypeError,
            "raise: exception class must be a subclass of BaseException");
        goto bad;
    }
#if PY_VERSION_HEX >= 0x03030000
    if (cause) {
#else
    if (cause && cause != Py_None) {
#endif
        PyObject *fixed_cause;
        if (cause == Py_None) {
            fixed_cause = NULL;
        } else if (PyExceptionClass_Check(cause)) {
            fixed_cause = PyObject_CallObject(cause, NULL);
            if (fixed_cause == NULL)
                goto bad;
        } else if (PyExceptionInstance_Check(cause)) {
            fixed_cause = cause;
            Py_INCREF(fixed_cause);
        } else {
            PyErr_SetString(PyExc_TypeError,
                            "exception causes must derive from "
                            "BaseException");
            goto bad;
        }
        PyException_SetCause(value, fixed_cause);
    }
    PyErr_SetObject(type, value);
    if (tb) {
#if CYTHON_COMPILING_IN_PYPY
        PyObject *tmp_type, *tmp_value, *tmp_tb;
        PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb);
        Py_INCREF(tb);
        PyErr_Restore(tmp_type, tmp_value, tb);
        Py_XDECREF(tmp_tb);
#else
        PyThreadState *tstate = PyThreadState_GET();
        PyObject* tmp_tb = tstate->curexc_traceback;
        if (tb != tmp_tb) {
            Py_INCREF(tb);
            tstate->curexc_traceback = tb;
            Py_XDECREF(tmp_tb);
        }
#endif
    }
bad:
    Py_XDECREF(owned_instance);
    return;
}
#endif

/* 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;
}

/* 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;
}

/* 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);
    assert(PyCFunction_Check(func));
    assert(METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST)));
    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());
    return (*((__Pyx_PyCFunctionFast)meth)) (self, args, nargs, NULL);
}
#endif  // CYTHON_FAST_PYCCALL

/* 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  // CPython < 3.6
#endif  // CYTHON_FAST_PYCALL

/* 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
#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_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

/* 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_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);
}

/* SliceObject */
        static CYTHON_INLINE int __Pyx_PyObject_SetSlice(PyObject* obj, PyObject* value,
        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_ass_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_ass_slice(obj, cstart, cstop, value);
    }
#endif
    mp = Py_TYPE(obj)->tp_as_mapping;
    if (likely(mp && mp->mp_ass_subscript))
#endif
    {
        int 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_ass_subscript(obj, py_slice, value);
#else
        result = value ? PyObject_SetItem(obj, py_slice, value) : PyObject_DelItem(obj, py_slice);
#endif
        if (!_py_slice) {
            Py_DECREF(py_slice);
        }
        return result;
    }
    PyErr_Format(PyExc_TypeError,
        "'%.200s' object does not support slice %.10s",
        Py_TYPE(obj)->tp_name, value ? "assignment" : "deletion");
bad:
    return -1;
}

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

/* 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;
}

/* ArgTypeTest */
        static void __Pyx_RaiseArgumentTypeInvalid(const char* name, PyObject *obj, PyTypeObject *type) {
    PyErr_Format(PyExc_TypeError,
        "Argument '%.200s' has incorrect type (expected %.200s, got %.200s)",
        name, type->tp_name, Py_TYPE(obj)->tp_name);
}
static CYTHON_INLINE int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed,
    const char *name, int exact)
{
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (none_allowed && obj == Py_None) return 1;
    else if (exact) {
        if (likely(Py_TYPE(obj) == type)) return 1;
        #if PY_MAJOR_VERSION == 2
        else if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1;
        #endif
    }
    else {
        if (likely(PyObject_TypeCheck(obj, type))) return 1;
    }
    __Pyx_RaiseArgumentTypeInvalid(name, obj, type);
    return 0;
}

/* 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 = 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;
        }
        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
}

/* ExtTypeTest */
        static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (unlikely(!type)) {
        PyErr_SetString(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (likely(PyObject_TypeCheck(obj, type)))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s",
                 Py_TYPE(obj)->tp_name, type->tp_name);
    return 0;
}

/* 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;
}

/* 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;
}

/* 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
    if (wraparound & unlikely(i < 0)) i += PyList_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyList_GET_SIZE(o)))) {
        PyObject *r = PyList_GET_ITEM(o, 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
    if (wraparound & unlikely(i < 0)) i += PyTuple_GET_SIZE(o);
    if ((!boundscheck) || likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) {
        PyObject *r = PyTuple_GET_ITEM(o, 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));
}

/* 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

/* PyFloatBinop */
          #if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyFloat_AddObjC(PyObject *op1, PyObject *op2, double floatval, CYTHON_UNUSED int inplace) {
    const double b = floatval;
    double a, result;
    if (likely(PyFloat_CheckExact(op1))) {
        a = PyFloat_AS_DOUBLE(op1);
    } else
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op1))) {
        a = (double) PyInt_AS_LONG(op1);
    } else
    #endif
    if (likely(PyLong_CheckExact(op1))) {
        #if CYTHON_USE_PYLONG_INTERNALS
        const digit* digits = ((PyLongObject*)op1)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op1);
        switch (size) {
            case  0: a = 0.0; break;
            case -1: a = -(double) digits[0]; break;
            case  1: a = (double) digits[0]; break;
            case -2:
            case 2:
                if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT && ((8 * sizeof(unsigned long) < 53) || (1 * PyLong_SHIFT < 53))) {
                    a = (double) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                    if ((8 * sizeof(unsigned long) < 53) || (2 * PyLong_SHIFT < 53) || (a < (double) (1L<<53))) {
                        if (size == -2)
                            a = -a;
                        break;
                    }
                }
            case -3:
            case 3:
                if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT && ((8 * sizeof(unsigned long) < 53) || (2 * PyLong_SHIFT < 53))) {
                    a = (double) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                    if ((8 * sizeof(unsigned long) < 53) || (3 * PyLong_SHIFT < 53) || (a < (double) (1L<<53))) {
                        if (size == -3)
                            a = -a;
                        break;
                    }
                }
            case -4:
            case 4:
                if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT && ((8 * sizeof(unsigned long) < 53) || (3 * PyLong_SHIFT < 53))) {
                    a = (double) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                    if ((8 * sizeof(unsigned long) < 53) || (4 * PyLong_SHIFT < 53) || (a < (double) (1L<<53))) {
                        if (size == -4)
                            a = -a;
                        break;
                    }
                }
            default:
        #else
        {
        #endif
            a = PyLong_AsDouble(op1);
            if (unlikely(a == -1.0 && PyErr_Occurred())) return NULL;
        }
    } else {
        return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
    }
        PyFPE_START_PROTECT("add", return NULL)
        result = a + b;
        PyFPE_END_PROTECT(result)
        return PyFloat_FromDouble(result);
}
#endif

/* PyObjectCallMethod0 */
            static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) {
    PyObject *method, *result = NULL;
    method = __Pyx_PyObject_GetAttrStr(obj, method_name);
    if (unlikely(!method)) goto bad;
#if CYTHON_UNPACK_METHODS
    if (likely(PyMethod_Check(method))) {
        PyObject *self = PyMethod_GET_SELF(method);
        if (likely(self)) {
            PyObject *function = PyMethod_GET_FUNCTION(method);
            result = __Pyx_PyObject_CallOneArg(function, self);
            Py_DECREF(method);
            return result;
        }
    }
#endif
    result = __Pyx_PyObject_CallNoArg(method);
    Py_DECREF(method);
bad:
    return result;
}

/* RaiseNoneIterError */
            static CYTHON_INLINE void __Pyx_RaiseNoneNotIterableError(void) {
    PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable");
}

/* UnpackTupleError */
            static void __Pyx_UnpackTupleError(PyObject *t, Py_ssize_t index) {
    if (t == Py_None) {
      __Pyx_RaiseNoneNotIterableError();
    } else if (PyTuple_GET_SIZE(t) < index) {
      __Pyx_RaiseNeedMoreValuesError(PyTuple_GET_SIZE(t));
    } else {
      __Pyx_RaiseTooManyValuesError(index);
    }
}

/* UnpackTuple2 */
            static CYTHON_INLINE int __Pyx_unpack_tuple2(PyObject* tuple, PyObject** pvalue1, PyObject** pvalue2,
                                             int is_tuple, int has_known_size, int decref_tuple) {
    Py_ssize_t index;
    PyObject *value1 = NULL, *value2 = NULL, *iter = NULL;
    if (!is_tuple && unlikely(!PyTuple_Check(tuple))) {
        iternextfunc iternext;
        iter = PyObject_GetIter(tuple);
        if (unlikely(!iter)) goto bad;
        if (decref_tuple) { Py_DECREF(tuple); tuple = NULL; }
        iternext = Py_TYPE(iter)->tp_iternext;
        value1 = iternext(iter); if (unlikely(!value1)) { index = 0; goto unpacking_failed; }
        value2 = iternext(iter); if (unlikely(!value2)) { index = 1; goto unpacking_failed; }
        if (!has_known_size && unlikely(__Pyx_IternextUnpackEndCheck(iternext(iter), 2))) goto bad;
        Py_DECREF(iter);
    } else {
        if (!has_known_size && unlikely(PyTuple_GET_SIZE(tuple) != 2)) {
            __Pyx_UnpackTupleError(tuple, 2);
            goto bad;
        }
#if CYTHON_COMPILING_IN_PYPY
        value1 = PySequence_ITEM(tuple, 0);
        if (unlikely(!value1)) goto bad;
        value2 = PySequence_ITEM(tuple, 1);
        if (unlikely(!value2)) goto bad;
#else
        value1 = PyTuple_GET_ITEM(tuple, 0);
        value2 = PyTuple_GET_ITEM(tuple, 1);
        Py_INCREF(value1);
        Py_INCREF(value2);
#endif
        if (decref_tuple) { Py_DECREF(tuple); }
    }
    *pvalue1 = value1;
    *pvalue2 = value2;
    return 0;
unpacking_failed:
    if (!has_known_size && __Pyx_IterFinish() == 0)
        __Pyx_RaiseNeedMoreValuesError(index);
bad:
    Py_XDECREF(iter);
    Py_XDECREF(value1);
    Py_XDECREF(value2);
    if (decref_tuple) { Py_XDECREF(tuple); }
    return -1;
}

/* dict_iter */
            static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_dict, PyObject* method_name,
                                                   Py_ssize_t* p_orig_length, int* p_source_is_dict) {
    is_dict = is_dict || likely(PyDict_CheckExact(iterable));
    *p_source_is_dict = is_dict;
#if !CYTHON_COMPILING_IN_PYPY
    if (is_dict) {
        *p_orig_length = PyDict_Size(iterable);
        Py_INCREF(iterable);
        return iterable;
    }
#endif
    *p_orig_length = 0;
    if (method_name) {
        PyObject* iter;
        iterable = __Pyx_PyObject_CallMethod0(iterable, method_name);
        if (!iterable)
            return NULL;
#if !CYTHON_COMPILING_IN_PYPY
        if (PyTuple_CheckExact(iterable) || PyList_CheckExact(iterable))
            return iterable;
#endif
        iter = PyObject_GetIter(iterable);
        Py_DECREF(iterable);
        return iter;
    }
    return PyObject_GetIter(iterable);
}
static CYTHON_INLINE int __Pyx_dict_iter_next(
        PyObject* iter_obj, CYTHON_NCP_UNUSED Py_ssize_t orig_length, CYTHON_NCP_UNUSED Py_ssize_t* ppos,
        PyObject** pkey, PyObject** pvalue, PyObject** pitem, int source_is_dict) {
    PyObject* next_item;
#if !CYTHON_COMPILING_IN_PYPY
    if (source_is_dict) {
        PyObject *key, *value;
        if (unlikely(orig_length != PyDict_Size(iter_obj))) {
            PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration");
            return -1;
        }
        if (unlikely(!PyDict_Next(iter_obj, ppos, &key, &value))) {
            return 0;
        }
        if (pitem) {
            PyObject* tuple = PyTuple_New(2);
            if (unlikely(!tuple)) {
                return -1;
            }
            Py_INCREF(key);
            Py_INCREF(value);
            PyTuple_SET_ITEM(tuple, 0, key);
            PyTuple_SET_ITEM(tuple, 1, value);
            *pitem = tuple;
        } else {
            if (pkey) {
                Py_INCREF(key);
                *pkey = key;
            }
            if (pvalue) {
                Py_INCREF(value);
                *pvalue = value;
            }
        }
        return 1;
    } else if (PyTuple_CheckExact(iter_obj)) {
        Py_ssize_t pos = *ppos;
        if (unlikely(pos >= PyTuple_GET_SIZE(iter_obj))) return 0;
        *ppos = pos + 1;
        next_item = PyTuple_GET_ITEM(iter_obj, pos);
        Py_INCREF(next_item);
    } else if (PyList_CheckExact(iter_obj)) {
        Py_ssize_t pos = *ppos;
        if (unlikely(pos >= PyList_GET_SIZE(iter_obj))) return 0;
        *ppos = pos + 1;
        next_item = PyList_GET_ITEM(iter_obj, pos);
        Py_INCREF(next_item);
    } else
#endif
    {
        next_item = PyIter_Next(iter_obj);
        if (unlikely(!next_item)) {
            return __Pyx_IterFinish();
        }
    }
    if (pitem) {
        *pitem = next_item;
    } else if (pkey && pvalue) {
        if (__Pyx_unpack_tuple2(next_item, pkey, pvalue, source_is_dict, source_is_dict, 1))
            return -1;
    } else if (pkey) {
        *pkey = next_item;
    } else {
        *pvalue = next_item;
    }
    return 1;
}

/* 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;
}

/* SetItemInt */
            static CYTHON_INLINE int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) {
    int r;
    if (!j) return -1;
    r = PyObject_SetItem(o, j, v);
    Py_DECREF(j);
    return r;
}
static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObject *v, 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) ? i : ((likely(i >= 0)) ? i : i + PyList_GET_SIZE(o));
        if ((!boundscheck) || likely((n >= 0) & (n < PyList_GET_SIZE(o)))) {
            PyObject* old = PyList_GET_ITEM(o, n);
            Py_INCREF(v);
            PyList_SET_ITEM(o, n, v);
            Py_DECREF(old);
            return 1;
        }
    } else {
        PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence;
        if (likely(m && m->sq_ass_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 -1;
                    PyErr_Clear();
                }
            }
            return m->sq_ass_item(o, i, v);
        }
    }
#else
#if CYTHON_COMPILING_IN_PYPY
    if (is_list || (PySequence_Check(o) && !PyDict_Check(o))) {
#else
    if (is_list || PySequence_Check(o)) {
#endif
        return PySequence_SetItem(o, i, v);
    }
#endif
    return __Pyx_SetItemInt_Generic(o, PyInt_FromSsize_t(i), v);
}

/* WriteUnraisableException */
              static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno,
                                  CYTHON_UNUSED int lineno, CYTHON_UNUSED const char *filename,
                                  int full_traceback, CYTHON_UNUSED int nogil) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    __Pyx_PyThreadState_declare
#ifdef WITH_THREAD
    PyGILState_STATE state;
    if (nogil)
        state = PyGILState_Ensure();
#ifdef _MSC_VER
    else state = (PyGILState_STATE)-1;
#endif
#endif
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&old_exc, &old_val, &old_tb);
    if (full_traceback) {
        Py_XINCREF(old_exc);
        Py_XINCREF(old_val);
        Py_XINCREF(old_tb);
        __Pyx_ErrRestore(old_exc, old_val, old_tb);
        PyErr_PrintEx(1);
    }
    #if PY_MAJOR_VERSION < 3
    ctx = PyString_FromString(name);
    #else
    ctx = PyUnicode_FromString(name);
    #endif
    __Pyx_ErrRestore(old_exc, old_val, old_tb);
    if (!ctx) {
        PyErr_WriteUnraisable(Py_None);
    } else {
        PyErr_WriteUnraisable(ctx);
        Py_DECREF(ctx);
    }
#ifdef WITH_THREAD
    if (nogil)
        PyGILState_Release(state);
#endif
}

/* 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;
}

/* None */
                  static CYTHON_INLINE void __Pyx_RaiseClosureNameError(const char *varname) {
    PyErr_Format(PyExc_NameError, "free variable '%s' referenced before assignment in enclosing scope", varname);
}

/* 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

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

/* 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;
}

/* PyIntBinop */
                      #if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyInt_SubtractObjC(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_subtract(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_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(op1)) {
        const long b = intval;
        double a = PyFloat_AS_DOUBLE(op1);
            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

/* PyFloatBinop */
                      #if !CYTHON_COMPILING_IN_PYPY
static PyObject* __Pyx_PyFloat_AddCObj(PyObject *op1, PyObject *op2, double floatval, CYTHON_UNUSED int inplace) {
    const double a = floatval;
    double b, result;
    if (likely(PyFloat_CheckExact(op2))) {
        b = PyFloat_AS_DOUBLE(op2);
    } else
    #if PY_MAJOR_VERSION < 3
    if (likely(PyInt_CheckExact(op2))) {
        b = (double) PyInt_AS_LONG(op2);
    } else
    #endif
    if (likely(PyLong_CheckExact(op2))) {
        #if CYTHON_USE_PYLONG_INTERNALS
        const digit* digits = ((PyLongObject*)op2)->ob_digit;
        const Py_ssize_t size = Py_SIZE(op2);
        switch (size) {
            case  0: b = 0.0; break;
            case -1: b = -(double) digits[0]; break;
            case  1: b = (double) digits[0]; break;
            case -2:
            case 2:
                if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT && ((8 * sizeof(unsigned long) < 53) || (1 * PyLong_SHIFT < 53))) {
                    b = (double) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                    if ((8 * sizeof(unsigned long) < 53) || (2 * PyLong_SHIFT < 53) || (b < (double) (1L<<53))) {
                        if (size == -2)
                            b = -b;
                        break;
                    }
                }
            case -3:
            case 3:
                if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT && ((8 * sizeof(unsigned long) < 53) || (2 * PyLong_SHIFT < 53))) {
                    b = (double) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                    if ((8 * sizeof(unsigned long) < 53) || (3 * PyLong_SHIFT < 53) || (b < (double) (1L<<53))) {
                        if (size == -3)
                            b = -b;
                        break;
                    }
                }
            case -4:
            case 4:
                if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT && ((8 * sizeof(unsigned long) < 53) || (3 * PyLong_SHIFT < 53))) {
                    b = (double) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]));
                    if ((8 * sizeof(unsigned long) < 53) || (4 * PyLong_SHIFT < 53) || (b < (double) (1L<<53))) {
                        if (size == -4)
                            b = -b;
                        break;
                    }
                }
            default:
        #else
        {
        #endif
            b = PyLong_AsDouble(op2);
            if (unlikely(b == -1.0 && PyErr_Occurred())) return NULL;
        }
    } else {
        return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2);
    }
        PyFPE_START_PROTECT("add", return NULL)
        result = a + b;
        PyFPE_END_PROTECT(result)
        return PyFloat_FromDouble(result);
}
#endif

/* GetVTable */
                        static void* __Pyx_GetVtable(PyObject *dict) {
    void* ptr;
    PyObject *ob = PyObject_GetItem(dict, __pyx_n_s_pyx_vtable);
    if (!ob)
        goto bad;
#if PY_VERSION_HEX >= 0x02070000
    ptr = PyCapsule_GetPointer(ob, 0);
#else
    ptr = PyCObject_AsVoidPtr(ob);
#endif
    if (!ptr && !PyErr_Occurred())
        PyErr_SetString(PyExc_RuntimeError, "invalid vtable found for imported type");
    Py_DECREF(ob);
    return ptr;
bad:
    Py_XDECREF(ob);
    return NULL;
}

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

/* 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;\
    }

/* CIntToPy */
                        static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) {
    const int neg_one = (int) -1, const_zero = (int) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(int) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(int) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(int) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(int) <= 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(int),
                                     little, !is_unsigned);
    }
}

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

/* CIntToPy */
                        static CYTHON_INLINE PyObject* __Pyx_PyInt_From_short(short value) {
    const short neg_one = (short) -1, const_zero = (short) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(short) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(short) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(short) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(short) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(short) <= 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(short),
                                     little, !is_unsigned);
    }
}

/* CIntToPy */
                        static CYTHON_INLINE PyObject* __Pyx_PyInt_From_uint32_t(uint32_t value) {
    const uint32_t neg_one = (uint32_t) -1, const_zero = (uint32_t) 0;
    const int is_unsigned = neg_one > const_zero;
    if (is_unsigned) {
        if (sizeof(uint32_t) < sizeof(long)) {
            return PyInt_FromLong((long) value);
        } else if (sizeof(uint32_t) <= sizeof(unsigned long)) {
            return PyLong_FromUnsignedLong((unsigned long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(uint32_t) <= sizeof(unsigned PY_LONG_LONG)) {
            return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value);
#endif
        }
    } else {
        if (sizeof(uint32_t) <= sizeof(long)) {
            return PyInt_FromLong((long) value);
#ifdef HAVE_LONG_LONG
        } else if (sizeof(uint32_t) <= 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(uint32_t),
                                     little, !is_unsigned);
    }
}

/* 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;
}

/* CIntFromPy */
                        static CYTHON_INLINE short __Pyx_PyInt_As_short(PyObject *x) {
    const short neg_one = (short) -1, const_zero = (short) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(short) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(short, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (short) 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 (short) 0;
                case  1: __PYX_VERIFY_RETURN_INT(short, digit, digits[0])
                case 2:
                    if (8 * sizeof(short) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(short, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(short) >= 2 * PyLong_SHIFT) {
                            return (short) (((((short)digits[1]) << PyLong_SHIFT) | (short)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(short) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(short, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(short) >= 3 * PyLong_SHIFT) {
                            return (short) (((((((short)digits[2]) << PyLong_SHIFT) | (short)digits[1]) << PyLong_SHIFT) | (short)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(short) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(short, 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(short) >= 4 * PyLong_SHIFT) {
                            return (short) (((((((((short)digits[3]) << PyLong_SHIFT) | (short)digits[2]) << PyLong_SHIFT) | (short)digits[1]) << PyLong_SHIFT) | (short)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 (short) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(short) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(short, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(short) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(short, 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 (short) 0;
                case -1: __PYX_VERIFY_RETURN_INT(short, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(short,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(short) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(short, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(short) - 1 > 2 * PyLong_SHIFT) {
                            return (short) (((short)-1)*(((((short)digits[1]) << PyLong_SHIFT) | (short)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(short) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(short, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(short) - 1 > 2 * PyLong_SHIFT) {
                            return (short) ((((((short)digits[1]) << PyLong_SHIFT) | (short)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(short) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(short, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(short) - 1 > 3 * PyLong_SHIFT) {
                            return (short) (((short)-1)*(((((((short)digits[2]) << PyLong_SHIFT) | (short)digits[1]) << PyLong_SHIFT) | (short)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(short) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(short, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(short) - 1 > 3 * PyLong_SHIFT) {
                            return (short) ((((((((short)digits[2]) << PyLong_SHIFT) | (short)digits[1]) << PyLong_SHIFT) | (short)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(short) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(short, 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(short) - 1 > 4 * PyLong_SHIFT) {
                            return (short) (((short)-1)*(((((((((short)digits[3]) << PyLong_SHIFT) | (short)digits[2]) << PyLong_SHIFT) | (short)digits[1]) << PyLong_SHIFT) | (short)digits[0])));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(short) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(short, 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(short) - 1 > 4 * PyLong_SHIFT) {
                            return (short) ((((((((((short)digits[3]) << PyLong_SHIFT) | (short)digits[2]) << PyLong_SHIFT) | (short)digits[1]) << PyLong_SHIFT) | (short)digits[0])));
                        }
                    }
                    break;
            }
#endif
            if (sizeof(short) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(short, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(short) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(short, 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
            short 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 (short) -1;
        }
    } else {
        short val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (short) -1;
        val = __Pyx_PyInt_As_short(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to short");
    return (short) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to short");
    return (short) -1;
}

/* CIntFromPy */
                        static CYTHON_INLINE size_t __Pyx_PyInt_As_size_t(PyObject *x) {
    const size_t neg_one = (size_t) -1, const_zero = (size_t) 0;
    const int is_unsigned = neg_one > const_zero;
#if PY_MAJOR_VERSION < 3
    if (likely(PyInt_Check(x))) {
        if (sizeof(size_t) < sizeof(long)) {
            __PYX_VERIFY_RETURN_INT(size_t, long, PyInt_AS_LONG(x))
        } else {
            long val = PyInt_AS_LONG(x);
            if (is_unsigned && unlikely(val < 0)) {
                goto raise_neg_overflow;
            }
            return (size_t) 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 (size_t) 0;
                case  1: __PYX_VERIFY_RETURN_INT(size_t, digit, digits[0])
                case 2:
                    if (8 * sizeof(size_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) >= 2 * PyLong_SHIFT) {
                            return (size_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(size_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) >= 3 * PyLong_SHIFT) {
                            return (size_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0]));
                        }
                    }
                    break;
                case 4:
                    if (8 * sizeof(size_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, 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(size_t) >= 4 * PyLong_SHIFT) {
                            return (size_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
#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 (size_t) -1;
                if (unlikely(result == 1))
                    goto raise_neg_overflow;
            }
#endif
            if (sizeof(size_t) <= sizeof(unsigned long)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, unsigned long, PyLong_AsUnsignedLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(size_t) <= sizeof(unsigned PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, 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 (size_t) 0;
                case -1: __PYX_VERIFY_RETURN_INT(size_t, sdigit, (sdigit) (-(sdigit)digits[0]))
                case  1: __PYX_VERIFY_RETURN_INT(size_t,  digit, +digits[0])
                case -2:
                    if (8 * sizeof(size_t) - 1 > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) {
                            return (size_t) (((size_t)-1)*(((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case 2:
                    if (8 * sizeof(size_t) > 1 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 2 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) {
                            return (size_t) ((((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case -3:
                    if (8 * sizeof(size_t) - 1 > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) {
                            return (size_t) (((size_t)-1)*(((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case 3:
                    if (8 * sizeof(size_t) > 2 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 3 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])))
                        } else if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) {
                            return (size_t) ((((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])));
                        }
                    }
                    break;
                case -4:
                    if (8 * sizeof(size_t) - 1 > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, 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(size_t) - 1 > 4 * PyLong_SHIFT) {
                            return (size_t) (((size_t)-1)*(((((((((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(size_t) > 3 * PyLong_SHIFT) {
                        if (8 * sizeof(unsigned long) > 4 * PyLong_SHIFT) {
                            __PYX_VERIFY_RETURN_INT(size_t, 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(size_t) - 1 > 4 * PyLong_SHIFT) {
                            return (size_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
            if (sizeof(size_t) <= sizeof(long)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, long, PyLong_AsLong(x))
#ifdef HAVE_LONG_LONG
            } else if (sizeof(size_t) <= sizeof(PY_LONG_LONG)) {
                __PYX_VERIFY_RETURN_INT_EXC(size_t, 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
            size_t 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 (size_t) -1;
        }
    } else {
        size_t val;
        PyObject *tmp = __Pyx_PyNumber_IntOrLong(x);
        if (!tmp) return (size_t) -1;
        val = __Pyx_PyInt_As_size_t(tmp);
        Py_DECREF(tmp);
        return val;
    }
raise_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "value too large to convert to size_t");
    return (size_t) -1;
raise_neg_overflow:
    PyErr_SetString(PyExc_OverflowError,
        "can't convert negative value to size_t");
    return (size_t) -1;
}

/* 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;
}

/* SwapException */
                        #if CYTHON_FAST_THREAD_STATE
static CYTHON_INLINE void __Pyx__ExceptionSwap(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;
    *type = tmp_type;
    *value = tmp_value;
    *tb = tmp_tb;
}
#else
static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) {
    PyObject *tmp_type, *tmp_value, *tmp_tb;
    PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb);
    PyErr_SetExcInfo(*type, *value, *tb);
    *type = tmp_type;
    *value = tmp_value;
    *tb = tmp_tb;
}
#endif

/* CoroutineBase */
                        #include <structmember.h>
#include <frameobject.h>
static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value);
static PyObject *__Pyx_Coroutine_Close(PyObject *self);
static PyObject *__Pyx_Coroutine_Throw(PyObject *gen, PyObject *args);
#define __Pyx_Coroutine_Undelegate(gen) Py_CLEAR((gen)->yieldfrom)
#if 1 || PY_VERSION_HEX < 0x030300B0
static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue) {
    PyObject *et, *ev, *tb;
    PyObject *value = NULL;
    __Pyx_PyThreadState_declare
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&et, &ev, &tb);
    if (!et) {
        Py_XDECREF(tb);
        Py_XDECREF(ev);
        Py_INCREF(Py_None);
        *pvalue = Py_None;
        return 0;
    }
    if (likely(et == PyExc_StopIteration)) {
        if (!ev) {
            Py_INCREF(Py_None);
            value = Py_None;
        }
#if PY_VERSION_HEX >= 0x030300A0
        else if (Py_TYPE(ev) == (PyTypeObject*)PyExc_StopIteration) {
            value = ((PyStopIterationObject *)ev)->value;
            Py_INCREF(value);
            Py_DECREF(ev);
        }
#endif
        else if (unlikely(PyTuple_Check(ev))) {
            if (PyTuple_GET_SIZE(ev) >= 1) {
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
                value = PyTuple_GET_ITEM(ev, 0);
                Py_INCREF(value);
#else
                value = PySequence_ITEM(ev, 0);
#endif
            } else {
                Py_INCREF(Py_None);
                value = Py_None;
            }
            Py_DECREF(ev);
        }
        else if (!PyObject_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration)) {
            value = ev;
        }
        if (likely(value)) {
            Py_XDECREF(tb);
            Py_DECREF(et);
            *pvalue = value;
            return 0;
        }
    } else if (!PyErr_GivenExceptionMatches(et, PyExc_StopIteration)) {
        __Pyx_ErrRestore(et, ev, tb);
        return -1;
    }
    PyErr_NormalizeException(&et, &ev, &tb);
    if (unlikely(!PyObject_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration))) {
        __Pyx_ErrRestore(et, ev, tb);
        return -1;
    }
    Py_XDECREF(tb);
    Py_DECREF(et);
#if PY_VERSION_HEX >= 0x030300A0
    value = ((PyStopIterationObject *)ev)->value;
    Py_INCREF(value);
    Py_DECREF(ev);
#else
    {
        PyObject* args = __Pyx_PyObject_GetAttrStr(ev, __pyx_n_s_args);
        Py_DECREF(ev);
        if (likely(args)) {
            value = PySequence_GetItem(args, 0);
            Py_DECREF(args);
        }
        if (unlikely(!value)) {
            __Pyx_ErrRestore(NULL, NULL, NULL);
            Py_INCREF(Py_None);
            value = Py_None;
        }
    }
#endif
    *pvalue = value;
    return 0;
}
#endif
static CYTHON_INLINE
void __Pyx_Coroutine_ExceptionClear(__pyx_CoroutineObject *self) {
    PyObject *exc_type = self->exc_type;
    PyObject *exc_value = self->exc_value;
    PyObject *exc_traceback = self->exc_traceback;
    self->exc_type = NULL;
    self->exc_value = NULL;
    self->exc_traceback = NULL;
    Py_XDECREF(exc_type);
    Py_XDECREF(exc_value);
    Py_XDECREF(exc_traceback);
}
static CYTHON_INLINE
int __Pyx_Coroutine_CheckRunning(__pyx_CoroutineObject *gen) {
    if (unlikely(gen->is_running)) {
        PyErr_SetString(PyExc_ValueError,
                        "generator already executing");
        return 1;
    }
    return 0;
}
static CYTHON_INLINE
PyObject *__Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value) {
    PyObject *retval;
    __Pyx_PyThreadState_declare
    assert(!self->is_running);
    if (unlikely(self->resume_label == 0)) {
        if (unlikely(value && value != Py_None)) {
            PyErr_SetString(PyExc_TypeError,
                            "can't send non-None value to a "
                            "just-started generator");
            return NULL;
        }
    }
    if (unlikely(self->resume_label == -1)) {
        PyErr_SetNone(PyExc_StopIteration);
        return NULL;
    }
    __Pyx_PyThreadState_assign
    if (value) {
#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_PYSTON
#else
        if (self->exc_traceback) {
            PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback;
            PyFrameObject *f = tb->tb_frame;
            Py_XINCREF(__pyx_tstate->frame);
            assert(f->f_back == NULL);
            f->f_back = __pyx_tstate->frame;
        }
#endif
        __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value,
                            &self->exc_traceback);
    } else {
        __Pyx_Coroutine_ExceptionClear(self);
    }
    self->is_running = 1;
    retval = self->body((PyObject *) self, value);
    self->is_running = 0;
    if (retval) {
        __Pyx_ExceptionSwap(&self->exc_type, &self->exc_value,
                            &self->exc_traceback);
#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_PYSTON
#else
        if (self->exc_traceback) {
            PyTracebackObject *tb = (PyTracebackObject *) self->exc_traceback;
            PyFrameObject *f = tb->tb_frame;
            Py_CLEAR(f->f_back);
        }
#endif
    } else {
        __Pyx_Coroutine_ExceptionClear(self);
    }
    return retval;
}
static CYTHON_INLINE
PyObject *__Pyx_Coroutine_MethodReturn(PyObject *retval) {
    if (unlikely(!retval && !PyErr_Occurred())) {
        PyErr_SetNone(PyExc_StopIteration);
    }
    return retval;
}
static CYTHON_INLINE
PyObject *__Pyx_Coroutine_FinishDelegation(__pyx_CoroutineObject *gen) {
    PyObject *ret;
    PyObject *val = NULL;
    __Pyx_Coroutine_Undelegate(gen);
    __Pyx_PyGen_FetchStopIterationValue(&val);
    ret = __Pyx_Coroutine_SendEx(gen, val);
    Py_XDECREF(val);
    return ret;
}
static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value) {
    PyObject *retval;
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self;
    PyObject *yf = gen->yieldfrom;
    if (unlikely(__Pyx_Coroutine_CheckRunning(gen)))
        return NULL;
    if (yf) {
        PyObject *ret;
        gen->is_running = 1;
        #ifdef __Pyx_Generator_USED
        if (__Pyx_Generator_CheckExact(yf)) {
            ret = __Pyx_Coroutine_Send(yf, value);
        } else
        #endif
        #ifdef __Pyx_Coroutine_USED
        if (__Pyx_Coroutine_CheckExact(yf)) {
            ret = __Pyx_Coroutine_Send(yf, value);
        } else
        #endif
        {
            if (value == Py_None)
                ret = Py_TYPE(yf)->tp_iternext(yf);
            else
                ret = __Pyx_PyObject_CallMethod1(yf, __pyx_n_s_send, value);
        }
        gen->is_running = 0;
        if (likely(ret)) {
            return ret;
        }
        retval = __Pyx_Coroutine_FinishDelegation(gen);
    } else {
        retval = __Pyx_Coroutine_SendEx(gen, value);
    }
    return __Pyx_Coroutine_MethodReturn(retval);
}
static int __Pyx_Coroutine_CloseIter(__pyx_CoroutineObject *gen, PyObject *yf) {
    PyObject *retval = NULL;
    int err = 0;
    #ifdef __Pyx_Generator_USED
    if (__Pyx_Generator_CheckExact(yf)) {
        retval = __Pyx_Coroutine_Close(yf);
        if (!retval)
            return -1;
    } else
    #endif
    #ifdef __Pyx_Coroutine_USED
    if (__Pyx_Coroutine_CheckExact(yf)) {
        retval = __Pyx_Coroutine_Close(yf);
        if (!retval)
            return -1;
    } else
    #endif
    {
        PyObject *meth;
        gen->is_running = 1;
        meth = __Pyx_PyObject_GetAttrStr(yf, __pyx_n_s_close);
        if (unlikely(!meth)) {
            if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
                PyErr_WriteUnraisable(yf);
            }
            PyErr_Clear();
        } else {
            retval = PyObject_CallFunction(meth, NULL);
            Py_DECREF(meth);
            if (!retval)
                err = -1;
        }
        gen->is_running = 0;
    }
    Py_XDECREF(retval);
    return err;
}
static PyObject *__Pyx_Generator_Next(PyObject *self) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self;
    PyObject *yf = gen->yieldfrom;
    if (unlikely(__Pyx_Coroutine_CheckRunning(gen)))
        return NULL;
    if (yf) {
        PyObject *ret;
        gen->is_running = 1;
        #ifdef __Pyx_Generator_USED
        if (__Pyx_Generator_CheckExact(yf)) {
            ret = __Pyx_Generator_Next(yf);
        } else
        #endif
            ret = Py_TYPE(yf)->tp_iternext(yf);
        gen->is_running = 0;
        if (likely(ret)) {
            return ret;
        }
        return __Pyx_Coroutine_FinishDelegation(gen);
    }
    return __Pyx_Coroutine_SendEx(gen, Py_None);
}
static PyObject *__Pyx_Coroutine_Close(PyObject *self) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
    PyObject *retval, *raised_exception;
    PyObject *yf = gen->yieldfrom;
    int err = 0;
    if (unlikely(__Pyx_Coroutine_CheckRunning(gen)))
        return NULL;
    if (yf) {
        Py_INCREF(yf);
        err = __Pyx_Coroutine_CloseIter(gen, yf);
        __Pyx_Coroutine_Undelegate(gen);
        Py_DECREF(yf);
    }
    if (err == 0)
        PyErr_SetNone(PyExc_GeneratorExit);
    retval = __Pyx_Coroutine_SendEx(gen, NULL);
    if (retval) {
        Py_DECREF(retval);
        PyErr_SetString(PyExc_RuntimeError,
                        "generator ignored GeneratorExit");
        return NULL;
    }
    raised_exception = PyErr_Occurred();
    if (!raised_exception
        || raised_exception == PyExc_StopIteration
        || raised_exception == PyExc_GeneratorExit
        || PyErr_GivenExceptionMatches(raised_exception, PyExc_GeneratorExit)
        || PyErr_GivenExceptionMatches(raised_exception, PyExc_StopIteration))
    {
        if (raised_exception) PyErr_Clear();
        Py_INCREF(Py_None);
        return Py_None;
    }
    return NULL;
}
static PyObject *__Pyx_Coroutine_Throw(PyObject *self, PyObject *args) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
    PyObject *typ;
    PyObject *tb = NULL;
    PyObject *val = NULL;
    PyObject *yf = gen->yieldfrom;
    if (!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb))
        return NULL;
    if (unlikely(__Pyx_Coroutine_CheckRunning(gen)))
        return NULL;
    if (yf) {
        PyObject *ret;
        Py_INCREF(yf);
        if (PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit)) {
            int err = __Pyx_Coroutine_CloseIter(gen, yf);
            Py_DECREF(yf);
            __Pyx_Coroutine_Undelegate(gen);
            if (err < 0)
                return __Pyx_Coroutine_MethodReturn(__Pyx_Coroutine_SendEx(gen, NULL));
            goto throw_here;
        }
        gen->is_running = 1;
        #ifdef __Pyx_Generator_USED
        if (__Pyx_Generator_CheckExact(yf)) {
            ret = __Pyx_Coroutine_Throw(yf, args);
        } else
        #endif
        #ifdef __Pyx_Coroutine_USED
        if (__Pyx_Coroutine_CheckExact(yf)) {
            ret = __Pyx_Coroutine_Throw(yf, args);
        } else
        #endif
        {
            PyObject *meth = __Pyx_PyObject_GetAttrStr(yf, __pyx_n_s_throw);
            if (unlikely(!meth)) {
                Py_DECREF(yf);
                if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
                    gen->is_running = 0;
                    return NULL;
                }
                PyErr_Clear();
                __Pyx_Coroutine_Undelegate(gen);
                gen->is_running = 0;
                goto throw_here;
            }
            ret = PyObject_CallObject(meth, args);
            Py_DECREF(meth);
        }
        gen->is_running = 0;
        Py_DECREF(yf);
        if (!ret) {
            ret = __Pyx_Coroutine_FinishDelegation(gen);
        }
        return __Pyx_Coroutine_MethodReturn(ret);
    }
throw_here:
    __Pyx_Raise(typ, val, tb, NULL);
    return __Pyx_Coroutine_MethodReturn(__Pyx_Coroutine_SendEx(gen, NULL));
}
static int __Pyx_Coroutine_traverse(PyObject *self, visitproc visit, void *arg) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
    Py_VISIT(gen->closure);
    Py_VISIT(gen->classobj);
    Py_VISIT(gen->yieldfrom);
    Py_VISIT(gen->exc_type);
    Py_VISIT(gen->exc_value);
    Py_VISIT(gen->exc_traceback);
    return 0;
}
static int __Pyx_Coroutine_clear(PyObject *self) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
    Py_CLEAR(gen->closure);
    Py_CLEAR(gen->classobj);
    Py_CLEAR(gen->yieldfrom);
    Py_CLEAR(gen->exc_type);
    Py_CLEAR(gen->exc_value);
    Py_CLEAR(gen->exc_traceback);
    Py_CLEAR(gen->gi_name);
    Py_CLEAR(gen->gi_qualname);
    return 0;
}
static void __Pyx_Coroutine_dealloc(PyObject *self) {
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
    PyObject_GC_UnTrack(gen);
    if (gen->gi_weakreflist != NULL)
        PyObject_ClearWeakRefs(self);
    if (gen->resume_label > 0) {
        PyObject_GC_Track(self);
#if PY_VERSION_HEX >= 0x030400a1
        if (PyObject_CallFinalizerFromDealloc(self))
#else
        Py_TYPE(gen)->tp_del(self);
        if (self->ob_refcnt > 0)
#endif
        {
            return;
        }
        PyObject_GC_UnTrack(self);
    }
    __Pyx_Coroutine_clear(self);
    PyObject_GC_Del(gen);
}
static void __Pyx_Coroutine_del(PyObject *self) {
    PyObject *res;
    PyObject *error_type, *error_value, *error_traceback;
    __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self;
    __Pyx_PyThreadState_declare
    if (gen->resume_label <= 0)
        return ;
#if PY_VERSION_HEX < 0x030400a1
    assert(self->ob_refcnt == 0);
    self->ob_refcnt = 1;
#endif
    __Pyx_PyThreadState_assign
    __Pyx_ErrFetch(&error_type, &error_value, &error_traceback);
    res = __Pyx_Coroutine_Close(self);
    if (res == NULL)
        PyErr_WriteUnraisable(self);
    else
        Py_DECREF(res);
    __Pyx_ErrRestore(error_type, error_value, error_traceback);
#if PY_VERSION_HEX < 0x030400a1
    assert(self->ob_refcnt > 0);
    if (--self->ob_refcnt == 0) {
        return;
    }
    {
        Py_ssize_t refcnt = self->ob_refcnt;
        _Py_NewReference(self);
        self->ob_refcnt = refcnt;
    }
#if CYTHON_COMPILING_IN_CPYTHON
    assert(PyType_IS_GC(self->ob_type) &&
           _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED);
    _Py_DEC_REFTOTAL;
#endif
#ifdef COUNT_ALLOCS
    --Py_TYPE(self)->tp_frees;
    --Py_TYPE(self)->tp_allocs;
#endif
#endif
}
static PyObject *
__Pyx_Coroutine_get_name(__pyx_CoroutineObject *self)
{
    PyObject *name = self->gi_name;
    if (unlikely(!name)) name = Py_None;
    Py_INCREF(name);
    return name;
}
static int
__Pyx_Coroutine_set_name(__pyx_CoroutineObject *self, 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 = self->gi_name;
    Py_INCREF(value);
    self->gi_name = value;
    Py_XDECREF(tmp);
    return 0;
}
static PyObject *
__Pyx_Coroutine_get_qualname(__pyx_CoroutineObject *self)
{
    PyObject *name = self->gi_qualname;
    if (unlikely(!name)) name = Py_None;
    Py_INCREF(name);
    return name;
}
static int
__Pyx_Coroutine_set_qualname(__pyx_CoroutineObject *self, 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 = self->gi_qualname;
    Py_INCREF(value);
    self->gi_qualname = value;
    Py_XDECREF(tmp);
    return 0;
}
static __pyx_CoroutineObject *__Pyx__Coroutine_New(
            PyTypeObject* type, __pyx_coroutine_body_t body, PyObject *closure,
            PyObject *name, PyObject *qualname, PyObject *module_name) {
    __pyx_CoroutineObject *gen = PyObject_GC_New(__pyx_CoroutineObject, type);
    if (gen == NULL)
        return NULL;
    gen->body = body;
    gen->closure = closure;
    Py_XINCREF(closure);
    gen->is_running = 0;
    gen->resume_label = 0;
    gen->classobj = NULL;
    gen->yieldfrom = NULL;
    gen->exc_type = NULL;
    gen->exc_value = NULL;
    gen->exc_traceback = NULL;
    gen->gi_weakreflist = NULL;
    Py_XINCREF(qualname);
    gen->gi_qualname = qualname;
    Py_XINCREF(name);
    gen->gi_name = name;
    Py_XINCREF(module_name);
    gen->gi_modulename = module_name;
    PyObject_GC_Track(gen);
    return gen;
}

/* PatchModuleWithCoroutine */
                            static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code) {
#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
    int result;
    PyObject *globals, *result_obj;
    globals = PyDict_New();  if (unlikely(!globals)) goto ignore;
    result = PyDict_SetItemString(globals, "_cython_coroutine_type",
    #ifdef __Pyx_Coroutine_USED
        (PyObject*)__pyx_CoroutineType);
    #else
        Py_None);
    #endif
    if (unlikely(result < 0)) goto ignore;
    result = PyDict_SetItemString(globals, "_cython_generator_type",
    #ifdef __Pyx_Generator_USED
        (PyObject*)__pyx_GeneratorType);
    #else
        Py_None);
    #endif
    if (unlikely(result < 0)) goto ignore;
    if (unlikely(PyDict_SetItemString(globals, "_module", module) < 0)) goto ignore;
    if (unlikely(PyDict_SetItemString(globals, "__builtins__", __pyx_b) < 0)) goto ignore;
    result_obj = PyRun_String(py_code, Py_file_input, globals, globals);
    if (unlikely(!result_obj)) goto ignore;
    Py_DECREF(result_obj);
    Py_DECREF(globals);
    return module;
ignore:
    Py_XDECREF(globals);
    PyErr_WriteUnraisable(module);
    if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, "Cython module failed to patch module with custom type", 1) < 0)) {
        Py_DECREF(module);
        module = NULL;
    }
#else
    py_code++;
#endif
    return module;
}

/* PatchGeneratorABC */
                            #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
static PyObject* __Pyx_patch_abc_module(PyObject *module);
static PyObject* __Pyx_patch_abc_module(PyObject *module) {
    module = __Pyx_Coroutine_patch_module(
        module, ""
"if _cython_generator_type is not None:\n"
"    try: Generator = _module.Generator\n"
"    except AttributeError: pass\n"
"    else: Generator.register(_cython_generator_type)\n"
"if _cython_coroutine_type is not None:\n"
"    try: Coroutine = _module.Coroutine\n"
"    except AttributeError: pass\n"
"    else: Coroutine.register(_cython_coroutine_type)\n"
    );
    return module;
}
#endif
static int __Pyx_patch_abc(void) {
#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED)
    static int abc_patched = 0;
    if (!abc_patched) {
        PyObject *module;
        module = PyImport_ImportModule((PY_VERSION_HEX >= 0x03030000) ? "collections.abc" : "collections");
        if (!module) {
            PyErr_WriteUnraisable(NULL);
            if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning,
                    ((PY_VERSION_HEX >= 0x03030000) ?
                        "Cython module failed to register with collections.abc module" :
                        "Cython module failed to register with collections module"), 1) < 0)) {
                return -1;
            }
        } else {
            module = __Pyx_patch_abc_module(module);
            abc_patched = 1;
            if (unlikely(!module))
                return -1;
            Py_DECREF(module);
        }
        module = PyImport_ImportModule("backports_abc");
        if (module) {
            module = __Pyx_patch_abc_module(module);
            Py_XDECREF(module);
        }
        if (!module) {
            PyErr_Clear();
        }
    }
#else
    if (0) __Pyx_Coroutine_patch_module(NULL, NULL);
#endif
    return 0;
}

/* Generator */
                            static PyMethodDef __pyx_Generator_methods[] = {
    {"send", (PyCFunction) __Pyx_Coroutine_Send, METH_O,
     (char*) PyDoc_STR("send(arg) -> send 'arg' into generator,\nreturn next yielded value or raise StopIteration.")},
    {"throw", (PyCFunction) __Pyx_Coroutine_Throw, METH_VARARGS,
     (char*) PyDoc_STR("throw(typ[,val[,tb]]) -> raise exception in generator,\nreturn next yielded value or raise StopIteration.")},
    {"close", (PyCFunction) __Pyx_Coroutine_Close, METH_NOARGS,
     (char*) PyDoc_STR("close() -> raise GeneratorExit inside generator.")},
    {0, 0, 0, 0}
};
static PyMemberDef __pyx_Generator_memberlist[] = {
    {(char *) "gi_running", T_BOOL, offsetof(__pyx_CoroutineObject, is_running), READONLY, NULL},
    {(char*) "gi_yieldfrom", T_OBJECT, offsetof(__pyx_CoroutineObject, yieldfrom), READONLY,
     (char*) PyDoc_STR("object being iterated by 'yield from', or None")},
    {0, 0, 0, 0, 0}
};
static PyGetSetDef __pyx_Generator_getsets[] = {
    {(char *) "__name__", (getter)__Pyx_Coroutine_get_name, (setter)__Pyx_Coroutine_set_name,
     (char*) PyDoc_STR("name of the generator"), 0},
    {(char *) "__qualname__", (getter)__Pyx_Coroutine_get_qualname, (setter)__Pyx_Coroutine_set_qualname,
     (char*) PyDoc_STR("qualified name of the generator"), 0},
    {0, 0, 0, 0, 0}
};
static PyTypeObject __pyx_GeneratorType_type = {
    PyVarObject_HEAD_INIT(0, 0)
    "generator",
    sizeof(__pyx_CoroutineObject),
    0,
    (destructor) __Pyx_Coroutine_dealloc,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE,
    0,
    (traverseproc) __Pyx_Coroutine_traverse,
    0,
    0,
    offsetof(__pyx_CoroutineObject, gi_weakreflist),
    0,
    (iternextfunc) __Pyx_Generator_Next,
    __pyx_Generator_methods,
    __pyx_Generator_memberlist,
    __pyx_Generator_getsets,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
#if PY_VERSION_HEX >= 0x030400a1
    0,
#else
    __Pyx_Coroutine_del,
#endif
    0,
#if PY_VERSION_HEX >= 0x030400a1
    __Pyx_Coroutine_del,
#endif
};
static int __pyx_Generator_init(void) {
    __pyx_GeneratorType_type.tp_getattro = PyObject_GenericGetAttr;
    __pyx_GeneratorType_type.tp_iter = PyObject_SelfIter;
    __pyx_GeneratorType = __Pyx_FetchCommonType(&__pyx_GeneratorType_type);
    if (unlikely(!__pyx_GeneratorType)) {
        return -1;
    }
    return 0;
}

/* 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;
}

/* ModuleImport */
                            #ifndef __PYX_HAVE_RT_ImportModule
#define __PYX_HAVE_RT_ImportModule
static PyObject *__Pyx_ImportModule(const char *name) {
    PyObject *py_name = 0;
    PyObject *py_module = 0;
    py_name = __Pyx_PyIdentifier_FromString(name);
    if (!py_name)
        goto bad;
    py_module = PyImport_Import(py_name);
    Py_DECREF(py_name);
    return py_module;
bad:
    Py_XDECREF(py_name);
    return 0;
}
#endif

/* TypeImport */
                            #ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType
static PyTypeObject *__Pyx_ImportType(const char *module_name, const char *class_name,
    size_t size, int strict)
{
    PyObject *py_module = 0;
    PyObject *result = 0;
    PyObject *py_name = 0;
    char warning[200];
    Py_ssize_t basicsize;
#ifdef Py_LIMITED_API
    PyObject *py_basicsize;
#endif
    py_module = __Pyx_ImportModule(module_name);
    if (!py_module)
        goto bad;
    py_name = __Pyx_PyIdentifier_FromString(class_name);
    if (!py_name)
        goto bad;
    result = PyObject_GetAttr(py_module, py_name);
    Py_DECREF(py_name);
    py_name = 0;
    Py_DECREF(py_module);
    py_module = 0;
    if (!result)
        goto bad;
    if (!PyType_Check(result)) {
        PyErr_Format(PyExc_TypeError,
            "%.200s.%.200s is not a type object",
            module_name, class_name);
        goto bad;
    }
#ifndef Py_LIMITED_API
    basicsize = ((PyTypeObject *)result)->tp_basicsize;
#else
    py_basicsize = PyObject_GetAttrString(result, "__basicsize__");
    if (!py_basicsize)
        goto bad;
    basicsize = PyLong_AsSsize_t(py_basicsize);
    Py_DECREF(py_basicsize);
    py_basicsize = 0;
    if (basicsize == (Py_ssize_t)-1 && PyErr_Occurred())
        goto bad;
#endif
    if (!strict && (size_t)basicsize > size) {
        PyOS_snprintf(warning, sizeof(warning),
            "%s.%s size changed, may indicate binary incompatibility. Expected %zd, got %zd",
            module_name, class_name, basicsize, size);
        if (PyErr_WarnEx(NULL, warning, 0) < 0) goto bad;
    }
    else if ((size_t)basicsize != size) {
        PyErr_Format(PyExc_ValueError,
            "%.200s.%.200s has the wrong size, try recompiling. Expected %zd, got %zd",
            module_name, class_name, basicsize, size);
        goto bad;
    }
    return (PyTypeObject *)result;
bad:
    Py_XDECREF(py_module);
    Py_XDECREF(result);
    return NULL;
}
#endif

/* VoidPtrImport */
                            #ifndef __PYX_HAVE_RT_ImportVoidPtr
#define __PYX_HAVE_RT_ImportVoidPtr
static int __Pyx_ImportVoidPtr(PyObject *module, const char *name, void **p, const char *sig) {
    PyObject *d = 0;
    PyObject *cobj = 0;
    d = PyObject_GetAttrString(module, (char *)"__pyx_capi__");
    if (!d)
        goto bad;
    cobj = PyDict_GetItemString(d, name);
    if (!cobj) {
        PyErr_Format(PyExc_ImportError,
            "%.200s does not export expected C variable %.200s",
                PyModule_GetName(module), name);
        goto bad;
    }
#if PY_VERSION_HEX >= 0x02070000
    if (!PyCapsule_IsValid(cobj, sig)) {
        PyErr_Format(PyExc_TypeError,
            "C variable %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
             PyModule_GetName(module), name, sig, PyCapsule_GetName(cobj));
        goto bad;
    }
    *p = PyCapsule_GetPointer(cobj, sig);
#else
    {const char *desc, *s1, *s2;
    desc = (const char *)PyCObject_GetDesc(cobj);
    if (!desc)
        goto bad;
    s1 = desc; s2 = sig;
    while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
    if (*s1 != *s2) {
        PyErr_Format(PyExc_TypeError,
            "C variable %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
             PyModule_GetName(module), name, sig, desc);
        goto bad;
    }
    *p = PyCObject_AsVoidPtr(cobj);}
#endif
    if (!(*p))
        goto bad;
    Py_DECREF(d);
    return 0;
bad:
    Py_XDECREF(d);
    return -1;
}
#endif

/* FunctionImport */
                            #ifndef __PYX_HAVE_RT_ImportFunction
#define __PYX_HAVE_RT_ImportFunction
static int __Pyx_ImportFunction(PyObject *module, const char *funcname, void (**f)(void), const char *sig) {
    PyObject *d = 0;
    PyObject *cobj = 0;
    union {
        void (*fp)(void);
        void *p;
    } tmp;
    d = PyObject_GetAttrString(module, (char *)"__pyx_capi__");
    if (!d)
        goto bad;
    cobj = PyDict_GetItemString(d, funcname);
    if (!cobj) {
        PyErr_Format(PyExc_ImportError,
            "%.200s does not export expected C function %.200s",
                PyModule_GetName(module), funcname);
        goto bad;
    }
#if PY_VERSION_HEX >= 0x02070000
    if (!PyCapsule_IsValid(cobj, sig)) {
        PyErr_Format(PyExc_TypeError,
            "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
             PyModule_GetName(module), funcname, sig, PyCapsule_GetName(cobj));
        goto bad;
    }
    tmp.p = PyCapsule_GetPointer(cobj, sig);
#else
    {const char *desc, *s1, *s2;
    desc = (const char *)PyCObject_GetDesc(cobj);
    if (!desc)
        goto bad;
    s1 = desc; s2 = sig;
    while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
    if (*s1 != *s2) {
        PyErr_Format(PyExc_TypeError,
            "C function %.200s.%.200s has wrong signature (expected %.500s, got %.500s)",
             PyModule_GetName(module), funcname, sig, desc);
        goto bad;
    }
    tmp.p = PyCObject_AsVoidPtr(cobj);}
#endif
    *f = tmp.fp;
    if (!(*f))
        goto bad;
    Py_DECREF(d);
    return 0;
bad:
    Py_XDECREF(d);
    return -1;
}
#endif

/* 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;
        ++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 char* __Pyx_PyObject_AsString(PyObject* o) {
    Py_ssize_t ignore;
    return __Pyx_PyObject_AsStringAndSize(o, &ignore);
}
static CYTHON_INLINE 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 */
