graph-knowledge-doc-parser 0.2.15__tar.gz → 0.2.17__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.
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/PKG-INFO +41 -3
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/README.md +37 -0
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/document_ingester_logger.py +43 -30
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/llm_structured_output.py +9 -10
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/models.py +98 -67
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/ocr.py +122 -63
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/pdf2png.py +12 -3
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/semantic_document_splitting_layerwise_edits.py +203 -539
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/semantic_graph_import.py +247 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/semantic_indexing_contracts.py +136 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/semantic_pointer_matching.py +183 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/semantic_source_text.py +67 -0
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/text_processing_utils.py +2 -1
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/utils/langchain.py +107 -40
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/utils/version_chaining.py +11 -1
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/workflow_ingest/__init__.py +103 -4
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/adapters.py +587 -0
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/workflow_ingest/cache.py +14 -15
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/workflow_ingest/cli.py +55 -15
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/workflow_ingest/clients.py +91 -32
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/workflow_ingest/demo_harness.py +70 -10
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/design.py +438 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/document_adapters.py +921 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/document_grouping.py +458 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/document_models.py +635 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/handler_exports.py +113 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/handler_layerwise.py +683 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/handler_postparse.py +208 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/handler_state.py +140 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/handler_strategy_steps.py +306 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/handler_support.py +167 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/handlers.py +196 -0
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/workflow_ingest/layered_contracts.py +13 -17
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/layerwise_boundaries.py +348 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/layerwise_boundary_contracts.py +139 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/layerwise_boundary_pipeline.py +859 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/layerwise_boundary_prompts.py +391 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/layerwise_contracts.py +69 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/layerwise_invocation.py +108 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/layerwise_llm.py +1285 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/layerwise_payloads.py +139 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/layerwise_review.py +190 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/layerwise_source_spans.py +199 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/model_validation.py +18 -0
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/workflow_ingest/models.py +35 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_artifacts.py +72 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_file_io.py +72 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_finalization.py +217 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_generators.py +296 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_inputs.py +148 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_page_ingestion.py +186 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_page_processing.py +453 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_page_runner.py +373 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_pdf_rendering.py +346 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_pipeline.py +205 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_pipeline_contracts.py +148 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_preparation.py +209 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_progress.py +32 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_progress_state.py +138 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_provider_smoke.py +133 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_providers.py +749 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_quality.py +244 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_quality_policy.py +298 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_runtime.py +491 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_runtime_common.py +31 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_runtime_contracts.py +101 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_runtime_finalization.py +166 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_runtime_grouping.py +144 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_runtime_grouping_state.py +61 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_runtime_grouping_steps.py +384 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_runtime_lineage.py +106 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_runtime_page.py +223 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_runtime_page_state.py +250 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_runtime_root_steps.py +449 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_runtime_state.py +374 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_source_plan.py +172 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_state_schema.py +124 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_state_store.py +1382 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_state_types.py +32 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_summary_state.py +136 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/ocr_summary_workflow.py +218 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/page_index.py +686 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/page_index_candidates.py +659 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/page_index_classification.py +233 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/page_index_contracts.py +193 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/page_index_provider.py +693 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/page_index_provider_support.py +56 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/page_index_refinement.py +434 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/page_index_source_text.py +61 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/page_index_tree.py +384 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/parser_core.py +755 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/parser_core_commit.py +563 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/parser_core_contracts.py +122 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/parser_core_diagnostics.py +78 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/parser_core_legacy.py +98 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/parser_core_session.py +239 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/parser_core_validation.py +634 -0
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/workflow_ingest/parsing.py +41 -1
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/pdf_native.py +343 -0
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/workflow_ingest/probe.py +27 -24
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/workflow_ingest/providers.py +75 -15
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/workflow_ingest/runners.py +55 -12
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/runtime_contracts.py +46 -0
- graph_knowledge_doc_parser-0.2.17/kg_doc_parser/workflow_ingest/sdk_boundary.py +20 -0
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/workflow_ingest/semantics.py +85 -13
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/workflow_ingest/serialization.py +55 -14
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/workflow_ingest/service.py +168 -52
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/workflow_ingest/strategy.py +2 -1
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/pyproject.toml +5 -3
- graph_knowledge_doc_parser-0.2.15/kg_doc_parser/workflow_ingest/adapters.py +0 -324
- graph_knowledge_doc_parser-0.2.15/kg_doc_parser/workflow_ingest/design.py +0 -252
- graph_knowledge_doc_parser-0.2.15/kg_doc_parser/workflow_ingest/handlers.py +0 -1297
- graph_knowledge_doc_parser-0.2.15/kg_doc_parser/workflow_ingest/layerwise_llm.py +0 -2989
- graph_knowledge_doc_parser-0.2.15/kg_doc_parser/workflow_ingest/ocr_pipeline.py +0 -1701
- graph_knowledge_doc_parser-0.2.15/kg_doc_parser/workflow_ingest/page_index.py +0 -3021
- graph_knowledge_doc_parser-0.2.15/kg_doc_parser/workflow_ingest/parser_core.py +0 -2118
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/__init__.py +0 -0
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/cast_hinting.py +0 -0
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/document_ingest_log_config.py +0 -0
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/utils/__init__.py +0 -0
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/utils/bounded_threadpool_executor.py +0 -0
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/utils/file_loaders.py +0 -0
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/utils/log.py +0 -0
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/workflow_ingest/_kogwistar.py +0 -0
- {graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/workflow_ingest/smoke_assets.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: graph-knowledge-doc-parser
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.17
|
|
4
4
|
Summary: doc parser using llm driven engine with graph knowledge awareness
|
|
5
5
|
Author: humblemat810
|
|
6
6
|
Author-email: 67593116+humblemat810@users.noreply.github.com
|
|
@@ -21,7 +21,7 @@ Provides-Extra: openai
|
|
|
21
21
|
Provides-Extra: vertex
|
|
22
22
|
Requires-Dist: diskcache (>=5.6,<6.0) ; platform_python_implementation == "PyPy"
|
|
23
23
|
Requires-Dist: joblib (>=1.5.3,<2.0.0) ; platform_python_implementation == "CPython"
|
|
24
|
-
Requires-Dist: kogwistar (==0.6.
|
|
24
|
+
Requires-Dist: kogwistar (==0.6.15)
|
|
25
25
|
Requires-Dist: langchain-core (>=1.2.5,<2.0.0)
|
|
26
26
|
Requires-Dist: langchain-google-genai (>=4.1.2,<5.0.0) ; extra == "gemini" or extra == "cloud"
|
|
27
27
|
Requires-Dist: langchain-google-vertexai (>=3.2.4,<4.0.0) ; extra == "vertex" or extra == "cloud"
|
|
@@ -30,8 +30,9 @@ Requires-Dist: mcp (>=2.2.0,<3.0.0)
|
|
|
30
30
|
Requires-Dist: pathspec (>=0.12.1,<0.13.0)
|
|
31
31
|
Requires-Dist: pdf2image (>=1.17.0,<2.0.0)
|
|
32
32
|
Requires-Dist: pikepdf (>=10.1.0,<11.0.0) ; platform_python_implementation != "PyPy"
|
|
33
|
+
Requires-Dist: pillow (==11.3.0)
|
|
33
34
|
Requires-Dist: pydantic (>=2.12.5,<3.0.0)
|
|
34
|
-
Requires-Dist: pydantic-extension (>=0.0.
|
|
35
|
+
Requires-Dist: pydantic-extension (>=0.0.8,<0.0.9)
|
|
35
36
|
Requires-Dist: pypdf (>=6.5.0,<7.0.0)
|
|
36
37
|
Requires-Dist: rapidfuzz (>=3.14.3,<4.0.0)
|
|
37
38
|
Requires-Dist: typing-extensions (>=4.8.0,<5.0.0)
|
|
@@ -230,6 +231,43 @@ An example template is provided in [`.env.example`](.env.example).
|
|
|
230
231
|
|
|
231
232
|
## Provider Guide
|
|
232
233
|
|
|
234
|
+
### OCR provider abstraction
|
|
235
|
+
|
|
236
|
+
`run_ocr_source_workflow(...)` remains the single OCR workflow entrypoint.
|
|
237
|
+
Existing chat providers (`gemini`, `ollama`, `openai`, `azure`, `vertex`, and
|
|
238
|
+
the local OpenAI-compatible `bonsai` alias) use the existing structured OCR
|
|
239
|
+
contract. The Codex bridge can also receive OCR images when it is configured
|
|
240
|
+
with a vision-capable Codex model and the bridge's CLI image forwarding is
|
|
241
|
+
available.
|
|
242
|
+
|
|
243
|
+
Docling is an optional adapter selected with `KG_DOC_OCR_PROVIDER=docling` and
|
|
244
|
+
`KG_DOC_OCR_ENGINE` set to `rapidocr`, `easyocr`, `tesseract`, `tesserocr`,
|
|
245
|
+
`ocrmac`, or `nemotron-ocr`. Install Docling and the selected engine separately;
|
|
246
|
+
the base package does not install these dependencies. The adapter returns
|
|
247
|
+
page-level geometry when it cannot prove precise word coordinates rather than
|
|
248
|
+
inventing them.
|
|
249
|
+
|
|
250
|
+
Direct local OCR is also available without Docling:
|
|
251
|
+
`KG_DOC_OCR_PROVIDER=rapidocr` uses `rapidocr-onnxruntime`, and
|
|
252
|
+
`KG_DOC_OCR_PROVIDER=easyocr` uses `easyocr`. These adapters preserve one
|
|
253
|
+
typed cluster per detected text region and its pixel bounding box. They do not
|
|
254
|
+
claim table structure or merged-cell semantics; use the Docling path when
|
|
255
|
+
layout interpretation is required.
|
|
256
|
+
|
|
257
|
+
User VLM adapters can be registered explicitly with
|
|
258
|
+
`register_ocr_provider(name, provider)` and selected with
|
|
259
|
+
`KG_DOC_OCR_PROVIDER=custom` plus `KG_DOC_OCR_MODEL=<name>`. A KServe v2
|
|
260
|
+
endpoint is available with `KG_DOC_OCR_PROVIDER=kserve`; it sends a base64
|
|
261
|
+
image to `/v2/models/<model>/infer` and accepts only a response that can be
|
|
262
|
+
validated as the existing `OCRClusterResponse` (model-specific tensor layouts
|
|
263
|
+
should use a registered adapter).
|
|
264
|
+
|
|
265
|
+
Run `ocr-provider-smoke --output-dir experiments/ocr-provider-smoke` for an
|
|
266
|
+
offline capability report. Add `--live --image <page.png>` to execute one real
|
|
267
|
+
OCR request through the same provider path used by the workflow. The live
|
|
268
|
+
result is sanitized and written beside the report; page artifacts, resume
|
|
269
|
+
state, and diagnostics from a full workflow run remain separate and durable.
|
|
270
|
+
|
|
233
271
|
The workflow layer is vendor-neutral, but the concrete OCR, parser, and embedding
|
|
234
272
|
backends are selected by config.
|
|
235
273
|
|
|
@@ -189,6 +189,43 @@ An example template is provided in [`.env.example`](.env.example).
|
|
|
189
189
|
|
|
190
190
|
## Provider Guide
|
|
191
191
|
|
|
192
|
+
### OCR provider abstraction
|
|
193
|
+
|
|
194
|
+
`run_ocr_source_workflow(...)` remains the single OCR workflow entrypoint.
|
|
195
|
+
Existing chat providers (`gemini`, `ollama`, `openai`, `azure`, `vertex`, and
|
|
196
|
+
the local OpenAI-compatible `bonsai` alias) use the existing structured OCR
|
|
197
|
+
contract. The Codex bridge can also receive OCR images when it is configured
|
|
198
|
+
with a vision-capable Codex model and the bridge's CLI image forwarding is
|
|
199
|
+
available.
|
|
200
|
+
|
|
201
|
+
Docling is an optional adapter selected with `KG_DOC_OCR_PROVIDER=docling` and
|
|
202
|
+
`KG_DOC_OCR_ENGINE` set to `rapidocr`, `easyocr`, `tesseract`, `tesserocr`,
|
|
203
|
+
`ocrmac`, or `nemotron-ocr`. Install Docling and the selected engine separately;
|
|
204
|
+
the base package does not install these dependencies. The adapter returns
|
|
205
|
+
page-level geometry when it cannot prove precise word coordinates rather than
|
|
206
|
+
inventing them.
|
|
207
|
+
|
|
208
|
+
Direct local OCR is also available without Docling:
|
|
209
|
+
`KG_DOC_OCR_PROVIDER=rapidocr` uses `rapidocr-onnxruntime`, and
|
|
210
|
+
`KG_DOC_OCR_PROVIDER=easyocr` uses `easyocr`. These adapters preserve one
|
|
211
|
+
typed cluster per detected text region and its pixel bounding box. They do not
|
|
212
|
+
claim table structure or merged-cell semantics; use the Docling path when
|
|
213
|
+
layout interpretation is required.
|
|
214
|
+
|
|
215
|
+
User VLM adapters can be registered explicitly with
|
|
216
|
+
`register_ocr_provider(name, provider)` and selected with
|
|
217
|
+
`KG_DOC_OCR_PROVIDER=custom` plus `KG_DOC_OCR_MODEL=<name>`. A KServe v2
|
|
218
|
+
endpoint is available with `KG_DOC_OCR_PROVIDER=kserve`; it sends a base64
|
|
219
|
+
image to `/v2/models/<model>/infer` and accepts only a response that can be
|
|
220
|
+
validated as the existing `OCRClusterResponse` (model-specific tensor layouts
|
|
221
|
+
should use a registered adapter).
|
|
222
|
+
|
|
223
|
+
Run `ocr-provider-smoke --output-dir experiments/ocr-provider-smoke` for an
|
|
224
|
+
offline capability report. Add `--live --image <page.png>` to execute one real
|
|
225
|
+
OCR request through the same provider path used by the workflow. The live
|
|
226
|
+
result is sanitized and written beside the report; page artifacts, resume
|
|
227
|
+
state, and diagnostics from a full workflow run remain separate and durable.
|
|
228
|
+
|
|
192
229
|
The workflow layer is vendor-neutral, but the concrete OCR, parser, and embedding
|
|
193
230
|
backends are selected by config.
|
|
194
231
|
|
|
@@ -82,6 +82,7 @@ NOTES
|
|
|
82
82
|
|
|
83
83
|
from __future__ import annotations
|
|
84
84
|
|
|
85
|
+
import logging
|
|
85
86
|
import os
|
|
86
87
|
import queue
|
|
87
88
|
import sqlite3
|
|
@@ -91,9 +92,9 @@ import traceback
|
|
|
91
92
|
from collections.abc import Mapping
|
|
92
93
|
from contextlib import closing
|
|
93
94
|
from dataclasses import dataclass
|
|
94
|
-
from datetime import
|
|
95
|
+
from datetime import UTC, datetime
|
|
95
96
|
from threading import Lock
|
|
96
|
-
from typing import Protocol
|
|
97
|
+
from typing import Protocol, runtime_checkable
|
|
97
98
|
from uuid import UUID
|
|
98
99
|
|
|
99
100
|
from langchain_core.callbacks.base import BaseCallbackHandler
|
|
@@ -103,6 +104,8 @@ from langchain_core.outputs.llm_result import LLMResult
|
|
|
103
104
|
|
|
104
105
|
from kg_doc_parser.workflow_ingest.serialization import safe_json_dumps
|
|
105
106
|
|
|
107
|
+
_LOGGER = logging.getLogger(__name__)
|
|
108
|
+
|
|
106
109
|
|
|
107
110
|
class TextRedactor(Protocol):
|
|
108
111
|
"""Redact one text value before it is written to ingestion telemetry."""
|
|
@@ -110,6 +113,12 @@ class TextRedactor(Protocol):
|
|
|
110
113
|
def __call__(self, text: str, /) -> str: ...
|
|
111
114
|
|
|
112
115
|
|
|
116
|
+
@runtime_checkable
|
|
117
|
+
class _UsageMetadataCarrier(Protocol):
|
|
118
|
+
@property
|
|
119
|
+
def usage_metadata(self) -> object: ...
|
|
120
|
+
|
|
121
|
+
|
|
113
122
|
def _metadata_float(value: object, default: float = 0.0) -> float:
|
|
114
123
|
if isinstance(value, bool):
|
|
115
124
|
return float(value)
|
|
@@ -368,9 +377,9 @@ class SQLiteIngestEventWriter:
|
|
|
368
377
|
with closing(conn.execute("PRAGMA wal_checkpoint;")):
|
|
369
378
|
pass
|
|
370
379
|
conn.commit()
|
|
371
|
-
except
|
|
380
|
+
except (OSError, sqlite3.Error) as exc:
|
|
372
381
|
# Swallow writer shutdown errors; don't crash application exit.
|
|
373
|
-
|
|
382
|
+
_LOGGER.debug("telemetry writer checkpoint failed during shutdown: %r", exc)
|
|
374
383
|
|
|
375
384
|
def _flush(self, batch: list[_IngestEvent]) -> None:
|
|
376
385
|
rows = [
|
|
@@ -434,7 +443,7 @@ def _best_effort_error_location(exc: BaseException) -> tuple[str | None, int | N
|
|
|
434
443
|
|
|
435
444
|
def _utc_now_iso() -> str:
|
|
436
445
|
"""UTC ISO timestamp with timezone, suitable for sqlite TEXT."""
|
|
437
|
-
return datetime.now(
|
|
446
|
+
return datetime.now(UTC).isoformat()
|
|
438
447
|
|
|
439
448
|
|
|
440
449
|
# ---------------------------
|
|
@@ -444,6 +453,12 @@ def _as_mapping(value: object) -> Mapping[str, object]:
|
|
|
444
453
|
return value if isinstance(value, Mapping) else {}
|
|
445
454
|
|
|
446
455
|
|
|
456
|
+
def _message_usage_metadata(message: object) -> Mapping[str, object]:
|
|
457
|
+
if isinstance(message, _UsageMetadataCarrier):
|
|
458
|
+
return _as_mapping(message.usage_metadata)
|
|
459
|
+
return {}
|
|
460
|
+
|
|
461
|
+
|
|
447
462
|
def _invoked_model_name(kwargs: Mapping[str, object]) -> str | None:
|
|
448
463
|
inv_params = _as_mapping(kwargs.get("invocation_params"))
|
|
449
464
|
m = inv_params.get("model")
|
|
@@ -559,10 +574,10 @@ class DocumentIngestSQLiteCallback(BaseCallbackHandler):
|
|
|
559
574
|
{
|
|
560
575
|
"type": m.type,
|
|
561
576
|
"content": self._clip(str(m.content)),
|
|
562
|
-
"additional_kwargs":
|
|
563
|
-
"response_metadata":
|
|
564
|
-
"name":
|
|
565
|
-
"id":
|
|
577
|
+
"additional_kwargs": m.additional_kwargs,
|
|
578
|
+
"response_metadata": m.response_metadata,
|
|
579
|
+
"name": m.name,
|
|
580
|
+
"id": m.id,
|
|
566
581
|
}
|
|
567
582
|
for m in batch
|
|
568
583
|
]
|
|
@@ -672,24 +687,22 @@ class DocumentIngestSQLiteCallback(BaseCallbackHandler):
|
|
|
672
687
|
# LangChain response.generations: List[List[Generation]]
|
|
673
688
|
for gen_list in response.generations:
|
|
674
689
|
for gen in gen_list:
|
|
675
|
-
if isinstance(gen, ChatGeneration)
|
|
690
|
+
if isinstance(gen, ChatGeneration):
|
|
676
691
|
msg = gen.message
|
|
677
|
-
# Gemini usage_metadata is
|
|
678
|
-
usage =
|
|
692
|
+
# Gemini usage_metadata is an optional provider extension.
|
|
693
|
+
usage = _message_usage_metadata(msg)
|
|
679
694
|
if usage:
|
|
680
|
-
input_tokens =
|
|
681
|
-
output_tokens =
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
except Exception:
|
|
689
|
-
reasoning_tokens = 0
|
|
695
|
+
input_tokens = _metadata_int_or_none(usage.get("input_tokens")) or 0
|
|
696
|
+
output_tokens = _metadata_int_or_none(usage.get("output_tokens")) or 0
|
|
697
|
+
cached_tokens = _metadata_int_or_none(
|
|
698
|
+
_as_mapping(usage.get("input_token_details")).get("cache_read")
|
|
699
|
+
) or 0
|
|
700
|
+
reasoning_tokens = _metadata_int_or_none(
|
|
701
|
+
_as_mapping(usage.get("output_token_details")).get("reasoning")
|
|
702
|
+
) or 0
|
|
690
703
|
|
|
691
704
|
# Model name is often in generation_info
|
|
692
|
-
gi =
|
|
705
|
+
gi = gen.generation_info or {}
|
|
693
706
|
model_name = gi.get("model_name") or model_name
|
|
694
707
|
if model_name is None:
|
|
695
708
|
inv_params = kwargs.get("invocation_params")
|
|
@@ -711,7 +724,7 @@ class DocumentIngestSQLiteCallback(BaseCallbackHandler):
|
|
|
711
724
|
"output_tokens": output_tokens,
|
|
712
725
|
"cached_tokens": cached_tokens,
|
|
713
726
|
"reasoning_tokens": reasoning_tokens,
|
|
714
|
-
"response_llm_output":
|
|
727
|
+
"response_llm_output": response.llm_output,
|
|
715
728
|
}
|
|
716
729
|
if self.log_responses:
|
|
717
730
|
outs: list[dict[str, object]] = []
|
|
@@ -724,16 +737,16 @@ class DocumentIngestSQLiteCallback(BaseCallbackHandler):
|
|
|
724
737
|
item["text"] = self._clip(str(gen.text))
|
|
725
738
|
|
|
726
739
|
# Chat-y
|
|
727
|
-
if isinstance(gen, ChatGeneration)
|
|
740
|
+
if isinstance(gen, ChatGeneration):
|
|
728
741
|
msg = gen.message
|
|
729
742
|
item["message"] = {
|
|
730
|
-
"type":
|
|
731
|
-
"content": self._clip(str(
|
|
732
|
-
"additional_kwargs":
|
|
733
|
-
"response_metadata":
|
|
743
|
+
"type": msg.type,
|
|
744
|
+
"content": self._clip(str(msg.content)),
|
|
745
|
+
"additional_kwargs": msg.additional_kwargs,
|
|
746
|
+
"response_metadata": msg.response_metadata,
|
|
734
747
|
}
|
|
735
748
|
|
|
736
|
-
item["generation_info"] =
|
|
749
|
+
item["generation_info"] = gen.generation_info
|
|
737
750
|
outs.append(item)
|
|
738
751
|
|
|
739
752
|
payload["outputs"] = outs
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import
|
|
3
|
+
from typing import Literal, Protocol, Self, TypeAlias, TypedDict, cast
|
|
4
4
|
|
|
5
5
|
from kogwistar.llm_tasks.providers import (
|
|
6
6
|
SupportsStructuredOutput,
|
|
7
7
|
)
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
from kogwistar.llm_tasks.providers import StructuredModelLike
|
|
11
|
-
else:
|
|
12
|
-
class StructuredModelLike(Protocol):
|
|
13
|
-
"""Compatibility fallback for released Core versions."""
|
|
9
|
+
from .workflow_ingest.serialization import JsonValue
|
|
14
10
|
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
class StructuredModelLike(Protocol):
|
|
12
|
+
"""Compatibility contract across released Core provider exports."""
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
@classmethod
|
|
15
|
+
def model_validate(cls, payload: object, /) -> Self: ...
|
|
16
|
+
|
|
17
|
+
@classmethod
|
|
18
|
+
def model_json_schema(cls) -> dict[str, JsonValue]: ...
|
|
20
19
|
|
|
21
20
|
# Keep the historical parser names as aliases, but use the core contracts as
|
|
22
21
|
# the single source of truth for provider/schema compatibility.
|
{graph_knowledge_doc_parser-0.2.15 → graph_knowledge_doc_parser-0.2.17}/kg_doc_parser/models.py
RENAMED
|
@@ -45,12 +45,15 @@ Edges (Relationships):
|
|
|
45
45
|
- relation: "HAS_CHILD"
|
|
46
46
|
- type: "relationship"
|
|
47
47
|
"""
|
|
48
|
+
from collections import Counter
|
|
49
|
+
|
|
48
50
|
if True:
|
|
49
51
|
import logging
|
|
50
52
|
logger = logging.getLogger(__name__)
|
|
51
53
|
logger.addHandler(logging.NullHandler())
|
|
52
54
|
logger.debug("loading models")
|
|
53
55
|
from typing import Literal, Self, TypeAlias
|
|
56
|
+
|
|
54
57
|
from pydantic import BaseModel, Field, ValidationInfo, field_validator, model_validator
|
|
55
58
|
from pydantic_extension.model_slicing import (
|
|
56
59
|
DtoType,
|
|
@@ -58,9 +61,36 @@ from pydantic_extension.model_slicing import (
|
|
|
58
61
|
)
|
|
59
62
|
from pydantic_extension.model_slicing.mixin import DtoField
|
|
60
63
|
|
|
64
|
+
|
|
65
|
+
def _meaningful_ordering_error(expected_ids: set[int], ordering: list[int]) -> str:
|
|
66
|
+
"""Describe an invalid reading-order permutation for retry feedback."""
|
|
67
|
+
|
|
68
|
+
missing_ids = sorted(expected_ids - set(ordering))
|
|
69
|
+
unknown_ids = sorted(set(ordering) - expected_ids)
|
|
70
|
+
duplicate_ids = sorted(
|
|
71
|
+
cluster_id
|
|
72
|
+
for cluster_id, count in Counter(ordering).items()
|
|
73
|
+
if count > 1
|
|
74
|
+
)
|
|
75
|
+
return (
|
|
76
|
+
"meaningful_ordering must be the authoritative reading-order permutation "
|
|
77
|
+
"of every text and non-text cluster exactly once; "
|
|
78
|
+
f"expected_cluster_ids={sorted(expected_ids)!r}; "
|
|
79
|
+
f"returned_ordering={ordering!r}; "
|
|
80
|
+
f"missing_cluster_ids={missing_ids!r}; "
|
|
81
|
+
f"unknown_cluster_ids={unknown_ids!r}; "
|
|
82
|
+
f"duplicate_ordering_ids={duplicate_ids!r}"
|
|
83
|
+
)
|
|
84
|
+
|
|
61
85
|
JsonPrimitive = str | int | float | bool | None
|
|
62
|
-
JsonValue: TypeAlias = JsonPrimitive | list["JsonValue"] | dict[str, "JsonValue"]
|
|
63
|
-
JsonObject: TypeAlias = dict[str, JsonValue]
|
|
86
|
+
JsonValue: TypeAlias = JsonPrimitive | list["JsonValue"] | dict[str, "JsonValue"] # noqa: UP040 - PyPy 3.11 support
|
|
87
|
+
JsonObject: TypeAlias = dict[str, JsonValue] # noqa: UP040 - PyPy 3.11 support
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class ModelInvariantError(ValueError):
|
|
91
|
+
"""Raised when an OCR model cannot satisfy its structural contract."""
|
|
92
|
+
|
|
93
|
+
|
|
64
94
|
#========================= OCR DOC
|
|
65
95
|
|
|
66
96
|
# pre-validation model
|
|
@@ -83,6 +113,13 @@ class TextCluster(ModeSlicingMixin, BaseModel):
|
|
|
83
113
|
bb_y_min: DtoType[float] = Field(description='the bounding box y min in pixel coordinate of the text_cluster. ')
|
|
84
114
|
bb_y_max: DtoType[float] = Field(description='the bounding box y max in pixel coordinate of the text_cluster. ')
|
|
85
115
|
cluster_number: int = Field(description="per page unique number of the cluster, starting from 0")
|
|
116
|
+
continuation_id: DtoType[str | None] = Field(
|
|
117
|
+
default=None,
|
|
118
|
+
description=(
|
|
119
|
+
"Optional provider- or user-supplied identifier shared only by text "
|
|
120
|
+
"fragments known to continue the same paragraph across adjacent pages."
|
|
121
|
+
),
|
|
122
|
+
)
|
|
86
123
|
class NonTextCluster(ModeSlicingMixin, BaseModel):
|
|
87
124
|
"""Recognised meaningful objects other than OCR characters, include image, figures. """
|
|
88
125
|
description: DtoType[str] = Field(description='the description or summary of the non-OCR object')
|
|
@@ -102,7 +139,7 @@ class OCRClusterResponse(ModeSlicingMixin, BaseModel):
|
|
|
102
139
|
'Arabic numeral such as 1, 2, 3... or letter such as "a", "b", "c"...\n'
|
|
103
140
|
'Sometimes the are surrounded by symbols such as "- 1 -", "- 2 -"'
|
|
104
141
|
r"Can be null/none if there is no page order assigned and printed and found in the scanned texts. Do not assign page number. Only use page number found.")
|
|
105
|
-
meaningful_ordering : DtoType[list[int]] = Field(description="The
|
|
142
|
+
meaningful_ordering : DtoType[list[int]] = Field(description="The authoritative reading order of all text and non-text clusters, from first to last meaningful item. Must contain every cluster number exactly once and no others. ")
|
|
106
143
|
page_x_min : DtoType[float]=Field(description='the page x min in pixel coordinate. ')
|
|
107
144
|
page_x_max : DtoType[float]=Field(description='the page x max in pixel coordinate. ')
|
|
108
145
|
page_y_min : DtoType[float]=Field(description='the page y min in pixel coordinate. ')
|
|
@@ -115,20 +152,59 @@ class OCRClusterResponse(ModeSlicingMixin, BaseModel):
|
|
|
115
152
|
'"low", "medium" or "high". '
|
|
116
153
|
'low: text barely legible. medium: Legible with non smooth due to pixelation. high: texts are easily and highly identifiable. ' )
|
|
117
154
|
contains_table: DtoType[bool] = Field(description='Whether this page contains table. ')
|
|
155
|
+
unresolved_item_count: DtoType[int] = Field(
|
|
156
|
+
default=0,
|
|
157
|
+
ge=0,
|
|
158
|
+
description=(
|
|
159
|
+
'Number of provider-recognised items that could not be represented '
|
|
160
|
+
'with a usable bounding box or modality record.'
|
|
161
|
+
),
|
|
162
|
+
)
|
|
163
|
+
source_item_count: DtoType[int | None] = Field(
|
|
164
|
+
default=None,
|
|
165
|
+
ge=0,
|
|
166
|
+
description=(
|
|
167
|
+
'Total number of source items observed by the provider. When set, '
|
|
168
|
+
'the sum of represented text/non-text clusters and unresolved items '
|
|
169
|
+
'must equal this count.'
|
|
170
|
+
),
|
|
171
|
+
)
|
|
172
|
+
spatial_accuracy: DtoType[Literal['page', 'region', 'line', 'word', 'character']] = Field(
|
|
173
|
+
default='page',
|
|
174
|
+
description=(
|
|
175
|
+
'The declared precision of the bounding boxes. Use page for a '
|
|
176
|
+
'synthetic page-wide fallback; providers with item-level boxes '
|
|
177
|
+
'must explicitly declare region or finer precision.'
|
|
178
|
+
),
|
|
179
|
+
)
|
|
118
180
|
|
|
119
181
|
@model_validator(mode='after')
|
|
120
182
|
def check_cluster_meaningful_ordering_agreement(self) -> Self:
|
|
121
|
-
|
|
183
|
+
all_clusters = self.OCR_text_clusters + self.non_text_objects
|
|
184
|
+
if bool(self.is_empty_page) == (len(all_clusters) > 0):
|
|
122
185
|
raise ValueError(
|
|
123
|
-
f"is_empty_page value {self.is_empty_page} disagree with
|
|
124
|
-
f"len={len(
|
|
186
|
+
f"is_empty_page value {self.is_empty_page} disagree with OCR clusters "
|
|
187
|
+
f"len={len(all_clusters)}"
|
|
125
188
|
)
|
|
126
|
-
|
|
127
|
-
overlap_id =
|
|
189
|
+
all_ids = [item.cluster_number for item in all_clusters]
|
|
190
|
+
overlap_id = {
|
|
191
|
+
cluster_id
|
|
192
|
+
for cluster_id, count in Counter(all_ids).items()
|
|
193
|
+
if count > 1
|
|
194
|
+
}
|
|
128
195
|
if overlap_id:
|
|
129
196
|
raise ValueError(f"cluster number from non_text_objects block and ocr text blocks must be ALL distinct. Overlapped ids: {list(overlap_id)}")
|
|
130
|
-
|
|
131
|
-
|
|
197
|
+
all_ids_set = set(all_ids)
|
|
198
|
+
if len(self.meaningful_ordering) != len(all_ids_set) or set(self.meaningful_ordering) != all_ids_set:
|
|
199
|
+
raise ValueError(_meaningful_ordering_error(all_ids_set, self.meaningful_ordering))
|
|
200
|
+
if self.source_item_count is not None:
|
|
201
|
+
accounted_item_count = len(all_clusters) + self.unresolved_item_count
|
|
202
|
+
if self.source_item_count != accounted_item_count:
|
|
203
|
+
raise ValueError(
|
|
204
|
+
"OCR source item accounting does not reconcile "
|
|
205
|
+
f"({self.source_item_count} observed versus "
|
|
206
|
+
f"{accounted_item_count} represented or unresolved)"
|
|
207
|
+
)
|
|
132
208
|
return self
|
|
133
209
|
|
|
134
210
|
|
|
@@ -155,9 +231,11 @@ class SplitPage(OCRClusterResponseBc):
|
|
|
155
231
|
def model_dump(self, *arg: object, **kwarg: object) -> JsonObject:
|
|
156
232
|
return self.to_doc()
|
|
157
233
|
def dump_raw(self, *arg: object, **kwarg: object) -> JsonObject:
|
|
158
|
-
|
|
234
|
+
options = {**kwarg, "exclude": ["refined_version"]}
|
|
235
|
+
return super().model_dump(*arg, **options)
|
|
159
236
|
def dump_supercede_parse(self, *arg: object, **kwarg: object) -> JsonObject:
|
|
160
|
-
|
|
237
|
+
options = {**kwarg, "exclude": ["refined_version", "metadata"]}
|
|
238
|
+
return super().model_dump(*arg, **options)
|
|
161
239
|
@model_validator(mode="after")
|
|
162
240
|
def roundtrip_invariant(self, info: ValidationInfo) -> "SplitPage":
|
|
163
241
|
# Context may be None if caller didn't pass it
|
|
@@ -216,61 +294,14 @@ class SplitPage(OCRClusterResponseBc):
|
|
|
216
294
|
c_return['contains_table'] = self.contains_table
|
|
217
295
|
return c_return
|
|
218
296
|
else:
|
|
219
|
-
#
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
# expected_next = min(ocr_clus_nums + sig_clus_nums)
|
|
228
|
-
if ocr_clus_nums:
|
|
229
|
-
start_num = min(ocr_clus_nums + non_clus_nums)
|
|
230
|
-
if start_num not in [0, 1]:
|
|
231
|
-
raise ValueError("only allow 0-indexed based or 1-indexed based cluster numbers")
|
|
232
|
-
expected_next = start_num
|
|
233
|
-
while expected_next < start_num + (len(ocr_clus_nums) + len(non_clus_nums)):
|
|
234
|
-
if (i_ocr <len(ocr_cluster)) and expected_next == ocr_cluster[i_ocr].cluster_number:
|
|
235
|
-
i_ocr += 1
|
|
236
|
-
# elif (i_sig < len(target.signature_blocks)) and expected_next == target.signature_blocks[i_sig].cluster_number:
|
|
237
|
-
# i_sig += 1
|
|
238
|
-
elif (i_non_ocr < len(non_ocr_cluster)) and expected_next == non_ocr_cluster[i_non_ocr].cluster_number:
|
|
239
|
-
i_non_ocr += 1
|
|
240
|
-
else:
|
|
241
|
-
raise Exception(f'expected index {expected_next} not found in both ocr_cluster nor signature_blocks')
|
|
242
|
-
expected_next += 1
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
id_sorted_text_cluster = sorted(ocr_cluster, key=lambda x : x.cluster_number )
|
|
246
|
-
if len(id_sorted_text_cluster) != len({i.cluster_number for i in id_sorted_text_cluster}):
|
|
247
|
-
raise ValueError("OCR cluster numbers must be unique")
|
|
248
|
-
is_normal = True
|
|
249
|
-
shift = 0 # try zero indexing sanity
|
|
250
|
-
c : TextCluster #| TextCluster_yolo_bb
|
|
251
|
-
for i, c in enumerate(id_sorted_text_cluster):
|
|
252
|
-
|
|
253
|
-
if c.cluster_number != i:
|
|
254
|
-
is_normal = False
|
|
255
|
-
break
|
|
256
|
-
c2: TextCluster #| TextCluster_yolo_bb
|
|
257
|
-
if not is_normal:
|
|
258
|
-
is_normal = True
|
|
259
|
-
shift = -1 # try one-indexing sanity
|
|
260
|
-
for i, c2 in enumerate(id_sorted_text_cluster):
|
|
261
|
-
if c2.cluster_number != i+1:
|
|
262
|
-
is_normal = False
|
|
263
|
-
break
|
|
264
|
-
# sig_num = set([i.cluster_number for i in self.signature_blocks])
|
|
265
|
-
if not set(self.meaningful_ordering) <= {i.cluster_number for i in self.OCR_text_clusters}:
|
|
266
|
-
raise ValueError("meaningful_ordering references an unknown OCR cluster")
|
|
267
|
-
if is_normal:
|
|
268
|
-
# is sorted list where index is order + shift
|
|
269
|
-
texts = '\n'.join(id_sorted_text_cluster[i+shift].text for i in self.meaningful_ordering)
|
|
270
|
-
else:
|
|
271
|
-
# general case
|
|
272
|
-
tcd = {x.cluster_number:x for x in id_sorted_text_cluster}
|
|
273
|
-
texts = '\n'.join(tcd[i].text for i in self.meaningful_ordering)
|
|
297
|
+
# This legacy projection contains text only. The raw SplitPage
|
|
298
|
+
# retains every modality and its full authoritative ordering.
|
|
299
|
+
text_by_number = {cluster.cluster_number: cluster for cluster in ocr_cluster}
|
|
300
|
+
texts = '\n'.join(
|
|
301
|
+
text_by_number[cluster_number].text
|
|
302
|
+
for cluster_number in self.meaningful_ordering
|
|
303
|
+
if cluster_number in text_by_number
|
|
304
|
+
)
|
|
274
305
|
c_return: JsonObject = {}
|
|
275
306
|
c_return['pdf_page_num'] = self.pdf_page_num
|
|
276
307
|
c_return['printed_page_number'] = self.printed_page_number
|