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!
This commit is contained in:
Tal Einat 2017-07-05 12:07:02 +03:00
parent 6b78c48255
commit 91bf9d0c5f
3 changed files with 17 additions and 16 deletions

View File

@ -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

View File

@ -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):

View File

@ -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,
))
)
]