Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the InvisibleTextItem #80

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion docling_core/types/doc/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from docling_core.types.base import _JSON_POINTER_REGEX
from docling_core.types.doc import BoundingBox, Size
from docling_core.types.doc.base import ImageRefMode
from docling_core.types.doc.labels import DocItemLabel, GroupLabel
from docling_core.types.doc.labels import DocItemLabel, GroupLabel, InvisibleTextLabel
from docling_core.types.legacy_doc.tokens import DocumentToken
from docling_core.utils.file import relative_path

Expand Down Expand Up @@ -640,6 +640,13 @@ def export_to_document_tokens(
return body


class InvisibleTextItem(TextItem):
"""InvisibleTextItem."""

label: typing.Literal[DocItemLabel.INVISIBLE_TEXT] = DocItemLabel.INVISIBLE_TEXT
category: InvisibleTextLabel


class SectionHeaderItem(TextItem):
"""SectionItem."""

Expand Down
10 changes: 10 additions & 0 deletions docling_core/types/doc/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,22 @@ class DocItemLabel(str, Enum):
# Additional labels for markup-based formats (e.g. HTML, Word)
PARAGRAPH = "paragraph" # explicitly a paragraph and not arbitrary text
REFERENCE = "reference"
INVISIBLE_TEXT = "invisible_text"

def __str__(self):
"""Get string value."""
return str(self.value)


class InvisibleTextLabel(str, Enum):
Copy link
Contributor

@cau-git cau-git Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not introduce an additional dimension just forInvisibleTextLabel, let's avoid to have a second-level dependency to DocItemLabel.INVISIBLE_TEXT, and just put straight:

DocItemLabel.COMMENT # For speech-bubble comments where supported (we could enable it for some backends)
DocItemLabel.NOTE # For author or slide notes

as regular labels. Then, we can add these to the furniture (same as for heading or footers) and enable that the furniture can be iterated over together with the rest.

"""InvisibleTextLabel."""

UNSPECIFIED = "unspecified"

INVISIBLE_TEXT = "invisible_text"
AUTHOR_NOTE = "author_note"


class GroupLabel(str, Enum):
"""GroupLabel."""

Expand Down
3 changes: 2 additions & 1 deletion docs/DoclingDocument.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@
"form",
"key_value_region",
"paragraph",
"reference"
"reference",
"invisible_text"
],
"title": "DocItemLabel",
"type": "string"
Expand Down
8 changes: 8 additions & 0 deletions test/data/docling_document/unit/InvisibleTextItem.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
category: author_note
children: []
label: invisible_text
orig: whatever
parent: null
prov: []
self_ref: '#'
text: whatever
11 changes: 10 additions & 1 deletion test/test_docling_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
DocumentOrigin,
FloatingItem,
ImageRef,
InvisibleTextItem,
KeyValueItem,
ListItem,
PictureItem,
Expand All @@ -30,7 +31,7 @@
TableItem,
TextItem,
)
from docling_core.types.doc.labels import DocItemLabel, GroupLabel
from docling_core.types.doc.labels import DocItemLabel, GroupLabel, InvisibleTextLabel

GENERATE = False

Expand Down Expand Up @@ -138,6 +139,14 @@ def verify(dc, obj):
)
verify(dc, obj)

elif dc is InvisibleTextItem:
obj = dc(
text="whatever",
orig="whatever",
self_ref="#",
category=InvisibleTextLabel.AUTHOR_NOTE,
)
verify(dc, obj)
else:
# print(f"{dc.__name__} is not known")
assert False, "new derived class detected {dc.__name__}: {e}"
Expand Down