Fix/combine adjacent (#1426)

* Fix combine_adjacent arg of HighlightedText

* Delete multilingual_named_entity_recognition_using_mbert.md

* Fix file components.py style

* Fix style gradio/components.py

* Add adjacent_separator parameter to HighlightedText class

Co-authored-by: martina.fumanelli <martina.fumanelli@MBP-di-martinafumanelli.local>
Co-authored-by: martina.fumanelli <martina.fumanelli@MBPdimaumanelli.homenet.telecomitalia.it>
This commit is contained in:
Martina Fumanelli 2022-06-02 19:44:58 +02:00 committed by GitHub
parent 188d8bc65d
commit 74ccf3e957
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2758,6 +2758,7 @@ class HighlightedText(Changeable, IOComponent):
color_map: Dict[str, str] = None, color_map: Dict[str, str] = None,
show_legend: bool = False, show_legend: bool = False,
combine_adjacent: bool = False, combine_adjacent: bool = False,
adjacent_separator: str = "",
label: Optional[str] = None, label: Optional[str] = None,
show_label: bool = True, show_label: bool = True,
visible: bool = True, visible: bool = True,
@ -2766,7 +2767,10 @@ class HighlightedText(Changeable, IOComponent):
): ):
""" """
Parameters: Parameters:
value (List[Tuple[str, str | Number | None]]): Default value to show value (List[Tuple[str, str | Number | None]]): Default value to show.
color_map (Dict[str, str]): Map between category and respective colors.
combine_adjacent (bool): If True, will merge the labels of adjacent tokens belonging to the same category.
adjacent_separator (str): Specifies the separator to be used between tokens if combine_adjacent is True.
show_legend (bool): whether to show span categories in a separate legend or inline. show_legend (bool): whether to show span categories in a separate legend or inline.
label (Optional[str]): component name in interface. label (Optional[str]): component name in interface.
show_label (bool): if True, will display label. show_label (bool): if True, will display label.
@ -2780,6 +2784,7 @@ class HighlightedText(Changeable, IOComponent):
) )
self.show_legend = show_legend self.show_legend = show_legend
self.combine_adjacent = combine_adjacent self.combine_adjacent = combine_adjacent
self.adjacent_separator = adjacent_separator
self.value = self.postprocess(value) self.value = self.postprocess(value)
IOComponent.__init__( IOComponent.__init__(
self, self,
@ -2834,7 +2839,7 @@ class HighlightedText(Changeable, IOComponent):
running_text = text running_text = text
running_category = category running_category = category
elif category == running_category: elif category == running_category:
running_text += text running_text += self.adjacent_separator + text
else: else:
output.append((running_text, running_category)) output.append((running_text, running_category))
running_text = text running_text = text