Skip to content

Commit a4fc569

Browse files
committed
✨ add support for classifications in custom docs
1 parent 18047dc commit a4fc569

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

mindee/documents/custom_document.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
class CustomDocument(Document):
77
fields: Dict[str, dict]
88
"""Dictionary of all fields in the document"""
9+
classifications: Dict[str, dict]
10+
"""Dictionary of all classifications in the document"""
911

1012
def __init__(
1113
self,
@@ -39,14 +41,24 @@ def _build_from_api_prediction(
3941
:param page_n: Page number for multi pages pdf input
4042
"""
4143
self.fields = {}
44+
self.classifications = {}
4245
for field_name in api_prediction:
4346
field = api_prediction[field_name]
44-
field["page_n"] = page_n
45-
self.fields[field_name] = field
47+
# Only classifications have the 'value' attribute.
48+
if "value" in field:
49+
self.classifications[field_name] = field
50+
# Only value lists have the 'values' attribute.
51+
elif "values" in field:
52+
field["page_n"] = page_n
53+
self.fields[field_name] = field
4654
setattr(self, field_name, field)
4755

4856
def __str__(self) -> str:
49-
custom_doc_str = f"----- {self.type} -----\n"
57+
custom_doc_str = (
58+
f"----- {self.type} -----\nFilename: {self.filename or ''}".rstrip() + "\n"
59+
)
60+
for name, info in self.classifications.items():
61+
custom_doc_str += f"{name}: {info['value']}\n"
5062
for name, info in self.fields.items():
5163
custom_doc_str += "%s: %s\n" % (
5264
name,

0 commit comments

Comments
 (0)