From 54abc44f648f863d6e2c694f0b0fcb93540399fd Mon Sep 17 00:00:00 2001 From: Richard Boyd Date: Tue, 6 Aug 2019 09:38:31 -0400 Subject: [PATCH] some code cleanup --- nlp/algorithms/finder/time_finder.py | 104 --------------------------- 1 file changed, 104 deletions(-) diff --git a/nlp/algorithms/finder/time_finder.py b/nlp/algorithms/finder/time_finder.py index d85a8587..1e1bf04d 100644 --- a/nlp/algorithms/finder/time_finder.py +++ b/nlp/algorithms/finder/time_finder.py @@ -416,9 +416,6 @@ _str_brackets = r'[(){}\[\]]' _regex_brackets = re.compile(_str_brackets) -#_CANDIDATE_FIELDS = ['start', 'end', 'match_text', 'regex'] -#_Candidate = namedtuple('_Candidate', _CANDIDATE_FIELDS) - ############################################################################### def enable_debug(): @@ -427,107 +424,6 @@ def enable_debug(): _TRACE = True -# ############################################################################### -# def _has_overlap(a1, b1, a2, b2): -# """ -# Determine if intervals [a1, b1) and [a2, b2) overlap at all. -# """ - -# assert a1 <= b1 -# assert a2 <= b2 - -# if b2 <= a1: -# return False -# elif a2 >= b1: -# return False -# else: -# return True - -# ############################################################################### -# def _remove_overlap(candidates): -# """ -# Given a set of match candidates, resolve into nonoverlapping matches. -# Take the longest match at any given position. - -# ASSUMES that the candidate list has been sorted by matching text length, -# from longest to shortest. -# """ - -# if _TRACE: -# print('called _remove_overlap...') - -# results = [] -# overlaps = [] -# indices = [i for i in range(len(candidates))] - -# i = 0 -# while i < len(indices): - -# if _TRACE: -# print('\tstarting indices: {0}'.format(indices)) - -# index_i = indices[i] -# start_i = candidates[index_i].start -# end_i = candidates[index_i].end -# len_i = end_i - start_i - -# overlaps.append(i) -# candidate_index = index_i - -# j = i+1 -# while j < len(indices): -# index_j = indices[j] -# start_j = candidates[index_j].start -# end_j = candidates[index_j].end -# len_j = end_j - start_j - -# # does candidate[j] overlap candidate[i] at all -# if _has_overlap(start_i, end_i, start_j, end_j): -# if _TRACE: -# print('\t\t{0} OVERLAPS {1}, lengths {2}, {3}'. -# format(candidates[index_i].match_text, -# candidates[index_j].match_text, -# len_i, len_j)) -# overlaps.append(j) -# # keep the longest match at any overlap region -# if len_j > len_i: -# start_i = start_j -# end_i = end_j -# len_i = len_j -# candidate_index = index_j -# j += 1 - -# if _TRACE: -# print('\t\t\twinner: {0}'. -# format(candidates[candidate_index].match_text)) -# print('\t\t\tappending {0} to results'. -# format(candidates[candidate_index].match_text)) - -# results.append(candidates[candidate_index]) - -# if _TRACE: -# print('\t\toverlaps: {0}'.format(overlaps)) - -# # remove all overlaps -# new_indices = [] -# for k in range(len(indices)): -# if k not in overlaps: -# new_indices.append(indices[k]) -# indices = new_indices - -# if _TRACE: -# print('\t\tindices after removing overlaps: {0}'.format(indices)) - -# if 0 == len(indices): -# break - -# # start over -# i = 0 -# overlaps = [] - -# return results - - ############################################################################### def _clean_sentence(sentence): """