-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TLDR-419 add confidence annotation (#301)
* add new annotation * add confidence extracting * add test for confidence annotation * add confidence annotation to documentation * fix flake * add mergeable field for annotation * review fixes
- Loading branch information
1 parent
9a5704c
commit 28fd511
Showing
9 changed files
with
69 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
dedoc/data_structures/concrete_annotations/confidence_annotation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from flask_restx import fields, Api, Model | ||
|
||
from dedoc.data_structures.annotation import Annotation | ||
|
||
|
||
class ConfidenceAnnotation(Annotation): | ||
""" | ||
Confidence level of some recognized with OCR text inside the line. | ||
""" | ||
name = "confidence" | ||
|
||
def __init__(self, start: int, end: int, value: str) -> None: | ||
""" | ||
:param start: start of the text | ||
:param end: end of the text (not included) | ||
:param value: confidence level in "percents" (float or integer number from 0 to 100) | ||
""" | ||
try: | ||
assert 0.0 <= float(value) <= 100.0 | ||
except ValueError: | ||
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, is_mergeable=False) | ||
|
||
@staticmethod | ||
def get_api_dict(api: Api) -> Model: | ||
return api.model('BoldAnnotation', { | ||
'start': fields.Integer(description='annotation start index', required=True, example=0), | ||
'end': fields.Integer(description='annotation end index', required=True, example=4), | ||
'value': fields.String(description='confidence value', required=True, example="95") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters