fix uninitialized variable
This commit is contained in:
parent
0e6466d835
commit
7139004214
|
@ -132,6 +132,7 @@ PyObject* levenshtein(PyObject* /*self*/, PyObject* args, PyObject* keywds)
|
|||
}
|
||||
}
|
||||
|
||||
// todo improve error message for None
|
||||
if (!valid_str(py_s1, "s1") || !valid_str(py_s2, "s2")) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -141,7 +142,7 @@ PyObject* levenshtein(PyObject* /*self*/, PyObject* args, PyObject* keywds)
|
|||
|
||||
std::size_t result = mpark::visit(LevenshteinVisitor(insert_cost, delete_cost, replace_cost, (std::size_t)max),
|
||||
s1_view, s2_view);
|
||||
|
||||
|
||||
if (result == (std::size_t)-1) {
|
||||
return PyLong_FromLong(-1);
|
||||
}
|
||||
|
@ -249,6 +250,7 @@ PyObject* hamming(PyObject* /*self*/, PyObject* args, PyObject* keywds)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
// todo improve error message for None
|
||||
if (!valid_str(py_s1, "s1") || !valid_str(py_s2, "s2")) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -64,7 +64,12 @@ Insertion = 1, Deletion = 1, Substitution = 1:
|
|||
Myers algorithm is described in [3]_
|
||||
|
||||
|
||||
Insertion = 1, Deletion = 1, Substitution = 2:
|
||||
Insertion = 1, Deletion = 1, Substitution >= Insertion + Deletion:
|
||||
when ``Substitution >= Insertion + Deletion`` set
|
||||
``Substitution = Insertion + Deletion``
|
||||
since every Substitution can be performed as Insertion + Deletion
|
||||
so in this case treat Substitution as 2
|
||||
|
||||
- if max is 0 the similarity can be calculated using a direct comparision,
|
||||
since no difference between the strings is allowed. The time complexity of
|
||||
this algorithm is ``O(N)``.
|
||||
|
@ -151,9 +156,8 @@ R"(normalized_levenshtein($module, s1, s2, weights = (1, 1, 1), processor = None
|
|||
|
||||
Calculates a normalized levenshtein distance using custom
|
||||
costs for insertion, deletion and substitution. So far only the following
|
||||
combinations are supported:
|
||||
- weights = (1, 1, 1)
|
||||
- weights = (1, 1, 2)
|
||||
weights are supported:
|
||||
- weights = (1, 1, N) with N >= 1
|
||||
|
||||
further combinations might be supported in the future
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 45d277a48d7fa5aa0fab37416ed561be4a7f4090
|
||||
Subproject commit ec59b2dd24aacdce25974c27197d296e991ab9ac
|
|
@ -3,6 +3,6 @@ rapid string matching library
|
|||
"""
|
||||
__author__ = "Max Bachmann"
|
||||
__license__ = "MIT"
|
||||
__version__ = "1.0.0"
|
||||
__version__ = "1.0.1"
|
||||
|
||||
from rapidfuzz import process, fuzz, utils, levenshtein, string_metric
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import unittest
|
||||
import pytest
|
||||
|
||||
from rapidfuzz import string_metric
|
||||
|
||||
def test_empty_string():
|
||||
"""
|
||||
when both strings are empty this is a perfect match
|
||||
"""
|
||||
assert string_metric.levenshtein("", "") == 0
|
||||
assert string_metric.levenshtein("", "", (1,1,0)) == 0
|
||||
assert string_metric.levenshtein("", "", (1,1,2)) == 0
|
||||
assert string_metric.levenshtein("", "", (1,1,5)) == 0
|
||||
assert string_metric.levenshtein("", "", (3,7,5)) == 0
|
||||
|
||||
def test_simple_unicode_tests():
|
||||
"""
|
||||
some very simple tests using unicode with scorers
|
||||
to catch relatively obvious implementation errors
|
||||
"""
|
||||
s1 = u"ÁÄ"
|
||||
s2 = "ABCD"
|
||||
assert string_metric.levenshtein(s1, s2) == 4
|
||||
assert string_metric.levenshtein(s1, s2, (1,1,0)) == 2
|
||||
assert string_metric.levenshtein(s1, s2, (1,1,2)) == 6
|
||||
assert string_metric.levenshtein(s1, s2, (1,1,5)) == 6
|
||||
assert string_metric.levenshtein(s1, s2, (3,7,5)) == 24
|
||||
|
||||
assert string_metric.levenshtein(s1, s1) == 0
|
||||
assert string_metric.levenshtein(s1, s1, (1,1,0)) == 0
|
||||
assert string_metric.levenshtein(s1, s1, (1,1,2)) == 0
|
||||
assert string_metric.levenshtein(s1, s1, (1,1,5)) == 0
|
||||
assert string_metric.levenshtein(s1, s1, (3,7,5)) == 0
|
||||
|
||||
def test_help():
|
||||
"""
|
||||
test that all help texts can be printed without throwing an exception,
|
||||
since they are implemented in C++ aswell
|
||||
"""
|
||||
help(string_metric.levenshtein)
|
||||
help(string_metric.normalized_levenshtein)
|
||||
help(string_metric.hamming)
|
||||
help(string_metric.normalized_hamming)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
Loading…
Reference in New Issue