Skip to content

Commit

Permalink
#418 switched to display_value. #416 related. Now we don't modify the…
Browse files Browse the repository at this point in the history
… oriainal value, since it affects on the `SynonymsCollection` behavior.
  • Loading branch information
nicolay-r committed Nov 25, 2022
1 parent de81638 commit 5420b74
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions arekit/common/entities/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,33 @@ def __init__(self, value, e_type, group_index=None):
self.__value = value.lower()
self.__type = e_type
self.__group_index = group_index
self.__caption = None
self.__display_value = None

@property
def GroupIndex(self):
return self.__group_index

@property
def Value(self):
return self.__value

@property
def DisplayValue(self):
""" Now, we consider the default value in case
of the undefined caption, and caption otherwise.
of the undefined caption, and display_value otherwise.
"""
return self.__value if self.__caption is None else self.__caption
return self.__value if self.__display_value is None else self.__display_value

@property
def Type(self):
return self.__type

def set_caption(self, caption):
def set_display_value(self, caption):
""" Caption allows to customize the original value.
Required for optional value modification.
"""
assert(isinstance(caption, str))
self.__caption = caption
self.__display_value = caption

def set_group_index(self, value):
assert(isinstance(value, int) and value >= -1)
Expand Down
2 changes: 1 addition & 1 deletion arekit/contrib/utils/pipelines/items/text/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def __optionally_register(prts_to_join):

for entity_ind, entity_part_ind in enumerate(origin_entity_ind):
entity = origin_entities[entity_ind]
entity.set_caption(translated_parts[entity_part_ind])
entity.set_display_value(translated_parts[entity_part_ind])
translated_parts[entity_part_ind] = entity

return translated_parts

0 comments on commit 5420b74

Please sign in to comment.