Skip to content

Commit

Permalink
add mergeable field for annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
dronperminov committed Jul 31, 2023
1 parent 999a174 commit b04b471
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion dedoc/data_structures/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Annotation(Serializable):
Look to the concrete kind of annotations to get mode examples.
"""

def __init__(self, start: int, end: int, name: str, value: str) -> None:
def __init__(self, start: int, end: int, name: str, value: str, mergeable: bool = True) -> None:
"""
Some kind of text information about symbols between start and end.
For example Annotation(1, 13, "italic", "True") says that text between 1st and 13th symbol was writen in italic.
Expand All @@ -21,11 +21,13 @@ def __init__(self, start: int, end: int, name: str, value: str) -> None:
:param end: end of the annotated text (end isn't included)
:param name: annotation's name
:param value: information about annotated text
:param mergeable: is it possible to merge annotations with the same value
"""
self.start = start
self.end = end
self.name = name
self.value = value
self.mergeable = mergeable

def __eq__(self, o: object) -> bool:
if not isinstance(o, Annotation):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, start: int, end: int, value: str) -> None:
raise ValueError("the value of confidence annotation should be float value")
except AssertionError:
raise ValueError("the value of confidence annotation should be in range [0, 100]")
super().__init__(start=start, end=end, name=ConfidenceAnnotation.name, value=value)
super().__init__(start=start, end=end, name=ConfidenceAnnotation.name, value=value, mergeable=False)

@staticmethod
def get_api_dict(api: Api) -> Model:
Expand Down
2 changes: 1 addition & 1 deletion dedoc/utils/annotation_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def _merge_one_group(self, annotations: List[Annotation], spaces: List[Space]) -
"""
Merge one group annotations, assume that all annotations has the same name and value
"""
if len(annotations) <= 1:
if len(annotations) <= 1 or not annotations[0].mergeable:
return annotations
self.__check_annotations_group(annotations)
result = []
Expand Down

0 comments on commit b04b471

Please sign in to comment.