Skip to content

Commit

Permalink
#355 refactoring. (id func)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolay-r committed Jul 26, 2022
1 parent f146497 commit 1a5e673
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions arekit/common/evaluation/comparators/text_opinions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,22 @@ def __create_index_by_id(context_opinions, id_func):
index[id_func(o_etalon)] = o_etalon
return index

def __iter_diff_core(self, etalon_context_opinions, test_context_opinions):
def __iter_diff_core(self, etalon_context_opinions, test_context_opinions, id_func):
""" Perform the comparison by the exact
"""
assert(isinstance(etalon_context_opinions, list))
assert(isinstance(test_context_opinions, list))
assert(callable(id_func))

test_by_id = TextOpinionBasedComparator.__create_index_by_id(
test_context_opinions, id_func=self.context_opinion_to_id)
test_context_opinions, id_func=id_func)

etalon_by_id = TextOpinionBasedComparator.__create_index_by_id(
etalon_context_opinions, id_func=self.context_opinion_to_id)
etalon_context_opinions, id_func=id_func)

for o_etalon in etalon_context_opinions:
assert(isinstance(o_etalon, ContextOpinion))
o_id = self.context_opinion_to_id(o_etalon)
o_id = id_func(o_etalon)
o_test = test_by_id[o_id] if o_id in test_by_id else None
has_opinion = o_test is not None

Expand All @@ -64,7 +65,7 @@ def __iter_diff_core(self, etalon_context_opinions, test_context_opinions):

for o_test in test_context_opinions:
assert(isinstance(o_test, ContextOpinion))
o_id = self.context_opinion_to_id(o_test)
o_id = id_func(o_test)
has_opinion = etalon_by_id[o_id] if o_id in etalon_by_id else None

if has_opinion:
Expand All @@ -87,7 +88,9 @@ def calc_diff(self, etalon, test, is_label_supported):
assert(isinstance(test, list))
assert(callable(is_label_supported))

it = self.__iter_diff_core(etalon_context_opinions=etalon, test_context_opinions=test)
it = self.__iter_diff_core(etalon_context_opinions=etalon,
test_context_opinions=test,
id_func=self.context_opinion_to_id)

# Cache all rows into `rows` array
rows = []
Expand Down

0 comments on commit 1a5e673

Please sign in to comment.