From 91bf9d0c5f10f0f0ea824209d02cabce5439674f Mon Sep 17 00:00:00 2001 From: Tal Einat Date: Wed, 5 Jul 2017 12:07:02 +0300 Subject: [PATCH] make c_find_near_matches_generic_ngrams also accept search_params also fixed tests which were not passing search_params where needed Note: only updated the .pyx file, the compiled .c file isn't updated! --- src/fuzzysearch/_generic_search.pyx | 6 +++--- tests/test_generic_search.py | 3 +-- tests/test_generic_search_cython.py | 24 +++++++++++++----------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/fuzzysearch/_generic_search.pyx b/src/fuzzysearch/_generic_search.pyx index 4e3d5f0..b2a0adf 100644 --- a/src/fuzzysearch/_generic_search.pyx +++ b/src/fuzzysearch/_generic_search.pyx @@ -238,9 +238,7 @@ cdef _c_find_near_matches_generic_linear_programming( -def c_find_near_matches_generic_ngrams(subsequence, sequence, - max_substitutions, max_insertions, - max_deletions, max_l_dist=None): +def c_find_near_matches_generic_ngrams(subsequence, sequence, search_params): """search for near-matches of subsequence in sequence This searches for near-matches, where the nearly-matching parts of the @@ -259,6 +257,8 @@ def c_find_near_matches_generic_ngrams(subsequence, sequence, if not subsequence: raise ValueError('Given subsequence is empty!') + max_substitutions, max_insertions, max_deletions, max_l_dist = search_params.unpacked + # optimization: prepare some often used things in advance cdef size_t _subseq_len = len(subsequence) cdef size_t _subseq_len_minus_one = _subseq_len - 1 diff --git a/tests/test_generic_search.py b/tests/test_generic_search.py index 1d6a9c5..97f04a5 100644 --- a/tests/test_generic_search.py +++ b/tests/test_generic_search.py @@ -343,8 +343,7 @@ class TestGenericSearchNgrams(TestGenericSearchBase, TestNgramsBase, unittest.TestCase): def search(self, pattern, sequence, max_subs, max_ins, max_dels, - max_l_dist=None): - return fnm_generic_ngrams(pattern, sequence, + max_l_dist=None): return fnm_generic_ngrams(pattern, sequence, LevenshteinSearchParams(max_subs, max_ins, max_dels, max_l_dist)) def expectedOutcomes(self, search_results, expected_outcomes): diff --git a/tests/test_generic_search_cython.py b/tests/test_generic_search_cython.py index c2f41d0..431be84 100644 --- a/tests/test_generic_search_cython.py +++ b/tests/test_generic_search_cython.py @@ -1,7 +1,7 @@ from tests.compat import unittest from tests.utils import skip_if_arguments_are_unicode from tests.test_levenshtein import TestFindNearMatchesLevenshteinBase -from fuzzysearch.common import Match, get_best_match_in_group, group_matches +from fuzzysearch.common import Match, get_best_match_in_group, group_matches, LevenshteinSearchParams from tests.test_substitutions_only import TestSubstitionsOnlyBase from tests.test_generic_search import TestGenericSearchBase @@ -24,8 +24,7 @@ else: for group in group_matches( c_fnm_generic_lp(subsequence, sequence, - max_l_dist, max_l_dist, - max_l_dist, max_l_dist) + LevenshteinSearchParams(max_l_dist, max_l_dist, max_l_dist, max_l_dist)) ) ] @@ -38,8 +37,7 @@ else: for group in group_matches( c_fnm_generic_ngrams(subsequence, sequence, - max_l_dist, max_l_dist, - max_l_dist, max_l_dist) + LevenshteinSearchParams(max_l_dist, max_l_dist, max_l_dist, max_l_dist)) ) ] @@ -51,7 +49,7 @@ else: return list( c_fnm_generic_lp(subsequence, sequence, - max_subs, 0, 0, max_subs) + LevenshteinSearchParams(max_subs, 0, 0, max_subs)) ) def expectedOutcomes(self, search_results, expected_outcomes, @@ -69,7 +67,7 @@ else: for group in group_matches( c_fnm_generic_ngrams(subsequence, sequence, - max_subs, 0, 0, max_subs) + LevenshteinSearchParams(max_subs, 0, 0, max_subs)) ) ] @@ -94,8 +92,10 @@ else: max_l_dist=None): return list(c_fnm_generic_lp(pattern, sequence, - max_subs, max_ins, - max_dels, max_l_dist)) + LevenshteinSearchParams( + max_subs, max_ins, + max_dels, max_l_dist, + ))) def expectedOutcomes(self, search_result, expected_outcomes, *args, **kw): @@ -135,8 +135,10 @@ else: for group in group_matches( c_fnm_generic_ngrams(pattern, sequence, - max_subs, max_ins, - max_dels, max_l_dist) + LevenshteinSearchParams( + max_subs, max_ins, + max_dels, max_l_dist, + )) ) ]