From bc872f986a6ed156de46b356bd4e4a00b229005c Mon Sep 17 00:00:00 2001 From: Adrian Altenhoff Date: Thu, 24 Jan 2019 16:09:42 +0100 Subject: [PATCH] implement relative similarity cutoff for results Constructor accepts now an additional optional argument (rel_sim_cutoff) that specifies a cutoff for the relative difference of a lower scoring match such that it is still returned. --- fuzzyset/__init__.py | 15 +- fuzzyset/cfuzzyset.c | 2608 +++++++++++++++++++++++----------------- fuzzyset/cfuzzyset.pyx | 23 +- 3 files changed, 1525 insertions(+), 1121 deletions(-) diff --git a/fuzzyset/__init__.py b/fuzzyset/__init__.py index cd197fc..1abb598 100644 --- a/fuzzyset/__init__.py +++ b/fuzzyset/__init__.py @@ -10,15 +10,17 @@ __all__ = ('FuzzySet',) + class FuzzySet(object): " Fuzzily match a string " - def __init__(self, iterable=(), gram_size_lower=2, gram_size_upper=3, use_levenshtein=True): + def __init__(self, iterable=(), gram_size_lower=2, gram_size_upper=3, use_levenshtein=True, rel_sim_cutoff=1): self.exact_set = {} self.match_dict = collections.defaultdict(list) self.items = {} self.use_levenshtein = use_levenshtein self.gram_size_lower = gram_size_lower self.gram_size_upper = gram_size_upper + self.rel_sim_cutoff = rel_sim_cutoff for i in range(gram_size_lower, gram_size_upper + 1): self.items[i] = [] for value in iterable: @@ -46,7 +48,7 @@ def __add(self, value, gram_size): def __getitem__(self, value): lvalue = value.lower() result = self.exact_set.get(lvalue) - if result: + if result and self.rel_sim_cutoff >= 1: return [(1, result)] for i in range(self.gram_size_upper, self.gram_size_lower - 1, -1): results = self.__get(value, i) @@ -78,9 +80,9 @@ def __get(self, value, gram_size): for _, matched in results[:50]] results.sort(reverse=True, key=operator.itemgetter(0)) + score_threshold = results[0][0] * min(1.0, self.rel_sim_cutoff) return [(score, self.exact_set[lval]) for score, lval in results - if score == results[0][0]] - + if score >= score_threshold] def get(self, key, default=None): try: @@ -94,6 +96,7 @@ def __nonzero__(self): def __len__(self): return len(self.exact_set) + def _distance(str1, str2): distance = Levenshtein.distance(str1, str2) if len(str1) > len(str2): @@ -101,12 +104,14 @@ def _distance(str1, str2): else: return 1 - float(distance) / len(str2) + def _gram_counter(value, gram_size=2): result = collections.defaultdict(int) for value in _iterate_grams(value, gram_size): result[value] += 1 return result + def _iterate_grams(value, gram_size=2): simplified = '-' + _non_word_re.sub('', value.lower()) + '-' len_diff = gram_size - len(simplified) @@ -115,6 +120,7 @@ def _iterate_grams(value, gram_size=2): for i in range(len(simplified) - gram_size + 1): yield simplified[i:i + gram_size] + def _other_test(): with open('./origin_cities') as cities: for line in cities: @@ -124,6 +130,7 @@ def _other_test(): elif isinstance(result, list): print("{}: {}".format(line.strip(), result)) + if __name__ == '__main__': pass #_other_test() diff --git a/fuzzyset/cfuzzyset.c b/fuzzyset/cfuzzyset.c index 842d9ed..7248a45 100644 --- a/fuzzyset/cfuzzyset.c +++ b/fuzzyset/cfuzzyset.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.28.4 */ +/* Generated by Cython 0.29.3 */ #define PY_SSIZE_T_CLEAN #include "Python.h" @@ -7,7 +7,8 @@ #elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) #error Cython requires Python 2.6+ or Python 3.3+. #else -#define CYTHON_ABI "0_28_4" +#define CYTHON_ABI "0_29_3" +#define CYTHON_HEX_VERSION 0x001D03F0 #define CYTHON_FUTURE_DIVISION 0 #include #ifndef offsetof @@ -78,6 +79,10 @@ #define CYTHON_PEP489_MULTI_PHASE_INIT 0 #undef CYTHON_USE_TP_FINALIZE #define CYTHON_USE_TP_FINALIZE 0 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 #elif defined(PYSTON_VERSION) #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_PYSTON 1 @@ -115,6 +120,10 @@ #define CYTHON_PEP489_MULTI_PHASE_INIT 0 #undef CYTHON_USE_TP_FINALIZE #define CYTHON_USE_TP_FINALIZE 0 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 #else #define CYTHON_COMPILING_IN_PYPY 0 #define CYTHON_COMPILING_IN_PYSTON 0 @@ -168,11 +177,17 @@ #define CYTHON_FAST_PYCALL 1 #endif #ifndef CYTHON_PEP489_MULTI_PHASE_INIT - #define CYTHON_PEP489_MULTI_PHASE_INIT (0 && PY_VERSION_HEX >= 0x03050000) + #define CYTHON_PEP489_MULTI_PHASE_INIT (PY_VERSION_HEX >= 0x03050000) #endif #ifndef CYTHON_USE_TP_FINALIZE #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1) #endif + #ifndef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX >= 0x030600B1) + #endif + #ifndef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK (PY_VERSION_HEX >= 0x030700A3) + #endif #endif #if !defined(CYTHON_FAST_PYCCALL) #define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1) @@ -182,6 +197,9 @@ #undef SHIFT #undef BASE #undef MASK + #ifdef SIZEOF_VOID_P + enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; + #endif #endif #ifndef __has_attribute #define __has_attribute(x) 0 @@ -308,6 +326,9 @@ #ifndef Py_TPFLAGS_HAVE_FINALIZE #define Py_TPFLAGS_HAVE_FINALIZE 0 #endif +#ifndef METH_STACKLESS + #define METH_STACKLESS 0 +#endif #if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL) #ifndef METH_FASTCALL #define METH_FASTCALL 0x80 @@ -321,15 +342,40 @@ #endif #if CYTHON_FAST_PYCCALL #define __Pyx_PyFastCFunction_Check(func)\ - ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS))))) + ((PyCFunction_Check(func) && (METH_FASTCALL == (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS))))) #else #define __Pyx_PyFastCFunction_Check(func) 0 #endif +#if CYTHON_USE_DICT_VERSIONS +#define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ + (version_var) = __PYX_GET_DICT_VERSION(dict);\ + (cache_var) = (value); +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\ + (VAR) = __pyx_dict_cached_value;\ + } else {\ + (VAR) = __pyx_dict_cached_value = (LOOKUP);\ + __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\ + }\ + } +#else +#define __PYX_GET_DICT_VERSION(dict) (0) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); +#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_CPYTHON && PY_VERSION_HEX < 0x030400A1 + #define PyMem_RawMalloc(n) PyMem_Malloc(n) + #define PyMem_RawRealloc(p, n) PyMem_Realloc(p, n) + #define PyMem_RawFree(p) PyMem_Free(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) @@ -352,7 +398,7 @@ typedef int Py_tss_t; static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) { *key = PyThread_create_key(); - return 0; // PyThread_create_key reports success always + return 0; } static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) { Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t)); @@ -375,7 +421,7 @@ static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) { static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { return PyThread_get_key_value(*key); } -#endif // TSS (Thread Specific Storage) API +#endif #if CYTHON_COMPILING_IN_CPYTHON || defined(_PyDict_NewPresized) #define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n)) #else @@ -437,8 +483,8 @@ static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { #if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Format) #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt) #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)) +#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) +#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) #if PY_MAJOR_VERSION >= 3 #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) #else @@ -591,6 +637,9 @@ typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* enc (sizeof(type) == sizeof(Py_ssize_t) &&\ (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\ v == (type)PY_SSIZE_T_MAX))) ) +static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) { + return (size_t) i < (size_t) limit; +} #if defined (__cplusplus) && __cplusplus >= 201103L #include #define __Pyx_sst_abs(value) std::abs(value) @@ -649,6 +698,7 @@ static CYTHON_INLINE size_t __Pyx_Py_UNICODE_strlen(const Py_UNICODE *u) { #define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None) static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b); static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); +static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*); static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x); #define __Pyx_PySequence_Tuple(obj)\ (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj)) @@ -729,7 +779,7 @@ static int __Pyx_init_sys_getdefaultencoding_params(void) { 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)); + __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1); if (!__PYX_DEFAULT_STRING_ENCODING) goto bad; strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c); Py_DECREF(default_encoding); @@ -774,7 +824,7 @@ struct __pyx_obj_9cfuzzyset_cFuzzySet; struct __pyx_opt_args_9cfuzzyset__gram_counter; struct __pyx_opt_args_9cfuzzyset__iterate_grams; -/* "cfuzzyset.pyx":185 +/* "cfuzzyset.pyx":194 * * @cython.boundscheck(False) * cdef dict _gram_counter(unicode value, int gram_size=2): # <<<<<<<<<<<<<< @@ -786,7 +836,7 @@ struct __pyx_opt_args_9cfuzzyset__gram_counter { int gram_size; }; -/* "cfuzzyset.pyx":200 +/* "cfuzzyset.pyx":209 * cdef unicode hyphens = u'-----------' * * cdef list _iterate_grams(unicode value, int gram_size=2): # <<<<<<<<<<<<<< @@ -814,6 +864,7 @@ struct __pyx_obj_9cfuzzyset_cFuzzySet { int gram_size_lower; int gram_size_upper; int use_levenshtein; + double rel_sim_cutoff; }; @@ -926,6 +977,18 @@ static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, #else #define __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs) _PyFunction_FastCallDict(func, args, nargs, kwargs) #endif +#define __Pyx_BUILD_ASSERT_EXPR(cond)\ + (sizeof(char [1 - 2*!(cond)]) - 1) +#ifndef Py_MEMBER_SIZE +#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member) +#endif + static size_t __pyx_pyframe_localsplus_offset = 0; + #include "frameobject.h" + #define __Pxy_PyFrame_Initialize_Offsets()\ + ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\ + (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus))) + #define __Pyx_PyFrame_GetLocalsplus(frame)\ + (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset)) #endif /* PyObjectCall.proto */ @@ -935,6 +998,9 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg #define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) #endif +/* PyObjectCall2Args.proto */ +static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2); + /* PyObjectCallMethO.proto */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg); @@ -944,7 +1010,25 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); /* GetModuleGlobalName.proto */ -static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name); +#if CYTHON_USE_DICT_VERSIONS +#define __Pyx_GetModuleGlobalName(var, name) {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ + (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ + __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} +#define __Pyx_GetModuleGlobalNameUncached(var, name) {\ + PY_UINT64_T __pyx_dict_version;\ + PyObject *__pyx_dict_cached_value;\ + (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); +#else +#define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) +#define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name) +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); +#endif /* PyObjectCallNoArg.proto */ #if CYTHON_COMPILING_IN_CPYTHON @@ -1007,11 +1091,11 @@ static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObje (likely((cfunc)->flag == METH_NOARGS) ? (*((cfunc)->func))(self, NULL) :\ (PY_VERSION_HEX >= 0x030600B1 && likely((cfunc)->flag == METH_FASTCALL) ?\ (PY_VERSION_HEX >= 0x030700A0 ?\ - (*(__Pyx_PyCFunctionFast)(cfunc)->func)(self, &__pyx_empty_tuple, 0) :\ - (*(__Pyx_PyCFunctionFastWithKeywords)(cfunc)->func)(self, &__pyx_empty_tuple, 0, NULL)) :\ + (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)(cfunc)->func)(self, &__pyx_empty_tuple, 0) :\ + (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, &__pyx_empty_tuple, 0, NULL)) :\ (PY_VERSION_HEX >= 0x030700A0 && (cfunc)->flag == (METH_FASTCALL | METH_KEYWORDS) ?\ - (*(__Pyx_PyCFunctionFastWithKeywords)(cfunc)->func)(self, &__pyx_empty_tuple, 0, NULL) :\ - (likely((cfunc)->flag == (METH_VARARGS | METH_KEYWORDS)) ? ((*(PyCFunctionWithKeywords)(cfunc)->func)(self, __pyx_empty_tuple, NULL)) :\ + (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, &__pyx_empty_tuple, 0, NULL) :\ + (likely((cfunc)->flag == (METH_VARARGS | METH_KEYWORDS)) ? ((*(PyCFunctionWithKeywords)(void*)(PyCFunction)(cfunc)->func)(self, __pyx_empty_tuple, NULL)) :\ ((cfunc)->flag == METH_VARARGS ? (*((cfunc)->func))(self, __pyx_empty_tuple) :\ __Pyx__CallUnboundCMethod0(cfunc, self)))))) :\ __Pyx__CallUnboundCMethod0(cfunc, self)) @@ -1066,9 +1150,11 @@ static CYTHON_INLINE int __Pyx_IterFinish(void); /* UnpackItemEndCheck.proto */ static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected); +/* PyObjectGetMethod.proto */ +static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method); + /* PyObjectCallMethod1.proto */ static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg); -static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg); /* append.proto */ static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x); @@ -1151,6 +1237,11 @@ static CYTHON_INLINE PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* k #define __Pyx_PyObject_GetItem(obj, key) PyObject_GetItem(obj, key) #endif +/* GetTopmostException.proto */ +#if CYTHON_USE_EXC_INFO_STACK +static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate); +#endif + /* SaveResetException.proto */ #if CYTHON_FAST_THREAD_STATE #define __Pyx_ExceptionSave(type, value, tb) __Pyx__ExceptionSave(__pyx_tstate, type, value, tb) @@ -1304,10 +1395,10 @@ int __pyx_module_is_main_cfuzzyset = 0; static PyObject *__pyx_builtin_range; static PyObject *__pyx_builtin_KeyError; static PyObject *__pyx_builtin_TypeError; +static const char __pyx_k_[] = "-"; static const char __pyx_k_w[] = "[^\\w, ]+"; -static const char __pyx_k__3[] = "-"; -static const char __pyx_k__4[] = ""; -static const char __pyx_k__9[] = "-----------"; +static const char __pyx_k__2[] = ""; +static const char __pyx_k__7[] = "-----------"; static const char __pyx_k_re[] = "re"; static const char __pyx_k_add[] = "add"; static const char __pyx_k_get[] = "_get"; @@ -1315,6 +1406,7 @@ static const char __pyx_k_key[] = "key"; static const char __pyx_k_sub[] = "sub"; static const char __pyx_k_main[] = "__main__"; static const char __pyx_k_math[] = "math"; +static const char __pyx_k_name[] = "__name__"; static const char __pyx_k_sort[] = "sort"; static const char __pyx_k_test[] = "__test__"; static const char __pyx_k_add_2[] = "_add"; @@ -1335,6 +1427,7 @@ static const char __pyx_k_distance[] = "distance"; static const char __pyx_k_iterable[] = "iterable"; static const char __pyx_k_operator[] = "operator"; static const char __pyx_k_TypeError[] = "TypeError"; +static const char __pyx_k_cFuzzySet[] = "cFuzzySet"; static const char __pyx_k_cfuzzyset[] = "cfuzzyset"; static const char __pyx_k_exact_set[] = "exact_set"; static const char __pyx_k_gram_size[] = "gram_size"; @@ -1344,22 +1437,24 @@ static const char __pyx_k_pyx_vtable[] = "__pyx_vtable__"; static const char __pyx_k_Levenshtein[] = "Levenshtein"; static const char __pyx_k_collections[] = "collections"; static const char __pyx_k_pickle_creator[] = "_pickle_creator"; +static const char __pyx_k_rel_sim_cutoff[] = "rel_sim_cutoff"; static const char __pyx_k_gram_size_lower[] = "gram_size_lower"; static const char __pyx_k_gram_size_upper[] = "gram_size_upper"; static const char __pyx_k_use_levenshtein[] = "use_levenshtein"; static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; static const char __pyx_k_fuzzyset_cfuzzyset_pyx[] = "fuzzyset/cfuzzyset.pyx"; static const char __pyx_k_Expecting_string_or_unicode_rece[] = "Expecting string or unicode, received "; +static PyObject *__pyx_kp_u_; static PyObject *__pyx_kp_s_Expecting_string_or_unicode_rece; static PyObject *__pyx_n_s_KeyError; static PyObject *__pyx_n_s_Levenshtein; static PyObject *__pyx_n_s_TypeError; -static PyObject *__pyx_kp_u__3; -static PyObject *__pyx_kp_s__4; -static PyObject *__pyx_kp_u__9; +static PyObject *__pyx_kp_s__2; +static PyObject *__pyx_kp_u__7; static PyObject *__pyx_n_s_add; static PyObject *__pyx_n_s_add_2; static PyObject *__pyx_n_s_append; +static PyObject *__pyx_n_s_cFuzzySet; static PyObject *__pyx_n_s_cfuzzyset; static PyObject *__pyx_n_s_cline_in_traceback; static PyObject *__pyx_n_s_collections; @@ -1381,11 +1476,13 @@ static PyObject *__pyx_n_s_lower; static PyObject *__pyx_n_s_main; static PyObject *__pyx_n_s_match_dict; static PyObject *__pyx_n_s_math; +static PyObject *__pyx_n_s_name; static PyObject *__pyx_n_s_operator; static PyObject *__pyx_n_s_pickle_creator; static PyObject *__pyx_n_s_pyx_vtable; static PyObject *__pyx_n_s_range; static PyObject *__pyx_n_s_re; +static PyObject *__pyx_n_s_rel_sim_cutoff; static PyObject *__pyx_n_s_result; static PyObject *__pyx_n_s_reverse; static PyObject *__pyx_n_s_sort; @@ -1396,7 +1493,7 @@ static PyObject *__pyx_n_s_value; static PyObject *__pyx_n_s_values; static PyObject *__pyx_n_s_version; static PyObject *__pyx_kp_s_w; -static int __pyx_pf_9cfuzzyset_9cFuzzySet___cinit__(struct __pyx_obj_9cfuzzyset_cFuzzySet *__pyx_v_self, PyObject *__pyx_v_iterable, int __pyx_v_gram_size_lower, int __pyx_v_gram_size_upper, int __pyx_v_use_levenshtein); /* proto */ +static int __pyx_pf_9cfuzzyset_9cFuzzySet___cinit__(struct __pyx_obj_9cfuzzyset_cFuzzySet *__pyx_v_self, PyObject *__pyx_v_iterable, int __pyx_v_gram_size_lower, int __pyx_v_gram_size_upper, int __pyx_v_use_levenshtein, double __pyx_v_rel_sim_cutoff); /* proto */ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_2__reduce__(struct __pyx_obj_9cfuzzyset_cFuzzySet *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_4add(struct __pyx_obj_9cfuzzyset_cFuzzySet *__pyx_v_self, PyObject *__pyx_v_in_val); /* proto */ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_6_add(struct __pyx_obj_9cfuzzyset_cFuzzySet *__pyx_v_self, PyObject *__pyx_v_value, int __pyx_v_gram_size); /* proto */ @@ -1405,27 +1502,25 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_10_get(struct __pyx_obj_9cfuzzys static Py_ssize_t __pyx_pf_9cfuzzyset_9cFuzzySet_12__len__(struct __pyx_obj_9cfuzzyset_cFuzzySet *__pyx_v_self); /* proto */ static int __pyx_pf_9cfuzzyset_9cFuzzySet_14__nonzero__(struct __pyx_obj_9cfuzzyset_cFuzzySet *__pyx_v_self); /* proto */ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_16get(struct __pyx_obj_9cfuzzyset_cFuzzySet *__pyx_v_self, PyObject *__pyx_v_key, PyObject *__pyx_v_default); /* proto */ -static PyObject *__pyx_pf_9cfuzzyset__pickle_creator(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_exact_set, PyObject *__pyx_v_match_dict, PyObject *__pyx_v_items, PyObject *__pyx_v_gram_size_lower, PyObject *__pyx_v_gram_size_upper, PyObject *__pyx_v_use_levenshtein); /* proto */ +static PyObject *__pyx_pf_9cfuzzyset__pickle_creator(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_exact_set, PyObject *__pyx_v_match_dict, PyObject *__pyx_v_items, PyObject *__pyx_v_gram_size_lower, PyObject *__pyx_v_gram_size_upper, PyObject *__pyx_v_use_levenshtein, PyObject *__pyx_v_rel_sim_cutoff); /* proto */ static PyObject *__pyx_tp_new_9cfuzzyset_cFuzzySet(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_items = {0, &__pyx_n_s_items, 0, 0, 0}; static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_values = {0, &__pyx_n_s_values, 0, 0, 0}; static PyObject *__pyx_int_0; static PyObject *__pyx_int_1; static PyObject *__pyx_int_16; -static PyObject *__pyx_tuple_; -static PyObject *__pyx_tuple__2; +static PyObject *__pyx_tuple__3; +static PyObject *__pyx_tuple__4; static PyObject *__pyx_tuple__5; -static PyObject *__pyx_tuple__6; -static PyObject *__pyx_tuple__7; -static PyObject *__pyx_codeobj__8; +static PyObject *__pyx_codeobj__6; /* Late includes */ -/* "cfuzzyset.pyx":27 - * cdef int use_levenshtein +/* "cfuzzyset.pyx":28 + * cdef double rel_sim_cutoff * - * def __cinit__(self, iterable=(), int gram_size_lower=2, int gram_size_upper=3, int use_levenshtein=True): # <<<<<<<<<<<<<< + * def __cinit__(self, iterable=(), int gram_size_lower=2, int gram_size_upper=3, int use_levenshtein=True, # <<<<<<<<<<<<<< + * double rel_sim_cutoff=1.0): * assert gram_size_upper < 4 and gram_size_upper > 0 - * assert gram_size_lower < 4 and gram_size_lower > 0 */ /* Python wrapper */ @@ -1435,17 +1530,20 @@ static int __pyx_pw_9cfuzzyset_9cFuzzySet_1__cinit__(PyObject *__pyx_v_self, PyO int __pyx_v_gram_size_lower; int __pyx_v_gram_size_upper; int __pyx_v_use_levenshtein; + double __pyx_v_rel_sim_cutoff; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_iterable,&__pyx_n_s_gram_size_lower,&__pyx_n_s_gram_size_upper,&__pyx_n_s_use_levenshtein,0}; - PyObject* values[4] = {0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_iterable,&__pyx_n_s_gram_size_lower,&__pyx_n_s_gram_size_upper,&__pyx_n_s_use_levenshtein,&__pyx_n_s_rel_sim_cutoff,0}; + PyObject* values[5] = {0,0,0,0,0}; values[0] = ((PyObject *)__pyx_empty_tuple); 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); + CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); @@ -1482,12 +1580,20 @@ static int __pyx_pw_9cfuzzyset_9cFuzzySet_1__cinit__(PyObject *__pyx_v_self, PyO PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_use_levenshtein); if (value) { values[3] = value; kw_args--; } } + CYTHON_FALLTHROUGH; + case 4: + if (kw_args > 0) { + PyObject* value = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_rel_sim_cutoff); + if (value) { values[4] = value; kw_args--; } + } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 27, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "__cinit__") < 0)) __PYX_ERR(0, 28, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { + case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); + CYTHON_FALLTHROUGH; case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); CYTHON_FALLTHROUGH; case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); @@ -1502,37 +1608,42 @@ static int __pyx_pw_9cfuzzyset_9cFuzzySet_1__cinit__(PyObject *__pyx_v_self, PyO } __pyx_v_iterable = values[0]; if (values[1]) { - __pyx_v_gram_size_lower = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_gram_size_lower == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 27, __pyx_L3_error) + __pyx_v_gram_size_lower = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_gram_size_lower == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 28, __pyx_L3_error) } else { __pyx_v_gram_size_lower = ((int)2); } if (values[2]) { - __pyx_v_gram_size_upper = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_gram_size_upper == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 27, __pyx_L3_error) + __pyx_v_gram_size_upper = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_gram_size_upper == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 28, __pyx_L3_error) } else { __pyx_v_gram_size_upper = ((int)3); } if (values[3]) { - __pyx_v_use_levenshtein = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_use_levenshtein == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 27, __pyx_L3_error) + __pyx_v_use_levenshtein = __Pyx_PyInt_As_int(values[3]); if (unlikely((__pyx_v_use_levenshtein == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 28, __pyx_L3_error) } else { __pyx_v_use_levenshtein = ((int)1); } + if (values[4]) { + __pyx_v_rel_sim_cutoff = __pyx_PyFloat_AsDouble(values[4]); if (unlikely((__pyx_v_rel_sim_cutoff == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 29, __pyx_L3_error) + } else { + __pyx_v_rel_sim_cutoff = ((double)1.0); + } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 4, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 27, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 5, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 28, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("cfuzzyset.cFuzzySet.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_9cfuzzyset_9cFuzzySet___cinit__(((struct __pyx_obj_9cfuzzyset_cFuzzySet *)__pyx_v_self), __pyx_v_iterable, __pyx_v_gram_size_lower, __pyx_v_gram_size_upper, __pyx_v_use_levenshtein); + __pyx_r = __pyx_pf_9cfuzzyset_9cFuzzySet___cinit__(((struct __pyx_obj_9cfuzzyset_cFuzzySet *)__pyx_v_self), __pyx_v_iterable, __pyx_v_gram_size_lower, __pyx_v_gram_size_upper, __pyx_v_use_levenshtein, __pyx_v_rel_sim_cutoff); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static int __pyx_pf_9cfuzzyset_9cFuzzySet___cinit__(struct __pyx_obj_9cfuzzyset_cFuzzySet *__pyx_v_self, PyObject *__pyx_v_iterable, int __pyx_v_gram_size_lower, int __pyx_v_gram_size_upper, int __pyx_v_use_levenshtein) { +static int __pyx_pf_9cfuzzyset_9cFuzzySet___cinit__(struct __pyx_obj_9cfuzzyset_cFuzzySet *__pyx_v_self, PyObject *__pyx_v_iterable, int __pyx_v_gram_size_lower, int __pyx_v_gram_size_upper, int __pyx_v_use_levenshtein, double __pyx_v_rel_sim_cutoff) { int __pyx_v_i; PyObject *__pyx_v_value = NULL; int __pyx_r; @@ -1548,12 +1659,11 @@ static int __pyx_pf_9cfuzzyset_9cFuzzySet___cinit__(struct __pyx_obj_9cfuzzyset_ PyObject *(*__pyx_t_9)(PyObject *); PyObject *__pyx_t_10 = NULL; PyObject *__pyx_t_11 = NULL; - PyObject *__pyx_t_12 = NULL; __Pyx_RefNannySetupContext("__cinit__", 0); - /* "cfuzzyset.pyx":28 - * - * def __cinit__(self, iterable=(), int gram_size_lower=2, int gram_size_upper=3, int use_levenshtein=True): + /* "cfuzzyset.pyx":30 + * def __cinit__(self, iterable=(), int gram_size_lower=2, int gram_size_upper=3, int use_levenshtein=True, + * double rel_sim_cutoff=1.0): * assert gram_size_upper < 4 and gram_size_upper > 0 # <<<<<<<<<<<<<< * assert gram_size_lower < 4 and gram_size_lower > 0 * assert gram_size_lower <= gram_size_upper @@ -1571,17 +1681,17 @@ static int __pyx_pf_9cfuzzyset_9cFuzzySet___cinit__(struct __pyx_obj_9cfuzzyset_ __pyx_L3_bool_binop_done:; if (unlikely(!__pyx_t_1)) { PyErr_SetNone(PyExc_AssertionError); - __PYX_ERR(0, 28, __pyx_L1_error) + __PYX_ERR(0, 30, __pyx_L1_error) } } #endif - /* "cfuzzyset.pyx":29 - * def __cinit__(self, iterable=(), int gram_size_lower=2, int gram_size_upper=3, int use_levenshtein=True): + /* "cfuzzyset.pyx":31 + * double rel_sim_cutoff=1.0): * assert gram_size_upper < 4 and gram_size_upper > 0 * assert gram_size_lower < 4 and gram_size_lower > 0 # <<<<<<<<<<<<<< * assert gram_size_lower <= gram_size_upper - * self.exact_set = {} + * assert rel_sim_cutoff <= 1.0 and rel_sim_cutoff >= 0 */ #ifndef CYTHON_WITHOUT_ASSERTIONS if (unlikely(!Py_OptimizeFlag)) { @@ -1596,35 +1706,60 @@ static int __pyx_pf_9cfuzzyset_9cFuzzySet___cinit__(struct __pyx_obj_9cfuzzyset_ __pyx_L5_bool_binop_done:; if (unlikely(!__pyx_t_1)) { PyErr_SetNone(PyExc_AssertionError); - __PYX_ERR(0, 29, __pyx_L1_error) + __PYX_ERR(0, 31, __pyx_L1_error) } } #endif - /* "cfuzzyset.pyx":30 + /* "cfuzzyset.pyx":32 * assert gram_size_upper < 4 and gram_size_upper > 0 * assert gram_size_lower < 4 and gram_size_lower > 0 * assert gram_size_lower <= gram_size_upper # <<<<<<<<<<<<<< + * assert rel_sim_cutoff <= 1.0 and rel_sim_cutoff >= 0 * self.exact_set = {} - * self.match_dict = {} */ #ifndef CYTHON_WITHOUT_ASSERTIONS if (unlikely(!Py_OptimizeFlag)) { if (unlikely(!((__pyx_v_gram_size_lower <= __pyx_v_gram_size_upper) != 0))) { PyErr_SetNone(PyExc_AssertionError); - __PYX_ERR(0, 30, __pyx_L1_error) + __PYX_ERR(0, 32, __pyx_L1_error) } } #endif - /* "cfuzzyset.pyx":31 + /* "cfuzzyset.pyx":33 * assert gram_size_lower < 4 and gram_size_lower > 0 * assert gram_size_lower <= gram_size_upper + * assert rel_sim_cutoff <= 1.0 and rel_sim_cutoff >= 0 # <<<<<<<<<<<<<< + * self.exact_set = {} + * self.match_dict = {} + */ + #ifndef CYTHON_WITHOUT_ASSERTIONS + if (unlikely(!Py_OptimizeFlag)) { + __pyx_t_2 = ((__pyx_v_rel_sim_cutoff <= 1.0) != 0); + if (__pyx_t_2) { + } else { + __pyx_t_1 = __pyx_t_2; + goto __pyx_L7_bool_binop_done; + } + __pyx_t_2 = ((__pyx_v_rel_sim_cutoff >= 0.0) != 0); + __pyx_t_1 = __pyx_t_2; + __pyx_L7_bool_binop_done:; + if (unlikely(!__pyx_t_1)) { + PyErr_SetNone(PyExc_AssertionError); + __PYX_ERR(0, 33, __pyx_L1_error) + } + } + #endif + + /* "cfuzzyset.pyx":34 + * assert gram_size_lower <= gram_size_upper + * assert rel_sim_cutoff <= 1.0 and rel_sim_cutoff >= 0 * self.exact_set = {} # <<<<<<<<<<<<<< * self.match_dict = {} * self.items = {} */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 31, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 34, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __Pyx_GOTREF(__pyx_v_self->exact_set); @@ -1632,14 +1767,14 @@ static int __pyx_pf_9cfuzzyset_9cFuzzySet___cinit__(struct __pyx_obj_9cfuzzyset_ __pyx_v_self->exact_set = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; - /* "cfuzzyset.pyx":32 - * assert gram_size_lower <= gram_size_upper + /* "cfuzzyset.pyx":35 + * assert rel_sim_cutoff <= 1.0 and rel_sim_cutoff >= 0 * self.exact_set = {} * self.match_dict = {} # <<<<<<<<<<<<<< * self.items = {} * cdef int i */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 32, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 35, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __Pyx_GOTREF(__pyx_v_self->match_dict); @@ -1647,14 +1782,14 @@ static int __pyx_pf_9cfuzzyset_9cFuzzySet___cinit__(struct __pyx_obj_9cfuzzyset_ __pyx_v_self->match_dict = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; - /* "cfuzzyset.pyx":33 + /* "cfuzzyset.pyx":36 * self.exact_set = {} * self.match_dict = {} * self.items = {} # <<<<<<<<<<<<<< * cdef int i * for i in range(gram_size_lower, gram_size_upper + 1): */ - __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 33, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 36, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __Pyx_GOTREF(__pyx_v_self->items); @@ -1662,7 +1797,7 @@ static int __pyx_pf_9cfuzzyset_9cFuzzySet___cinit__(struct __pyx_obj_9cfuzzyset_ __pyx_v_self->items = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; - /* "cfuzzyset.pyx":35 + /* "cfuzzyset.pyx":38 * self.items = {} * cdef int i * for i in range(gram_size_lower, gram_size_upper + 1): # <<<<<<<<<<<<<< @@ -1674,27 +1809,27 @@ static int __pyx_pf_9cfuzzyset_9cFuzzySet___cinit__(struct __pyx_obj_9cfuzzyset_ for (__pyx_t_6 = __pyx_v_gram_size_lower; __pyx_t_6 < __pyx_t_5; __pyx_t_6+=1) { __pyx_v_i = __pyx_t_6; - /* "cfuzzyset.pyx":36 + /* "cfuzzyset.pyx":39 * cdef int i * for i in range(gram_size_lower, gram_size_upper + 1): * self.items[i] = [] # <<<<<<<<<<<<<< * self.gram_size_lower = gram_size_lower * self.gram_size_upper = gram_size_upper */ - __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 36, __pyx_L1_error) + __pyx_t_3 = PyList_New(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 39, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (unlikely(__pyx_v_self->items == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 36, __pyx_L1_error) + __PYX_ERR(0, 39, __pyx_L1_error) } - __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 36, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_i); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 39, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - if (unlikely(PyDict_SetItem(__pyx_v_self->items, __pyx_t_7, __pyx_t_3) < 0)) __PYX_ERR(0, 36, __pyx_L1_error) + if (unlikely(PyDict_SetItem(__pyx_v_self->items, __pyx_t_7, __pyx_t_3) < 0)) __PYX_ERR(0, 39, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } - /* "cfuzzyset.pyx":37 + /* "cfuzzyset.pyx":40 * for i in range(gram_size_lower, gram_size_upper + 1): * self.items[i] = [] * self.gram_size_lower = gram_size_lower # <<<<<<<<<<<<<< @@ -1703,27 +1838,36 @@ static int __pyx_pf_9cfuzzyset_9cFuzzySet___cinit__(struct __pyx_obj_9cfuzzyset_ */ __pyx_v_self->gram_size_lower = __pyx_v_gram_size_lower; - /* "cfuzzyset.pyx":38 + /* "cfuzzyset.pyx":41 * self.items[i] = [] * self.gram_size_lower = gram_size_lower * self.gram_size_upper = gram_size_upper # <<<<<<<<<<<<<< * self.use_levenshtein = use_levenshtein - * for value in iterable: + * self.rel_sim_cutoff = rel_sim_cutoff */ __pyx_v_self->gram_size_upper = __pyx_v_gram_size_upper; - /* "cfuzzyset.pyx":39 + /* "cfuzzyset.pyx":42 * self.gram_size_lower = gram_size_lower * self.gram_size_upper = gram_size_upper * self.use_levenshtein = use_levenshtein # <<<<<<<<<<<<<< + * self.rel_sim_cutoff = rel_sim_cutoff * for value in iterable: - * self.add(value) */ __pyx_v_self->use_levenshtein = __pyx_v_use_levenshtein; - /* "cfuzzyset.pyx":40 + /* "cfuzzyset.pyx":43 * self.gram_size_upper = gram_size_upper * self.use_levenshtein = use_levenshtein + * self.rel_sim_cutoff = rel_sim_cutoff # <<<<<<<<<<<<<< + * for value in iterable: + * self.add(value) + */ + __pyx_v_self->rel_sim_cutoff = __pyx_v_rel_sim_cutoff; + + /* "cfuzzyset.pyx":44 + * self.use_levenshtein = use_levenshtein + * self.rel_sim_cutoff = rel_sim_cutoff * for value in iterable: # <<<<<<<<<<<<<< * self.add(value) * @@ -1732,26 +1876,26 @@ static int __pyx_pf_9cfuzzyset_9cFuzzySet___cinit__(struct __pyx_obj_9cfuzzyset_ __pyx_t_3 = __pyx_v_iterable; __Pyx_INCREF(__pyx_t_3); __pyx_t_8 = 0; __pyx_t_9 = NULL; } else { - __pyx_t_8 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_iterable); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 40, __pyx_L1_error) + __pyx_t_8 = -1; __pyx_t_3 = PyObject_GetIter(__pyx_v_iterable); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_9 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 40, __pyx_L1_error) + __pyx_t_9 = Py_TYPE(__pyx_t_3)->tp_iternext; if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 44, __pyx_L1_error) } for (;;) { if (likely(!__pyx_t_9)) { if (likely(PyList_CheckExact(__pyx_t_3))) { if (__pyx_t_8 >= PyList_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_8); __Pyx_INCREF(__pyx_t_7); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 40, __pyx_L1_error) + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_3, __pyx_t_8); __Pyx_INCREF(__pyx_t_7); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 44, __pyx_L1_error) #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_3, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 40, __pyx_L1_error) + __pyx_t_7 = PySequence_ITEM(__pyx_t_3, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); #endif } else { if (__pyx_t_8 >= PyTuple_GET_SIZE(__pyx_t_3)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_8); __Pyx_INCREF(__pyx_t_7); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 40, __pyx_L1_error) + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_3, __pyx_t_8); __Pyx_INCREF(__pyx_t_7); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 44, __pyx_L1_error) #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_3, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 40, __pyx_L1_error) + __pyx_t_7 = PySequence_ITEM(__pyx_t_3, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); #endif } @@ -1761,7 +1905,7 @@ static int __pyx_pf_9cfuzzyset_9cFuzzySet___cinit__(struct __pyx_obj_9cfuzzyset_ PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 40, __pyx_L1_error) + else __PYX_ERR(0, 44, __pyx_L1_error) } break; } @@ -1770,14 +1914,14 @@ static int __pyx_pf_9cfuzzyset_9cFuzzySet___cinit__(struct __pyx_obj_9cfuzzyset_ __Pyx_XDECREF_SET(__pyx_v_value, __pyx_t_7); __pyx_t_7 = 0; - /* "cfuzzyset.pyx":41 - * self.use_levenshtein = use_levenshtein + /* "cfuzzyset.pyx":45 + * self.rel_sim_cutoff = rel_sim_cutoff * for value in iterable: * self.add(value) # <<<<<<<<<<<<<< * * def __reduce__(self): */ - __pyx_t_10 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_add); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 41, __pyx_L1_error) + __pyx_t_10 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_add); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 45, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_11 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_10))) { @@ -1789,44 +1933,16 @@ static int __pyx_pf_9cfuzzyset_9cFuzzySet___cinit__(struct __pyx_obj_9cfuzzyset_ __Pyx_DECREF_SET(__pyx_t_10, function); } } - if (!__pyx_t_11) { - __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_v_value); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 41, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - } else { - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_v_value}; - __pyx_t_7 = __Pyx_PyFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 41, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GOTREF(__pyx_t_7); - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_10)) { - PyObject *__pyx_temp[2] = {__pyx_t_11, __pyx_v_value}; - __pyx_t_7 = __Pyx_PyCFunction_FastCall(__pyx_t_10, __pyx_temp+1-1, 1+1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 41, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; - __Pyx_GOTREF(__pyx_t_7); - } else - #endif - { - __pyx_t_12 = PyTuple_New(1+1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 41, __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_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_12, 0+1, __pyx_v_value); - __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_10, __pyx_t_12, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 41, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; - } - } + __pyx_t_7 = (__pyx_t_11) ? __Pyx_PyObject_Call2Args(__pyx_t_10, __pyx_t_11, __pyx_v_value) : __Pyx_PyObject_CallOneArg(__pyx_t_10, __pyx_v_value); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 45, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - /* "cfuzzyset.pyx":40 - * self.gram_size_upper = gram_size_upper + /* "cfuzzyset.pyx":44 * self.use_levenshtein = use_levenshtein + * self.rel_sim_cutoff = rel_sim_cutoff * for value in iterable: # <<<<<<<<<<<<<< * self.add(value) * @@ -1834,12 +1950,12 @@ static int __pyx_pf_9cfuzzyset_9cFuzzySet___cinit__(struct __pyx_obj_9cfuzzyset_ } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - /* "cfuzzyset.pyx":27 - * cdef int use_levenshtein + /* "cfuzzyset.pyx":28 + * cdef double rel_sim_cutoff * - * def __cinit__(self, iterable=(), int gram_size_lower=2, int gram_size_upper=3, int use_levenshtein=True): # <<<<<<<<<<<<<< + * def __cinit__(self, iterable=(), int gram_size_lower=2, int gram_size_upper=3, int use_levenshtein=True, # <<<<<<<<<<<<<< + * double rel_sim_cutoff=1.0): * assert gram_size_upper < 4 and gram_size_upper > 0 - * assert gram_size_lower < 4 and gram_size_lower > 0 */ /* function exit code */ @@ -1850,7 +1966,6 @@ static int __pyx_pf_9cfuzzyset_9cFuzzySet___cinit__(struct __pyx_obj_9cfuzzyset_ __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_10); __Pyx_XDECREF(__pyx_t_11); - __Pyx_XDECREF(__pyx_t_12); __Pyx_AddTraceback("cfuzzyset.cFuzzySet.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; @@ -1859,7 +1974,7 @@ static int __pyx_pf_9cfuzzyset_9cFuzzySet___cinit__(struct __pyx_obj_9cfuzzyset_ return __pyx_r; } -/* "cfuzzyset.pyx":43 +/* "cfuzzyset.pyx":47 * self.add(value) * * def __reduce__(self): # <<<<<<<<<<<<<< @@ -1888,9 +2003,10 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_2__reduce__(struct __pyx_obj_9cf PyObject *__pyx_t_3 = NULL; PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; __Pyx_RefNannySetupContext("__reduce__", 0); - /* "cfuzzyset.pyx":44 + /* "cfuzzyset.pyx":48 * * def __reduce__(self): * return ( # <<<<<<<<<<<<<< @@ -1899,94 +2015,107 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_2__reduce__(struct __pyx_obj_9cf */ __Pyx_XDECREF(__pyx_r); - /* "cfuzzyset.pyx":45 + /* "cfuzzyset.pyx":49 * def __reduce__(self): * return ( * _pickle_creator, # <<<<<<<<<<<<<< * ( * self.exact_set, */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_pickle_creator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 45, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pickle_creator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 49, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - /* "cfuzzyset.pyx":50 + /* "cfuzzyset.pyx":54 * self.match_dict, * self.items, * self.gram_size_lower, # <<<<<<<<<<<<<< * self.gram_size_upper, - * self.use_levenshtein + * self.use_levenshtein, */ - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->gram_size_lower); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 50, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_self->gram_size_lower); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 54, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - /* "cfuzzyset.pyx":51 + /* "cfuzzyset.pyx":55 * self.items, * self.gram_size_lower, * self.gram_size_upper, # <<<<<<<<<<<<<< - * self.use_levenshtein - * ) + * self.use_levenshtein, + * self.rel_sim_cutoff */ - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->gram_size_upper); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 51, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_self->gram_size_upper); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 55, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - /* "cfuzzyset.pyx":52 + /* "cfuzzyset.pyx":56 * self.gram_size_lower, * self.gram_size_upper, - * self.use_levenshtein # <<<<<<<<<<<<<< + * self.use_levenshtein, # <<<<<<<<<<<<<< + * self.rel_sim_cutoff * ) - * ) */ - __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_self->use_levenshtein); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 52, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_self->use_levenshtein); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 56, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - /* "cfuzzyset.pyx":47 + /* "cfuzzyset.pyx":57 + * self.gram_size_upper, + * self.use_levenshtein, + * self.rel_sim_cutoff # <<<<<<<<<<<<<< + * ) + * ) + */ + __pyx_t_5 = PyFloat_FromDouble(__pyx_v_self->rel_sim_cutoff); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 57, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + + /* "cfuzzyset.pyx":51 * _pickle_creator, * ( * self.exact_set, # <<<<<<<<<<<<<< * self.match_dict, * self.items, */ - __pyx_t_5 = PyTuple_New(6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 47, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyTuple_New(7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 51, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); __Pyx_INCREF(__pyx_v_self->exact_set); __Pyx_GIVEREF(__pyx_v_self->exact_set); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_self->exact_set); + PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_self->exact_set); __Pyx_INCREF(__pyx_v_self->match_dict); __Pyx_GIVEREF(__pyx_v_self->match_dict); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_self->match_dict); + PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_self->match_dict); __Pyx_INCREF(__pyx_v_self->items); __Pyx_GIVEREF(__pyx_v_self->items); - PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_self->items); + PyTuple_SET_ITEM(__pyx_t_6, 2, __pyx_v_self->items); __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_2); + PyTuple_SET_ITEM(__pyx_t_6, 3, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_6, 4, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_5, 5, __pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_6, 5, __pyx_t_4); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_6, 6, __pyx_t_5); __pyx_t_2 = 0; __pyx_t_3 = 0; __pyx_t_4 = 0; + __pyx_t_5 = 0; - /* "cfuzzyset.pyx":45 + /* "cfuzzyset.pyx":49 * def __reduce__(self): * return ( * _pickle_creator, # <<<<<<<<<<<<<< * ( * self.exact_set, */ - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 45, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 49, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); - __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_6); __pyx_t_1 = 0; + __pyx_t_6 = 0; + __pyx_r = __pyx_t_5; __pyx_t_5 = 0; - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; goto __pyx_L0; - /* "cfuzzyset.pyx":43 + /* "cfuzzyset.pyx":47 * self.add(value) * * def __reduce__(self): # <<<<<<<<<<<<<< @@ -2001,6 +2130,7 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_2__reduce__(struct __pyx_obj_9cf __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("cfuzzyset.cFuzzySet.__reduce__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; @@ -2009,7 +2139,7 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_2__reduce__(struct __pyx_obj_9cf return __pyx_r; } -/* "cfuzzyset.pyx":56 +/* "cfuzzyset.pyx":61 * ) * * def add(self, object in_val): # <<<<<<<<<<<<<< @@ -2046,26 +2176,26 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_4add(struct __pyx_obj_9cfuzzyset int __pyx_t_8; __Pyx_RefNannySetupContext("add", 0); - /* "cfuzzyset.pyx":57 + /* "cfuzzyset.pyx":62 * * def add(self, object in_val): * value = _convert_val(in_val) # <<<<<<<<<<<<<< * cdef unicode lvalue * with cython.nonecheck(True): */ - __pyx_t_1 = __pyx_f_9cfuzzyset__convert_val(__pyx_v_in_val); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 57, __pyx_L1_error) + __pyx_t_1 = __pyx_f_9cfuzzyset__convert_val(__pyx_v_in_val); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 62, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_value = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "cfuzzyset.pyx":60 + /* "cfuzzyset.pyx":65 * cdef unicode lvalue * with cython.nonecheck(True): * lvalue = value.lower() # <<<<<<<<<<<<<< * if lvalue in self.exact_set: * return */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_lower); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 60, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_lower); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 65, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -2077,19 +2207,16 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_4add(struct __pyx_obj_9cfuzzyset __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, 60, __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, 60, __pyx_L1_error) - } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 65, __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, 60, __pyx_L1_error) + 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, 65, __pyx_L1_error) __pyx_v_lvalue = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "cfuzzyset.pyx":61 + /* "cfuzzyset.pyx":66 * with cython.nonecheck(True): * lvalue = value.lower() * if lvalue in self.exact_set: # <<<<<<<<<<<<<< @@ -2098,13 +2225,13 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_4add(struct __pyx_obj_9cfuzzyset */ if (unlikely(__pyx_v_self->exact_set == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); - __PYX_ERR(0, 61, __pyx_L1_error) + __PYX_ERR(0, 66, __pyx_L1_error) } - __pyx_t_4 = (__Pyx_PyDict_ContainsTF(__pyx_v_lvalue, __pyx_v_self->exact_set, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 61, __pyx_L1_error) + __pyx_t_4 = (__Pyx_PyDict_ContainsTF(__pyx_v_lvalue, __pyx_v_self->exact_set, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 66, __pyx_L1_error) __pyx_t_5 = (__pyx_t_4 != 0); if (__pyx_t_5) { - /* "cfuzzyset.pyx":62 + /* "cfuzzyset.pyx":67 * lvalue = value.lower() * if lvalue in self.exact_set: * return # <<<<<<<<<<<<<< @@ -2115,7 +2242,7 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_4add(struct __pyx_obj_9cfuzzyset __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "cfuzzyset.pyx":61 + /* "cfuzzyset.pyx":66 * with cython.nonecheck(True): * lvalue = value.lower() * if lvalue in self.exact_set: # <<<<<<<<<<<<<< @@ -2124,7 +2251,7 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_4add(struct __pyx_obj_9cfuzzyset */ } - /* "cfuzzyset.pyx":64 + /* "cfuzzyset.pyx":69 * return * cdef int i * for i in range(self.gram_size_lower, self.gram_size_upper + 1): # <<<<<<<<<<<<<< @@ -2136,19 +2263,19 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_4add(struct __pyx_obj_9cfuzzyset for (__pyx_t_8 = __pyx_v_self->gram_size_lower; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=1) { __pyx_v_i = __pyx_t_8; - /* "cfuzzyset.pyx":65 + /* "cfuzzyset.pyx":70 * cdef int i * for i in range(self.gram_size_lower, self.gram_size_upper + 1): * self._add(value, i) # <<<<<<<<<<<<<< * * @cython.nonecheck(False) */ - __pyx_t_1 = ((struct __pyx_vtabstruct_9cfuzzyset_cFuzzySet *)__pyx_v_self->__pyx_vtab)->_add(__pyx_v_self, __pyx_v_value, __pyx_v_i, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 65, __pyx_L1_error) + __pyx_t_1 = ((struct __pyx_vtabstruct_9cfuzzyset_cFuzzySet *)__pyx_v_self->__pyx_vtab)->_add(__pyx_v_self, __pyx_v_value, __pyx_v_i, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 70, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } - /* "cfuzzyset.pyx":56 + /* "cfuzzyset.pyx":61 * ) * * def add(self, object in_val): # <<<<<<<<<<<<<< @@ -2173,7 +2300,7 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_4add(struct __pyx_obj_9cfuzzyset return __pyx_r; } -/* "cfuzzyset.pyx":68 +/* "cfuzzyset.pyx":73 * * @cython.nonecheck(False) * cpdef _add(self, unicode value, int gram_size): # <<<<<<<<<<<<<< @@ -2217,77 +2344,93 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ /* Check if called by wrapper */ if (unlikely(__pyx_skip_dispatch)) ; /* Check if overridden in Python */ - else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_add_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 68, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_9cfuzzyset_9cFuzzySet_7_add)) { - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_gram_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 68, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_4 = __pyx_t_1; __pyx_t_5 = NULL; - __pyx_t_6 = 0; - 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); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_value, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 68, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_value, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 68, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else + else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) { + #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP + static PY_UINT64_T tp_dict_version = 0, obj_dict_version = 0; + if (likely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dict && tp_dict_version == __PYX_GET_DICT_VERSION(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dict) && (!Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset || obj_dict_version == __PYX_GET_DICT_VERSION(_PyObject_GetDictPtr(((PyObject *)__pyx_v_self)))))); + else { + PY_UINT64_T type_dict_guard = (likely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dict)) ? __PYX_GET_DICT_VERSION(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dict) : 0; #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 68, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_5) { - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_add_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 73, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_9cfuzzyset_9cFuzzySet_7_add)) { + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_gram_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 73, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_4 = __pyx_t_1; __pyx_t_5 = NULL; + __pyx_t_6 = 0; + 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); + __pyx_t_6 = 1; + } } - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_value); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 68, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_value, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 73, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_value, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 73, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 73, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_5) { + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; + } + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_value); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 73, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L0; } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP + tp_dict_version = likely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dict) ? __PYX_GET_DICT_VERSION(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dict) : 0; + obj_dict_version = likely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset) ? __PYX_GET_DICT_VERSION(_PyObject_GetDictPtr(((PyObject *)__pyx_v_self))) : 0; + if (unlikely(type_dict_guard != tp_dict_version)) { + tp_dict_version = obj_dict_version = 0; + } + #endif __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; + #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + #endif } - /* "cfuzzyset.pyx":69 + /* "cfuzzyset.pyx":74 * @cython.nonecheck(False) * cpdef _add(self, unicode value, int gram_size): * cdef unicode lvalue = value.lower() # <<<<<<<<<<<<<< * cdef list items = self.items[gram_size] * cdef int idx = len(items) */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_lower); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 69, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_lower); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 74, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -2299,19 +2442,16 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ __Pyx_DECREF_SET(__pyx_t_2, function); } } - if (__pyx_t_4) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 69, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 69, __pyx_L1_error) - } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 74, __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, 69, __pyx_L1_error) + 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, 74, __pyx_L1_error) __pyx_v_lvalue = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "cfuzzyset.pyx":70 + /* "cfuzzyset.pyx":75 * cpdef _add(self, unicode value, int gram_size): * cdef unicode lvalue = value.lower() * cdef list items = self.items[gram_size] # <<<<<<<<<<<<<< @@ -2320,18 +2460,18 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ */ if (unlikely(__pyx_v_self->items == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 70, __pyx_L1_error) + __PYX_ERR(0, 75, __pyx_L1_error) } - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_gram_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 70, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_gram_size); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_self->items, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 70, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_self->items, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 70, __pyx_L1_error) + if (!(likely(PyList_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_2)->tp_name), 0))) __PYX_ERR(0, 75, __pyx_L1_error) __pyx_v_items = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "cfuzzyset.pyx":71 + /* "cfuzzyset.pyx":76 * cdef unicode lvalue = value.lower() * cdef list items = self.items[gram_size] * cdef int idx = len(items) # <<<<<<<<<<<<<< @@ -2340,12 +2480,12 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ */ if (unlikely(__pyx_v_items == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 71, __pyx_L1_error) + __PYX_ERR(0, 76, __pyx_L1_error) } - __pyx_t_8 = PyList_GET_SIZE(__pyx_v_items); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 71, __pyx_L1_error) + __pyx_t_8 = PyList_GET_SIZE(__pyx_v_items); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 76, __pyx_L1_error) __pyx_v_idx = __pyx_t_8; - /* "cfuzzyset.pyx":72 + /* "cfuzzyset.pyx":77 * cdef list items = self.items[gram_size] * cdef int idx = len(items) * items.append(0) # <<<<<<<<<<<<<< @@ -2354,11 +2494,11 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ */ if (unlikely(__pyx_v_items == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "append"); - __PYX_ERR(0, 72, __pyx_L1_error) + __PYX_ERR(0, 77, __pyx_L1_error) } - __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_items, __pyx_int_0); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 72, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyList_Append(__pyx_v_items, __pyx_int_0); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 77, __pyx_L1_error) - /* "cfuzzyset.pyx":73 + /* "cfuzzyset.pyx":78 * cdef int idx = len(items) * items.append(0) * cdef dict grams = _gram_counter(lvalue, gram_size) # <<<<<<<<<<<<<< @@ -2367,12 +2507,12 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ */ __pyx_t_10.__pyx_n = 1; __pyx_t_10.gram_size = __pyx_v_gram_size; - __pyx_t_2 = __pyx_f_9cfuzzyset__gram_counter(__pyx_v_lvalue, &__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 73, __pyx_L1_error) + __pyx_t_2 = __pyx_f_9cfuzzyset__gram_counter(__pyx_v_lvalue, &__pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 78, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_grams = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "cfuzzyset.pyx":74 + /* "cfuzzyset.pyx":79 * items.append(0) * cdef dict grams = _gram_counter(lvalue, gram_size) * cdef double total = 0 # <<<<<<<<<<<<<< @@ -2381,7 +2521,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ */ __pyx_v_total = 0.0; - /* "cfuzzyset.pyx":77 + /* "cfuzzyset.pyx":82 * cdef int i * cdef int tmp * cdef list values = list(grams.values()) # <<<<<<<<<<<<<< @@ -2390,42 +2530,42 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ */ if (unlikely(__pyx_v_grams == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "values"); - __PYX_ERR(0, 77, __pyx_L1_error) + __PYX_ERR(0, 82, __pyx_L1_error) } - __pyx_t_2 = __Pyx_PyDict_Values(__pyx_v_grams); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 77, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyDict_Values(__pyx_v_grams); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 82, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = PySequence_List(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 77, __pyx_L1_error) + __pyx_t_1 = PySequence_List(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 82, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_values = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "cfuzzyset.pyx":79 + /* "cfuzzyset.pyx":84 * cdef list values = list(grams.values()) * with cython.boundscheck(False): * for i in range(len(values)): # <<<<<<<<<<<<<< * tmp = values[i] * total += tmp * tmp */ - __pyx_t_8 = PyList_GET_SIZE(__pyx_v_values); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 79, __pyx_L1_error) + __pyx_t_8 = PyList_GET_SIZE(__pyx_v_values); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 84, __pyx_L1_error) __pyx_t_11 = __pyx_t_8; for (__pyx_t_6 = 0; __pyx_t_6 < __pyx_t_11; __pyx_t_6+=1) { __pyx_v_i = __pyx_t_6; - /* "cfuzzyset.pyx":80 + /* "cfuzzyset.pyx":85 * with cython.boundscheck(False): * for i in range(len(values)): * tmp = values[i] # <<<<<<<<<<<<<< * total += tmp * tmp * cdef double norm = sqrt(total) */ - __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_values, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 80, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_values, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 85, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 80, __pyx_L1_error) + __pyx_t_12 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_12 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 85, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_tmp = __pyx_t_12; - /* "cfuzzyset.pyx":81 + /* "cfuzzyset.pyx":86 * for i in range(len(values)): * tmp = values[i] * total += tmp * tmp # <<<<<<<<<<<<<< @@ -2435,7 +2575,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ __pyx_v_total = (__pyx_v_total + (__pyx_v_tmp * __pyx_v_tmp)); } - /* "cfuzzyset.pyx":82 + /* "cfuzzyset.pyx":87 * tmp = values[i] * total += tmp * tmp * cdef double norm = sqrt(total) # <<<<<<<<<<<<<< @@ -2444,16 +2584,16 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ */ __pyx_v_norm = sqrt(__pyx_v_total); - /* "cfuzzyset.pyx":83 + /* "cfuzzyset.pyx":88 * total += tmp * tmp * cdef double norm = sqrt(total) * items[idx] = (norm, lvalue) # <<<<<<<<<<<<<< * cdef tuple new_val * for gram, occ in grams.items(): */ - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_norm); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 83, __pyx_L1_error) + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_norm); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 88, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 83, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 88, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); @@ -2463,12 +2603,12 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ __pyx_t_1 = 0; if (unlikely(__pyx_v_items == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 83, __pyx_L1_error) + __PYX_ERR(0, 88, __pyx_L1_error) } - if (unlikely(__Pyx_SetItemInt(__pyx_v_items, __pyx_v_idx, __pyx_t_2, int, 1, __Pyx_PyInt_From_int, 1, 1, 1) < 0)) __PYX_ERR(0, 83, __pyx_L1_error) + if (unlikely(__Pyx_SetItemInt(__pyx_v_items, __pyx_v_idx, __pyx_t_2, int, 1, __Pyx_PyInt_From_int, 1, 1, 1) < 0)) __PYX_ERR(0, 88, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "cfuzzyset.pyx":85 + /* "cfuzzyset.pyx":90 * items[idx] = (norm, lvalue) * cdef tuple new_val * for gram, occ in grams.items(): # <<<<<<<<<<<<<< @@ -2477,17 +2617,17 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ */ if (unlikely(__pyx_v_grams == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "items"); - __PYX_ERR(0, 85, __pyx_L1_error) + __PYX_ERR(0, 90, __pyx_L1_error) } - __pyx_t_2 = __Pyx_PyDict_Items(__pyx_v_grams); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 85, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyDict_Items(__pyx_v_grams); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 90, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (likely(PyList_CheckExact(__pyx_t_2)) || PyTuple_CheckExact(__pyx_t_2)) { __pyx_t_1 = __pyx_t_2; __Pyx_INCREF(__pyx_t_1); __pyx_t_8 = 0; __pyx_t_13 = NULL; } else { - __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 85, __pyx_L1_error) + __pyx_t_8 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 90, __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, 85, __pyx_L1_error) + __pyx_t_13 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 90, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; for (;;) { @@ -2495,17 +2635,17 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ if (likely(PyList_CheckExact(__pyx_t_1))) { if (__pyx_t_8 >= 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_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 85, __pyx_L1_error) + __pyx_t_2 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 90, __pyx_L1_error) #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 85, __pyx_L1_error) + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 90, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #endif } else { if (__pyx_t_8 >= 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_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 85, __pyx_L1_error) + __pyx_t_2 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_8); __Pyx_INCREF(__pyx_t_2); __pyx_t_8++; if (unlikely(0 < 0)) __PYX_ERR(0, 90, __pyx_L1_error) #else - __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 85, __pyx_L1_error) + __pyx_t_2 = PySequence_ITEM(__pyx_t_1, __pyx_t_8); __pyx_t_8++; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 90, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #endif } @@ -2515,7 +2655,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 85, __pyx_L1_error) + else __PYX_ERR(0, 90, __pyx_L1_error) } break; } @@ -2527,7 +2667,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 85, __pyx_L1_error) + __PYX_ERR(0, 90, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { @@ -2540,15 +2680,15 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ __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, 85, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 90, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 85, __pyx_L1_error) + __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 90, __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, 85, __pyx_L1_error) + __pyx_t_3 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 90, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_14 = Py_TYPE(__pyx_t_3)->tp_iternext; @@ -2556,7 +2696,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ __Pyx_GOTREF(__pyx_t_4); index = 1; __pyx_t_7 = __pyx_t_14(__pyx_t_3); if (unlikely(!__pyx_t_7)) goto __pyx_L7_unpacking_failed; __Pyx_GOTREF(__pyx_t_7); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_3), 2) < 0) __PYX_ERR(0, 85, __pyx_L1_error) + if (__Pyx_IternextUnpackEndCheck(__pyx_t_14(__pyx_t_3), 2) < 0) __PYX_ERR(0, 90, __pyx_L1_error) __pyx_t_14 = NULL; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L8_unpacking_done; @@ -2564,7 +2704,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_14 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 85, __pyx_L1_error) + __PYX_ERR(0, 90, __pyx_L1_error) __pyx_L8_unpacking_done:; } __Pyx_XDECREF_SET(__pyx_v_gram, __pyx_t_4); @@ -2572,16 +2712,16 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ __Pyx_XDECREF_SET(__pyx_v_occ, __pyx_t_7); __pyx_t_7 = 0; - /* "cfuzzyset.pyx":86 + /* "cfuzzyset.pyx":91 * cdef tuple new_val * for gram, occ in grams.items(): * new_val = (idx, occ) # <<<<<<<<<<<<<< * if gram in self.match_dict: * self.match_dict[gram].append(new_val) */ - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 91, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 86, __pyx_L1_error) + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 91, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_2); @@ -2592,7 +2732,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ __Pyx_XDECREF_SET(__pyx_v_new_val, ((PyObject*)__pyx_t_7)); __pyx_t_7 = 0; - /* "cfuzzyset.pyx":87 + /* "cfuzzyset.pyx":92 * for gram, occ in grams.items(): * new_val = (idx, occ) * if gram in self.match_dict: # <<<<<<<<<<<<<< @@ -2601,13 +2741,13 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ */ if (unlikely(__pyx_v_self->match_dict == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); - __PYX_ERR(0, 87, __pyx_L1_error) + __PYX_ERR(0, 92, __pyx_L1_error) } - __pyx_t_15 = (__Pyx_PyDict_ContainsTF(__pyx_v_gram, __pyx_v_self->match_dict, Py_EQ)); if (unlikely(__pyx_t_15 < 0)) __PYX_ERR(0, 87, __pyx_L1_error) + __pyx_t_15 = (__Pyx_PyDict_ContainsTF(__pyx_v_gram, __pyx_v_self->match_dict, Py_EQ)); if (unlikely(__pyx_t_15 < 0)) __PYX_ERR(0, 92, __pyx_L1_error) __pyx_t_16 = (__pyx_t_15 != 0); if (__pyx_t_16) { - /* "cfuzzyset.pyx":88 + /* "cfuzzyset.pyx":93 * new_val = (idx, occ) * if gram in self.match_dict: * self.match_dict[gram].append(new_val) # <<<<<<<<<<<<<< @@ -2616,14 +2756,14 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ */ if (unlikely(__pyx_v_self->match_dict == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 88, __pyx_L1_error) + __PYX_ERR(0, 93, __pyx_L1_error) } - __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_self->match_dict, __pyx_v_gram); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 88, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_self->match_dict, __pyx_v_gram); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 93, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __pyx_t_9 = __Pyx_PyObject_Append(__pyx_t_7, __pyx_v_new_val); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 88, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyObject_Append(__pyx_t_7, __pyx_v_new_val); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 93, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - /* "cfuzzyset.pyx":87 + /* "cfuzzyset.pyx":92 * for gram, occ in grams.items(): * new_val = (idx, occ) * if gram in self.match_dict: # <<<<<<<<<<<<<< @@ -2633,7 +2773,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ goto __pyx_L9; } - /* "cfuzzyset.pyx":90 + /* "cfuzzyset.pyx":95 * self.match_dict[gram].append(new_val) * else: * self.match_dict[gram] = [new_val] # <<<<<<<<<<<<<< @@ -2641,21 +2781,21 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ * */ /*else*/ { - __pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 90, __pyx_L1_error) + __pyx_t_7 = PyList_New(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_INCREF(__pyx_v_new_val); __Pyx_GIVEREF(__pyx_v_new_val); PyList_SET_ITEM(__pyx_t_7, 0, __pyx_v_new_val); if (unlikely(__pyx_v_self->match_dict == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 90, __pyx_L1_error) + __PYX_ERR(0, 95, __pyx_L1_error) } - if (unlikely(PyDict_SetItem(__pyx_v_self->match_dict, __pyx_v_gram, __pyx_t_7) < 0)) __PYX_ERR(0, 90, __pyx_L1_error) + if (unlikely(PyDict_SetItem(__pyx_v_self->match_dict, __pyx_v_gram, __pyx_t_7) < 0)) __PYX_ERR(0, 95, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } __pyx_L9:; - /* "cfuzzyset.pyx":85 + /* "cfuzzyset.pyx":90 * items[idx] = (norm, lvalue) * cdef tuple new_val * for gram, occ in grams.items(): # <<<<<<<<<<<<<< @@ -2665,7 +2805,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "cfuzzyset.pyx":91 + /* "cfuzzyset.pyx":96 * else: * self.match_dict[gram] = [new_val] * self.exact_set[lvalue] = value # <<<<<<<<<<<<<< @@ -2674,11 +2814,11 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__add(struct __pyx_obj_9cfuzzyset_ */ if (unlikely(__pyx_v_self->exact_set == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 91, __pyx_L1_error) + __PYX_ERR(0, 96, __pyx_L1_error) } - if (unlikely(PyDict_SetItem(__pyx_v_self->exact_set, __pyx_v_lvalue, __pyx_v_value) < 0)) __PYX_ERR(0, 91, __pyx_L1_error) + if (unlikely(PyDict_SetItem(__pyx_v_self->exact_set, __pyx_v_lvalue, __pyx_v_value) < 0)) __PYX_ERR(0, 96, __pyx_L1_error) - /* "cfuzzyset.pyx":68 + /* "cfuzzyset.pyx":73 * * @cython.nonecheck(False) * cpdef _add(self, unicode value, int gram_size): # <<<<<<<<<<<<<< @@ -2742,11 +2882,11 @@ static PyObject *__pyx_pw_9cfuzzyset_9cFuzzySet_7_add(PyObject *__pyx_v_self, Py case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_gram_size)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_add", 1, 2, 2, 1); __PYX_ERR(0, 68, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("_add", 1, 2, 2, 1); __PYX_ERR(0, 73, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_add") < 0)) __PYX_ERR(0, 68, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_add") < 0)) __PYX_ERR(0, 73, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; @@ -2755,17 +2895,17 @@ static PyObject *__pyx_pw_9cfuzzyset_9cFuzzySet_7_add(PyObject *__pyx_v_self, Py values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_value = ((PyObject*)values[0]); - __pyx_v_gram_size = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_gram_size == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 68, __pyx_L3_error) + __pyx_v_gram_size = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_gram_size == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 73, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_add", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 68, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("_add", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 73, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("cfuzzyset.cFuzzySet._add", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_value), (&PyUnicode_Type), 1, "value", 1))) __PYX_ERR(0, 68, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_value), (&PyUnicode_Type), 1, "value", 1))) __PYX_ERR(0, 73, __pyx_L1_error) __pyx_r = __pyx_pf_9cfuzzyset_9cFuzzySet_6_add(((struct __pyx_obj_9cfuzzyset_cFuzzySet *)__pyx_v_self), __pyx_v_value, __pyx_v_gram_size); /* function exit code */ @@ -2783,7 +2923,7 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_6_add(struct __pyx_obj_9cfuzzyse PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("_add", 0); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_9cfuzzyset_9cFuzzySet__add(__pyx_v_self, __pyx_v_value, __pyx_v_gram_size, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 68, __pyx_L1_error) + __pyx_t_1 = __pyx_f_9cfuzzyset_9cFuzzySet__add(__pyx_v_self, __pyx_v_value, __pyx_v_gram_size, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 73, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -2800,7 +2940,7 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_6_add(struct __pyx_obj_9cfuzzyse return __pyx_r; } -/* "cfuzzyset.pyx":95 +/* "cfuzzyset.pyx":100 * @cython.nonecheck(False) * @cython.boundscheck(False) * def __getitem__(self, object in_val): # <<<<<<<<<<<<<< @@ -2833,31 +2973,32 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_8__getitem__(struct __pyx_obj_9c PyObject *__pyx_t_3 = NULL; int __pyx_t_4; int __pyx_t_5; - long __pyx_t_6; + int __pyx_t_6; long __pyx_t_7; - int __pyx_t_8; + long __pyx_t_8; + int __pyx_t_9; __Pyx_RefNannySetupContext("__getitem__", 0); - /* "cfuzzyset.pyx":96 + /* "cfuzzyset.pyx":101 * @cython.boundscheck(False) * def __getitem__(self, object in_val): * cdef unicode value = _convert_val(in_val) # <<<<<<<<<<<<<< * cdef unicode lvalue * with cython.nonecheck(True): */ - __pyx_t_1 = __pyx_f_9cfuzzyset__convert_val(__pyx_v_in_val); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 96, __pyx_L1_error) + __pyx_t_1 = __pyx_f_9cfuzzyset__convert_val(__pyx_v_in_val); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 101, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_value = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "cfuzzyset.pyx":99 + /* "cfuzzyset.pyx":104 * cdef unicode lvalue * with cython.nonecheck(True): * lvalue = value.lower() # <<<<<<<<<<<<<< - * if lvalue in self.exact_set: + * if lvalue in self.exact_set and self.rel_sim_cutoff >= 1.0: * return [(1, self.exact_set[lvalue])] */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_lower); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 99, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_lower); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 104, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -2869,36 +3010,41 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_8__getitem__(struct __pyx_obj_9c __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, 99, __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, 99, __pyx_L1_error) - } + __pyx_t_1 = (__pyx_t_3) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_3) : __Pyx_PyObject_CallNoArg(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 104, __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, 99, __pyx_L1_error) + 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, 104, __pyx_L1_error) __pyx_v_lvalue = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "cfuzzyset.pyx":100 + /* "cfuzzyset.pyx":105 * with cython.nonecheck(True): * lvalue = value.lower() - * if lvalue in self.exact_set: # <<<<<<<<<<<<<< + * if lvalue in self.exact_set and self.rel_sim_cutoff >= 1.0: # <<<<<<<<<<<<<< * return [(1, self.exact_set[lvalue])] * cdef int i */ if (unlikely(__pyx_v_self->exact_set == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); - __PYX_ERR(0, 100, __pyx_L1_error) + __PYX_ERR(0, 105, __pyx_L1_error) } - __pyx_t_4 = (__Pyx_PyDict_ContainsTF(__pyx_v_lvalue, __pyx_v_self->exact_set, Py_EQ)); if (unlikely(__pyx_t_4 < 0)) __PYX_ERR(0, 100, __pyx_L1_error) - __pyx_t_5 = (__pyx_t_4 != 0); - if (__pyx_t_5) { + __pyx_t_5 = (__Pyx_PyDict_ContainsTF(__pyx_v_lvalue, __pyx_v_self->exact_set, Py_EQ)); if (unlikely(__pyx_t_5 < 0)) __PYX_ERR(0, 105, __pyx_L1_error) + __pyx_t_6 = (__pyx_t_5 != 0); + if (__pyx_t_6) { + } else { + __pyx_t_4 = __pyx_t_6; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_6 = ((__pyx_v_self->rel_sim_cutoff >= 1.0) != 0); + __pyx_t_4 = __pyx_t_6; + __pyx_L4_bool_binop_done:; + if (__pyx_t_4) { - /* "cfuzzyset.pyx":101 + /* "cfuzzyset.pyx":106 * lvalue = value.lower() - * if lvalue in self.exact_set: + * if lvalue in self.exact_set and self.rel_sim_cutoff >= 1.0: * return [(1, self.exact_set[lvalue])] # <<<<<<<<<<<<<< * cdef int i * results = None @@ -2906,11 +3052,11 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_8__getitem__(struct __pyx_obj_9c __Pyx_XDECREF(__pyx_r); if (unlikely(__pyx_v_self->exact_set == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 101, __pyx_L1_error) + __PYX_ERR(0, 106, __pyx_L1_error) } - __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_self->exact_set, __pyx_v_lvalue); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 101, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_self->exact_set, __pyx_v_lvalue); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 106, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 101, __pyx_L1_error) + __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 106, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_int_1); __Pyx_GIVEREF(__pyx_int_1); @@ -2918,7 +3064,7 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_8__getitem__(struct __pyx_obj_9c __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 101, __pyx_L1_error) + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 106, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_2); PyList_SET_ITEM(__pyx_t_1, 0, __pyx_t_2); @@ -2927,16 +3073,16 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_8__getitem__(struct __pyx_obj_9c __pyx_t_1 = 0; goto __pyx_L0; - /* "cfuzzyset.pyx":100 + /* "cfuzzyset.pyx":105 * with cython.nonecheck(True): * lvalue = value.lower() - * if lvalue in self.exact_set: # <<<<<<<<<<<<<< + * if lvalue in self.exact_set and self.rel_sim_cutoff >= 1.0: # <<<<<<<<<<<<<< * return [(1, self.exact_set[lvalue])] * cdef int i */ } - /* "cfuzzyset.pyx":103 + /* "cfuzzyset.pyx":108 * return [(1, self.exact_set[lvalue])] * cdef int i * results = None # <<<<<<<<<<<<<< @@ -2946,42 +3092,42 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_8__getitem__(struct __pyx_obj_9c __Pyx_INCREF(Py_None); __pyx_v_results = Py_None; - /* "cfuzzyset.pyx":104 + /* "cfuzzyset.pyx":109 * cdef int i * results = None * for i in range(self.gram_size_upper, self.gram_size_lower - 1, -1): # <<<<<<<<<<<<<< * results = self._get(value, i) * if results is not None: */ - __pyx_t_6 = (__pyx_v_self->gram_size_lower - 1); - __pyx_t_7 = __pyx_t_6; - for (__pyx_t_8 = __pyx_v_self->gram_size_upper; __pyx_t_8 > __pyx_t_7; __pyx_t_8-=1) { - __pyx_v_i = __pyx_t_8; + __pyx_t_7 = (__pyx_v_self->gram_size_lower - 1); + __pyx_t_8 = __pyx_t_7; + for (__pyx_t_9 = __pyx_v_self->gram_size_upper; __pyx_t_9 > __pyx_t_8; __pyx_t_9-=1) { + __pyx_v_i = __pyx_t_9; - /* "cfuzzyset.pyx":105 + /* "cfuzzyset.pyx":110 * results = None * for i in range(self.gram_size_upper, self.gram_size_lower - 1, -1): * results = self._get(value, i) # <<<<<<<<<<<<<< * if results is not None: * return results */ - __pyx_t_1 = ((struct __pyx_vtabstruct_9cfuzzyset_cFuzzySet *)__pyx_v_self->__pyx_vtab)->_get(__pyx_v_self, __pyx_v_value, __pyx_v_i, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 105, __pyx_L1_error) + __pyx_t_1 = ((struct __pyx_vtabstruct_9cfuzzyset_cFuzzySet *)__pyx_v_self->__pyx_vtab)->_get(__pyx_v_self, __pyx_v_value, __pyx_v_i, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 110, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_results, __pyx_t_1); __pyx_t_1 = 0; - /* "cfuzzyset.pyx":106 + /* "cfuzzyset.pyx":111 * for i in range(self.gram_size_upper, self.gram_size_lower - 1, -1): * results = self._get(value, i) * if results is not None: # <<<<<<<<<<<<<< * return results * raise KeyError(in_val) */ - __pyx_t_5 = (__pyx_v_results != Py_None); - __pyx_t_4 = (__pyx_t_5 != 0); - if (__pyx_t_4) { + __pyx_t_4 = (__pyx_v_results != Py_None); + __pyx_t_6 = (__pyx_t_4 != 0); + if (__pyx_t_6) { - /* "cfuzzyset.pyx":107 + /* "cfuzzyset.pyx":112 * results = self._get(value, i) * if results is not None: * return results # <<<<<<<<<<<<<< @@ -2993,7 +3139,7 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_8__getitem__(struct __pyx_obj_9c __pyx_r = __pyx_v_results; goto __pyx_L0; - /* "cfuzzyset.pyx":106 + /* "cfuzzyset.pyx":111 * for i in range(self.gram_size_upper, self.gram_size_lower - 1, -1): * results = self._get(value, i) * if results is not None: # <<<<<<<<<<<<<< @@ -3003,20 +3149,20 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_8__getitem__(struct __pyx_obj_9c } } - /* "cfuzzyset.pyx":108 + /* "cfuzzyset.pyx":113 * if results is not None: * return results * raise KeyError(in_val) # <<<<<<<<<<<<<< * * @cython.nonecheck(False) */ - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_v_in_val); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 108, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_KeyError, __pyx_v_in_val); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 113, __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, 108, __pyx_L1_error) + __PYX_ERR(0, 113, __pyx_L1_error) - /* "cfuzzyset.pyx":95 + /* "cfuzzyset.pyx":100 * @cython.nonecheck(False) * @cython.boundscheck(False) * def __getitem__(self, object in_val): # <<<<<<<<<<<<<< @@ -3040,7 +3186,7 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_8__getitem__(struct __pyx_obj_9c return __pyx_r; } -/* "cfuzzyset.pyx":112 +/* "cfuzzyset.pyx":117 * @cython.nonecheck(False) * @cython.boundscheck(False) * cpdef _get(self, unicode value, int gram_size): # <<<<<<<<<<<<<< @@ -3054,6 +3200,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ PyObject *__pyx_v_matches = 0; PyObject *__pyx_v_grams = 0; double __pyx_v_norm; + double __pyx_v_score_threshold; int __pyx_v_tmp; PyObject *__pyx_v_values = 0; int __pyx_v_idx; @@ -3084,82 +3231,99 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ Py_ssize_t __pyx_t_14; PyObject *(*__pyx_t_15)(PyObject *); int __pyx_t_16; + double __pyx_t_17; __Pyx_RefNannySetupContext("_get", 0); __Pyx_INCREF(__pyx_v_value); /* Check if called by wrapper */ if (unlikely(__pyx_skip_dispatch)) ; /* Check if overridden in Python */ - else if (unlikely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0)) { - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 112, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)__pyx_pw_9cfuzzyset_9cFuzzySet_11_get)) { - __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_gram_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 112, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_3); - __Pyx_INCREF(__pyx_t_1); - __pyx_t_4 = __pyx_t_1; __pyx_t_5 = NULL; - __pyx_t_6 = 0; - 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); - __pyx_t_6 = 1; - } - } - #if CYTHON_FAST_PYCALL - if (PyFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_value, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 112, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else - #endif - #if CYTHON_FAST_PYCCALL - if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { - PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_value, __pyx_t_3}; - __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 112, __pyx_L1_error) - __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - } else + else if (unlikely((Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset != 0) || (Py_TYPE(((PyObject *)__pyx_v_self))->tp_flags & (Py_TPFLAGS_IS_ABSTRACT | Py_TPFLAGS_HEAPTYPE)))) { + #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP + static PY_UINT64_T tp_dict_version = 0, obj_dict_version = 0; + if (likely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dict && tp_dict_version == __PYX_GET_DICT_VERSION(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dict) && (!Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset || obj_dict_version == __PYX_GET_DICT_VERSION(_PyObject_GetDictPtr(((PyObject *)__pyx_v_self)))))); + else { + PY_UINT64_T type_dict_guard = (likely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dict)) ? __PYX_GET_DICT_VERSION(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dict) : 0; #endif - { - __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 112, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - if (__pyx_t_5) { - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_get); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 117, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!PyCFunction_Check(__pyx_t_1) || (PyCFunction_GET_FUNCTION(__pyx_t_1) != (PyCFunction)(void*)__pyx_pw_9cfuzzyset_9cFuzzySet_11_get)) { + __Pyx_XDECREF(__pyx_r); + __pyx_t_3 = __Pyx_PyInt_From_int(__pyx_v_gram_size); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 117, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_t_1); + __pyx_t_4 = __pyx_t_1; __pyx_t_5 = NULL; + __pyx_t_6 = 0; + 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); + __pyx_t_6 = 1; + } } - __Pyx_INCREF(__pyx_v_value); - __Pyx_GIVEREF(__pyx_v_value); - PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_value); - __Pyx_GIVEREF(__pyx_t_3); - PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_3); - __pyx_t_3 = 0; - __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 112, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_value, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 117, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(__pyx_t_4)) { + PyObject *__pyx_temp[3] = {__pyx_t_5, __pyx_v_value, __pyx_t_3}; + __pyx_t_2 = __Pyx_PyCFunction_FastCall(__pyx_t_4, __pyx_temp+1-__pyx_t_6, 2+__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 117, __pyx_L1_error) + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } else + #endif + { + __pyx_t_7 = PyTuple_New(2+__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 117, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (__pyx_t_5) { + __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); __pyx_t_5 = NULL; + } + __Pyx_INCREF(__pyx_v_value); + __Pyx_GIVEREF(__pyx_v_value); + PyTuple_SET_ITEM(__pyx_t_7, 0+__pyx_t_6, __pyx_v_value); + __Pyx_GIVEREF(__pyx_t_3); + PyTuple_SET_ITEM(__pyx_t_7, 1+__pyx_t_6, __pyx_t_3); + __pyx_t_3 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_t_7, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 117, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_2; + __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L0; } - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_r = __pyx_t_2; - __pyx_t_2 = 0; + #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP + tp_dict_version = likely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dict) ? __PYX_GET_DICT_VERSION(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dict) : 0; + obj_dict_version = likely(Py_TYPE(((PyObject *)__pyx_v_self))->tp_dictoffset) ? __PYX_GET_DICT_VERSION(_PyObject_GetDictPtr(((PyObject *)__pyx_v_self))) : 0; + if (unlikely(type_dict_guard != tp_dict_version)) { + tp_dict_version = obj_dict_version = 0; + } + #endif __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - goto __pyx_L0; + #if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_PYTYPE_LOOKUP } - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + #endif } - /* "cfuzzyset.pyx":113 + /* "cfuzzyset.pyx":118 * @cython.boundscheck(False) * cpdef _get(self, unicode value, int gram_size): * cdef unicode lvalue = value.lower() # <<<<<<<<<<<<<< * cdef dict matches = {} * cdef dict grams = _gram_counter(lvalue, gram_size) */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_lower); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 113, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_value, __pyx_n_s_lower); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 118, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = NULL; if (CYTHON_UNPACK_METHODS && likely(PyMethod_Check(__pyx_t_2))) { @@ -3171,55 +3335,52 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ __Pyx_DECREF_SET(__pyx_t_2, function); } } - if (__pyx_t_4) { - __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 113, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - } else { - __pyx_t_1 = __Pyx_PyObject_CallNoArg(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 113, __pyx_L1_error) - } + __pyx_t_1 = (__pyx_t_4) ? __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_4) : __Pyx_PyObject_CallNoArg(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 118, __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, 113, __pyx_L1_error) + 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, 118, __pyx_L1_error) __pyx_v_lvalue = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "cfuzzyset.pyx":114 + /* "cfuzzyset.pyx":119 * cpdef _get(self, unicode value, int gram_size): * cdef unicode lvalue = value.lower() * cdef dict matches = {} # <<<<<<<<<<<<<< * cdef dict grams = _gram_counter(lvalue, gram_size) * cdef double norm = 0 */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 114, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 119, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_matches = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "cfuzzyset.pyx":115 + /* "cfuzzyset.pyx":120 * cdef unicode lvalue = value.lower() * cdef dict matches = {} * cdef dict grams = _gram_counter(lvalue, gram_size) # <<<<<<<<<<<<<< * cdef double norm = 0 - * cdef int tmp + * cdef double score_threshold */ __pyx_t_8.__pyx_n = 1; __pyx_t_8.gram_size = __pyx_v_gram_size; - __pyx_t_1 = __pyx_f_9cfuzzyset__gram_counter(__pyx_v_lvalue, &__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 115, __pyx_L1_error) + __pyx_t_1 = __pyx_f_9cfuzzyset__gram_counter(__pyx_v_lvalue, &__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 120, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_grams = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "cfuzzyset.pyx":116 + /* "cfuzzyset.pyx":121 * cdef dict matches = {} * cdef dict grams = _gram_counter(lvalue, gram_size) * cdef double norm = 0 # <<<<<<<<<<<<<< + * cdef double score_threshold * cdef int tmp - * cdef list values = list(grams.values()) */ __pyx_v_norm = 0.0; - /* "cfuzzyset.pyx":118 - * cdef double norm = 0 + /* "cfuzzyset.pyx":124 + * cdef double score_threshold * cdef int tmp * cdef list values = list(grams.values()) # <<<<<<<<<<<<<< * for tmp in values: @@ -3227,17 +3388,17 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ */ if (unlikely(__pyx_v_grams == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "values"); - __PYX_ERR(0, 118, __pyx_L1_error) + __PYX_ERR(0, 124, __pyx_L1_error) } - __pyx_t_1 = __Pyx_PyDict_Values(__pyx_v_grams); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 118, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_Values(__pyx_v_grams); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 124, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 118, __pyx_L1_error) + __pyx_t_2 = PySequence_List(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 124, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_values = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "cfuzzyset.pyx":119 + /* "cfuzzyset.pyx":125 * cdef int tmp * cdef list values = list(grams.values()) * for tmp in values: # <<<<<<<<<<<<<< @@ -3248,16 +3409,16 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ for (;;) { if (__pyx_t_9 >= 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_9); __Pyx_INCREF(__pyx_t_1); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 119, __pyx_L1_error) + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_9); __Pyx_INCREF(__pyx_t_1); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 125, __pyx_L1_error) #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 119, __pyx_L1_error) + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 125, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); #endif - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 119, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_1); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 125, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_tmp = __pyx_t_6; - /* "cfuzzyset.pyx":120 + /* "cfuzzyset.pyx":126 * cdef list values = list(grams.values()) * for tmp in values: * norm += tmp * tmp # <<<<<<<<<<<<<< @@ -3266,7 +3427,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ */ __pyx_v_norm = (__pyx_v_norm + (__pyx_v_tmp * __pyx_v_tmp)); - /* "cfuzzyset.pyx":119 + /* "cfuzzyset.pyx":125 * cdef int tmp * cdef list values = list(grams.values()) * for tmp in values: # <<<<<<<<<<<<<< @@ -3276,7 +3437,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "cfuzzyset.pyx":121 + /* "cfuzzyset.pyx":127 * for tmp in values: * norm += tmp * tmp * norm = sqrt(norm) # <<<<<<<<<<<<<< @@ -3285,7 +3446,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ */ __pyx_v_norm = sqrt(__pyx_v_norm); - /* "cfuzzyset.pyx":127 + /* "cfuzzyset.pyx":133 * cdef int match_score * cdef unicode gram * cdef list items = self.items[gram_size] # <<<<<<<<<<<<<< @@ -3294,18 +3455,18 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ */ if (unlikely(__pyx_v_self->items == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 127, __pyx_L1_error) + __PYX_ERR(0, 133, __pyx_L1_error) } - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_gram_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 127, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_gram_size); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 133, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_self->items, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 127, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_self->items, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 127, __pyx_L1_error) + if (!(likely(PyList_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "list", Py_TYPE(__pyx_t_1)->tp_name), 0))) __PYX_ERR(0, 133, __pyx_L1_error) __pyx_v_items = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "cfuzzyset.pyx":129 + /* "cfuzzyset.pyx":135 * cdef list items = self.items[gram_size] * * for gram, occ in grams.items(): # <<<<<<<<<<<<<< @@ -3314,17 +3475,17 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ */ if (unlikely(__pyx_v_grams == Py_None)) { PyErr_Format(PyExc_AttributeError, "'NoneType' object has no attribute '%.30s'", "items"); - __PYX_ERR(0, 129, __pyx_L1_error) + __PYX_ERR(0, 135, __pyx_L1_error) } - __pyx_t_1 = __Pyx_PyDict_Items(__pyx_v_grams); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_Items(__pyx_v_grams); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 135, __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_9 = 0; __pyx_t_10 = NULL; } else { - __pyx_t_9 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 129, __pyx_L1_error) + __pyx_t_9 = -1; __pyx_t_2 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 135, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_10 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 129, __pyx_L1_error) + __pyx_t_10 = Py_TYPE(__pyx_t_2)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 135, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; for (;;) { @@ -3332,17 +3493,17 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ if (likely(PyList_CheckExact(__pyx_t_2))) { if (__pyx_t_9 >= 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_9); __Pyx_INCREF(__pyx_t_1); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 129, __pyx_L1_error) + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_9); __Pyx_INCREF(__pyx_t_1); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 135, __pyx_L1_error) #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error) + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 135, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); #endif } else { if (__pyx_t_9 >= 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_9); __Pyx_INCREF(__pyx_t_1); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 129, __pyx_L1_error) + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_2, __pyx_t_9); __Pyx_INCREF(__pyx_t_1); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 135, __pyx_L1_error) #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 129, __pyx_L1_error) + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 135, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); #endif } @@ -3352,7 +3513,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 129, __pyx_L1_error) + else __PYX_ERR(0, 135, __pyx_L1_error) } break; } @@ -3364,7 +3525,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 129, __pyx_L1_error) + __PYX_ERR(0, 135, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { @@ -3377,15 +3538,15 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ __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, 129, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 135, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 129, __pyx_L1_error) + __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 135, __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, 129, __pyx_L1_error) + __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 135, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_11 = Py_TYPE(__pyx_t_3)->tp_iternext; @@ -3393,7 +3554,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ __Pyx_GOTREF(__pyx_t_4); index = 1; __pyx_t_7 = __pyx_t_11(__pyx_t_3); if (unlikely(!__pyx_t_7)) goto __pyx_L7_unpacking_failed; __Pyx_GOTREF(__pyx_t_7); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_3), 2) < 0) __PYX_ERR(0, 129, __pyx_L1_error) + if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_3), 2) < 0) __PYX_ERR(0, 135, __pyx_L1_error) __pyx_t_11 = NULL; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L8_unpacking_done; @@ -3401,17 +3562,17 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_11 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 129, __pyx_L1_error) + __PYX_ERR(0, 135, __pyx_L1_error) __pyx_L8_unpacking_done:; } - if (!(likely(PyUnicode_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(0, 129, __pyx_L1_error) - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 129, __pyx_L1_error) + if (!(likely(PyUnicode_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(0, 135, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_7); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 135, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_XDECREF_SET(__pyx_v_gram, ((PyObject*)__pyx_t_4)); __pyx_t_4 = 0; __pyx_v_occ = __pyx_t_6; - /* "cfuzzyset.pyx":130 + /* "cfuzzyset.pyx":136 * * for gram, occ in grams.items(): * if gram in self.match_dict: # <<<<<<<<<<<<<< @@ -3420,13 +3581,13 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ */ if (unlikely(__pyx_v_self->match_dict == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not iterable"); - __PYX_ERR(0, 130, __pyx_L1_error) + __PYX_ERR(0, 136, __pyx_L1_error) } - __pyx_t_12 = (__Pyx_PyDict_ContainsTF(__pyx_v_gram, __pyx_v_self->match_dict, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 130, __pyx_L1_error) + __pyx_t_12 = (__Pyx_PyDict_ContainsTF(__pyx_v_gram, __pyx_v_self->match_dict, Py_EQ)); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 136, __pyx_L1_error) __pyx_t_13 = (__pyx_t_12 != 0); if (__pyx_t_13) { - /* "cfuzzyset.pyx":131 + /* "cfuzzyset.pyx":137 * for gram, occ in grams.items(): * if gram in self.match_dict: * for idx, other_occ in self.match_dict[gram]: # <<<<<<<<<<<<<< @@ -3435,17 +3596,17 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ */ if (unlikely(__pyx_v_self->match_dict == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 131, __pyx_L1_error) + __PYX_ERR(0, 137, __pyx_L1_error) } - __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_self->match_dict, __pyx_v_gram); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 131, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_self->match_dict, __pyx_v_gram); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 137, __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_14 = 0; __pyx_t_15 = NULL; } else { - __pyx_t_14 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 131, __pyx_L1_error) + __pyx_t_14 = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 137, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __pyx_t_15 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 131, __pyx_L1_error) + __pyx_t_15 = Py_TYPE(__pyx_t_7)->tp_iternext; if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 137, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; for (;;) { @@ -3453,17 +3614,17 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ if (likely(PyList_CheckExact(__pyx_t_7))) { if (__pyx_t_14 >= 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_14); __Pyx_INCREF(__pyx_t_1); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 131, __pyx_L1_error) + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_7, __pyx_t_14); __Pyx_INCREF(__pyx_t_1); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 137, __pyx_L1_error) #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_7, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 131, __pyx_L1_error) + __pyx_t_1 = PySequence_ITEM(__pyx_t_7, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 137, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); #endif } else { if (__pyx_t_14 >= 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_14); __Pyx_INCREF(__pyx_t_1); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 131, __pyx_L1_error) + __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_7, __pyx_t_14); __Pyx_INCREF(__pyx_t_1); __pyx_t_14++; if (unlikely(0 < 0)) __PYX_ERR(0, 137, __pyx_L1_error) #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_7, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 131, __pyx_L1_error) + __pyx_t_1 = PySequence_ITEM(__pyx_t_7, __pyx_t_14); __pyx_t_14++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 137, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); #endif } @@ -3473,7 +3634,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 131, __pyx_L1_error) + else __PYX_ERR(0, 137, __pyx_L1_error) } break; } @@ -3485,7 +3646,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 131, __pyx_L1_error) + __PYX_ERR(0, 137, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { @@ -3498,15 +3659,15 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(__pyx_t_3); #else - __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 131, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 137, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 131, __pyx_L1_error) + __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 137, __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_5 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 131, __pyx_L1_error) + __pyx_t_5 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 137, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_11 = Py_TYPE(__pyx_t_5)->tp_iternext; @@ -3514,7 +3675,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ __Pyx_GOTREF(__pyx_t_4); index = 1; __pyx_t_3 = __pyx_t_11(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L12_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_5), 2) < 0) __PYX_ERR(0, 131, __pyx_L1_error) + if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_5), 2) < 0) __PYX_ERR(0, 137, __pyx_L1_error) __pyx_t_11 = NULL; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L13_unpacking_done; @@ -3522,52 +3683,52 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_11 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 131, __pyx_L1_error) + __PYX_ERR(0, 137, __pyx_L1_error) __pyx_L13_unpacking_done:; } - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 131, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 137, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_16 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_16 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 131, __pyx_L1_error) + __pyx_t_16 = __Pyx_PyInt_As_int(__pyx_t_3); if (unlikely((__pyx_t_16 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 137, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_idx = __pyx_t_6; __pyx_v_other_occ = __pyx_t_16; - /* "cfuzzyset.pyx":132 + /* "cfuzzyset.pyx":138 * if gram in self.match_dict: * for idx, other_occ in self.match_dict[gram]: * if idx in matches: # <<<<<<<<<<<<<< * matches[idx] += occ * other_occ * else: */ - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 132, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 138, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_13 = (__Pyx_PyDict_ContainsTF(__pyx_t_1, __pyx_v_matches, Py_EQ)); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 132, __pyx_L1_error) + __pyx_t_13 = (__Pyx_PyDict_ContainsTF(__pyx_t_1, __pyx_v_matches, Py_EQ)); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 138, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_12 = (__pyx_t_13 != 0); if (__pyx_t_12) { - /* "cfuzzyset.pyx":133 + /* "cfuzzyset.pyx":139 * for idx, other_occ in self.match_dict[gram]: * if idx in matches: * matches[idx] += occ * other_occ # <<<<<<<<<<<<<< * else: * matches[idx] = occ * other_occ */ - __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 133, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 139, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_matches, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 133, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyDict_GetItem(__pyx_v_matches, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 139, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_v_occ * __pyx_v_other_occ)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 133, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyInt_From_int((__pyx_v_occ * __pyx_v_other_occ)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 139, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 133, __pyx_L1_error) + __pyx_t_5 = PyNumber_InPlaceAdd(__pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 139, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - if (unlikely(PyDict_SetItem(__pyx_v_matches, __pyx_t_1, __pyx_t_5) < 0)) __PYX_ERR(0, 133, __pyx_L1_error) + if (unlikely(PyDict_SetItem(__pyx_v_matches, __pyx_t_1, __pyx_t_5) < 0)) __PYX_ERR(0, 139, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "cfuzzyset.pyx":132 + /* "cfuzzyset.pyx":138 * if gram in self.match_dict: * for idx, other_occ in self.match_dict[gram]: * if idx in matches: # <<<<<<<<<<<<<< @@ -3577,7 +3738,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ goto __pyx_L14; } - /* "cfuzzyset.pyx":135 + /* "cfuzzyset.pyx":141 * matches[idx] += occ * other_occ * else: * matches[idx] = occ * other_occ # <<<<<<<<<<<<<< @@ -3585,17 +3746,17 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ * if not matches: */ /*else*/ { - __pyx_t_1 = __Pyx_PyInt_From_int((__pyx_v_occ * __pyx_v_other_occ)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 135, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyInt_From_int((__pyx_v_occ * __pyx_v_other_occ)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 141, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 135, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_idx); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 141, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - if (unlikely(PyDict_SetItem(__pyx_v_matches, __pyx_t_5, __pyx_t_1) < 0)) __PYX_ERR(0, 135, __pyx_L1_error) + if (unlikely(PyDict_SetItem(__pyx_v_matches, __pyx_t_5, __pyx_t_1) < 0)) __PYX_ERR(0, 141, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_L14:; - /* "cfuzzyset.pyx":131 + /* "cfuzzyset.pyx":137 * for gram, occ in grams.items(): * if gram in self.match_dict: * for idx, other_occ in self.match_dict[gram]: # <<<<<<<<<<<<<< @@ -3605,7 +3766,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ } __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - /* "cfuzzyset.pyx":130 + /* "cfuzzyset.pyx":136 * * for gram, occ in grams.items(): * if gram in self.match_dict: # <<<<<<<<<<<<<< @@ -3614,7 +3775,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ */ } - /* "cfuzzyset.pyx":129 + /* "cfuzzyset.pyx":135 * cdef list items = self.items[gram_size] * * for gram, occ in grams.items(): # <<<<<<<<<<<<<< @@ -3624,18 +3785,18 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - /* "cfuzzyset.pyx":137 + /* "cfuzzyset.pyx":143 * matches[idx] = occ * other_occ * * if not matches: # <<<<<<<<<<<<<< * return None * */ - __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_matches); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 137, __pyx_L1_error) + __pyx_t_12 = __Pyx_PyObject_IsTrue(__pyx_v_matches); if (unlikely(__pyx_t_12 < 0)) __PYX_ERR(0, 143, __pyx_L1_error) __pyx_t_13 = ((!__pyx_t_12) != 0); if (__pyx_t_13) { - /* "cfuzzyset.pyx":138 + /* "cfuzzyset.pyx":144 * * if not matches: * return None # <<<<<<<<<<<<<< @@ -3646,7 +3807,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; - /* "cfuzzyset.pyx":137 + /* "cfuzzyset.pyx":143 * matches[idx] = occ * other_occ * * if not matches: # <<<<<<<<<<<<<< @@ -3655,32 +3816,32 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ */ } - /* "cfuzzyset.pyx":141 + /* "cfuzzyset.pyx":147 * * # cosine similarity * cdef list results = [(match_score / items[idx][0], items[idx][1]) # <<<<<<<<<<<<<< * for idx, match_score in matches.items()] * results.sort(reverse=True, key=operator.itemgetter(0)) */ - __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 141, __pyx_L1_error) + __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 147, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - /* "cfuzzyset.pyx":142 + /* "cfuzzyset.pyx":148 * # cosine similarity * cdef list results = [(match_score / items[idx][0], items[idx][1]) * for idx, match_score in matches.items()] # <<<<<<<<<<<<<< * results.sort(reverse=True, key=operator.itemgetter(0)) * */ - __pyx_t_7 = __Pyx_PyDict_Items(__pyx_v_matches); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyDict_Items(__pyx_v_matches); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 148, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); if (likely(PyList_CheckExact(__pyx_t_7)) || PyTuple_CheckExact(__pyx_t_7)) { __pyx_t_1 = __pyx_t_7; __Pyx_INCREF(__pyx_t_1); __pyx_t_9 = 0; __pyx_t_10 = NULL; } else { - __pyx_t_9 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_9 = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_10 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_10 = Py_TYPE(__pyx_t_1)->tp_iternext; if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 148, __pyx_L1_error) } __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; for (;;) { @@ -3688,17 +3849,17 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ if (likely(PyList_CheckExact(__pyx_t_1))) { if (__pyx_t_9 >= PyList_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_9); __Pyx_INCREF(__pyx_t_7); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_1, __pyx_t_9); __Pyx_INCREF(__pyx_t_7); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 148, __pyx_L1_error) #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 148, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); #endif } else { if (__pyx_t_9 >= PyTuple_GET_SIZE(__pyx_t_1)) break; #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS - __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_9); __Pyx_INCREF(__pyx_t_7); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_7 = PyTuple_GET_ITEM(__pyx_t_1, __pyx_t_9); __Pyx_INCREF(__pyx_t_7); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 148, __pyx_L1_error) #else - __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_7 = PySequence_ITEM(__pyx_t_1, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 148, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); #endif } @@ -3708,7 +3869,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ PyObject* exc_type = PyErr_Occurred(); if (exc_type) { if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); - else __PYX_ERR(0, 142, __pyx_L1_error) + else __PYX_ERR(0, 148, __pyx_L1_error) } break; } @@ -3720,7 +3881,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 142, __pyx_L1_error) + __PYX_ERR(0, 148, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { @@ -3733,15 +3894,15 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(__pyx_t_4); #else - __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 148, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 148, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } else { Py_ssize_t index = -1; - __pyx_t_3 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_3 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 148, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_11 = Py_TYPE(__pyx_t_3)->tp_iternext; @@ -3749,7 +3910,7 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ __Pyx_GOTREF(__pyx_t_5); index = 1; __pyx_t_4 = __pyx_t_11(__pyx_t_3); if (unlikely(!__pyx_t_4)) goto __pyx_L18_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_3), 2) < 0) __PYX_ERR(0, 142, __pyx_L1_error) + if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_3), 2) < 0) __PYX_ERR(0, 148, __pyx_L1_error) __pyx_t_11 = NULL; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L19_unpacking_done; @@ -3757,48 +3918,48 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_11 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 142, __pyx_L1_error) + __PYX_ERR(0, 148, __pyx_L1_error) __pyx_L19_unpacking_done:; } - __pyx_t_16 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_16 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_16 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_16 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 148, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 142, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyInt_As_int(__pyx_t_4); if (unlikely((__pyx_t_6 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 148, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_idx = __pyx_t_16; __pyx_v_match_score = __pyx_t_6; - /* "cfuzzyset.pyx":141 + /* "cfuzzyset.pyx":147 * * # cosine similarity * cdef list results = [(match_score / items[idx][0], items[idx][1]) # <<<<<<<<<<<<<< * for idx, match_score in matches.items()] * results.sort(reverse=True, key=operator.itemgetter(0)) */ - __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_match_score); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 141, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyInt_From_int(__pyx_v_match_score); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 147, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); if (unlikely(__pyx_v_items == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 141, __pyx_L1_error) + __PYX_ERR(0, 147, __pyx_L1_error) } - __pyx_t_4 = __Pyx_GetItemInt_List(__pyx_v_items, __pyx_v_idx, int, 1, __Pyx_PyInt_From_int, 1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 141, __pyx_L1_error) + __pyx_t_4 = __Pyx_GetItemInt_List(__pyx_v_items, __pyx_v_idx, int, 1, __Pyx_PyInt_From_int, 1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 147, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); - __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 141, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetItemInt(__pyx_t_4, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 147, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyNumber_Divide(__pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 141, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyNumber_Divide(__pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 147, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(__pyx_v_items == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 141, __pyx_L1_error) + __PYX_ERR(0, 147, __pyx_L1_error) } - __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_items, __pyx_v_idx, int, 1, __Pyx_PyInt_From_int, 1, 1, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 141, __pyx_L1_error) + __pyx_t_5 = __Pyx_GetItemInt_List(__pyx_v_items, __pyx_v_idx, int, 1, __Pyx_PyInt_From_int, 1, 1, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 147, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_5, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 141, __pyx_L1_error) + __pyx_t_7 = __Pyx_GetItemInt(__pyx_t_5, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 147, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 141, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 147, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); @@ -3806,10 +3967,10 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_7); __pyx_t_4 = 0; __pyx_t_7 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_5))) __PYX_ERR(0, 141, __pyx_L1_error) + if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_5))) __PYX_ERR(0, 147, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "cfuzzyset.pyx":142 + /* "cfuzzyset.pyx":148 * # cosine similarity * cdef list results = [(match_score / items[idx][0], items[idx][1]) * for idx, match_score in matches.items()] # <<<<<<<<<<<<<< @@ -3821,35 +3982,47 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ __pyx_v_results = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "cfuzzyset.pyx":143 + /* "cfuzzyset.pyx":149 * cdef list results = [(match_score / items[idx][0], items[idx][1]) * for idx, match_score in matches.items()] * results.sort(reverse=True, key=operator.itemgetter(0)) # <<<<<<<<<<<<<< * * if self.use_levenshtein: */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_results, __pyx_n_s_sort); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 143, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_results, __pyx_n_s_sort); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 149, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 143, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 149, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reverse, Py_True) < 0) __PYX_ERR(0, 143, __pyx_L1_error) - __pyx_t_5 = __Pyx_GetModuleGlobalName(__pyx_n_s_operator); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 143, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_itemgetter); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 143, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_reverse, Py_True) < 0) __PYX_ERR(0, 149, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_operator); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 149, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_7, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 143, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_itemgetter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 149, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_key, __pyx_t_5) < 0) __PYX_ERR(0, 143, __pyx_L1_error) + __pyx_t_7 = NULL; + if (CYTHON_UNPACK_METHODS && unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + } + } + __pyx_t_5 = (__pyx_t_7) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_7, __pyx_int_0) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_int_0); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 149, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PyDict_SetItem(__pyx_t_1, __pyx_n_s_key, __pyx_t_5) < 0) __PYX_ERR(0, 149, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 143, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_empty_tuple, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 149, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - /* "cfuzzyset.pyx":145 + /* "cfuzzyset.pyx":151 * results.sort(reverse=True, key=operator.itemgetter(0)) * * if self.use_levenshtein: # <<<<<<<<<<<<<< @@ -3859,33 +4032,33 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ __pyx_t_13 = (__pyx_v_self->use_levenshtein != 0); if (__pyx_t_13) { - /* "cfuzzyset.pyx":146 + /* "cfuzzyset.pyx":152 * * if self.use_levenshtein: * results = [(distance(matched, value), matched) # <<<<<<<<<<<<<< * for _, matched in results[:50]] * results.sort(reverse=True, key=operator.itemgetter(0)) */ - __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 146, __pyx_L1_error) + __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 152, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - /* "cfuzzyset.pyx":147 + /* "cfuzzyset.pyx":153 * if self.use_levenshtein: * results = [(distance(matched, value), matched) * for _, matched in results[:50]] # <<<<<<<<<<<<<< * results.sort(reverse=True, key=operator.itemgetter(0)) * */ - __pyx_t_1 = __Pyx_PyList_GetSlice(__pyx_v_results, 0, 50); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 147, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyList_GetSlice(__pyx_v_results, 0, 50); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 153, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __pyx_t_1; __Pyx_INCREF(__pyx_t_2); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; for (;;) { if (__pyx_t_9 >= 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_9); __Pyx_INCREF(__pyx_t_1); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 147, __pyx_L1_error) + __pyx_t_1 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_9); __Pyx_INCREF(__pyx_t_1); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 153, __pyx_L1_error) #else - __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 147, __pyx_L1_error) + __pyx_t_1 = PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 153, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); #endif if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { @@ -3894,36 +4067,36 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 147, __pyx_L1_error) + __PYX_ERR(0, 153, __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_4 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_7 = PyTuple_GET_ITEM(sequence, 1); } else { - __pyx_t_7 = PyList_GET_ITEM(sequence, 0); - __pyx_t_4 = PyList_GET_ITEM(sequence, 1); + __pyx_t_4 = PyList_GET_ITEM(sequence, 0); + __pyx_t_7 = PyList_GET_ITEM(sequence, 1); } - __Pyx_INCREF(__pyx_t_7); __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_7); #else - __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 147, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 147, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 153, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 153, __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, 147, __pyx_L1_error) + __pyx_t_3 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 153, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_11 = Py_TYPE(__pyx_t_3)->tp_iternext; - index = 0; __pyx_t_7 = __pyx_t_11(__pyx_t_3); if (unlikely(!__pyx_t_7)) goto __pyx_L23_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - index = 1; __pyx_t_4 = __pyx_t_11(__pyx_t_3); if (unlikely(!__pyx_t_4)) goto __pyx_L23_unpacking_failed; + index = 0; __pyx_t_4 = __pyx_t_11(__pyx_t_3); if (unlikely(!__pyx_t_4)) goto __pyx_L23_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_3), 2) < 0) __PYX_ERR(0, 147, __pyx_L1_error) + index = 1; __pyx_t_7 = __pyx_t_11(__pyx_t_3); if (unlikely(!__pyx_t_7)) goto __pyx_L23_unpacking_failed; + __Pyx_GOTREF(__pyx_t_7); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_3), 2) < 0) __PYX_ERR(0, 153, __pyx_L1_error) __pyx_t_11 = NULL; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L24_unpacking_done; @@ -3931,36 +4104,36 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_11 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 147, __pyx_L1_error) + __PYX_ERR(0, 153, __pyx_L1_error) __pyx_L24_unpacking_done:; } - __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_XDECREF_SET(__pyx_v_matched, __pyx_t_4); + __Pyx_XDECREF_SET(__pyx_v__, __pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF_SET(__pyx_v_matched, __pyx_t_7); + __pyx_t_7 = 0; - /* "cfuzzyset.pyx":146 + /* "cfuzzyset.pyx":152 * * if self.use_levenshtein: * results = [(distance(matched, value), matched) # <<<<<<<<<<<<<< * for _, matched in results[:50]] * results.sort(reverse=True, key=operator.itemgetter(0)) */ - if (!(likely(PyUnicode_CheckExact(__pyx_v_matched))||((__pyx_v_matched) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_matched)->tp_name), 0))) __PYX_ERR(0, 146, __pyx_L1_error) - __pyx_t_1 = PyFloat_FromDouble(__pyx_f_9cfuzzyset_distance(((PyObject*)__pyx_v_matched), __pyx_v_value)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 146, __pyx_L1_error) + if (!(likely(PyUnicode_CheckExact(__pyx_v_matched))||((__pyx_v_matched) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_matched)->tp_name), 0))) __PYX_ERR(0, 152, __pyx_L1_error) + __pyx_t_1 = PyFloat_FromDouble(__pyx_f_9cfuzzyset_distance(((PyObject*)__pyx_v_matched), __pyx_v_value)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 152, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 146, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 152, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_1); __Pyx_INCREF(__pyx_v_matched); __Pyx_GIVEREF(__pyx_v_matched); - PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_matched); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_v_matched); __pyx_t_1 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_5, (PyObject*)__pyx_t_4))) __PYX_ERR(0, 146, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(__Pyx_ListComp_Append(__pyx_t_5, (PyObject*)__pyx_t_7))) __PYX_ERR(0, 152, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - /* "cfuzzyset.pyx":147 + /* "cfuzzyset.pyx":153 * if self.use_levenshtein: * results = [(distance(matched, value), matched) * for _, matched in results[:50]] # <<<<<<<<<<<<<< @@ -3972,97 +4145,128 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ __Pyx_DECREF_SET(__pyx_v_results, ((PyObject*)__pyx_t_5)); __pyx_t_5 = 0; - /* "cfuzzyset.pyx":148 + /* "cfuzzyset.pyx":154 * results = [(distance(matched, value), matched) * for _, matched in results[:50]] * results.sort(reverse=True, key=operator.itemgetter(0)) # <<<<<<<<<<<<<< * - * return [(score, self.exact_set[value]) + * score_threshold = results[0][0] * self.rel_sim_cutoff */ - __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_results, __pyx_n_s_sort); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 148, __pyx_L1_error) + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_results, __pyx_n_s_sort); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 148, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_reverse, Py_True) < 0) __PYX_ERR(0, 148, __pyx_L1_error) - __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_operator); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 148, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); - __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_itemgetter); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 148, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_reverse, Py_True) < 0) __PYX_ERR(0, 154, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_operator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 148, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_itemgetter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_key, __pyx_t_4) < 0) __PYX_ERR(0, 148, __pyx_L1_error) + __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); + } + } + __pyx_t_7 = (__pyx_t_1) ? __Pyx_PyObject_Call2Args(__pyx_t_4, __pyx_t_1, __pyx_int_0) : __Pyx_PyObject_CallOneArg(__pyx_t_4, __pyx_int_0); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 154, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 148, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_key, __pyx_t_7) < 0) __PYX_ERR(0, 154, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_empty_tuple, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 154, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - /* "cfuzzyset.pyx":150 + /* "cfuzzyset.pyx":156 * results.sort(reverse=True, key=operator.itemgetter(0)) * + * score_threshold = results[0][0] * self.rel_sim_cutoff # <<<<<<<<<<<<<< + * return [(score, self.exact_set[value]) + * for score, value in results + */ + __pyx_t_7 = __Pyx_GetItemInt(PyList_GET_ITEM(__pyx_v_results, 0), 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 156, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_2 = PyFloat_FromDouble(__pyx_v_self->rel_sim_cutoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 156, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_5 = PyNumber_Multiply(__pyx_t_7, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 156, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_17 = __pyx_PyFloat_AsDouble(__pyx_t_5); if (unlikely((__pyx_t_17 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 156, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_score_threshold = __pyx_t_17; + + /* "cfuzzyset.pyx":157 + * + * score_threshold = results[0][0] * self.rel_sim_cutoff * return [(score, self.exact_set[value]) # <<<<<<<<<<<<<< * for score, value in results - * if score == results[0][0]] + * if score >= score_threshold] */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 150, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 157, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); - /* "cfuzzyset.pyx":151 - * + /* "cfuzzyset.pyx":158 + * score_threshold = results[0][0] * self.rel_sim_cutoff * return [(score, self.exact_set[value]) * for score, value in results # <<<<<<<<<<<<<< - * if score == results[0][0]] + * if score >= score_threshold] * else: */ __pyx_t_2 = __pyx_v_results; __Pyx_INCREF(__pyx_t_2); __pyx_t_9 = 0; for (;;) { if (__pyx_t_9 >= 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_9); __Pyx_INCREF(__pyx_t_5); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 151, __pyx_L1_error) + __pyx_t_7 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_9); __Pyx_INCREF(__pyx_t_7); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 158, __pyx_L1_error) #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 151, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 158, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); #endif - if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) { - PyObject* sequence = __pyx_t_5; + if ((likely(PyTuple_CheckExact(__pyx_t_7))) || (PyList_CheckExact(__pyx_t_7))) { + PyObject* sequence = __pyx_t_7; Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 151, __pyx_L1_error) + __PYX_ERR(0, 158, __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); + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); } else { - __pyx_t_1 = PyList_GET_ITEM(sequence, 0); - __pyx_t_7 = PyList_GET_ITEM(sequence, 1); + __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); - __Pyx_INCREF(__pyx_t_7); #else - __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 151, __pyx_L1_error) + __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 158, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 158, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 151, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); #endif - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } else { Py_ssize_t index = -1; - __pyx_t_3 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 151, __pyx_L1_error) + __pyx_t_3 = PyObject_GetIter(__pyx_t_7); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 158, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_11 = Py_TYPE(__pyx_t_3)->tp_iternext; - index = 0; __pyx_t_1 = __pyx_t_11(__pyx_t_3); if (unlikely(!__pyx_t_1)) goto __pyx_L27_unpacking_failed; + index = 0; __pyx_t_4 = __pyx_t_11(__pyx_t_3); if (unlikely(!__pyx_t_4)) goto __pyx_L27_unpacking_failed; + __Pyx_GOTREF(__pyx_t_4); + index = 1; __pyx_t_1 = __pyx_t_11(__pyx_t_3); if (unlikely(!__pyx_t_1)) goto __pyx_L27_unpacking_failed; __Pyx_GOTREF(__pyx_t_1); - index = 1; __pyx_t_7 = __pyx_t_11(__pyx_t_3); if (unlikely(!__pyx_t_7)) goto __pyx_L27_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_3), 2) < 0) __PYX_ERR(0, 151, __pyx_L1_error) + if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_3), 2) < 0) __PYX_ERR(0, 158, __pyx_L1_error) __pyx_t_11 = NULL; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L28_unpacking_done; @@ -4070,77 +4274,77 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_11 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 151, __pyx_L1_error) + __PYX_ERR(0, 158, __pyx_L1_error) __pyx_L28_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, 151, __pyx_L1_error) - __Pyx_XDECREF_SET(__pyx_v_score, __pyx_t_1); + 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, 158, __pyx_L1_error) + __Pyx_XDECREF_SET(__pyx_v_score, __pyx_t_4); + __pyx_t_4 = 0; + __Pyx_DECREF_SET(__pyx_v_value, ((PyObject*)__pyx_t_1)); __pyx_t_1 = 0; - __Pyx_DECREF_SET(__pyx_v_value, ((PyObject*)__pyx_t_7)); - __pyx_t_7 = 0; - /* "cfuzzyset.pyx":152 + /* "cfuzzyset.pyx":159 * return [(score, self.exact_set[value]) * for score, value in results - * if score == results[0][0]] # <<<<<<<<<<<<<< + * if score >= score_threshold] # <<<<<<<<<<<<<< * else: - * return [(score / norm, self.exact_set[value]) + * score_threshold = results[0][0] * self.rel_sim_cutoff */ - __pyx_t_5 = __Pyx_GetItemInt(PyList_GET_ITEM(__pyx_v_results, 0), 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 152, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); - __pyx_t_7 = PyObject_RichCompare(__pyx_v_score, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 152, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 152, __pyx_L1_error) + __pyx_t_7 = PyFloat_FromDouble(__pyx_v_score_threshold); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 159, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_1 = PyObject_RichCompare(__pyx_v_score, __pyx_t_7, Py_GE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 159, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 159, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_13) { - /* "cfuzzyset.pyx":150 - * results.sort(reverse=True, key=operator.itemgetter(0)) + /* "cfuzzyset.pyx":157 * + * score_threshold = results[0][0] * self.rel_sim_cutoff * return [(score, self.exact_set[value]) # <<<<<<<<<<<<<< * for score, value in results - * if score == results[0][0]] + * if score >= score_threshold] */ if (unlikely(__pyx_v_self->exact_set == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 150, __pyx_L1_error) + __PYX_ERR(0, 157, __pyx_L1_error) } - __pyx_t_7 = __Pyx_PyDict_GetItem(__pyx_v_self->exact_set, __pyx_v_value); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 150, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_self->exact_set, __pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 157, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 157, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); - __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 150, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_5); __Pyx_INCREF(__pyx_v_score); __Pyx_GIVEREF(__pyx_v_score); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_score); - __Pyx_GIVEREF(__pyx_t_7); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_7); - __pyx_t_7 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_t_5))) __PYX_ERR(0, 150, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_score); + __Pyx_GIVEREF(__pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_1); + __pyx_t_1 = 0; + if (unlikely(__Pyx_ListComp_Append(__pyx_t_5, (PyObject*)__pyx_t_7))) __PYX_ERR(0, 157, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; - /* "cfuzzyset.pyx":152 + /* "cfuzzyset.pyx":159 * return [(score, self.exact_set[value]) * for score, value in results - * if score == results[0][0]] # <<<<<<<<<<<<<< + * if score >= score_threshold] # <<<<<<<<<<<<<< * else: - * return [(score / norm, self.exact_set[value]) + * score_threshold = results[0][0] * self.rel_sim_cutoff */ } - /* "cfuzzyset.pyx":151 - * + /* "cfuzzyset.pyx":158 + * score_threshold = results[0][0] * self.rel_sim_cutoff * return [(score, self.exact_set[value]) * for score, value in results # <<<<<<<<<<<<<< - * if score == results[0][0]] + * if score >= score_threshold] * else: */ } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; goto __pyx_L0; - /* "cfuzzyset.pyx":145 + /* "cfuzzyset.pyx":151 * results.sort(reverse=True, key=operator.itemgetter(0)) * * if self.use_levenshtein: # <<<<<<<<<<<<<< @@ -4149,32 +4353,51 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ */ } - /* "cfuzzyset.pyx":154 - * if score == results[0][0]] + /* "cfuzzyset.pyx":161 + * if score >= score_threshold] * else: - * return [(score / norm, self.exact_set[value]) # <<<<<<<<<<<<<< + * score_threshold = results[0][0] * self.rel_sim_cutoff # <<<<<<<<<<<<<< + * return [(score / norm, self.exact_set[value]) * for score, value in results - * if score == results[0][0]] */ /*else*/ { - __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = PyList_New(0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 154, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_GetItemInt(PyList_GET_ITEM(__pyx_v_results, 0), 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 161, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = PyFloat_FromDouble(__pyx_v_self->rel_sim_cutoff); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 161, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_7 = PyNumber_Multiply(__pyx_t_5, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 161, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_17 = __pyx_PyFloat_AsDouble(__pyx_t_7); if (unlikely((__pyx_t_17 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 161, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_v_score_threshold = __pyx_t_17; - /* "cfuzzyset.pyx":155 + /* "cfuzzyset.pyx":162 * else: + * score_threshold = results[0][0] * self.rel_sim_cutoff + * return [(score / norm, self.exact_set[value]) # <<<<<<<<<<<<<< + * for score, value in results + * if score == score_threshold] + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_7 = PyList_New(0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 162, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + + /* "cfuzzyset.pyx":163 + * score_threshold = results[0][0] * self.rel_sim_cutoff * return [(score / norm, self.exact_set[value]) * for score, value in results # <<<<<<<<<<<<<< - * if score == results[0][0]] + * if score == score_threshold] * */ __pyx_t_2 = __pyx_v_results; __Pyx_INCREF(__pyx_t_2); __pyx_t_9 = 0; for (;;) { if (__pyx_t_9 >= 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_9); __Pyx_INCREF(__pyx_t_5); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 155, __pyx_L1_error) + __pyx_t_5 = PyList_GET_ITEM(__pyx_t_2, __pyx_t_9); __Pyx_INCREF(__pyx_t_5); __pyx_t_9++; if (unlikely(0 < 0)) __PYX_ERR(0, 163, __pyx_L1_error) #else - __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 155, __pyx_L1_error) + __pyx_t_5 = PySequence_ITEM(__pyx_t_2, __pyx_t_9); __pyx_t_9++; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 163, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) { @@ -4183,36 +4406,36 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); - __PYX_ERR(0, 155, __pyx_L1_error) + __PYX_ERR(0, 163, __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_1 = PyTuple_GET_ITEM(sequence, 1); + __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); + __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); } else { - __pyx_t_7 = PyList_GET_ITEM(sequence, 0); - __pyx_t_1 = PyList_GET_ITEM(sequence, 1); + __pyx_t_1 = PyList_GET_ITEM(sequence, 0); + __pyx_t_4 = PyList_GET_ITEM(sequence, 1); } - __Pyx_INCREF(__pyx_t_7); __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_4); #else - __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 155, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); - __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 155, __pyx_L1_error) + __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 163, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 163, __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_3 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 155, __pyx_L1_error) + __pyx_t_3 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 163, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_11 = Py_TYPE(__pyx_t_3)->tp_iternext; - index = 0; __pyx_t_7 = __pyx_t_11(__pyx_t_3); if (unlikely(!__pyx_t_7)) goto __pyx_L32_unpacking_failed; - __Pyx_GOTREF(__pyx_t_7); - index = 1; __pyx_t_1 = __pyx_t_11(__pyx_t_3); if (unlikely(!__pyx_t_1)) goto __pyx_L32_unpacking_failed; + index = 0; __pyx_t_1 = __pyx_t_11(__pyx_t_3); if (unlikely(!__pyx_t_1)) goto __pyx_L32_unpacking_failed; __Pyx_GOTREF(__pyx_t_1); - if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_3), 2) < 0) __PYX_ERR(0, 155, __pyx_L1_error) + index = 1; __pyx_t_4 = __pyx_t_11(__pyx_t_3); if (unlikely(!__pyx_t_4)) goto __pyx_L32_unpacking_failed; + __Pyx_GOTREF(__pyx_t_4); + if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_3), 2) < 0) __PYX_ERR(0, 163, __pyx_L1_error) __pyx_t_11 = NULL; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L33_unpacking_done; @@ -4220,83 +4443,83 @@ static PyObject *__pyx_f_9cfuzzyset_9cFuzzySet__get(struct __pyx_obj_9cfuzzyset_ __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_11 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); - __PYX_ERR(0, 155, __pyx_L1_error) + __PYX_ERR(0, 163, __pyx_L1_error) __pyx_L33_unpacking_done:; } - 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, 155, __pyx_L1_error) - __Pyx_XDECREF_SET(__pyx_v_score, __pyx_t_7); - __pyx_t_7 = 0; - __Pyx_DECREF_SET(__pyx_v_value, ((PyObject*)__pyx_t_1)); + if (!(likely(PyUnicode_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_t_4)->tp_name), 0))) __PYX_ERR(0, 163, __pyx_L1_error) + __Pyx_XDECREF_SET(__pyx_v_score, __pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF_SET(__pyx_v_value, ((PyObject*)__pyx_t_4)); + __pyx_t_4 = 0; - /* "cfuzzyset.pyx":156 + /* "cfuzzyset.pyx":164 * return [(score / norm, self.exact_set[value]) * for score, value in results - * if score == results[0][0]] # <<<<<<<<<<<<<< + * if score == score_threshold] # <<<<<<<<<<<<<< * * def __len__(self): */ - __pyx_t_5 = __Pyx_GetItemInt(PyList_GET_ITEM(__pyx_v_results, 0), 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 156, __pyx_L1_error) + __pyx_t_5 = PyFloat_FromDouble(__pyx_v_score_threshold); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 164, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __pyx_t_1 = PyObject_RichCompare(__pyx_v_score, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 156, __pyx_L1_error) + __pyx_t_4 = PyObject_RichCompare(__pyx_v_score, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 164, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; - __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 156, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely(__pyx_t_13 < 0)) __PYX_ERR(0, 164, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_13) { - /* "cfuzzyset.pyx":154 - * if score == results[0][0]] + /* "cfuzzyset.pyx":162 * else: + * score_threshold = results[0][0] * self.rel_sim_cutoff * return [(score / norm, self.exact_set[value]) # <<<<<<<<<<<<<< * for score, value in results - * if score == results[0][0]] + * if score == score_threshold] */ - __pyx_t_1 = PyFloat_FromDouble(__pyx_v_norm); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_1); - __pyx_t_5 = __Pyx_PyNumber_Divide(__pyx_v_score, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 154, __pyx_L1_error) + __pyx_t_4 = PyFloat_FromDouble(__pyx_v_norm); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 162, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyNumber_Divide(__pyx_v_score, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 162, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); - __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(__pyx_v_self->exact_set == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 154, __pyx_L1_error) + __PYX_ERR(0, 162, __pyx_L1_error) } - __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_self->exact_set, __pyx_v_value); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 154, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_self->exact_set, __pyx_v_value); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 162, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 162, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 154, __pyx_L1_error) - __Pyx_GOTREF(__pyx_t_7); __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_5); - __Pyx_GIVEREF(__pyx_t_1); - PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_1); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4); __pyx_t_5 = 0; - __pyx_t_1 = 0; - if (unlikely(__Pyx_ListComp_Append(__pyx_t_4, (PyObject*)__pyx_t_7))) __PYX_ERR(0, 154, __pyx_L1_error) - __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_4 = 0; + if (unlikely(__Pyx_ListComp_Append(__pyx_t_7, (PyObject*)__pyx_t_1))) __PYX_ERR(0, 162, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "cfuzzyset.pyx":156 + /* "cfuzzyset.pyx":164 * return [(score / norm, self.exact_set[value]) * for score, value in results - * if score == results[0][0]] # <<<<<<<<<<<<<< + * if score == score_threshold] # <<<<<<<<<<<<<< * * def __len__(self): */ } - /* "cfuzzyset.pyx":155 - * else: + /* "cfuzzyset.pyx":163 + * score_threshold = results[0][0] * self.rel_sim_cutoff * return [(score / norm, self.exact_set[value]) * for score, value in results # <<<<<<<<<<<<<< - * if score == results[0][0]] + * if score == score_threshold] * */ } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_r = __pyx_t_4; - __pyx_t_4 = 0; + __pyx_r = __pyx_t_7; + __pyx_t_7 = 0; goto __pyx_L0; } - /* "cfuzzyset.pyx":112 + /* "cfuzzyset.pyx":117 * @cython.nonecheck(False) * @cython.boundscheck(False) * cpdef _get(self, unicode value, int gram_size): # <<<<<<<<<<<<<< @@ -4362,11 +4585,11 @@ static PyObject *__pyx_pw_9cfuzzyset_9cFuzzySet_11_get(PyObject *__pyx_v_self, P case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_gram_size)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_get", 1, 2, 2, 1); __PYX_ERR(0, 112, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("_get", 1, 2, 2, 1); __PYX_ERR(0, 117, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_get") < 0)) __PYX_ERR(0, 112, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_get") < 0)) __PYX_ERR(0, 117, __pyx_L3_error) } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; @@ -4375,17 +4598,17 @@ static PyObject *__pyx_pw_9cfuzzyset_9cFuzzySet_11_get(PyObject *__pyx_v_self, P values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_value = ((PyObject*)values[0]); - __pyx_v_gram_size = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_gram_size == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 112, __pyx_L3_error) + __pyx_v_gram_size = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_gram_size == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 117, __pyx_L3_error) } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_get", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 112, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("_get", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 117, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("cfuzzyset.cFuzzySet._get", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_value), (&PyUnicode_Type), 1, "value", 1))) __PYX_ERR(0, 112, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_value), (&PyUnicode_Type), 1, "value", 1))) __PYX_ERR(0, 117, __pyx_L1_error) __pyx_r = __pyx_pf_9cfuzzyset_9cFuzzySet_10_get(((struct __pyx_obj_9cfuzzyset_cFuzzySet *)__pyx_v_self), __pyx_v_value, __pyx_v_gram_size); /* function exit code */ @@ -4403,7 +4626,7 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_10_get(struct __pyx_obj_9cfuzzys PyObject *__pyx_t_1 = NULL; __Pyx_RefNannySetupContext("_get", 0); __Pyx_XDECREF(__pyx_r); - __pyx_t_1 = __pyx_f_9cfuzzyset_9cFuzzySet__get(__pyx_v_self, __pyx_v_value, __pyx_v_gram_size, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 112, __pyx_L1_error) + __pyx_t_1 = __pyx_f_9cfuzzyset_9cFuzzySet__get(__pyx_v_self, __pyx_v_value, __pyx_v_gram_size, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 117, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; @@ -4420,8 +4643,8 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_10_get(struct __pyx_obj_9cfuzzys return __pyx_r; } -/* "cfuzzyset.pyx":158 - * if score == results[0][0]] +/* "cfuzzyset.pyx":166 + * if score == score_threshold] * * def __len__(self): # <<<<<<<<<<<<<< * return len(self.exact_set) @@ -4448,7 +4671,7 @@ static Py_ssize_t __pyx_pf_9cfuzzyset_9cFuzzySet_12__len__(struct __pyx_obj_9cfu Py_ssize_t __pyx_t_2; __Pyx_RefNannySetupContext("__len__", 0); - /* "cfuzzyset.pyx":159 + /* "cfuzzyset.pyx":167 * * def __len__(self): * return len(self.exact_set) # <<<<<<<<<<<<<< @@ -4459,15 +4682,15 @@ static Py_ssize_t __pyx_pf_9cfuzzyset_9cFuzzySet_12__len__(struct __pyx_obj_9cfu __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, 159, __pyx_L1_error) + __PYX_ERR(0, 167, __pyx_L1_error) } - __pyx_t_2 = PyDict_Size(__pyx_t_1); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 159, __pyx_L1_error) + __pyx_t_2 = PyDict_Size(__pyx_t_1); if (unlikely(__pyx_t_2 == ((Py_ssize_t)-1))) __PYX_ERR(0, 167, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; goto __pyx_L0; - /* "cfuzzyset.pyx":158 - * if score == results[0][0]] + /* "cfuzzyset.pyx":166 + * if score == score_threshold] * * def __len__(self): # <<<<<<<<<<<<<< * return len(self.exact_set) @@ -4484,7 +4707,7 @@ static Py_ssize_t __pyx_pf_9cfuzzyset_9cFuzzySet_12__len__(struct __pyx_obj_9cfu return __pyx_r; } -/* "cfuzzyset.pyx":161 +/* "cfuzzyset.pyx":169 * return len(self.exact_set) * * def __nonzero__(self): # <<<<<<<<<<<<<< @@ -4511,18 +4734,18 @@ static int __pyx_pf_9cfuzzyset_9cFuzzySet_14__nonzero__(struct __pyx_obj_9cfuzzy int __pyx_t_1; __Pyx_RefNannySetupContext("__nonzero__", 0); - /* "cfuzzyset.pyx":162 + /* "cfuzzyset.pyx":170 * * def __nonzero__(self): * return bool(self.exact_set) # <<<<<<<<<<<<<< * * def get(self, object key, object default=None): */ - __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->exact_set); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 162, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->exact_set); if (unlikely(__pyx_t_1 < 0)) __PYX_ERR(0, 170, __pyx_L1_error) __pyx_r = (!(!__pyx_t_1)); goto __pyx_L0; - /* "cfuzzyset.pyx":161 + /* "cfuzzyset.pyx":169 * return len(self.exact_set) * * def __nonzero__(self): # <<<<<<<<<<<<<< @@ -4539,7 +4762,7 @@ static int __pyx_pf_9cfuzzyset_9cFuzzySet_14__nonzero__(struct __pyx_obj_9cfuzzy return __pyx_r; } -/* "cfuzzyset.pyx":164 +/* "cfuzzyset.pyx":172 * return bool(self.exact_set) * * def get(self, object key, object default=None): # <<<<<<<<<<<<<< @@ -4583,7 +4806,7 @@ static PyObject *__pyx_pw_9cfuzzyset_9cFuzzySet_17get(PyObject *__pyx_v_self, Py } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get") < 0)) __PYX_ERR(0, 164, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "get") < 0)) __PYX_ERR(0, 172, __pyx_L3_error) } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { @@ -4599,7 +4822,7 @@ static PyObject *__pyx_pw_9cfuzzyset_9cFuzzySet_17get(PyObject *__pyx_v_self, Py } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("get", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 164, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("get", 0, 1, 2, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 172, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("cfuzzyset.cFuzzySet.get", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); @@ -4624,7 +4847,7 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_16get(struct __pyx_obj_9cfuzzyse PyObject *__pyx_t_7 = NULL; __Pyx_RefNannySetupContext("get", 0); - /* "cfuzzyset.pyx":165 + /* "cfuzzyset.pyx":173 * * def get(self, object key, object default=None): * try: # <<<<<<<<<<<<<< @@ -4640,7 +4863,7 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_16get(struct __pyx_obj_9cfuzzyse __Pyx_XGOTREF(__pyx_t_3); /*try:*/ { - /* "cfuzzyset.pyx":166 + /* "cfuzzyset.pyx":174 * def get(self, object key, object default=None): * try: * return self[key] # <<<<<<<<<<<<<< @@ -4648,13 +4871,13 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_16get(struct __pyx_obj_9cfuzzyse * return default */ __Pyx_XDECREF(__pyx_r); - __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 166, __pyx_L3_error) + __pyx_t_4 = __Pyx_PyObject_GetItem(((PyObject *)__pyx_v_self), __pyx_v_key); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 174, __pyx_L3_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L7_try_return; - /* "cfuzzyset.pyx":165 + /* "cfuzzyset.pyx":173 * * def get(self, object key, object default=None): * try: # <<<<<<<<<<<<<< @@ -4665,7 +4888,7 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_16get(struct __pyx_obj_9cfuzzyse __pyx_L3_error:; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; - /* "cfuzzyset.pyx":167 + /* "cfuzzyset.pyx":175 * try: * return self[key] * except KeyError: # <<<<<<<<<<<<<< @@ -4675,12 +4898,12 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_16get(struct __pyx_obj_9cfuzzyse __pyx_t_5 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); if (__pyx_t_5) { __Pyx_AddTraceback("cfuzzyset.cFuzzySet.get", __pyx_clineno, __pyx_lineno, __pyx_filename); - if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 167, __pyx_L5_except_error) + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 175, __pyx_L5_except_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GOTREF(__pyx_t_6); __Pyx_GOTREF(__pyx_t_7); - /* "cfuzzyset.pyx":168 + /* "cfuzzyset.pyx":176 * return self[key] * except KeyError: * return default # <<<<<<<<<<<<<< @@ -4698,7 +4921,7 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_16get(struct __pyx_obj_9cfuzzyse goto __pyx_L5_except_error; __pyx_L5_except_error:; - /* "cfuzzyset.pyx":165 + /* "cfuzzyset.pyx":173 * * def get(self, object key, object default=None): * try: # <<<<<<<<<<<<<< @@ -4724,7 +4947,7 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_16get(struct __pyx_obj_9cfuzzyse goto __pyx_L0; } - /* "cfuzzyset.pyx":164 + /* "cfuzzyset.pyx":172 * return bool(self.exact_set) * * def get(self, object key, object default=None): # <<<<<<<<<<<<<< @@ -4745,7 +4968,7 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_16get(struct __pyx_obj_9cfuzzyse return __pyx_r; } -/* "cfuzzyset.pyx":171 +/* "cfuzzyset.pyx":179 * * * def _pickle_creator(exact_set, # <<<<<<<<<<<<<< @@ -4755,7 +4978,7 @@ static PyObject *__pyx_pf_9cfuzzyset_9cFuzzySet_16get(struct __pyx_obj_9cfuzzyse /* Python wrapper */ static PyObject *__pyx_pw_9cfuzzyset_1_pickle_creator(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyMethodDef __pyx_mdef_9cfuzzyset_1_pickle_creator = {"_pickle_creator", (PyCFunction)__pyx_pw_9cfuzzyset_1_pickle_creator, METH_VARARGS|METH_KEYWORDS, 0}; +static PyMethodDef __pyx_mdef_9cfuzzyset_1_pickle_creator = {"_pickle_creator", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_9cfuzzyset_1_pickle_creator, METH_VARARGS|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_9cfuzzyset_1_pickle_creator(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_exact_set = 0; PyObject *__pyx_v_match_dict = 0; @@ -4763,16 +4986,19 @@ static PyObject *__pyx_pw_9cfuzzyset_1_pickle_creator(PyObject *__pyx_self, PyOb PyObject *__pyx_v_gram_size_lower = 0; PyObject *__pyx_v_gram_size_upper = 0; PyObject *__pyx_v_use_levenshtein = 0; + PyObject *__pyx_v_rel_sim_cutoff = 0; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("_pickle_creator (wrapper)", 0); { - static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_exact_set,&__pyx_n_s_match_dict,&__pyx_n_s_items,&__pyx_n_s_gram_size_lower,&__pyx_n_s_gram_size_upper,&__pyx_n_s_use_levenshtein,0}; - PyObject* values[6] = {0,0,0,0,0,0}; + static PyObject **__pyx_pyargnames[] = {&__pyx_n_s_exact_set,&__pyx_n_s_match_dict,&__pyx_n_s_items,&__pyx_n_s_gram_size_lower,&__pyx_n_s_gram_size_upper,&__pyx_n_s_use_levenshtein,&__pyx_n_s_rel_sim_cutoff,0}; + PyObject* values[7] = {0,0,0,0,0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; const Py_ssize_t pos_args = PyTuple_GET_SIZE(__pyx_args); switch (pos_args) { + case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); + CYTHON_FALLTHROUGH; case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); CYTHON_FALLTHROUGH; case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); @@ -4797,37 +5023,43 @@ static PyObject *__pyx_pw_9cfuzzyset_1_pickle_creator(PyObject *__pyx_self, PyOb case 1: if (likely((values[1] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_match_dict)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_pickle_creator", 1, 6, 6, 1); __PYX_ERR(0, 171, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("_pickle_creator", 1, 7, 7, 1); __PYX_ERR(0, 179, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 2: if (likely((values[2] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_items)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_pickle_creator", 1, 6, 6, 2); __PYX_ERR(0, 171, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("_pickle_creator", 1, 7, 7, 2); __PYX_ERR(0, 179, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 3: if (likely((values[3] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_gram_size_lower)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_pickle_creator", 1, 6, 6, 3); __PYX_ERR(0, 171, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("_pickle_creator", 1, 7, 7, 3); __PYX_ERR(0, 179, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 4: if (likely((values[4] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_gram_size_upper)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_pickle_creator", 1, 6, 6, 4); __PYX_ERR(0, 171, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("_pickle_creator", 1, 7, 7, 4); __PYX_ERR(0, 179, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 5: if (likely((values[5] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_use_levenshtein)) != 0)) kw_args--; else { - __Pyx_RaiseArgtupleInvalid("_pickle_creator", 1, 6, 6, 5); __PYX_ERR(0, 171, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("_pickle_creator", 1, 7, 7, 5); __PYX_ERR(0, 179, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 6: + if (likely((values[6] = __Pyx_PyDict_GetItemStr(__pyx_kwds, __pyx_n_s_rel_sim_cutoff)) != 0)) kw_args--; + else { + __Pyx_RaiseArgtupleInvalid("_pickle_creator", 1, 7, 7, 6); __PYX_ERR(0, 179, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { - if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_pickle_creator") < 0)) __PYX_ERR(0, 171, __pyx_L3_error) + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, pos_args, "_pickle_creator") < 0)) __PYX_ERR(0, 179, __pyx_L3_error) } - } else if (PyTuple_GET_SIZE(__pyx_args) != 6) { + } else if (PyTuple_GET_SIZE(__pyx_args) != 7) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); @@ -4836,6 +5068,7 @@ static PyObject *__pyx_pw_9cfuzzyset_1_pickle_creator(PyObject *__pyx_self, PyOb values[3] = PyTuple_GET_ITEM(__pyx_args, 3); values[4] = PyTuple_GET_ITEM(__pyx_args, 4); values[5] = PyTuple_GET_ITEM(__pyx_args, 5); + values[6] = PyTuple_GET_ITEM(__pyx_args, 6); } __pyx_v_exact_set = values[0]; __pyx_v_match_dict = values[1]; @@ -4843,23 +5076,24 @@ static PyObject *__pyx_pw_9cfuzzyset_1_pickle_creator(PyObject *__pyx_self, PyOb __pyx_v_gram_size_lower = values[3]; __pyx_v_gram_size_upper = values[4]; __pyx_v_use_levenshtein = values[5]; + __pyx_v_rel_sim_cutoff = values[6]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; - __Pyx_RaiseArgtupleInvalid("_pickle_creator", 1, 6, 6, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 171, __pyx_L3_error) + __Pyx_RaiseArgtupleInvalid("_pickle_creator", 1, 7, 7, PyTuple_GET_SIZE(__pyx_args)); __PYX_ERR(0, 179, __pyx_L3_error) __pyx_L3_error:; __Pyx_AddTraceback("cfuzzyset._pickle_creator", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; - __pyx_r = __pyx_pf_9cfuzzyset__pickle_creator(__pyx_self, __pyx_v_exact_set, __pyx_v_match_dict, __pyx_v_items, __pyx_v_gram_size_lower, __pyx_v_gram_size_upper, __pyx_v_use_levenshtein); + __pyx_r = __pyx_pf_9cfuzzyset__pickle_creator(__pyx_self, __pyx_v_exact_set, __pyx_v_match_dict, __pyx_v_items, __pyx_v_gram_size_lower, __pyx_v_gram_size_upper, __pyx_v_use_levenshtein, __pyx_v_rel_sim_cutoff); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } -static PyObject *__pyx_pf_9cfuzzyset__pickle_creator(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_exact_set, PyObject *__pyx_v_match_dict, PyObject *__pyx_v_items, PyObject *__pyx_v_gram_size_lower, PyObject *__pyx_v_gram_size_upper, PyObject *__pyx_v_use_levenshtein) { +static PyObject *__pyx_pf_9cfuzzyset__pickle_creator(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_exact_set, PyObject *__pyx_v_match_dict, PyObject *__pyx_v_items, PyObject *__pyx_v_gram_size_lower, PyObject *__pyx_v_gram_size_upper, PyObject *__pyx_v_use_levenshtein, PyObject *__pyx_v_rel_sim_cutoff) { struct __pyx_obj_9cfuzzyset_cFuzzySet *__pyx_v_result = NULL; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations @@ -4867,14 +5101,14 @@ static PyObject *__pyx_pf_9cfuzzyset__pickle_creator(CYTHON_UNUSED PyObject *__p PyObject *__pyx_t_2 = NULL; __Pyx_RefNannySetupContext("_pickle_creator", 0); - /* "cfuzzyset.pyx":177 - * gram_size_upper, - * use_levenshtein): - * result = cFuzzySet((), gram_size_lower, gram_size_upper, use_levenshtein) # <<<<<<<<<<<<<< + /* "cfuzzyset.pyx":186 + * use_levenshtein, + * rel_sim_cutoff): + * result = cFuzzySet((), gram_size_lower, gram_size_upper, use_levenshtein, rel_sim_cutoff) # <<<<<<<<<<<<<< * result.match_dict = match_dict * result.exact_set = exact_set */ - __pyx_t_1 = PyTuple_New(4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 177, __pyx_L1_error) + __pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 186, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_empty_tuple); __Pyx_GIVEREF(__pyx_empty_tuple); @@ -4888,20 +5122,23 @@ static PyObject *__pyx_pf_9cfuzzyset__pickle_creator(CYTHON_UNUSED PyObject *__p __Pyx_INCREF(__pyx_v_use_levenshtein); __Pyx_GIVEREF(__pyx_v_use_levenshtein); PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_use_levenshtein); - __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_9cfuzzyset_cFuzzySet), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 177, __pyx_L1_error) + __Pyx_INCREF(__pyx_v_rel_sim_cutoff); + __Pyx_GIVEREF(__pyx_v_rel_sim_cutoff); + PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_v_rel_sim_cutoff); + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_9cfuzzyset_cFuzzySet), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 186, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_result = ((struct __pyx_obj_9cfuzzyset_cFuzzySet *)__pyx_t_2); __pyx_t_2 = 0; - /* "cfuzzyset.pyx":178 - * use_levenshtein): - * result = cFuzzySet((), gram_size_lower, gram_size_upper, use_levenshtein) + /* "cfuzzyset.pyx":187 + * rel_sim_cutoff): + * result = cFuzzySet((), gram_size_lower, gram_size_upper, use_levenshtein, rel_sim_cutoff) * result.match_dict = match_dict # <<<<<<<<<<<<<< * result.exact_set = exact_set * result.items = items */ - if (!(likely(PyDict_CheckExact(__pyx_v_match_dict))||((__pyx_v_match_dict) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_v_match_dict)->tp_name), 0))) __PYX_ERR(0, 178, __pyx_L1_error) + if (!(likely(PyDict_CheckExact(__pyx_v_match_dict))||((__pyx_v_match_dict) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_v_match_dict)->tp_name), 0))) __PYX_ERR(0, 187, __pyx_L1_error) __pyx_t_2 = __pyx_v_match_dict; __Pyx_INCREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); @@ -4910,14 +5147,14 @@ static PyObject *__pyx_pf_9cfuzzyset__pickle_creator(CYTHON_UNUSED PyObject *__p __pyx_v_result->match_dict = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "cfuzzyset.pyx":179 - * result = cFuzzySet((), gram_size_lower, gram_size_upper, use_levenshtein) + /* "cfuzzyset.pyx":188 + * result = cFuzzySet((), gram_size_lower, gram_size_upper, use_levenshtein, rel_sim_cutoff) * result.match_dict = match_dict * result.exact_set = exact_set # <<<<<<<<<<<<<< * result.items = items * return result */ - if (!(likely(PyDict_CheckExact(__pyx_v_exact_set))||((__pyx_v_exact_set) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_v_exact_set)->tp_name), 0))) __PYX_ERR(0, 179, __pyx_L1_error) + if (!(likely(PyDict_CheckExact(__pyx_v_exact_set))||((__pyx_v_exact_set) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_v_exact_set)->tp_name), 0))) __PYX_ERR(0, 188, __pyx_L1_error) __pyx_t_2 = __pyx_v_exact_set; __Pyx_INCREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); @@ -4926,14 +5163,14 @@ static PyObject *__pyx_pf_9cfuzzyset__pickle_creator(CYTHON_UNUSED PyObject *__p __pyx_v_result->exact_set = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "cfuzzyset.pyx":180 + /* "cfuzzyset.pyx":189 * result.match_dict = match_dict * result.exact_set = exact_set * result.items = items # <<<<<<<<<<<<<< * return result * */ - if (!(likely(PyDict_CheckExact(__pyx_v_items))||((__pyx_v_items) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_v_items)->tp_name), 0))) __PYX_ERR(0, 180, __pyx_L1_error) + if (!(likely(PyDict_CheckExact(__pyx_v_items))||((__pyx_v_items) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "dict", Py_TYPE(__pyx_v_items)->tp_name), 0))) __PYX_ERR(0, 189, __pyx_L1_error) __pyx_t_2 = __pyx_v_items; __Pyx_INCREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); @@ -4942,7 +5179,7 @@ static PyObject *__pyx_pf_9cfuzzyset__pickle_creator(CYTHON_UNUSED PyObject *__p __pyx_v_result->items = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; - /* "cfuzzyset.pyx":181 + /* "cfuzzyset.pyx":190 * result.exact_set = exact_set * result.items = items * return result # <<<<<<<<<<<<<< @@ -4954,7 +5191,7 @@ static PyObject *__pyx_pf_9cfuzzyset__pickle_creator(CYTHON_UNUSED PyObject *__p __pyx_r = ((PyObject *)__pyx_v_result); goto __pyx_L0; - /* "cfuzzyset.pyx":171 + /* "cfuzzyset.pyx":179 * * * def _pickle_creator(exact_set, # <<<<<<<<<<<<<< @@ -4975,7 +5212,7 @@ static PyObject *__pyx_pf_9cfuzzyset__pickle_creator(CYTHON_UNUSED PyObject *__p return __pyx_r; } -/* "cfuzzyset.pyx":185 +/* "cfuzzyset.pyx":194 * * @cython.boundscheck(False) * cdef dict _gram_counter(unicode value, int gram_size=2): # <<<<<<<<<<<<<< @@ -5007,19 +5244,19 @@ static PyObject *__pyx_f_9cfuzzyset__gram_counter(PyObject *__pyx_v_value, struc } } - /* "cfuzzyset.pyx":186 + /* "cfuzzyset.pyx":195 * @cython.boundscheck(False) * cdef dict _gram_counter(unicode value, int gram_size=2): * cdef dict results = {} # <<<<<<<<<<<<<< * cdef list grams = _iterate_grams(value, gram_size) * cdef unicode gram */ - __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 186, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 195, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_results = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "cfuzzyset.pyx":187 + /* "cfuzzyset.pyx":196 * cdef dict _gram_counter(unicode value, int gram_size=2): * cdef dict results = {} * cdef list grams = _iterate_grams(value, gram_size) # <<<<<<<<<<<<<< @@ -5028,12 +5265,12 @@ static PyObject *__pyx_f_9cfuzzyset__gram_counter(PyObject *__pyx_v_value, struc */ __pyx_t_2.__pyx_n = 1; __pyx_t_2.gram_size = __pyx_v_gram_size; - __pyx_t_1 = __pyx_f_9cfuzzyset__iterate_grams(__pyx_v_value, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 187, __pyx_L1_error) + __pyx_t_1 = __pyx_f_9cfuzzyset__iterate_grams(__pyx_v_value, &__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 196, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_grams = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "cfuzzyset.pyx":190 + /* "cfuzzyset.pyx":199 * cdef unicode gram * cdef int i * for i in range(len(grams)): # <<<<<<<<<<<<<< @@ -5042,14 +5279,14 @@ static PyObject *__pyx_f_9cfuzzyset__gram_counter(PyObject *__pyx_v_value, struc */ if (unlikely(__pyx_v_grams == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 190, __pyx_L1_error) + __PYX_ERR(0, 199, __pyx_L1_error) } - __pyx_t_3 = PyList_GET_SIZE(__pyx_v_grams); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 190, __pyx_L1_error) + __pyx_t_3 = PyList_GET_SIZE(__pyx_v_grams); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(0, 199, __pyx_L1_error) __pyx_t_4 = __pyx_t_3; for (__pyx_t_5 = 0; __pyx_t_5 < __pyx_t_4; __pyx_t_5+=1) { __pyx_v_i = __pyx_t_5; - /* "cfuzzyset.pyx":191 + /* "cfuzzyset.pyx":200 * cdef int i * for i in range(len(grams)): * gram = grams[i] # <<<<<<<<<<<<<< @@ -5058,35 +5295,35 @@ static PyObject *__pyx_f_9cfuzzyset__gram_counter(PyObject *__pyx_v_value, struc */ if (unlikely(__pyx_v_grams == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 191, __pyx_L1_error) + __PYX_ERR(0, 200, __pyx_L1_error) } - __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_grams, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 191, __pyx_L1_error) + __pyx_t_1 = __Pyx_GetItemInt_List(__pyx_v_grams, __pyx_v_i, int, 1, __Pyx_PyInt_From_int, 1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 200, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - 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, 191, __pyx_L1_error) + 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, 200, __pyx_L1_error) __Pyx_XDECREF_SET(__pyx_v_gram, ((PyObject*)__pyx_t_1)); __pyx_t_1 = 0; - /* "cfuzzyset.pyx":192 + /* "cfuzzyset.pyx":201 * for i in range(len(grams)): * gram = grams[i] * if gram not in results: # <<<<<<<<<<<<<< * results[gram] = 1 * else: */ - __pyx_t_6 = (__Pyx_PyDict_ContainsTF(__pyx_v_gram, __pyx_v_results, Py_NE)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 192, __pyx_L1_error) + __pyx_t_6 = (__Pyx_PyDict_ContainsTF(__pyx_v_gram, __pyx_v_results, Py_NE)); if (unlikely(__pyx_t_6 < 0)) __PYX_ERR(0, 201, __pyx_L1_error) __pyx_t_7 = (__pyx_t_6 != 0); if (__pyx_t_7) { - /* "cfuzzyset.pyx":193 + /* "cfuzzyset.pyx":202 * gram = grams[i] * if gram not in results: * results[gram] = 1 # <<<<<<<<<<<<<< * else: * results[gram] += 1 */ - if (unlikely(PyDict_SetItem(__pyx_v_results, __pyx_v_gram, __pyx_int_1) < 0)) __PYX_ERR(0, 193, __pyx_L1_error) + if (unlikely(PyDict_SetItem(__pyx_v_results, __pyx_v_gram, __pyx_int_1) < 0)) __PYX_ERR(0, 202, __pyx_L1_error) - /* "cfuzzyset.pyx":192 + /* "cfuzzyset.pyx":201 * for i in range(len(grams)): * gram = grams[i] * if gram not in results: # <<<<<<<<<<<<<< @@ -5096,7 +5333,7 @@ static PyObject *__pyx_f_9cfuzzyset__gram_counter(PyObject *__pyx_v_value, struc goto __pyx_L5; } - /* "cfuzzyset.pyx":195 + /* "cfuzzyset.pyx":204 * results[gram] = 1 * else: * results[gram] += 1 # <<<<<<<<<<<<<< @@ -5106,19 +5343,19 @@ static PyObject *__pyx_f_9cfuzzyset__gram_counter(PyObject *__pyx_v_value, struc /*else*/ { __Pyx_INCREF(__pyx_v_gram); __pyx_t_8 = __pyx_v_gram; - __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_results, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 195, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_results, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 204, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 195, __pyx_L1_error) + __pyx_t_9 = __Pyx_PyInt_AddObjC(__pyx_t_1, __pyx_int_1, 1, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 204, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - if (unlikely(PyDict_SetItem(__pyx_v_results, __pyx_t_8, __pyx_t_9) < 0)) __PYX_ERR(0, 195, __pyx_L1_error) + if (unlikely(PyDict_SetItem(__pyx_v_results, __pyx_t_8, __pyx_t_9) < 0)) __PYX_ERR(0, 204, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } __pyx_L5:; } - /* "cfuzzyset.pyx":196 + /* "cfuzzyset.pyx":205 * else: * results[gram] += 1 * return results # <<<<<<<<<<<<<< @@ -5130,7 +5367,7 @@ static PyObject *__pyx_f_9cfuzzyset__gram_counter(PyObject *__pyx_v_value, struc __pyx_r = __pyx_v_results; goto __pyx_L0; - /* "cfuzzyset.pyx":185 + /* "cfuzzyset.pyx":194 * * @cython.boundscheck(False) * cdef dict _gram_counter(unicode value, int gram_size=2): # <<<<<<<<<<<<<< @@ -5154,7 +5391,7 @@ static PyObject *__pyx_f_9cfuzzyset__gram_counter(PyObject *__pyx_v_value, struc return __pyx_r; } -/* "cfuzzyset.pyx":200 +/* "cfuzzyset.pyx":209 * cdef unicode hyphens = u'-----------' * * cdef list _iterate_grams(unicode value, int gram_size=2): # <<<<<<<<<<<<<< @@ -5189,14 +5426,14 @@ static PyObject *__pyx_f_9cfuzzyset__iterate_grams(PyObject *__pyx_v_value, stru } __Pyx_INCREF(__pyx_v_value); - /* "cfuzzyset.pyx":201 + /* "cfuzzyset.pyx":210 * * cdef list _iterate_grams(unicode value, int gram_size=2): * cdef unicode simplified = u'-' + _non_word_re.sub('', value) + u'-' # <<<<<<<<<<<<<< * cdef int len_diff = gram_size - len(simplified) * cdef list result = [] */ - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_9cfuzzyset__non_word_re, __pyx_n_s_sub); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 201, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_9cfuzzyset__non_word_re, __pyx_n_s_sub); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 210, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; __pyx_t_4 = 0; @@ -5212,48 +5449,48 @@ static PyObject *__pyx_f_9cfuzzyset__iterate_grams(PyObject *__pyx_v_value, stru } #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_2)) { - PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_kp_s__4, __pyx_v_value}; - __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, 201, __pyx_L1_error) + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_kp_s__2, __pyx_v_value}; + __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, 210, __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, __pyx_kp_s__4, __pyx_v_value}; - __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, 201, __pyx_L1_error) + PyObject *__pyx_temp[3] = {__pyx_t_3, __pyx_kp_s__2, __pyx_v_value}; + __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, 210, __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, 201, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 210, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (__pyx_t_3) { __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3); __pyx_t_3 = NULL; } - __Pyx_INCREF(__pyx_kp_s__4); - __Pyx_GIVEREF(__pyx_kp_s__4); - PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_kp_s__4); + __Pyx_INCREF(__pyx_kp_s__2); + __Pyx_GIVEREF(__pyx_kp_s__2); + PyTuple_SET_ITEM(__pyx_t_5, 0+__pyx_t_4, __pyx_kp_s__2); __Pyx_INCREF(__pyx_v_value); __Pyx_GIVEREF(__pyx_v_value); PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_value); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 201, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 210, __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 = PyNumber_Add(__pyx_kp_u__3, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 201, __pyx_L1_error) + __pyx_t_2 = PyNumber_Add(__pyx_kp_u_, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 210, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = PyNumber_Add(__pyx_t_2, __pyx_kp_u__3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 201, __pyx_L1_error) + __pyx_t_1 = PyNumber_Add(__pyx_t_2, __pyx_kp_u_); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 210, __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, 201, __pyx_L1_error) + 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, 210, __pyx_L1_error) __pyx_v_simplified = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "cfuzzyset.pyx":202 + /* "cfuzzyset.pyx":211 * cdef list _iterate_grams(unicode value, int gram_size=2): * cdef unicode simplified = u'-' + _non_word_re.sub('', value) + u'-' * cdef int len_diff = gram_size - len(simplified) # <<<<<<<<<<<<<< @@ -5262,24 +5499,24 @@ static PyObject *__pyx_f_9cfuzzyset__iterate_grams(PyObject *__pyx_v_value, stru */ if (unlikely(__pyx_v_simplified == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 202, __pyx_L1_error) + __PYX_ERR(0, 211, __pyx_L1_error) } - __pyx_t_6 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_simplified); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 202, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_simplified); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 211, __pyx_L1_error) __pyx_v_len_diff = (__pyx_v_gram_size - __pyx_t_6); - /* "cfuzzyset.pyx":203 + /* "cfuzzyset.pyx":212 * cdef unicode simplified = u'-' + _non_word_re.sub('', value) + u'-' * cdef int len_diff = gram_size - len(simplified) * cdef list result = [] # <<<<<<<<<<<<<< * with cython.boundscheck(False): * if len_diff > 0: */ - __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 203, __pyx_L1_error) + __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 212, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_result = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; - /* "cfuzzyset.pyx":205 + /* "cfuzzyset.pyx":214 * cdef list result = [] * with cython.boundscheck(False): * if len_diff > 0: # <<<<<<<<<<<<<< @@ -5289,7 +5526,7 @@ static PyObject *__pyx_f_9cfuzzyset__iterate_grams(PyObject *__pyx_v_value, stru __pyx_t_7 = ((__pyx_v_len_diff > 0) != 0); if (__pyx_t_7) { - /* "cfuzzyset.pyx":206 + /* "cfuzzyset.pyx":215 * with cython.boundscheck(False): * if len_diff > 0: * value += hyphens[:len_diff] # <<<<<<<<<<<<<< @@ -5298,17 +5535,17 @@ static PyObject *__pyx_f_9cfuzzyset__iterate_grams(PyObject *__pyx_v_value, stru */ if (unlikely(__pyx_v_9cfuzzyset_hyphens == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 206, __pyx_L1_error) + __PYX_ERR(0, 215, __pyx_L1_error) } - __pyx_t_1 = __Pyx_PyUnicode_Substring(__pyx_v_9cfuzzyset_hyphens, 0, __pyx_v_len_diff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 206, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyUnicode_Substring(__pyx_v_9cfuzzyset_hyphens, 0, __pyx_v_len_diff); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 215, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - __pyx_t_2 = __Pyx_PyUnicode_ConcatSafe(__pyx_v_value, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 206, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyUnicode_ConcatSafe(__pyx_v_value, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 215, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_value, ((PyObject*)__pyx_t_2)); __pyx_t_2 = 0; - /* "cfuzzyset.pyx":205 + /* "cfuzzyset.pyx":214 * cdef list result = [] * with cython.boundscheck(False): * if len_diff > 0: # <<<<<<<<<<<<<< @@ -5317,7 +5554,7 @@ static PyObject *__pyx_f_9cfuzzyset__iterate_grams(PyObject *__pyx_v_value, stru */ } - /* "cfuzzyset.pyx":207 + /* "cfuzzyset.pyx":216 * if len_diff > 0: * value += hyphens[:len_diff] * cdef int iterations = len(simplified) - gram_size + 1 # <<<<<<<<<<<<<< @@ -5326,12 +5563,12 @@ static PyObject *__pyx_f_9cfuzzyset__iterate_grams(PyObject *__pyx_v_value, stru */ if (unlikely(__pyx_v_simplified == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 207, __pyx_L1_error) + __PYX_ERR(0, 216, __pyx_L1_error) } - __pyx_t_6 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_simplified); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 207, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_simplified); if (unlikely(__pyx_t_6 == ((Py_ssize_t)-1))) __PYX_ERR(0, 216, __pyx_L1_error) __pyx_v_iterations = ((__pyx_t_6 - __pyx_v_gram_size) + 1); - /* "cfuzzyset.pyx":210 + /* "cfuzzyset.pyx":219 * cdef int i * with cython.boundscheck(False): * for i in range(iterations): # <<<<<<<<<<<<<< @@ -5343,7 +5580,7 @@ static PyObject *__pyx_f_9cfuzzyset__iterate_grams(PyObject *__pyx_v_value, stru for (__pyx_t_9 = 0; __pyx_t_9 < __pyx_t_8; __pyx_t_9+=1) { __pyx_v_i = __pyx_t_9; - /* "cfuzzyset.pyx":211 + /* "cfuzzyset.pyx":220 * with cython.boundscheck(False): * for i in range(iterations): * result.append(simplified[i:i + gram_size]) # <<<<<<<<<<<<<< @@ -5352,15 +5589,15 @@ static PyObject *__pyx_f_9cfuzzyset__iterate_grams(PyObject *__pyx_v_value, stru */ if (unlikely(__pyx_v_simplified == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); - __PYX_ERR(0, 211, __pyx_L1_error) + __PYX_ERR(0, 220, __pyx_L1_error) } - __pyx_t_2 = __Pyx_PyUnicode_Substring(__pyx_v_simplified, __pyx_v_i, (__pyx_v_i + __pyx_v_gram_size)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 211, __pyx_L1_error) + __pyx_t_2 = __Pyx_PyUnicode_Substring(__pyx_v_simplified, __pyx_v_i, (__pyx_v_i + __pyx_v_gram_size)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 220, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_2); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 211, __pyx_L1_error) + __pyx_t_10 = __Pyx_PyList_Append(__pyx_v_result, __pyx_t_2); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 220, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } - /* "cfuzzyset.pyx":212 + /* "cfuzzyset.pyx":221 * for i in range(iterations): * result.append(simplified[i:i + gram_size]) * return result # <<<<<<<<<<<<<< @@ -5372,7 +5609,7 @@ static PyObject *__pyx_f_9cfuzzyset__iterate_grams(PyObject *__pyx_v_value, stru __pyx_r = __pyx_v_result; goto __pyx_L0; - /* "cfuzzyset.pyx":200 + /* "cfuzzyset.pyx":209 * cdef unicode hyphens = u'-----------' * * cdef list _iterate_grams(unicode value, int gram_size=2): # <<<<<<<<<<<<<< @@ -5397,7 +5634,7 @@ static PyObject *__pyx_f_9cfuzzyset__iterate_grams(PyObject *__pyx_v_value, stru return __pyx_r; } -/* "cfuzzyset.pyx":214 +/* "cfuzzyset.pyx":223 * return result * * cdef unicode _convert_val(object value): # <<<<<<<<<<<<<< @@ -5414,7 +5651,7 @@ static PyObject *__pyx_f_9cfuzzyset__convert_val(PyObject *__pyx_v_value) { PyObject *__pyx_t_4 = NULL; __Pyx_RefNannySetupContext("_convert_val", 0); - /* "cfuzzyset.pyx":215 + /* "cfuzzyset.pyx":224 * * cdef unicode _convert_val(object value): * if isinstance(value, unicode): # <<<<<<<<<<<<<< @@ -5425,7 +5662,7 @@ static PyObject *__pyx_f_9cfuzzyset__convert_val(PyObject *__pyx_v_value) { __pyx_t_2 = (__pyx_t_1 != 0); if (__pyx_t_2) { - /* "cfuzzyset.pyx":216 + /* "cfuzzyset.pyx":225 * cdef unicode _convert_val(object value): * if isinstance(value, unicode): * return value # <<<<<<<<<<<<<< @@ -5433,12 +5670,12 @@ static PyObject *__pyx_f_9cfuzzyset__convert_val(PyObject *__pyx_v_value) { * return unicode(value) */ __Pyx_XDECREF(__pyx_r); - if (!(likely(PyUnicode_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 216, __pyx_L1_error) + if (!(likely(PyUnicode_CheckExact(__pyx_v_value))||((__pyx_v_value) == Py_None)||(PyErr_Format(PyExc_TypeError, "Expected %.16s, got %.200s", "unicode", Py_TYPE(__pyx_v_value)->tp_name), 0))) __PYX_ERR(0, 225, __pyx_L1_error) __Pyx_INCREF(__pyx_v_value); __pyx_r = ((PyObject*)__pyx_v_value); goto __pyx_L0; - /* "cfuzzyset.pyx":215 + /* "cfuzzyset.pyx":224 * * cdef unicode _convert_val(object value): * if isinstance(value, unicode): # <<<<<<<<<<<<<< @@ -5447,7 +5684,7 @@ static PyObject *__pyx_f_9cfuzzyset__convert_val(PyObject *__pyx_v_value) { */ } - /* "cfuzzyset.pyx":217 + /* "cfuzzyset.pyx":226 * if isinstance(value, unicode): * return value * elif isinstance(value, str): # <<<<<<<<<<<<<< @@ -5458,7 +5695,7 @@ static PyObject *__pyx_f_9cfuzzyset__convert_val(PyObject *__pyx_v_value) { __pyx_t_1 = (__pyx_t_2 != 0); if (likely(__pyx_t_1)) { - /* "cfuzzyset.pyx":218 + /* "cfuzzyset.pyx":227 * return value * elif isinstance(value, str): * return unicode(value) # <<<<<<<<<<<<<< @@ -5466,13 +5703,13 @@ static PyObject *__pyx_f_9cfuzzyset__convert_val(PyObject *__pyx_v_value) { * raise TypeError("Expecting string or unicode, received " + value) */ __Pyx_XDECREF(__pyx_r); - __pyx_t_3 = __Pyx_PyObject_Unicode(__pyx_v_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 218, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_Unicode(__pyx_v_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 227, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L0; - /* "cfuzzyset.pyx":217 + /* "cfuzzyset.pyx":226 * if isinstance(value, unicode): * return value * elif isinstance(value, str): # <<<<<<<<<<<<<< @@ -5481,7 +5718,7 @@ static PyObject *__pyx_f_9cfuzzyset__convert_val(PyObject *__pyx_v_value) { */ } - /* "cfuzzyset.pyx":220 + /* "cfuzzyset.pyx":229 * return unicode(value) * else: * raise TypeError("Expecting string or unicode, received " + value) # <<<<<<<<<<<<<< @@ -5489,17 +5726,17 @@ static PyObject *__pyx_f_9cfuzzyset__convert_val(PyObject *__pyx_v_value) { * cdef double distance(unicode str1, unicode str2): */ /*else*/ { - __pyx_t_3 = PyNumber_Add(__pyx_kp_s_Expecting_string_or_unicode_rece, __pyx_v_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 220, __pyx_L1_error) + __pyx_t_3 = PyNumber_Add(__pyx_kp_s_Expecting_string_or_unicode_rece, __pyx_v_value); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 229, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 220, __pyx_L1_error) + __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 229, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __PYX_ERR(0, 220, __pyx_L1_error) + __PYX_ERR(0, 229, __pyx_L1_error) } - /* "cfuzzyset.pyx":214 + /* "cfuzzyset.pyx":223 * return result * * cdef unicode _convert_val(object value): # <<<<<<<<<<<<<< @@ -5519,7 +5756,7 @@ static PyObject *__pyx_f_9cfuzzyset__convert_val(PyObject *__pyx_v_value) { return __pyx_r; } -/* "cfuzzyset.pyx":222 +/* "cfuzzyset.pyx":231 * raise TypeError("Expecting string or unicode, received " + value) * * cdef double distance(unicode str1, unicode str2): # <<<<<<<<<<<<<< @@ -5542,16 +5779,16 @@ static double __pyx_f_9cfuzzyset_distance(PyObject *__pyx_v_str1, PyObject *__py int __pyx_t_9; __Pyx_RefNannySetupContext("distance", 0); - /* "cfuzzyset.pyx":223 + /* "cfuzzyset.pyx":232 * * cdef double distance(unicode str1, unicode str2): * cdef double result = Levenshtein.distance(str1, str2) # <<<<<<<<<<<<<< * if len(str1) > len(str2): * return 1 - result / len(str1) */ - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_Levenshtein); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 223, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_Levenshtein); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 232, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); - __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_distance); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 223, __pyx_L1_error) + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_distance); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 232, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = NULL; @@ -5569,7 +5806,7 @@ static double __pyx_f_9cfuzzyset_distance(PyObject *__pyx_v_str1, PyObject *__py #if CYTHON_FAST_PYCALL if (PyFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_str1, __pyx_v_str2}; - __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 223, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 232, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GOTREF(__pyx_t_1); } else @@ -5577,13 +5814,13 @@ static double __pyx_f_9cfuzzyset_distance(PyObject *__pyx_v_str1, PyObject *__py #if CYTHON_FAST_PYCCALL if (__Pyx_PyFastCFunction_Check(__pyx_t_3)) { PyObject *__pyx_temp[3] = {__pyx_t_2, __pyx_v_str1, __pyx_v_str2}; - __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 223, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyCFunction_FastCall(__pyx_t_3, __pyx_temp+1-__pyx_t_4, 2+__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 232, __pyx_L1_error) __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_GOTREF(__pyx_t_1); } else #endif { - __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 223, __pyx_L1_error) + __pyx_t_5 = PyTuple_New(2+__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 232, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (__pyx_t_2) { __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_2); __pyx_t_2 = NULL; @@ -5594,16 +5831,16 @@ static double __pyx_f_9cfuzzyset_distance(PyObject *__pyx_v_str1, PyObject *__py __Pyx_INCREF(__pyx_v_str2); __Pyx_GIVEREF(__pyx_v_str2); PyTuple_SET_ITEM(__pyx_t_5, 1+__pyx_t_4, __pyx_v_str2); - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 223, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 232, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; - __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 223, __pyx_L1_error) + __pyx_t_6 = __pyx_PyFloat_AsDouble(__pyx_t_1); if (unlikely((__pyx_t_6 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 232, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_result = __pyx_t_6; - /* "cfuzzyset.pyx":224 + /* "cfuzzyset.pyx":233 * cdef double distance(unicode str1, unicode str2): * cdef double result = Levenshtein.distance(str1, str2) * if len(str1) > len(str2): # <<<<<<<<<<<<<< @@ -5612,18 +5849,18 @@ static double __pyx_f_9cfuzzyset_distance(PyObject *__pyx_v_str1, PyObject *__py */ if (unlikely(__pyx_v_str1 == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 224, __pyx_L1_error) + __PYX_ERR(0, 233, __pyx_L1_error) } - __pyx_t_7 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_str1); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 224, __pyx_L1_error) + __pyx_t_7 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_str1); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 233, __pyx_L1_error) if (unlikely(__pyx_v_str2 == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 224, __pyx_L1_error) + __PYX_ERR(0, 233, __pyx_L1_error) } - __pyx_t_8 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_str2); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 224, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_str2); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 233, __pyx_L1_error) __pyx_t_9 = ((__pyx_t_7 > __pyx_t_8) != 0); if (__pyx_t_9) { - /* "cfuzzyset.pyx":225 + /* "cfuzzyset.pyx":234 * cdef double result = Levenshtein.distance(str1, str2) * if len(str1) > len(str2): * return 1 - result / len(str1) # <<<<<<<<<<<<<< @@ -5632,17 +5869,17 @@ static double __pyx_f_9cfuzzyset_distance(PyObject *__pyx_v_str1, PyObject *__py */ if (unlikely(__pyx_v_str1 == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 225, __pyx_L1_error) + __PYX_ERR(0, 234, __pyx_L1_error) } - __pyx_t_8 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_str1); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 225, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_str1); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 234, __pyx_L1_error) if (unlikely(__pyx_t_8 == 0)) { PyErr_SetString(PyExc_ZeroDivisionError, "float division"); - __PYX_ERR(0, 225, __pyx_L1_error) + __PYX_ERR(0, 234, __pyx_L1_error) } __pyx_r = (1.0 - (__pyx_v_result / __pyx_t_8)); goto __pyx_L0; - /* "cfuzzyset.pyx":224 + /* "cfuzzyset.pyx":233 * cdef double distance(unicode str1, unicode str2): * cdef double result = Levenshtein.distance(str1, str2) * if len(str1) > len(str2): # <<<<<<<<<<<<<< @@ -5651,7 +5888,7 @@ static double __pyx_f_9cfuzzyset_distance(PyObject *__pyx_v_str1, PyObject *__py */ } - /* "cfuzzyset.pyx":227 + /* "cfuzzyset.pyx":236 * return 1 - result / len(str1) * else: * return 1 - result / len(str2) # <<<<<<<<<<<<<< @@ -5659,18 +5896,18 @@ static double __pyx_f_9cfuzzyset_distance(PyObject *__pyx_v_str1, PyObject *__py /*else*/ { if (unlikely(__pyx_v_str2 == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); - __PYX_ERR(0, 227, __pyx_L1_error) + __PYX_ERR(0, 236, __pyx_L1_error) } - __pyx_t_8 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_str2); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 227, __pyx_L1_error) + __pyx_t_8 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_str2); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 236, __pyx_L1_error) if (unlikely(__pyx_t_8 == 0)) { PyErr_SetString(PyExc_ZeroDivisionError, "float division"); - __PYX_ERR(0, 227, __pyx_L1_error) + __PYX_ERR(0, 236, __pyx_L1_error) } __pyx_r = (1.0 - (__pyx_v_result / __pyx_t_8)); goto __pyx_L0; } - /* "cfuzzyset.pyx":222 + /* "cfuzzyset.pyx":231 * raise TypeError("Expecting string or unicode, received " + value) * * cdef double distance(unicode str1, unicode str2): # <<<<<<<<<<<<<< @@ -5767,9 +6004,9 @@ static PyObject *__pyx_sq_item_9cfuzzyset_cFuzzySet(PyObject *o, Py_ssize_t i) { static PyMethodDef __pyx_methods_9cfuzzyset_cFuzzySet[] = { {"__reduce__", (PyCFunction)__pyx_pw_9cfuzzyset_9cFuzzySet_3__reduce__, METH_NOARGS, 0}, {"add", (PyCFunction)__pyx_pw_9cfuzzyset_9cFuzzySet_5add, METH_O, 0}, - {"_add", (PyCFunction)__pyx_pw_9cfuzzyset_9cFuzzySet_7_add, METH_VARARGS|METH_KEYWORDS, 0}, - {"_get", (PyCFunction)__pyx_pw_9cfuzzyset_9cFuzzySet_11_get, METH_VARARGS|METH_KEYWORDS, 0}, - {"get", (PyCFunction)__pyx_pw_9cfuzzyset_9cFuzzySet_17get, METH_VARARGS|METH_KEYWORDS, 0}, + {"_add", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_9cfuzzyset_9cFuzzySet_7_add, METH_VARARGS|METH_KEYWORDS, 0}, + {"_get", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_9cfuzzyset_9cFuzzySet_11_get, METH_VARARGS|METH_KEYWORDS, 0}, + {"get", (PyCFunction)(void*)(PyCFunctionWithKeywords)__pyx_pw_9cfuzzyset_9cFuzzySet_17get, METH_VARARGS|METH_KEYWORDS, 0}, {0, 0, 0, 0} }; @@ -5947,18 +6184,28 @@ static struct PyModuleDef __pyx_moduledef = { NULL /* m_free */ }; #endif +#ifndef CYTHON_SMALL_CODE +#if defined(__clang__) + #define CYTHON_SMALL_CODE +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) + #define CYTHON_SMALL_CODE __attribute__((cold)) +#else + #define CYTHON_SMALL_CODE +#endif +#endif static __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_kp_u_, __pyx_k_, sizeof(__pyx_k_), 0, 1, 0, 0}, {&__pyx_kp_s_Expecting_string_or_unicode_rece, __pyx_k_Expecting_string_or_unicode_rece, sizeof(__pyx_k_Expecting_string_or_unicode_rece), 0, 0, 1, 0}, {&__pyx_n_s_KeyError, __pyx_k_KeyError, sizeof(__pyx_k_KeyError), 0, 0, 1, 1}, {&__pyx_n_s_Levenshtein, __pyx_k_Levenshtein, sizeof(__pyx_k_Levenshtein), 0, 0, 1, 1}, {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1}, - {&__pyx_kp_u__3, __pyx_k__3, sizeof(__pyx_k__3), 0, 1, 0, 0}, - {&__pyx_kp_s__4, __pyx_k__4, sizeof(__pyx_k__4), 0, 0, 1, 0}, - {&__pyx_kp_u__9, __pyx_k__9, sizeof(__pyx_k__9), 0, 1, 0, 0}, + {&__pyx_kp_s__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 0, 1, 0}, + {&__pyx_kp_u__7, __pyx_k__7, sizeof(__pyx_k__7), 0, 1, 0, 0}, {&__pyx_n_s_add, __pyx_k_add, sizeof(__pyx_k_add), 0, 0, 1, 1}, {&__pyx_n_s_add_2, __pyx_k_add_2, sizeof(__pyx_k_add_2), 0, 0, 1, 1}, {&__pyx_n_s_append, __pyx_k_append, sizeof(__pyx_k_append), 0, 0, 1, 1}, + {&__pyx_n_s_cFuzzySet, __pyx_k_cFuzzySet, sizeof(__pyx_k_cFuzzySet), 0, 0, 1, 1}, {&__pyx_n_s_cfuzzyset, __pyx_k_cfuzzyset, sizeof(__pyx_k_cfuzzyset), 0, 0, 1, 1}, {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, {&__pyx_n_s_collections, __pyx_k_collections, sizeof(__pyx_k_collections), 0, 0, 1, 1}, @@ -5980,11 +6227,13 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, {&__pyx_n_s_match_dict, __pyx_k_match_dict, sizeof(__pyx_k_match_dict), 0, 0, 1, 1}, {&__pyx_n_s_math, __pyx_k_math, sizeof(__pyx_k_math), 0, 0, 1, 1}, + {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, {&__pyx_n_s_operator, __pyx_k_operator, sizeof(__pyx_k_operator), 0, 0, 1, 1}, {&__pyx_n_s_pickle_creator, __pyx_k_pickle_creator, sizeof(__pyx_k_pickle_creator), 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_range, __pyx_k_range, sizeof(__pyx_k_range), 0, 0, 1, 1}, {&__pyx_n_s_re, __pyx_k_re, sizeof(__pyx_k_re), 0, 0, 1, 1}, + {&__pyx_n_s_rel_sim_cutoff, __pyx_k_rel_sim_cutoff, sizeof(__pyx_k_rel_sim_cutoff), 0, 0, 1, 1}, {&__pyx_n_s_result, __pyx_k_result, sizeof(__pyx_k_result), 0, 0, 1, 1}, {&__pyx_n_s_reverse, __pyx_k_reverse, sizeof(__pyx_k_reverse), 0, 0, 1, 1}, {&__pyx_n_s_sort, __pyx_k_sort, sizeof(__pyx_k_sort), 0, 0, 1, 1}, @@ -5997,41 +6246,19 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_w, __pyx_k_w, sizeof(__pyx_k_w), 0, 0, 1, 0}, {0, 0, 0, 0, 0, 0, 0} }; -static int __Pyx_InitCachedBuiltins(void) { - __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 35, __pyx_L1_error) - __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(0, 108, __pyx_L1_error) - __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(0, 220, __pyx_L1_error) +static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { + __pyx_builtin_range = __Pyx_GetBuiltinName(__pyx_n_s_range); if (!__pyx_builtin_range) __PYX_ERR(0, 38, __pyx_L1_error) + __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(0, 113, __pyx_L1_error) + __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(0, 229, __pyx_L1_error) return 0; __pyx_L1_error:; return -1; } -static int __Pyx_InitCachedConstants(void) { +static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); - /* "cfuzzyset.pyx":143 - * cdef list results = [(match_score / items[idx][0], items[idx][1]) - * for idx, match_score in matches.items()] - * results.sort(reverse=True, key=operator.itemgetter(0)) # <<<<<<<<<<<<<< - * - * if self.use_levenshtein: - */ - __pyx_tuple_ = PyTuple_Pack(1, __pyx_int_0); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 143, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple_); - __Pyx_GIVEREF(__pyx_tuple_); - - /* "cfuzzyset.pyx":148 - * results = [(distance(matched, value), matched) - * for _, matched in results[:50]] - * results.sort(reverse=True, key=operator.itemgetter(0)) # <<<<<<<<<<<<<< - * - * return [(score, self.exact_set[value]) - */ - __pyx_tuple__2 = PyTuple_Pack(1, __pyx_int_0); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 148, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__2); - __Pyx_GIVEREF(__pyx_tuple__2); - /* "cfuzzyset.pyx":10 * import Levenshtein * @@ -6039,9 +6266,9 @@ static int __Pyx_InitCachedConstants(void) { * * from libc.math cimport sqrt */ - __pyx_tuple__5 = PyTuple_Pack(3, __pyx_int_0, __pyx_int_0, __pyx_int_16); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 10, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__5); - __Pyx_GIVEREF(__pyx_tuple__5); + __pyx_tuple__3 = PyTuple_Pack(3, __pyx_int_0, __pyx_int_0, __pyx_int_16); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 10, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__3); + __Pyx_GIVEREF(__pyx_tuple__3); /* "cfuzzyset.pyx":14 * from libc.math cimport sqrt @@ -6050,21 +6277,21 @@ static int __Pyx_InitCachedConstants(void) { * * */ - __pyx_tuple__6 = PyTuple_Pack(1, __pyx_kp_s_w); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 14, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__6); - __Pyx_GIVEREF(__pyx_tuple__6); + __pyx_tuple__4 = PyTuple_Pack(1, __pyx_kp_s_w); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__4); + __Pyx_GIVEREF(__pyx_tuple__4); - /* "cfuzzyset.pyx":171 + /* "cfuzzyset.pyx":179 * * * def _pickle_creator(exact_set, # <<<<<<<<<<<<<< * match_dict, * items, */ - __pyx_tuple__7 = PyTuple_Pack(7, __pyx_n_s_exact_set, __pyx_n_s_match_dict, __pyx_n_s_items, __pyx_n_s_gram_size_lower, __pyx_n_s_gram_size_upper, __pyx_n_s_use_levenshtein, __pyx_n_s_result); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 171, __pyx_L1_error) - __Pyx_GOTREF(__pyx_tuple__7); - __Pyx_GIVEREF(__pyx_tuple__7); - __pyx_codeobj__8 = (PyObject*)__Pyx_PyCode_New(6, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__7, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_fuzzyset_cfuzzyset_pyx, __pyx_n_s_pickle_creator, 171, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__8)) __PYX_ERR(0, 171, __pyx_L1_error) + __pyx_tuple__5 = PyTuple_Pack(8, __pyx_n_s_exact_set, __pyx_n_s_match_dict, __pyx_n_s_items, __pyx_n_s_gram_size_lower, __pyx_n_s_gram_size_upper, __pyx_n_s_use_levenshtein, __pyx_n_s_rel_sim_cutoff, __pyx_n_s_result); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 179, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__5); + __Pyx_GIVEREF(__pyx_tuple__5); + __pyx_codeobj__6 = (PyObject*)__Pyx_PyCode_New(7, 0, 8, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__5, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_fuzzyset_cfuzzyset_pyx, __pyx_n_s_pickle_creator, 179, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__6)) __PYX_ERR(0, 179, __pyx_L1_error) __Pyx_RefNannyFinishContext(); return 0; __pyx_L1_error:; @@ -6072,7 +6299,7 @@ static int __Pyx_InitCachedConstants(void) { return -1; } -static int __Pyx_InitGlobals(void) { +static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { __pyx_umethod_PyDict_Type_items.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); @@ -6084,13 +6311,13 @@ static int __Pyx_InitGlobals(void) { return -1; } -static int __Pyx_modinit_global_init_code(void); /*proto*/ -static int __Pyx_modinit_variable_export_code(void); /*proto*/ -static int __Pyx_modinit_function_export_code(void); /*proto*/ -static int __Pyx_modinit_type_init_code(void); /*proto*/ -static int __Pyx_modinit_type_import_code(void); /*proto*/ -static int __Pyx_modinit_variable_import_code(void); /*proto*/ -static int __Pyx_modinit_function_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/ static int __Pyx_modinit_global_init_code(void) { __Pyx_RefNannyDeclarations @@ -6131,7 +6358,7 @@ static int __Pyx_modinit_type_init_code(void) { __pyx_type_9cfuzzyset_cFuzzySet.tp_getattro = __Pyx_PyObject_GenericGetAttr; } if (__Pyx_SetVtable(__pyx_type_9cfuzzyset_cFuzzySet.tp_dict, __pyx_vtabptr_9cfuzzyset_cFuzzySet) < 0) __PYX_ERR(0, 17, __pyx_L1_error) - if (PyObject_SetAttrString(__pyx_m, "cFuzzySet", (PyObject *)&__pyx_type_9cfuzzyset_cFuzzySet) < 0) __PYX_ERR(0, 17, __pyx_L1_error) + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_cFuzzySet, (PyObject *)&__pyx_type_9cfuzzyset_cFuzzySet) < 0) __PYX_ERR(0, 17, __pyx_L1_error) __pyx_ptype_9cfuzzyset_cFuzzySet = &__pyx_type_9cfuzzyset_cFuzzySet; __Pyx_RefNannyFinishContext(); return 0; @@ -6178,15 +6405,6 @@ static int __Pyx_modinit_function_import_code(void) { #define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC #endif #endif -#ifndef CYTHON_SMALL_CODE -#if defined(__clang__) - #define CYTHON_SMALL_CODE -#elif defined(__GNUC__) && (!(defined(__cplusplus)) || (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4))) - #define CYTHON_SMALL_CODE __attribute__((optimize("Os"))) -#else - #define CYTHON_SMALL_CODE -#endif -#endif #if PY_MAJOR_VERSION < 3 @@ -6199,11 +6417,36 @@ __Pyx_PyMODINIT_FUNC PyInit_cfuzzyset(void) { return PyModuleDef_Init(&__pyx_moduledef); } -static int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name) { +static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { + #if PY_VERSION_HEX >= 0x030700A1 + static PY_INT64_T main_interpreter_id = -1; + PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp); + if (main_interpreter_id == -1) { + main_interpreter_id = current_id; + return (unlikely(current_id == -1)) ? -1 : 0; + } else if (unlikely(main_interpreter_id != current_id)) + #else + static PyInterpreterState *main_interpreter = NULL; + PyInterpreterState *current_interpreter = PyThreadState_Get()->interp; + if (!main_interpreter) { + main_interpreter = current_interpreter; + } else if (unlikely(main_interpreter != current_interpreter)) + #endif + { + PyErr_SetString( + PyExc_ImportError, + "Interpreter change detected - this module can only be loaded into one interpreter per process."); + return -1; + } + return 0; +} +static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) { PyObject *value = PyObject_GetAttrString(spec, from_name); int result = 0; if (likely(value)) { - result = PyDict_SetItemString(moddict, to_name, value); + if (allow_none || value != Py_None) { + result = PyDict_SetItemString(moddict, to_name, value); + } Py_DECREF(value); } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Clear(); @@ -6212,8 +6455,10 @@ static int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const ch } return result; } -static PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) { +static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *def) { PyObject *module = NULL, *moddict, *modname; + if (__Pyx_check_single_interpreter()) + return NULL; if (__pyx_m) return __Pyx_NewRef(__pyx_m); modname = PyObject_GetAttrString(spec, "name"); @@ -6223,10 +6468,10 @@ static PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *d if (unlikely(!module)) goto bad; moddict = PyModule_GetDict(module); if (unlikely(!moddict)) goto bad; - if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__") < 0)) goto bad; - if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__") < 0)) goto bad; - if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__") < 0)) goto bad; - if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__") < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad; return module; bad: Py_XDECREF(module); @@ -6234,7 +6479,7 @@ static PyObject* __pyx_pymod_create(PyObject *spec, CYTHON_UNUSED PyModuleDef *d } -static int __pyx_pymod_exec_cfuzzyset(PyObject *__pyx_pyinit_module) +static CYTHON_SMALL_CODE int __pyx_pymod_exec_cfuzzyset(PyObject *__pyx_pyinit_module) #endif #endif { @@ -6242,7 +6487,11 @@ static int __pyx_pymod_exec_cfuzzyset(PyObject *__pyx_pyinit_module) PyObject *__pyx_t_2 = NULL; __Pyx_RefNannyDeclarations #if CYTHON_PEP489_MULTI_PHASE_INIT - if (__pyx_m && __pyx_m == __pyx_pyinit_module) return 0; + if (__pyx_m) { + if (__pyx_m == __pyx_pyinit_module) return 0; + PyErr_SetString(PyExc_RuntimeError, "Module 'cfuzzyset' has already been imported. Re-initialisation is not supported."); + return -1; + } #elif PY_MAJOR_VERSION >= 3 if (__pyx_m) return __Pyx_NewRef(__pyx_m); #endif @@ -6257,6 +6506,9 @@ if (!__Pyx_RefNanny) { #endif __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_cfuzzyset(void)", 0); if (__Pyx_check_binary_version() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pxy_PyFrame_Initialize_Offsets + __Pxy_PyFrame_Initialize_Offsets(); + #endif __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) @@ -6311,7 +6563,7 @@ if (!__Pyx_RefNanny) { if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) #endif if (__pyx_module_is_main_cfuzzyset) { - if (PyObject_SetAttrString(__pyx_m, "__name__", __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) } #if PY_MAJOR_VERSION >= 3 { @@ -6405,7 +6657,7 @@ if (!__Pyx_RefNanny) { * * from libc.math cimport sqrt */ - if (PyDict_SetItem(__pyx_d, __pyx_n_s_version, __pyx_tuple__5) < 0) __PYX_ERR(0, 10, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_version, __pyx_tuple__3) < 0) __PYX_ERR(0, 10, __pyx_L1_error) /* "cfuzzyset.pyx":14 * from libc.math cimport sqrt @@ -6414,12 +6666,12 @@ if (!__Pyx_RefNanny) { * * */ - __pyx_t_1 = __Pyx_GetModuleGlobalName(__pyx_n_s_re); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 14, __pyx_L1_error) + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_re); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_compile); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__6, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 14, __pyx_L1_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_tuple__4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 14, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XGOTREF(__pyx_v_9cfuzzyset__non_word_re); @@ -6427,29 +6679,29 @@ if (!__Pyx_RefNanny) { __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; - /* "cfuzzyset.pyx":171 + /* "cfuzzyset.pyx":179 * * * def _pickle_creator(exact_set, # <<<<<<<<<<<<<< * match_dict, * items, */ - __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_9cfuzzyset_1_pickle_creator, NULL, __pyx_n_s_cfuzzyset); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 171, __pyx_L1_error) + __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_9cfuzzyset_1_pickle_creator, NULL, __pyx_n_s_cfuzzyset); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 179, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); - if (PyDict_SetItem(__pyx_d, __pyx_n_s_pickle_creator, __pyx_t_1) < 0) __PYX_ERR(0, 171, __pyx_L1_error) + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pickle_creator, __pyx_t_1) < 0) __PYX_ERR(0, 179, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; - /* "cfuzzyset.pyx":198 + /* "cfuzzyset.pyx":207 * return results * * cdef unicode hyphens = u'-----------' # <<<<<<<<<<<<<< * * cdef list _iterate_grams(unicode value, int gram_size=2): */ - __Pyx_INCREF(__pyx_kp_u__9); + __Pyx_INCREF(__pyx_kp_u__7); __Pyx_XGOTREF(__pyx_v_9cfuzzyset_hyphens); - __Pyx_DECREF_SET(__pyx_v_9cfuzzyset_hyphens, __pyx_kp_u__9); - __Pyx_GIVEREF(__pyx_kp_u__9); + __Pyx_DECREF_SET(__pyx_v_9cfuzzyset_hyphens, __pyx_kp_u__7); + __Pyx_GIVEREF(__pyx_kp_u__7); /* "cfuzzyset.pyx":1 * # encoding: utf-8 # <<<<<<<<<<<<<< @@ -6469,9 +6721,9 @@ if (!__Pyx_RefNanny) { __Pyx_XDECREF(__pyx_t_2); if (__pyx_m) { if (__pyx_d) { - __Pyx_AddTraceback("init cfuzzyset", 0, __pyx_lineno, __pyx_filename); + __Pyx_AddTraceback("init cfuzzyset", __pyx_clineno, __pyx_lineno, __pyx_filename); } - Py_DECREF(__pyx_m); __pyx_m = 0; + Py_CLEAR(__pyx_m); } else if (!PyErr_Occurred()) { PyErr_SetString(PyExc_ImportError, "init cfuzzyset"); } @@ -6492,9 +6744,9 @@ if (!__Pyx_RefNanny) { static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { PyObject *m = NULL, *p = NULL; void *r = NULL; - m = PyImport_ImportModule((char *)modname); + m = PyImport_ImportModule(modname); if (!m) goto end; - p = PyObject_GetAttrString(m, (char *)"RefNannyAPI"); + p = PyObject_GetAttrString(m, "RefNannyAPI"); if (!p) goto end; r = PyLong_AsVoidPtr(p); end: @@ -6682,7 +6934,7 @@ static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, P PyObject *self = PyCFunction_GET_SELF(func); int flags = PyCFunction_GET_FLAGS(func); assert(PyCFunction_Check(func)); - assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS))); + assert(METH_FASTCALL == (flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_KEYWORDS | METH_STACKLESS))); assert(nargs >= 0); assert(nargs == 0 || args != NULL); /* _PyCFunction_FastCallDict() must not be called with an exception set, @@ -6690,16 +6942,15 @@ static CYTHON_INLINE PyObject * __Pyx_PyCFunction_FastCall(PyObject *func_obj, P caller loses its exception */ assert(!PyErr_Occurred()); if ((PY_VERSION_HEX < 0x030700A0) || unlikely(flags & METH_KEYWORDS)) { - return (*((__Pyx_PyCFunctionFastWithKeywords)meth)) (self, args, nargs, NULL); + return (*((__Pyx_PyCFunctionFastWithKeywords)(void*)meth)) (self, args, nargs, NULL); } else { - return (*((__Pyx_PyCFunctionFast)meth)) (self, args, nargs); + return (*((__Pyx_PyCFunctionFast)(void*)meth)) (self, args, nargs); } } #endif /* 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; @@ -6717,7 +6968,7 @@ static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args if (f == NULL) { return NULL; } - fastlocals = f->f_localsplus; + fastlocals = __Pyx_PyFrame_GetLocalsplus(f); for (i = 0; i < na; i++) { Py_INCREF(*args); fastlocals[i] = *args++; @@ -6837,6 +7088,35 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg } #endif +/* PyObjectCall2Args */ +static CYTHON_UNUSED PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) { + PyObject *args, *result = NULL; + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(function)) { + PyObject *args[2] = {arg1, arg2}; + return __Pyx_PyFunction_FastCall(function, args, 2); + } + #endif + #if CYTHON_FAST_PYCCALL + if (__Pyx_PyFastCFunction_Check(function)) { + PyObject *args[2] = {arg1, arg2}; + return __Pyx_PyCFunction_FastCall(function, args, 2); + } + #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); + Py_INCREF(function); + result = __Pyx_PyObject_Call(function, args, NULL); + Py_DECREF(args); + Py_DECREF(function); +done: + return result; +} + /* PyObjectCallMethO */ #if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) { @@ -6898,34 +7178,42 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObjec #endif /* GetModuleGlobalName */ -static CYTHON_INLINE PyObject *__Pyx_GetModuleGlobalName(PyObject *name) { +#if CYTHON_USE_DICT_VERSIONS +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) +#else +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) +#endif +{ PyObject *result; #if !CYTHON_AVOID_BORROWED_REFS #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) if (likely(result)) { - Py_INCREF(result); + return __Pyx_NewRef(result); } else if (unlikely(PyErr_Occurred())) { - result = NULL; - } else { + return NULL; + } #else result = PyDict_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) if (likely(result)) { - Py_INCREF(result); - } else { + return __Pyx_NewRef(result); + } #endif #else result = PyObject_GetItem(__pyx_d, name); - if (!result) { - PyErr_Clear(); -#endif - result = __Pyx_GetBuiltinName(name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); } - return result; + PyErr_Clear(); +#endif + return __Pyx_GetBuiltinName(name); } /* PyObjectCallNoArg */ - #if CYTHON_COMPILING_IN_CPYTHON +#if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { #if CYTHON_FAST_PYCALL if (PyFunction_Check(func)) { @@ -6933,10 +7221,11 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { } #endif #ifdef __Pyx_CyFunction_USED - if (likely(PyCFunction_Check(func) || __Pyx_TypeCheck(func, __pyx_CyFunctionType))) { + if (likely(PyCFunction_Check(func) || __Pyx_CyFunction_Check(func))) #else - if (likely(PyCFunction_Check(func))) { + if (likely(PyCFunction_Check(func))) #endif + { if (likely(PyCFunction_GET_FLAGS(func) & METH_NOARGS)) { return __Pyx_PyObject_CallMethO(func, NULL); } @@ -6946,16 +7235,21 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { #endif /* DictGetItem */ - #if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY +#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); + if (unlikely(PyTuple_Check(key))) { + PyObject* args = PyTuple_Pack(1, key); + if (likely(args)) { + PyErr_SetObject(PyExc_KeyError, args); + Py_DECREF(args); + } + } else { + PyErr_SetObject(PyExc_KeyError, key); + } } return NULL; } @@ -6965,7 +7259,7 @@ static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) { #endif /* UnpackUnboundCMethod */ - static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) { +static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) { PyObject *method; method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name); if (unlikely(!method)) @@ -6978,14 +7272,14 @@ static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) { { PyMethodDescrObject *descr = (PyMethodDescrObject*) method; target->func = descr->d_method->ml_meth; - target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST); + target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS); } #endif return 0; } /* CallUnboundCMethod0 */ - static PyObject* __Pyx__CallUnboundCMethod0(__Pyx_CachedCFunction* cfunc, PyObject* self) { +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 @@ -7004,7 +7298,7 @@ static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) { } /* py_dict_values */ - static CYTHON_INLINE PyObject* __Pyx_PyDict_Values(PyObject* d) { +static CYTHON_INLINE PyObject* __Pyx_PyDict_Values(PyObject* d) { if (PY_MAJOR_VERSION >= 3) return __Pyx_CallUnboundCMethod0(&__pyx_umethod_PyDict_Type_values, d); else @@ -7012,7 +7306,7 @@ static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) { } /* GetItemInt */ - static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { +static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { PyObject *r; if (!j) return NULL; r = PyObject_GetItem(o, j); @@ -7027,7 +7321,7 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_ if (wraparound & unlikely(i < 0)) { wrapped_i += PyList_GET_SIZE(o); } - if ((!boundscheck) || likely((0 <= wrapped_i) & (wrapped_i < PyList_GET_SIZE(o)))) { + if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyList_GET_SIZE(o)))) { PyObject *r = PyList_GET_ITEM(o, wrapped_i); Py_INCREF(r); return r; @@ -7045,7 +7339,7 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize if (wraparound & unlikely(i < 0)) { wrapped_i += PyTuple_GET_SIZE(o); } - if ((!boundscheck) || likely((0 <= wrapped_i) & (wrapped_i < PyTuple_GET_SIZE(o)))) { + if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyTuple_GET_SIZE(o)))) { PyObject *r = PyTuple_GET_ITEM(o, wrapped_i); Py_INCREF(r); return r; @@ -7061,7 +7355,7 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, #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))))) { + if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) { PyObject *r = PyList_GET_ITEM(o, n); Py_INCREF(r); return r; @@ -7069,7 +7363,7 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, } 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)))) { + if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) { PyObject *r = PyTuple_GET_ITEM(o, n); Py_INCREF(r); return r; @@ -7099,7 +7393,7 @@ static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, } /* SetItemInt */ - static int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) { +static int __Pyx_SetItemInt_Generic(PyObject *o, PyObject *j, PyObject *v) { int r; if (!j) return -1; r = PyObject_SetItem(o, j, v); @@ -7111,7 +7405,7 @@ static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObje #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)))) { + if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o)))) { PyObject* old = PyList_GET_ITEM(o, n); Py_INCREF(v); PyList_SET_ITEM(o, n, v); @@ -7136,10 +7430,11 @@ static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObje } #else #if CYTHON_COMPILING_IN_PYPY - if (is_list || (PySequence_Check(o) && !PyDict_Check(o))) { + if (is_list || (PySequence_Check(o) && !PyDict_Check(o))) #else - if (is_list || PySequence_Check(o)) { + if (is_list || PySequence_Check(o)) #endif + { return PySequence_SetItem(o, i, v); } #endif @@ -7147,7 +7442,7 @@ static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObje } /* py_dict_items */ - static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d) { +static CYTHON_INLINE PyObject* __Pyx_PyDict_Items(PyObject* d) { if (PY_MAJOR_VERSION >= 3) return __Pyx_CallUnboundCMethod0(&__pyx_umethod_PyDict_Type_items, d); else @@ -7155,20 +7450,20 @@ static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObje } /* RaiseTooManyValuesToUnpack */ - static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { +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) { +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) { +static CYTHON_INLINE int __Pyx_IterFinish(void) { #if CYTHON_FAST_THREAD_STATE PyThreadState *tstate = __Pyx_PyThreadState_Current; PyObject* exc_type = tstate->curexc_type; @@ -7203,7 +7498,7 @@ static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObje } /* UnpackItemEndCheck */ - static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { +static int __Pyx_IternextUnpackEndCheck(PyObject *retval, Py_ssize_t expected) { if (unlikely(retval)) { Py_DECREF(retval); __Pyx_RaiseTooManyValuesError(expected); @@ -7214,59 +7509,122 @@ static CYTHON_INLINE int __Pyx_SetItemInt_Fast(PyObject *o, Py_ssize_t i, PyObje return 0; } -/* PyObjectCallMethod1 */ - static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) { - PyObject *result = NULL; -#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; +/* PyObjectGetMethod */ +static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) { + PyObject *attr; +#if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP + PyTypeObject *tp = Py_TYPE(obj); + PyObject *descr; + descrgetfunc f = NULL; + PyObject **dictptr, *dict; + int meth_found = 0; + assert (*method == NULL); + if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) { + attr = __Pyx_PyObject_GetAttrStr(obj, name); + goto try_unpack; + } + if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) { + return 0; + } + descr = _PyType_Lookup(tp, name); + if (likely(descr != NULL)) { + Py_INCREF(descr); +#if PY_MAJOR_VERSION >= 3 + #ifdef __Pyx_CyFunction_USED + if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr))) + #else + if (likely(PyFunction_Check(descr) || (Py_TYPE(descr) == &PyMethodDescr_Type))) + #endif +#else + #ifdef __Pyx_CyFunction_USED + if (likely(PyFunction_Check(descr) || __Pyx_CyFunction_Check(descr))) + #else + if (likely(PyFunction_Check(descr))) + #endif +#endif + { + meth_found = 1; + } else { + f = Py_TYPE(descr)->tp_descr_get; + if (f != NULL && PyDescr_IsData(descr)) { + attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); + Py_DECREF(descr); + goto try_unpack; } - #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); - result = __Pyx_PyObject_Call(function, args, NULL); - Py_DECREF(args); - Py_DECREF(function); - return result; } } + dictptr = _PyObject_GetDictPtr(obj); + if (dictptr != NULL && (dict = *dictptr) != NULL) { + Py_INCREF(dict); + attr = __Pyx_PyDict_GetItemStr(dict, name); + if (attr != NULL) { + Py_INCREF(attr); + Py_DECREF(dict); + Py_XDECREF(descr); + goto try_unpack; + } + Py_DECREF(dict); + } + if (meth_found) { + *method = descr; + return 1; + } + if (f != NULL) { + attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); + Py_DECREF(descr); + goto try_unpack; + } + if (descr != NULL) { + *method = descr; + return 0; + } + PyErr_Format(PyExc_AttributeError, +#if PY_MAJOR_VERSION >= 3 + "'%.50s' object has no attribute '%U'", + tp->tp_name, name); +#else + "'%.50s' object has no attribute '%.400s'", + tp->tp_name, PyString_AS_STRING(name)); #endif - result = __Pyx_PyObject_CallOneArg(method, arg); - goto done; -done: + return 0; +#else + attr = __Pyx_PyObject_GetAttrStr(obj, name); + goto try_unpack; +#endif +try_unpack: +#if CYTHON_UNPACK_METHODS + if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) { + PyObject *function = PyMethod_GET_FUNCTION(attr); + Py_INCREF(function); + Py_DECREF(attr); + *method = function; + return 1; + } +#endif + *method = attr; + return 0; +} + +/* PyObjectCallMethod1 */ +static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) { + PyObject *result = __Pyx_PyObject_CallOneArg(method, arg); + Py_DECREF(method); return result; } static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) { - PyObject *method, *result; - method = __Pyx_PyObject_GetAttrStr(obj, method_name); + PyObject *method = NULL, *result; + int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); + if (likely(is_method)) { + result = __Pyx_PyObject_Call2Args(method, obj, arg); + Py_DECREF(method); + return result; + } if (unlikely(!method)) return NULL; - result = __Pyx__PyObject_CallMethod1(method, arg); - Py_DECREF(method); - return result; + return __Pyx__PyObject_CallMethod1(method, arg); } /* append */ - static CYTHON_INLINE int __Pyx_PyObject_Append(PyObject* L, PyObject* x) { +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 { @@ -7279,7 +7637,7 @@ static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name } /* ArgTypeTest */ - static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact) +static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact) { if (unlikely(!type)) { PyErr_SetString(PyExc_SystemError, "Missing type object"); @@ -7300,7 +7658,7 @@ static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name } /* PyErrFetchRestore */ - #if CYTHON_FAST_THREAD_STATE +#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; @@ -7324,7 +7682,7 @@ static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject #endif /* RaiseException */ - #if PY_MAJOR_VERSION < 3 +#if PY_MAJOR_VERSION < 3 static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, CYTHON_UNUSED PyObject *cause) { __Pyx_PyThreadState_declare @@ -7483,7 +7841,7 @@ static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject #endif /* SliceTupleAndList */ - #if CYTHON_COMPILING_IN_CPYTHON +#if CYTHON_COMPILING_IN_CPYTHON static CYTHON_INLINE void __Pyx_crop_slice(Py_ssize_t* _start, Py_ssize_t* _stop, Py_ssize_t* _length) { Py_ssize_t start = *_start, stop = *_stop, length = *_length; if (start < 0) { @@ -7542,7 +7900,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyTuple_GetSlice( #endif /* ObjectGetItem */ - #if CYTHON_USE_TYPE_SLOTS +#if CYTHON_USE_TYPE_SLOTS static PyObject *__Pyx_PyObject_GetIndex(PyObject *obj, PyObject* index) { PyObject *runerr; Py_ssize_t key_value; @@ -7570,13 +7928,29 @@ static PyObject *__Pyx_PyObject_GetItem(PyObject *obj, PyObject* key) { } #endif +/* GetTopmostException */ +#if CYTHON_USE_EXC_INFO_STACK +static _PyErr_StackItem * +__Pyx_PyErr_GetTopmostException(PyThreadState *tstate) +{ + _PyErr_StackItem *exc_info = tstate->exc_info; + while ((exc_info->exc_type == NULL || exc_info->exc_type == Py_None) && + exc_info->previous_item != NULL) + { + exc_info = exc_info->previous_item; + } + return exc_info; +} +#endif + /* SaveResetException */ - #if CYTHON_FAST_THREAD_STATE +#if CYTHON_FAST_THREAD_STATE static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { - #if PY_VERSION_HEX >= 0x030700A3 - *type = tstate->exc_state.exc_type; - *value = tstate->exc_state.exc_value; - *tb = tstate->exc_state.exc_traceback; + #if CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate); + *type = exc_info->exc_type; + *value = exc_info->exc_value; + *tb = exc_info->exc_traceback; #else *type = tstate->exc_type; *value = tstate->exc_value; @@ -7588,13 +7962,14 @@ static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject * } static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { PyObject *tmp_type, *tmp_value, *tmp_tb; - #if PY_VERSION_HEX >= 0x030700A3 - tmp_type = tstate->exc_state.exc_type; - tmp_value = tstate->exc_state.exc_value; - tmp_tb = tstate->exc_state.exc_traceback; - tstate->exc_state.exc_type = type; - tstate->exc_state.exc_value = value; - tstate->exc_state.exc_traceback = tb; + #if CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = type; + exc_info->exc_value = value; + exc_info->exc_traceback = tb; #else tmp_type = tstate->exc_type; tmp_value = tstate->exc_value; @@ -7610,7 +7985,7 @@ static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject #endif /* PyErrExceptionMatches */ - #if CYTHON_FAST_THREAD_STATE +#if CYTHON_FAST_THREAD_STATE static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { Py_ssize_t i, n; n = PyTuple_GET_SIZE(tuple); @@ -7635,11 +8010,12 @@ static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tsta #endif /* GetException */ - #if CYTHON_FAST_THREAD_STATE -static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { +#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) { +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; @@ -7672,13 +8048,16 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) *value = local_value; *tb = local_tb; #if CYTHON_FAST_THREAD_STATE - #if PY_VERSION_HEX >= 0x030700A3 - tmp_type = tstate->exc_state.exc_type; - tmp_value = tstate->exc_state.exc_value; - tmp_tb = tstate->exc_state.exc_traceback; - tstate->exc_state.exc_type = local_type; - tstate->exc_state.exc_value = local_value; - tstate->exc_state.exc_traceback = local_tb; + #if CYTHON_USE_EXC_INFO_STACK + { + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = local_type; + exc_info->exc_value = local_value; + exc_info->exc_traceback = local_tb; + } #else tmp_type = tstate->exc_type; tmp_value = tstate->exc_value; @@ -7705,7 +8084,7 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) } /* PyIntBinop */ - #if !CYTHON_COMPILING_IN_PYPY +#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))) { @@ -7827,7 +8206,7 @@ static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED #endif /* PyUnicode_Substring */ - static CYTHON_INLINE PyObject* __Pyx_PyUnicode_Substring( +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_Substring( PyObject* text, Py_ssize_t start, Py_ssize_t stop) { Py_ssize_t length; if (unlikely(__Pyx_PyUnicode_READY(text) == -1)) return NULL; @@ -7853,7 +8232,7 @@ static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED } /* WriteUnraisableException */ - static void __Pyx_WriteUnraisable(const char *name, CYTHON_UNUSED int clineno, +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; @@ -7895,7 +8274,7 @@ static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, CYTHON_UNUSED } /* PyObject_GenericGetAttrNoDict */ - #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) { PyErr_Format(PyExc_AttributeError, #if PY_MAJOR_VERSION >= 3 @@ -7935,7 +8314,7 @@ static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj #endif /* PyObject_GenericGetAttr */ - #if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) { if (unlikely(Py_TYPE(obj)->tp_dictoffset)) { return PyObject_GenericGetAttr(obj, attr_name); @@ -7945,7 +8324,7 @@ static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_nam #endif /* SetVTable */ - static int __Pyx_SetVtable(PyObject *dict, void *vtable) { +static int __Pyx_SetVtable(PyObject *dict, void *vtable) { #if PY_VERSION_HEX >= 0x02070000 PyObject *ob = PyCapsule_New(vtable, 0, 0); #else @@ -7963,7 +8342,7 @@ static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_nam } /* Import */ - static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { PyObject *empty_list = 0; PyObject *module = 0; PyObject *global_dict = 0; @@ -8010,7 +8389,7 @@ static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_nam if (!py_level) goto bad; module = PyObject_CallFunctionObjArgs(py_import, - name, global_dict, empty_dict, list, py_level, NULL); + name, global_dict, empty_dict, list, py_level, (PyObject *)NULL); Py_DECREF(py_level); #else module = PyImport_ImportModuleLevelObject( @@ -8028,8 +8407,8 @@ static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_nam } /* CLineInTraceback */ - #ifndef CYTHON_CLINE_IN_TRACEBACK -static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_line) { +#ifndef CYTHON_CLINE_IN_TRACEBACK +static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line) { PyObject *use_cline; PyObject *ptype, *pvalue, *ptraceback; #if CYTHON_COMPILING_IN_CPYTHON @@ -8042,7 +8421,9 @@ static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_li #if CYTHON_COMPILING_IN_CPYTHON cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime); if (likely(cython_runtime_dict)) { - use_cline = __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback); + __PYX_PY_DICT_LOOKUP_IF_MODIFIED( + use_cline, *cython_runtime_dict, + __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback)) } else #endif { @@ -8059,7 +8440,7 @@ static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_li c_line = 0; PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False); } - else if (PyObject_Not(use_cline) != 0) { + else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) { c_line = 0; } __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback); @@ -8068,7 +8449,7 @@ static int __Pyx_CLineForTraceback(CYTHON_UNUSED PyThreadState *tstate, int c_li #endif /* CodeObjectCache */ - static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { +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; @@ -8148,7 +8529,7 @@ static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { } /* AddTraceback */ - #include "compile.h" +#include "compile.h" #include "frameobject.h" #include "traceback.h" static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( @@ -8233,7 +8614,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntFromPyVerify */ - #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ +#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) @@ -8255,8 +8636,8 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { - const int neg_one = (int) -1, const_zero = (int) 0; +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { + const int neg_one = (int) ((int) 0 - (int) 1), const_zero = (int) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(int) < sizeof(long)) { @@ -8286,8 +8667,8 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntToPy */ - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { - const long neg_one = (long) -1, const_zero = (long) 0; +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { + const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; if (is_unsigned) { if (sizeof(long) < sizeof(long)) { @@ -8317,8 +8698,8 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntFromPy */ - static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { - const int neg_one = (int) -1, const_zero = (int) 0; +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { + const int neg_one = (int) ((int) 0 - (int) 1), const_zero = (int) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { @@ -8506,8 +8887,8 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* CIntFromPy */ - static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { - const long neg_one = (long) -1, const_zero = (long) 0; +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { + const long neg_one = (long) ((long) 0 - (long) 1), const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; #if PY_MAJOR_VERSION < 3 if (likely(PyInt_Check(x))) { @@ -8695,7 +9076,7 @@ static void __Pyx_AddTraceback(const char *funcname, int c_line, } /* FastTypeChecks */ - #if CYTHON_COMPILING_IN_CPYTHON +#if CYTHON_COMPILING_IN_CPYTHON static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) { while (a) { a = a->tp_base; @@ -8795,7 +9176,7 @@ static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObj #endif /* CheckBinaryVersion */ - static int __Pyx_check_binary_version(void) { +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()); @@ -8811,7 +9192,7 @@ static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObj } /* InitStrings */ - static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { while (t->p) { #if PY_MAJOR_VERSION < 3 if (t->is_unicode) { @@ -8920,6 +9301,13 @@ static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { if (is_true | (x == Py_False) | (x == Py_None)) return is_true; else return PyObject_IsTrue(x); } +static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) { + int retval; + if (unlikely(!x)) return -1; + retval = __Pyx_PyObject_IsTrue(x); + Py_DECREF(x); + return retval; +} static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) { #if PY_MAJOR_VERSION >= 3 if (PyLong_Check(result)) { @@ -8997,7 +9385,7 @@ static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { if (sizeof(Py_ssize_t) >= sizeof(long)) return PyInt_AS_LONG(b); else - return PyInt_AsSsize_t(x); + return PyInt_AsSsize_t(b); } #endif if (likely(PyLong_CheckExact(b))) { diff --git a/fuzzyset/cfuzzyset.pyx b/fuzzyset/cfuzzyset.pyx index 1bbf972..d846022 100644 --- a/fuzzyset/cfuzzyset.pyx +++ b/fuzzyset/cfuzzyset.pyx @@ -23,11 +23,14 @@ cdef class cFuzzySet: cdef int gram_size_lower cdef int gram_size_upper cdef int use_levenshtein + cdef double rel_sim_cutoff - def __cinit__(self, iterable=(), int gram_size_lower=2, int gram_size_upper=3, int use_levenshtein=True): + def __cinit__(self, iterable=(), int gram_size_lower=2, int gram_size_upper=3, int use_levenshtein=True, + double rel_sim_cutoff=1.0): assert gram_size_upper < 4 and gram_size_upper > 0 assert gram_size_lower < 4 and gram_size_lower > 0 assert gram_size_lower <= gram_size_upper + assert rel_sim_cutoff <= 1.0 and rel_sim_cutoff >= 0 self.exact_set = {} self.match_dict = {} self.items = {} @@ -37,6 +40,7 @@ cdef class cFuzzySet: self.gram_size_lower = gram_size_lower self.gram_size_upper = gram_size_upper self.use_levenshtein = use_levenshtein + self.rel_sim_cutoff = rel_sim_cutoff for value in iterable: self.add(value) @@ -49,7 +53,8 @@ cdef class cFuzzySet: self.items, self.gram_size_lower, self.gram_size_upper, - self.use_levenshtein + self.use_levenshtein, + self.rel_sim_cutoff ) ) @@ -97,7 +102,7 @@ cdef class cFuzzySet: cdef unicode lvalue with cython.nonecheck(True): lvalue = value.lower() - if lvalue in self.exact_set: + if lvalue in self.exact_set and self.rel_sim_cutoff >= 1.0: return [(1, self.exact_set[lvalue])] cdef int i results = None @@ -114,6 +119,7 @@ cdef class cFuzzySet: cdef dict matches = {} cdef dict grams = _gram_counter(lvalue, gram_size) cdef double norm = 0 + cdef double score_threshold cdef int tmp cdef list values = list(grams.values()) for tmp in values: @@ -147,13 +153,15 @@ cdef class cFuzzySet: for _, matched in results[:50]] results.sort(reverse=True, key=operator.itemgetter(0)) + score_threshold = results[0][0] * self.rel_sim_cutoff return [(score, self.exact_set[value]) for score, value in results - if score == results[0][0]] + if score >= score_threshold] else: + score_threshold = results[0][0] * self.rel_sim_cutoff return [(score / norm, self.exact_set[value]) for score, value in results - if score == results[0][0]] + if score == score_threshold] def __len__(self): return len(self.exact_set) @@ -173,8 +181,9 @@ def _pickle_creator(exact_set, items, gram_size_lower, gram_size_upper, - use_levenshtein): - result = cFuzzySet((), gram_size_lower, gram_size_upper, use_levenshtein) + use_levenshtein, + rel_sim_cutoff): + result = cFuzzySet((), gram_size_lower, gram_size_upper, use_levenshtein, rel_sim_cutoff) result.match_dict = match_dict result.exact_set = exact_set result.items = items