Пример #1
0
def choose_search_func(search_params):
    max_substitutions, max_insertions, max_deletions, max_l_dist = search_params.unpacked

    # if the limitations are so strict that only exact matches are allowed,
    # use search_exact()
    if search_params.max_l_dist == 0:
        return lambda subsequence, sequence, search_params: [
            Match(index, index + len(subsequence), 0)
            for index in search_exact(subsequence, sequence)
        ]
        # return [
        #     Match(start_index, start_index + len(subsequence), 0)
        #     for start_index in search_exact(subsequence, sequence)
        # ]

    # if only substitutions are allowed, use find_near_matches_substitutions()
    elif max_insertions == 0 and max_deletions == 0:
        # max_subs = \
        #     min([x for x in [max_l_dist, max_substitutions] if x is not None])
        return lambda subsequence, sequence, search_params:\
            find_near_matches_substitutions(
                subsequence, sequence,
                min([x for x in [search_params.max_l_dist, search_params.max_substitutions] if x is not None])
            )

    # if it is enough to just take into account the maximum Levenshtein
    # distance, use find_near_matches_levenshtein()
    elif max_l_dist <= min(
        (max_substitutions if max_substitutions is not None else (1 << 29)),
        (max_insertions if max_insertions is not None else (1 << 29)),
        (max_deletions if max_deletions is not None else (1 << 29)),
    ):
        return lambda subsequence, sequence, search_params:\
            find_near_matches_levenshtein(subsequence, sequence, search_params.max_l_dist)

    # if none of the special cases above are met, use the most generic version
    else:
        return find_near_matches_generic
Пример #2
0
 def search(self, subsequence, sequence, max_l_dist):
     return consolidate_overlapping_matches(
         find_near_matches_levenshtein(subsequence, sequence, max_l_dist)
     )
Пример #3
0
 def search(self, subsequence, sequence, max_l_dist):
     return find_near_matches_levenshtein(subsequence, sequence, max_l_dist)
Пример #4
0
 def search(self, subsequence, sequence, max_l_dist):
     return consolidate_overlapping_matches(
         find_near_matches_levenshtein(subsequence, sequence, max_l_dist)
     )