docling-core 2.85.0__tar.gz → 2.87.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {docling_core-2.85.0 → docling_core-2.87.0}/PKG-INFO +1 -1
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/cli/view.py +1 -2
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/visualizer/layout_visualizer.py +1 -1
- docling_core-2.87.0/docling_core/types/doc/__init__.py +200 -0
- docling_core-2.87.0/docling_core/types/doc/common/__init__.py +1 -0
- docling_core-2.87.0/docling_core/types/doc/common/annotations.py +26 -0
- docling_core-2.87.0/docling_core/types/doc/common/constants.py +45 -0
- docling_core-2.87.0/docling_core/types/doc/common/content_layer.py +16 -0
- docling_core-2.87.0/docling_core/types/doc/common/formatting.py +23 -0
- docling_core-2.87.0/docling_core/types/doc/common/meta.py +290 -0
- docling_core-2.87.0/docling_core/types/doc/common/origin.py +68 -0
- docling_core-2.87.0/docling_core/types/doc/common/reference.py +188 -0
- docling_core-2.87.0/docling_core/types/doc/common/scalars.py +10 -0
- docling_core-2.87.0/docling_core/types/doc/common/source.py +72 -0
- docling_core-2.87.0/docling_core/types/doc/doctags.py +79 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/types/doc/document.py +225 -2909
- docling_core-2.87.0/docling_core/types/doc/items/__init__.py +1 -0
- docling_core-2.87.0/docling_core/types/doc/items/code.py +61 -0
- docling_core-2.87.0/docling_core/types/doc/items/content.py +29 -0
- docling_core-2.87.0/docling_core/types/doc/items/form.py +26 -0
- docling_core-2.87.0/docling_core/types/doc/items/group.py +61 -0
- docling_core-2.87.0/docling_core/types/doc/items/key_value.py +113 -0
- docling_core-2.87.0/docling_core/types/doc/items/node.py +233 -0
- docling_core-2.87.0/docling_core/types/doc/items/picture/__init__.py +1 -0
- docling_core-2.87.0/docling_core/types/doc/items/picture/charts.py +169 -0
- docling_core-2.87.0/docling_core/types/doc/items/picture/classification.py +27 -0
- docling_core-2.87.0/docling_core/types/doc/items/picture/meta.py +57 -0
- docling_core-2.87.0/docling_core/types/doc/items/picture/molecule.py +23 -0
- docling_core-2.87.0/docling_core/types/doc/items/picture/picture.py +274 -0
- docling_core-2.87.0/docling_core/types/doc/items/table/__init__.py +1 -0
- docling_core-2.87.0/docling_core/types/doc/items/table/table.py +359 -0
- docling_core-2.87.0/docling_core/types/doc/items/table/table_data.py +714 -0
- docling_core-2.87.0/docling_core/types/doc/items/text.py +152 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/types/doc/labels.py +1 -1
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/types/doc/page.py +6 -12
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/types/doc/utils.py +116 -13
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/utils/generate_docs.py +7 -6
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/utils/validators.py +18 -1
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core.egg-info/PKG-INFO +1 -1
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core.egg-info/SOURCES.txt +29 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/pyproject.toml +4 -1
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_doclang_archive.py +91 -0
- docling_core-2.87.0/test/test_upath_support.py +182 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_utils.py +25 -29
- docling_core-2.85.0/docling_core/types/doc/__init__.py +0 -104
- {docling_core-2.85.0 → docling_core-2.87.0}/LICENSE +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/README.md +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/__init__.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/cli/__init__.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/cli/serialize.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/experimental/__init__.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/experimental/serializer/__init__.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/experimental/serializer/outline.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/py.typed +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/search/__init__.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/search/package.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/__init__.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/chunker/__init__.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/chunker/base.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/chunker/chunk_expander.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/chunker/code_chunking/__init__.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/chunker/code_chunking/_language_code_chunkers.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/chunker/code_chunking/_utils.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/chunker/code_chunking/base_code_chunking_strategy.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/chunker/code_chunking/code_chunk.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/chunker/code_chunking/standard_code_chunking_strategy.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/chunker/doc_chunk.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/chunker/hierarchical_chunker.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/chunker/hybrid_chunker.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/chunker/line_chunker.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/chunker/page_chunker.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/chunker/tokenizer/__init__.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/chunker/tokenizer/base.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/chunker/tokenizer/huggingface.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/chunker/tokenizer/openai.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/deserializer/__init__.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/deserializer/base.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/deserializer/doclang.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/profiler/__init__.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/profiler/doc_profiler.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/serializer/__init__.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/serializer/_doclang_utils.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/serializer/azure.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/serializer/base.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/serializer/common.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/serializer/doclang.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/serializer/doctags.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/serializer/html.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/serializer/html_styles.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/serializer/latex.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/serializer/markdown.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/serializer/markdown_excel.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/serializer/plain_text.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/serializer/webvtt.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/visualizer/__init__.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/visualizer/base.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/visualizer/key_value_visualizer.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/visualizer/reading_order_visualizer.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/visualizer/table_visualizer.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/types/__init__.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/types/base.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/types/doc/base.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/types/doc/tokens.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/types/doc/webvtt.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/types/io/__init__.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/types/legacy_doc/__init__.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/types/legacy_doc/base.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/types/legacy_doc/document.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/utils/__init__.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/utils/alias.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/utils/file.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/utils/generate_jsonschema.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/utils/legacy.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core/utils/settings.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core.egg-info/dependency_links.txt +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core.egg-info/entry_points.txt +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core.egg-info/requires.txt +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/docling_core.egg-info/top_level.txt +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/setup.cfg +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_azure_serializer.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_base.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_chunk_expander.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_code_chunker.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_code_chunking_strategy.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_data_gen_flag.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_deserializer_doclang.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_doc_base.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_docling_doc.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_doctags_load.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_hierarchical_chunker.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_hierarchy.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_hybrid_chunker.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_latex_serialization.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_line_chunker.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_metadata.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_otsl_table_export.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_page.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_page_chunker.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_plain_text_serialization.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_profiler.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_regions_to_table.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_serialization.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_serialization_doclang.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_serialization_doctag.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_serialization_outline.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_visualization.py +0 -0
- {docling_core-2.85.0 → docling_core-2.87.0}/test/test_webvtt.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: docling-core
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.87.0
|
|
4
4
|
Summary: A python library to define and validate data types in Docling.
|
|
5
5
|
Author-email: Cesar Berrospi Ramis <ceb@zurich.ibm.com>, Panos Vagenas <pva@zurich.ibm.com>, Michele Dolfi <dol@zurich.ibm.com>, Christoph Auer <cau@zurich.ibm.com>, Peter Staar <taa@zurich.ibm.com>
|
|
6
6
|
Maintainer-email: Panos Vagenas <pva@zurich.ibm.com>, Michele Dolfi <dol@zurich.ibm.com>, Christoph Auer <cau@zurich.ibm.com>, Peter Staar <taa@zurich.ibm.com>, Cesar Berrospi Ramis <ceb@zurich.ibm.com>
|
|
@@ -69,8 +69,7 @@ def view(
|
|
|
69
69
|
image_mode=ImageRefMode.EMBEDDED,
|
|
70
70
|
split_page_view=split_view,
|
|
71
71
|
)
|
|
72
|
-
|
|
73
|
-
f.write(html_output)
|
|
72
|
+
target_path.write_text(html_output, encoding="utf-8")
|
|
74
73
|
webbrowser.open(url=f"file://{target_path.absolute().resolve()}")
|
|
75
74
|
|
|
76
75
|
|
{docling_core-2.85.0 → docling_core-2.87.0}/docling_core/transforms/visualizer/layout_visualizer.py
RENAMED
|
@@ -148,7 +148,7 @@ class LayoutVisualizer(BaseVisualizer):
|
|
|
148
148
|
images: Optional[dict[Optional[int], Image]] = None,
|
|
149
149
|
included_content_layers: Optional[set[ContentLayer]] = None,
|
|
150
150
|
):
|
|
151
|
-
"""Draw the document clusters and
|
|
151
|
+
"""Draw the document clusters and optionally the reading order."""
|
|
152
152
|
clusters = []
|
|
153
153
|
my_images: dict[Optional[int], Image] = {}
|
|
154
154
|
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"""Package for models defined by the Document type."""
|
|
2
|
+
|
|
3
|
+
from docling_core.types.doc.base import (
|
|
4
|
+
BoundingBox,
|
|
5
|
+
CoordOrigin,
|
|
6
|
+
ImageRefMode,
|
|
7
|
+
PydanticSerCtxKey,
|
|
8
|
+
Size,
|
|
9
|
+
)
|
|
10
|
+
from docling_core.types.doc.common.annotations import (
|
|
11
|
+
BaseAnnotation,
|
|
12
|
+
DescriptionAnnotation,
|
|
13
|
+
MiscAnnotation,
|
|
14
|
+
)
|
|
15
|
+
from docling_core.types.doc.common.content_layer import ContentLayer
|
|
16
|
+
from docling_core.types.doc.common.formatting import (
|
|
17
|
+
Formatting,
|
|
18
|
+
Script,
|
|
19
|
+
)
|
|
20
|
+
from docling_core.types.doc.common.meta import (
|
|
21
|
+
BaseMeta,
|
|
22
|
+
BasePrediction,
|
|
23
|
+
CodeMetaField,
|
|
24
|
+
DescriptionMetaField,
|
|
25
|
+
EntitiesMetaField,
|
|
26
|
+
EntityMention,
|
|
27
|
+
FloatingMeta,
|
|
28
|
+
KeywordsMetaField,
|
|
29
|
+
LanguageMetaField,
|
|
30
|
+
MetaFieldName,
|
|
31
|
+
MetaUtils,
|
|
32
|
+
SummaryMetaField,
|
|
33
|
+
TopicsMetaField,
|
|
34
|
+
)
|
|
35
|
+
from docling_core.types.doc.common.origin import (
|
|
36
|
+
DocumentOrigin,
|
|
37
|
+
)
|
|
38
|
+
from docling_core.types.doc.common.reference import (
|
|
39
|
+
FineRef,
|
|
40
|
+
ImageRef,
|
|
41
|
+
PageItem,
|
|
42
|
+
ProvenanceItem,
|
|
43
|
+
RefItem,
|
|
44
|
+
)
|
|
45
|
+
from docling_core.types.doc.common.scalars import (
|
|
46
|
+
CharSpan,
|
|
47
|
+
LevelNumber,
|
|
48
|
+
Uint64,
|
|
49
|
+
)
|
|
50
|
+
from docling_core.types.doc.common.source import (
|
|
51
|
+
BaseSource,
|
|
52
|
+
SourceType,
|
|
53
|
+
TrackSource,
|
|
54
|
+
)
|
|
55
|
+
from docling_core.types.doc.doctags import (
|
|
56
|
+
DocTagsDocument,
|
|
57
|
+
DocTagsPage,
|
|
58
|
+
)
|
|
59
|
+
from docling_core.types.doc.document import DoclingDocument
|
|
60
|
+
from docling_core.types.doc.items.code import CodeItem
|
|
61
|
+
from docling_core.types.doc.items.content import ContentItem
|
|
62
|
+
from docling_core.types.doc.items.form import (
|
|
63
|
+
FieldHeadingItem,
|
|
64
|
+
FieldItem,
|
|
65
|
+
FieldRegionItem,
|
|
66
|
+
FieldValueItem,
|
|
67
|
+
)
|
|
68
|
+
from docling_core.types.doc.items.group import (
|
|
69
|
+
GroupItem,
|
|
70
|
+
InlineGroup,
|
|
71
|
+
ListGroup,
|
|
72
|
+
OrderedList,
|
|
73
|
+
UnorderedList,
|
|
74
|
+
)
|
|
75
|
+
from docling_core.types.doc.items.key_value import (
|
|
76
|
+
FormItem,
|
|
77
|
+
GraphCell,
|
|
78
|
+
GraphData,
|
|
79
|
+
GraphLink,
|
|
80
|
+
KeyValueItem,
|
|
81
|
+
)
|
|
82
|
+
from docling_core.types.doc.items.node import (
|
|
83
|
+
DocItem,
|
|
84
|
+
FloatingItem,
|
|
85
|
+
NodeItem,
|
|
86
|
+
)
|
|
87
|
+
from docling_core.types.doc.items.picture.charts import (
|
|
88
|
+
ChartBar,
|
|
89
|
+
ChartLine,
|
|
90
|
+
ChartPoint,
|
|
91
|
+
ChartSlice,
|
|
92
|
+
ChartStackedBar,
|
|
93
|
+
PictureBarChartData,
|
|
94
|
+
PictureChartData,
|
|
95
|
+
PictureLineChartData,
|
|
96
|
+
PicturePieChartData,
|
|
97
|
+
PictureScatterChartData,
|
|
98
|
+
PictureStackedBarChartData,
|
|
99
|
+
PictureTabularChartData,
|
|
100
|
+
)
|
|
101
|
+
from docling_core.types.doc.items.picture.classification import (
|
|
102
|
+
PictureClassificationClass,
|
|
103
|
+
PictureClassificationData,
|
|
104
|
+
)
|
|
105
|
+
from docling_core.types.doc.items.picture.meta import (
|
|
106
|
+
MoleculeMetaField,
|
|
107
|
+
PictureClassificationMetaField,
|
|
108
|
+
PictureClassificationPrediction,
|
|
109
|
+
PictureMeta,
|
|
110
|
+
TabularChartMetaField,
|
|
111
|
+
)
|
|
112
|
+
from docling_core.types.doc.items.picture.molecule import PictureMoleculeData
|
|
113
|
+
from docling_core.types.doc.items.picture.picture import (
|
|
114
|
+
BasePictureData,
|
|
115
|
+
PictureDataType,
|
|
116
|
+
PictureDescriptionData,
|
|
117
|
+
PictureItem,
|
|
118
|
+
PictureMiscData,
|
|
119
|
+
)
|
|
120
|
+
from docling_core.types.doc.items.table.table import (
|
|
121
|
+
TableAnnotationType,
|
|
122
|
+
TableItem,
|
|
123
|
+
)
|
|
124
|
+
from docling_core.types.doc.items.table.table_data import (
|
|
125
|
+
AnyTableCell,
|
|
126
|
+
Orientation,
|
|
127
|
+
RichTableCell,
|
|
128
|
+
TableCell,
|
|
129
|
+
TableData,
|
|
130
|
+
)
|
|
131
|
+
from docling_core.types.doc.items.text import (
|
|
132
|
+
FormulaItem,
|
|
133
|
+
ListItem,
|
|
134
|
+
SectionHeaderItem,
|
|
135
|
+
TextItem,
|
|
136
|
+
TitleItem,
|
|
137
|
+
)
|
|
138
|
+
from docling_core.types.doc.labels import (
|
|
139
|
+
CodeLanguageLabel,
|
|
140
|
+
DocItemLabel,
|
|
141
|
+
GraphCellLabel,
|
|
142
|
+
GraphLinkLabel,
|
|
143
|
+
GroupLabel,
|
|
144
|
+
HumanLanguageLabel,
|
|
145
|
+
PictureClassificationLabel,
|
|
146
|
+
TableCellLabel,
|
|
147
|
+
)
|
|
148
|
+
from docling_core.types.doc.page import (
|
|
149
|
+
BitmapResource,
|
|
150
|
+
BoundingRectangle,
|
|
151
|
+
ColorChannelValue,
|
|
152
|
+
ColorMixin,
|
|
153
|
+
ColorRGBA,
|
|
154
|
+
Coord2D,
|
|
155
|
+
OrderedElement,
|
|
156
|
+
PageGeometry,
|
|
157
|
+
PageNumber,
|
|
158
|
+
ParsedPdfDocument,
|
|
159
|
+
PdfCellRenderingMode,
|
|
160
|
+
PdfHyperlink,
|
|
161
|
+
PdfLine,
|
|
162
|
+
PdfMetaData,
|
|
163
|
+
PdfPageBoundaryType,
|
|
164
|
+
PdfPageGeometry,
|
|
165
|
+
PdfShape,
|
|
166
|
+
PdfTableOfContents,
|
|
167
|
+
PdfTextCell,
|
|
168
|
+
PdfWidget,
|
|
169
|
+
SegmentedPage,
|
|
170
|
+
SegmentedPdfPage,
|
|
171
|
+
TextCell,
|
|
172
|
+
TextCellUnit,
|
|
173
|
+
TextDirection,
|
|
174
|
+
)
|
|
175
|
+
from docling_core.types.doc.tokens import (
|
|
176
|
+
DocumentToken,
|
|
177
|
+
TableToken,
|
|
178
|
+
)
|
|
179
|
+
from docling_core.types.doc.webvtt import (
|
|
180
|
+
WebVTTCueBlock,
|
|
181
|
+
WebVTTCueBoldSpan,
|
|
182
|
+
WebVTTCueClassSpan,
|
|
183
|
+
WebVTTCueComponent,
|
|
184
|
+
WebVTTCueComponentBase,
|
|
185
|
+
WebVTTCueComponentWithTerminator,
|
|
186
|
+
WebVTTCueIdentifier,
|
|
187
|
+
WebVTTCueInternalText,
|
|
188
|
+
WebVTTCueItalicSpan,
|
|
189
|
+
WebVTTCueLanguageSpan,
|
|
190
|
+
WebVTTCueLanguageSpanStartTag,
|
|
191
|
+
WebVTTCueSpanStartTag,
|
|
192
|
+
WebVTTCueSpanStartTagAnnotated,
|
|
193
|
+
WebVTTCueTextSpan,
|
|
194
|
+
WebVTTCueTimings,
|
|
195
|
+
WebVTTCueUnderlineSpan,
|
|
196
|
+
WebVTTCueVoiceSpan,
|
|
197
|
+
WebVTTFile,
|
|
198
|
+
WebVTTLineTerminator,
|
|
199
|
+
WebVTTTimestamp,
|
|
200
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Shared, cross-cutting value models for the Docling document model."""
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Generic annotation models shared across document items."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Literal
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class BaseAnnotation(BaseModel):
|
|
9
|
+
"""Base class for all annotation types."""
|
|
10
|
+
|
|
11
|
+
kind: str
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class DescriptionAnnotation(BaseAnnotation):
|
|
15
|
+
"""DescriptionAnnotation."""
|
|
16
|
+
|
|
17
|
+
kind: Literal["description"] = "description"
|
|
18
|
+
text: str
|
|
19
|
+
provenance: str
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class MiscAnnotation(BaseAnnotation):
|
|
23
|
+
"""MiscAnnotation."""
|
|
24
|
+
|
|
25
|
+
kind: Literal["misc"] = "misc"
|
|
26
|
+
content: dict[str, Any]
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""Document-level constants: schema version and default export label sets."""
|
|
2
|
+
|
|
3
|
+
from typing import Final
|
|
4
|
+
|
|
5
|
+
from docling_core.types.doc.labels import DocItemLabel
|
|
6
|
+
|
|
7
|
+
CURRENT_VERSION: Final = "1.10.0"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
DEFAULT_EXPORT_LABELS = {
|
|
11
|
+
DocItemLabel.TITLE,
|
|
12
|
+
DocItemLabel.DOCUMENT_INDEX,
|
|
13
|
+
DocItemLabel.SECTION_HEADER,
|
|
14
|
+
DocItemLabel.PARAGRAPH,
|
|
15
|
+
DocItemLabel.TABLE,
|
|
16
|
+
DocItemLabel.PICTURE,
|
|
17
|
+
DocItemLabel.FORMULA,
|
|
18
|
+
DocItemLabel.CHECKBOX_UNSELECTED,
|
|
19
|
+
DocItemLabel.CHECKBOX_SELECTED,
|
|
20
|
+
DocItemLabel.TEXT,
|
|
21
|
+
DocItemLabel.LIST_ITEM,
|
|
22
|
+
DocItemLabel.CODE,
|
|
23
|
+
DocItemLabel.REFERENCE,
|
|
24
|
+
DocItemLabel.PAGE_HEADER,
|
|
25
|
+
DocItemLabel.PAGE_FOOTER,
|
|
26
|
+
DocItemLabel.KEY_VALUE_REGION,
|
|
27
|
+
DocItemLabel.EMPTY_VALUE,
|
|
28
|
+
DocItemLabel.FIELD_KEY,
|
|
29
|
+
DocItemLabel.FIELD_VALUE,
|
|
30
|
+
DocItemLabel.FIELD_HEADING,
|
|
31
|
+
DocItemLabel.FIELD_HINT,
|
|
32
|
+
DocItemLabel.MARKER,
|
|
33
|
+
DocItemLabel.HANDWRITTEN_TEXT,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
DOCUMENT_TOKENS_EXPORT_LABELS = DEFAULT_EXPORT_LABELS.copy()
|
|
38
|
+
DOCUMENT_TOKENS_EXPORT_LABELS.update(
|
|
39
|
+
[
|
|
40
|
+
DocItemLabel.FOOTNOTE,
|
|
41
|
+
DocItemLabel.CAPTION,
|
|
42
|
+
DocItemLabel.KEY_VALUE_REGION,
|
|
43
|
+
DocItemLabel.FORM,
|
|
44
|
+
]
|
|
45
|
+
)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"""Content-layer enumeration for document nodes."""
|
|
2
|
+
|
|
3
|
+
from enum import Enum
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class ContentLayer(str, Enum):
|
|
7
|
+
"""ContentLayer."""
|
|
8
|
+
|
|
9
|
+
BODY = "body" # main content of the document
|
|
10
|
+
FURNITURE = "furniture" # eg page-headers/footers
|
|
11
|
+
BACKGROUND = "background" # eg watermarks
|
|
12
|
+
INVISIBLE = "invisible" # hidden or invisible text
|
|
13
|
+
NOTES = "notes" # author/speaker notes, corrections, etc
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
DEFAULT_CONTENT_LAYERS = {ContentLayer.BODY}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Text formatting models."""
|
|
2
|
+
|
|
3
|
+
from enum import Enum
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Script(str, Enum):
|
|
9
|
+
"""Text script position."""
|
|
10
|
+
|
|
11
|
+
BASELINE = "baseline"
|
|
12
|
+
SUB = "sub"
|
|
13
|
+
SUPER = "super"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Formatting(BaseModel):
|
|
17
|
+
"""Formatting."""
|
|
18
|
+
|
|
19
|
+
bold: bool = False
|
|
20
|
+
italic: bool = False
|
|
21
|
+
underline: bool = False
|
|
22
|
+
strikethrough: bool = False
|
|
23
|
+
script: Script = Script.BASELINE
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
"""Metadata models attached to document nodes."""
|
|
2
|
+
|
|
3
|
+
from enum import Enum
|
|
4
|
+
from typing import Annotated, Any, Final, Optional
|
|
5
|
+
|
|
6
|
+
from pydantic import (
|
|
7
|
+
BaseModel,
|
|
8
|
+
BeforeValidator,
|
|
9
|
+
ConfigDict,
|
|
10
|
+
Field,
|
|
11
|
+
FieldSerializationInfo,
|
|
12
|
+
field_serializer,
|
|
13
|
+
model_validator,
|
|
14
|
+
)
|
|
15
|
+
from typing_extensions import Self
|
|
16
|
+
|
|
17
|
+
from docling_core.types.base import UniqueList
|
|
18
|
+
from docling_core.types.doc.base import PydanticSerCtxKey, round_pydantic_float
|
|
19
|
+
from docling_core.types.doc.common.scalars import CharSpan
|
|
20
|
+
from docling_core.types.doc.labels import CodeLanguageLabel, HumanLanguageLabel
|
|
21
|
+
from docling_core.utils.validators import ensure_unique_list
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class _ExtraAllowingModel(BaseModel):
|
|
25
|
+
"""Base model allowing extra fields."""
|
|
26
|
+
|
|
27
|
+
model_config = ConfigDict(extra="allow")
|
|
28
|
+
|
|
29
|
+
def get_custom_part(self) -> dict[str, Any]:
|
|
30
|
+
"""Get the extra fields as a dictionary."""
|
|
31
|
+
return self.__pydantic_extra__ or {}
|
|
32
|
+
|
|
33
|
+
def _copy_without_extra(self) -> Self:
|
|
34
|
+
"""Create a copy without the extra fields."""
|
|
35
|
+
return self.model_validate(self.model_dump(exclude=set(self.get_custom_part())))
|
|
36
|
+
|
|
37
|
+
def _check_custom_field_format(self, key: str) -> None:
|
|
38
|
+
parts = key.split(MetaUtils._META_FIELD_NAMESPACE_DELIMITER, maxsplit=1)
|
|
39
|
+
if len(parts) != 2 or (not parts[0]) or (not parts[1]):
|
|
40
|
+
raise ValueError(
|
|
41
|
+
f"Custom meta field name must be in format 'namespace__field_name' (e.g. 'my_corp__max_size'): {key}"
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
@model_validator(mode="after")
|
|
45
|
+
def _validate_field_names(self) -> Self:
|
|
46
|
+
extra_dict = self.get_custom_part()
|
|
47
|
+
for key in self.model_dump():
|
|
48
|
+
if key in extra_dict:
|
|
49
|
+
self._check_custom_field_format(key=key)
|
|
50
|
+
elif MetaUtils._META_FIELD_NAMESPACE_DELIMITER in key:
|
|
51
|
+
raise ValueError(f"Standard meta field name must not contain '__': {key}")
|
|
52
|
+
|
|
53
|
+
return self
|
|
54
|
+
|
|
55
|
+
def __setattr__(self, name: str, value: Any) -> None:
|
|
56
|
+
super().__setattr__(name, value)
|
|
57
|
+
if name in self.get_custom_part():
|
|
58
|
+
self._check_custom_field_format(key=name)
|
|
59
|
+
|
|
60
|
+
def set_custom_field(self, namespace: str, name: str, value: Any) -> str:
|
|
61
|
+
"""Set a custom field and return the key."""
|
|
62
|
+
key = MetaUtils.create_meta_field_name(namespace=namespace, name=name)
|
|
63
|
+
setattr(self, key, value)
|
|
64
|
+
return key
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class BasePrediction(_ExtraAllowingModel):
|
|
68
|
+
"""Prediction field."""
|
|
69
|
+
|
|
70
|
+
confidence: Optional[float] = Field(
|
|
71
|
+
default=None,
|
|
72
|
+
ge=0,
|
|
73
|
+
le=1,
|
|
74
|
+
description="The confidence of the prediction.",
|
|
75
|
+
examples=[0.9, 0.42],
|
|
76
|
+
)
|
|
77
|
+
created_by: Optional[str] = Field(
|
|
78
|
+
default=None,
|
|
79
|
+
description="The origin of the prediction.",
|
|
80
|
+
examples=["ibm-granite/granite-docling-258M"],
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
@field_serializer("confidence")
|
|
84
|
+
def _serialize(self, value: float, info: FieldSerializationInfo) -> float:
|
|
85
|
+
return round_pydantic_float(value, info.context, PydanticSerCtxKey.CONFID_PREC)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class SummaryMetaField(BasePrediction):
|
|
89
|
+
"""Summary data."""
|
|
90
|
+
|
|
91
|
+
text: str
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class LanguageMetaField(BasePrediction):
|
|
95
|
+
"""Detected human language."""
|
|
96
|
+
|
|
97
|
+
code: HumanLanguageLabel
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
class MetaFieldName(str, Enum):
|
|
101
|
+
"""Standard meta field names attached to document nodes.
|
|
102
|
+
|
|
103
|
+
Note:
|
|
104
|
+
These enum members must be kept in sync with the fields of the `BaseMeta` class or its subclasses.
|
|
105
|
+
"""
|
|
106
|
+
|
|
107
|
+
SUMMARY = "summary"
|
|
108
|
+
"""A condensed natural-language summary of the content rooted at this node (e.g. a paragraph summary or section abstract)."""
|
|
109
|
+
|
|
110
|
+
LANGUAGE = "language"
|
|
111
|
+
"""The detected human language of the node content, expressed as a BCP 47 code (e.g. ``"en"``, ``"de"``)."""
|
|
112
|
+
|
|
113
|
+
ENTITIES = "entities"
|
|
114
|
+
"""Named entities extracted from the node text, such as persons, organisations, and locations."""
|
|
115
|
+
|
|
116
|
+
KEYWORDS = "keywords"
|
|
117
|
+
"""Salient terms or short keyphrases that characterise the node content. Values are order-preserving and unique."""
|
|
118
|
+
|
|
119
|
+
TOPICS = "topics"
|
|
120
|
+
"""Higher-level subject categories or thematic labels inferred for the node. Values are order-preserving and unique."""
|
|
121
|
+
|
|
122
|
+
DESCRIPTION = "description"
|
|
123
|
+
"""A free-text description of the node, typically used for non-textual items such as figures and images."""
|
|
124
|
+
|
|
125
|
+
CLASSIFICATION = "classification"
|
|
126
|
+
"""A classification label or category assigned to the node content (e.g. picture type, document genre)."""
|
|
127
|
+
|
|
128
|
+
MOLECULE = "molecule"
|
|
129
|
+
"""Structured chemical / molecule data associated with the node."""
|
|
130
|
+
|
|
131
|
+
TABULAR_CHART = "tabular_chart"
|
|
132
|
+
"""Tabular data extracted from a chart element."""
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class EntityMention(BasePrediction):
|
|
136
|
+
"""Entity mention extracted from text."""
|
|
137
|
+
|
|
138
|
+
text: Annotated[
|
|
139
|
+
str,
|
|
140
|
+
Field(description="Normalized text of the entity mention."),
|
|
141
|
+
]
|
|
142
|
+
orig: Annotated[
|
|
143
|
+
Optional[str],
|
|
144
|
+
Field(
|
|
145
|
+
description=(
|
|
146
|
+
"Exact source text extracted from the original charspan, "
|
|
147
|
+
"analogous to TextItem.orig. This may differ from 'text' when the "
|
|
148
|
+
"mention has been normalized."
|
|
149
|
+
)
|
|
150
|
+
),
|
|
151
|
+
] = None
|
|
152
|
+
label: Annotated[
|
|
153
|
+
Optional[str],
|
|
154
|
+
Field(description="Entity type or category."),
|
|
155
|
+
] = None
|
|
156
|
+
charspan: Annotated[
|
|
157
|
+
Optional[CharSpan],
|
|
158
|
+
Field(description="Character span (0-indexed) of the entity mention in the source text."),
|
|
159
|
+
] = None
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
class EntitiesMetaField(_ExtraAllowingModel):
|
|
163
|
+
"""Container for extracted entity mentions."""
|
|
164
|
+
|
|
165
|
+
mentions: Annotated[list[EntityMention], Field(min_length=1)]
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class KeywordsMetaField(_ExtraAllowingModel):
|
|
169
|
+
"""Container for a list of unique keywords / keyphrases."""
|
|
170
|
+
|
|
171
|
+
values: Annotated[UniqueList[str], BeforeValidator(ensure_unique_list), Field(min_length=1)]
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
class TopicsMetaField(_ExtraAllowingModel):
|
|
175
|
+
"""Container for a list of unique topics / subjects."""
|
|
176
|
+
|
|
177
|
+
values: Annotated[UniqueList[str], BeforeValidator(ensure_unique_list), Field(min_length=1)]
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
class BaseMeta(_ExtraAllowingModel):
|
|
181
|
+
"""Base class for metadata."""
|
|
182
|
+
|
|
183
|
+
summary: Annotated[
|
|
184
|
+
Optional[SummaryMetaField],
|
|
185
|
+
Field(
|
|
186
|
+
description="A condensed natural-language summary of the content rooted at this node.",
|
|
187
|
+
examples=[{"text": "A short company/location statement."}],
|
|
188
|
+
),
|
|
189
|
+
] = None
|
|
190
|
+
language: Annotated[
|
|
191
|
+
Optional[LanguageMetaField],
|
|
192
|
+
Field(
|
|
193
|
+
description="The detected human language of the node content, expressed as a BCP 47 code.",
|
|
194
|
+
examples=[{"code": "en"}],
|
|
195
|
+
),
|
|
196
|
+
] = None
|
|
197
|
+
entities: Annotated[
|
|
198
|
+
Optional[EntitiesMetaField],
|
|
199
|
+
Field(
|
|
200
|
+
description=(
|
|
201
|
+
"Named entities extracted from the node text (persons, organisations, locations, etc.). "
|
|
202
|
+
"Each mention carries the entity text, an optional type label, and an optional character span."
|
|
203
|
+
),
|
|
204
|
+
examples=[{"mentions": [{"text": "IBM", "label": "ORG", "charspan": [0, 3]}]}],
|
|
205
|
+
),
|
|
206
|
+
] = None
|
|
207
|
+
keywords: Annotated[
|
|
208
|
+
Optional[KeywordsMetaField],
|
|
209
|
+
Field(
|
|
210
|
+
description=(
|
|
211
|
+
"Salient terms or short keyphrases that characterise the node content. "
|
|
212
|
+
"Keywords are more specific than topics and typically correspond to individual words or "
|
|
213
|
+
"short multi-word expressions found in or closely related to the text. "
|
|
214
|
+
"Values are order-preserving and deduplicated."
|
|
215
|
+
),
|
|
216
|
+
examples=[{"values": ["transformer", "attention mechanism", "BERT"]}],
|
|
217
|
+
),
|
|
218
|
+
] = None
|
|
219
|
+
topics: Annotated[
|
|
220
|
+
Optional[TopicsMetaField],
|
|
221
|
+
Field(
|
|
222
|
+
description=(
|
|
223
|
+
"Higher-level subject categories or thematic labels inferred for the node content. "
|
|
224
|
+
"Topics are broader than keywords and describe the domain or theme rather than specific terms "
|
|
225
|
+
"(e.g., 'machine learning' rather than 'gradient descent'). "
|
|
226
|
+
"Values are order-preserving and deduplicated."
|
|
227
|
+
),
|
|
228
|
+
examples=[{"values": ["natural language processing", "computer vision"]}],
|
|
229
|
+
),
|
|
230
|
+
] = None
|
|
231
|
+
|
|
232
|
+
def has_content(self) -> bool:
|
|
233
|
+
"""Return True if this metadata contains any meaningful content."""
|
|
234
|
+
return any(self._value_has_content(value) for value in self.model_dump(exclude_none=True).values())
|
|
235
|
+
|
|
236
|
+
@staticmethod
|
|
237
|
+
def _value_has_content(value: Any) -> bool:
|
|
238
|
+
if value is None:
|
|
239
|
+
return False
|
|
240
|
+
if isinstance(value, list):
|
|
241
|
+
return any(BaseMeta._value_has_content(v) for v in value)
|
|
242
|
+
if isinstance(value, dict):
|
|
243
|
+
return any(BaseMeta._value_has_content(v) for v in value.values())
|
|
244
|
+
if isinstance(value, BaseModel):
|
|
245
|
+
return any(BaseMeta._value_has_content(v) for v in value.model_dump(exclude_none=True).values())
|
|
246
|
+
return True
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
class DescriptionMetaField(BasePrediction):
|
|
250
|
+
"""Description metadata field."""
|
|
251
|
+
|
|
252
|
+
text: str
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
class FloatingMeta(BaseMeta):
|
|
256
|
+
"""Metadata model for floating."""
|
|
257
|
+
|
|
258
|
+
description: Optional[DescriptionMetaField] = None
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
class CodeMetaField(BasePrediction):
|
|
262
|
+
"""Code representation for the respective item."""
|
|
263
|
+
|
|
264
|
+
text: str # the actual code
|
|
265
|
+
language: Optional[CodeLanguageLabel] = None
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
class MetaUtils:
|
|
269
|
+
"""Metadata-related utilities."""
|
|
270
|
+
|
|
271
|
+
_META_FIELD_NAMESPACE_DELIMITER: Final = "__"
|
|
272
|
+
_META_FIELD_LEGACY_NAMESPACE: Final = "docling_legacy"
|
|
273
|
+
|
|
274
|
+
@classmethod
|
|
275
|
+
def create_meta_field_name(
|
|
276
|
+
cls,
|
|
277
|
+
*,
|
|
278
|
+
namespace: str,
|
|
279
|
+
name: str,
|
|
280
|
+
) -> str:
|
|
281
|
+
"""Create a meta field name."""
|
|
282
|
+
return f"{namespace}{cls._META_FIELD_NAMESPACE_DELIMITER}{name}"
|
|
283
|
+
|
|
284
|
+
@classmethod
|
|
285
|
+
def _create_migrated_meta_field_name(
|
|
286
|
+
cls,
|
|
287
|
+
*,
|
|
288
|
+
name: str,
|
|
289
|
+
) -> str:
|
|
290
|
+
return cls.create_meta_field_name(namespace=cls._META_FIELD_LEGACY_NAMESPACE, name=name)
|