Skip to content

Commit aa957cf

Browse files
authored
fix: Updates for labels and methods to support document GT annotation (#293)
Update labels and get_color Signed-off-by: Christoph Auer <[email protected]>
1 parent e3bb22f commit aa957cf

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

docling_core/types/doc/labels.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class DocItemLabel(str, Enum):
2525
CHECKBOX_UNSELECTED = "checkbox_unselected"
2626
FORM = "form"
2727
KEY_VALUE_REGION = "key_value_region"
28+
GRADING_SCALE = "grading_scale" # for elements in forms, questionaires representing a grading scale
29+
# e.g. [strongly disagree | ... | ... | strongly agree]
2830

2931
# Additional labels for markup-based formats (e.g. HTML, Word)
3032
PARAGRAPH = "paragraph"
@@ -144,17 +146,43 @@ def __str__(self):
144146
"""Get string value."""
145147
return str(self.value)
146148

149+
@staticmethod
150+
def get_color(label: "TableCellLabel") -> Tuple[int, int, int]:
151+
"""Return the RGB color associated with a given label."""
152+
color_map = {
153+
TableCellLabel.COLUMN_HEADER: (255, 0, 0),
154+
TableCellLabel.ROW_HEADER: (0, 255, 0),
155+
TableCellLabel.ROW_SECTION: (0, 0, 255),
156+
TableCellLabel.BODY: (0, 255, 255),
157+
}
158+
return color_map.get(label, (0, 0, 0))
159+
147160

148161
class GraphCellLabel(str, Enum):
149162
"""GraphCellLabel."""
150163

151164
UNSPECIFIED = "unspecified"
152165

153-
KEY = "key"
154-
VALUE = "value"
155-
166+
KEY = "key" # used to designate a key (label) of a key-value element
167+
VALUE = "value" # Data value with or without explicit Key, but filled in,
168+
# e.g. telephone number, address, quantity, name, date
169+
EMPTY_VALUE = "empty_value" # used for empty value fields in fillable forms
156170
CHECKBOX = "checkbox"
157171

172+
def __str__(self):
173+
"""Get string value."""
174+
return str(self.value)
175+
176+
@staticmethod
177+
def get_color(label: "GraphCellLabel") -> Tuple[int, int, int]:
178+
"""Return the RGB color associated with a given label."""
179+
color_map = {
180+
GraphCellLabel.KEY: (255, 0, 0),
181+
GraphCellLabel.VALUE: (0, 255, 0),
182+
GraphCellLabel.EMPTY_VALUE: (0, 0, 255),
183+
}
184+
return color_map.get(label, (0, 0, 0))
185+
158186

159187
class GraphLinkLabel(str, Enum):
160188
"""GraphLinkLabel."""

docs/DoclingDocument.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@
682682
"unspecified",
683683
"key",
684684
"value",
685+
"empty_value",
685686
"checkbox"
686687
],
687688
"title": "GraphCellLabel",

0 commit comments

Comments
 (0)