mirror of
https://github.com/explosion/spaCy.git
synced 2024-11-11 12:18:04 +03:00
7c98245c0c
Add a simple levenshtein distance function using the implementation from the polyleven library as `spacy.matcher.levenshtein`.
16 lines
404 B
Cython
16 lines
404 B
Cython
# cython: profile=True, binding=True, infer_types=True
|
|
from cpython.object cimport PyObject
|
|
from libc.stdint cimport int64_t
|
|
|
|
from typing import Optional
|
|
|
|
|
|
cdef extern from "polyleven.c":
|
|
int64_t polyleven(PyObject *o1, PyObject *o2, int64_t k)
|
|
|
|
|
|
cpdef int64_t levenshtein(a: str, b: str, k: Optional[int] = None):
|
|
if k is None:
|
|
k = -1
|
|
return polyleven(<PyObject*>a, <PyObject*>b, k)
|