readanydoc 0.4.2__tar.gz → 0.4.4__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.
- {readanydoc-0.4.2 → readanydoc-0.4.4}/CHANGELOG.md +20 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/PKG-INFO +1 -1
- {readanydoc-0.4.2 → readanydoc-0.4.4}/plugins/readanydoc/.claude-plugin/plugin.json +1 -1
- {readanydoc-0.4.2 → readanydoc-0.4.4}/plugins/readanydoc/.mcp.json +1 -1
- {readanydoc-0.4.2 → readanydoc-0.4.4}/pyproject.toml +1 -1
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/__init__.py +1 -1
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/cli.py +15 -1
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/library.py +12 -3
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/mcp_server.py +6 -3
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/tasks/coded.py +2 -2
- readanydoc-0.4.4/readanydoc/tasks/coverage.py +445 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/tasks/extract.py +10 -4
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/tasks/field_report.py +26 -25
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/tasks/reply_schema.py +105 -23
- readanydoc-0.4.4/tests/tasks/test_coverage.py +81 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/tasks/test_required_choices.py +50 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/tasks/test_review.py +3 -3
- {readanydoc-0.4.2 → readanydoc-0.4.4}/.gitignore +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/LICENSE +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/README.md +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/docs/research/README.md +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/examples/showcase/README.md +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/plugins/readanydoc/.claude-plugin/icon.png +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/plugins/readanydoc/README.md +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/plugins/readanydoc/skills/read-documents/SKILL.md +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/api/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/api/__main__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/api/app.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/api/config.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/api/contracts.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/api/errors.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/api/inputs.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/api/schemas.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/api/service.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/api/webhooks.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/api/worker.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/bench/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/bench/catalog.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/bench/fetch.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/bench/grade.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/bench/report.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/bench/runner.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/bench/systems.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/cvsafe.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/data/model_limits.json +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/intake/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/intake/common.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/intake/docx_reader.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/intake/errors.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/intake/heic.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/intake/legacy.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/intake/msg.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/intake/pdf.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/intake/pptx_reader.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/intake/prepare.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/intake/sheets.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/intake/sniff.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/intake/text.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/integrations/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/integrations/langchain.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/integrations/llamaindex.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/layout/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/layout/base.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/layout/cached.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/layout/claude.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/layout/onnx.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/localmodels.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/model/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/model/document.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/model_limits.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/modelspec.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/paths.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/assemble.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/assembly/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/assembly/annotations.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/assembly/furniture.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/assembly/headings.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/assembly/paragraphs.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/assembly/tables.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/base.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/checks/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/checks/common.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/checks/complete.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/checks/flags.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/checks/gridrepair.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/checks/htmlgrid.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/checks/numbers.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/checks/reread.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/common.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/figures/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/figures/layout_pictures.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/figures/locate.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/forms/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/forms/acroform.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/forms/checkbox.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/forms/fillable.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/forms/grid.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/forms/lines.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/forms/locate.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/forms/region.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/forms/rules.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/ground.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/grounding/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/grounding/align.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/grounding/confidence.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/grounding/ocr.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/grounding/sources.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/grounding/tables.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/grounding/tokens.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/intake.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/layout.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/mdblocks.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/read.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/reading/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/reading/budget.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/reading/effort_route.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/reading/escalate.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/reading/evidence.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/reading/form_prefetch.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/reading/formulas.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/reading/fusion.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/reading/handwriting.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/reading/robust.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/reading/select.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/reading/strips.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/reading/tables.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/reading/zoom.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/reading/zoom_gate.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/reading/zoom_regions.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/reading/zoom_schedule.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/regions/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/regions/assemble.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/regions/complete.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/regions/crops.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/regions/fields.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/regions/formevidence.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/regions/forms.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/regions/furniture.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/regions/match.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/regions/structure.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/regions/tables.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/request.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/shape.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/shaping/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/shaping/agentic.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/shaping/chunking.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/shaping/embed.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/shaping/merge.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/shaping/options.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/shaping/page_range.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/shaping/response.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/shaping/searchable.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/shaping/summarize.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/shaping/tables.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/tables/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/tables/evidence.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/tables/hygiene.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/tables/prefetch.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/tables/reread.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/triage.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/typing/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/typing/layout.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/typing/markup.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/pipeline/verify.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/profiles.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/readers/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/readers/anthropic_api.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/readers/anthropic_batch.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/readers/base.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/readers/batch_mode.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/readers/cached.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/readers/claude_cli.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/readers/crop_cache.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/readers/live_cache.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/readers/ocr_words.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/readers/openai_compatible.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/readers/prompts.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/readers/sizing.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/readers/usage.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/serialize/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/serialize/citations.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/serialize/reducto.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/star.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/store/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/store/cleanup.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/store/db.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/store/files.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/store/jobs.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/tasks/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/tasks/classify.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/tasks/common.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/tasks/detect.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/tasks/edit.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/tasks/extract_extras.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/tasks/llm.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/tasks/schema.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/tasks/split.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/textlayer.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/textnorm.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/readanydoc/trace.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/research/README.md +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/research/benchmarks/README.md +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/results/README.md +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/api/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/api/conftest.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/api/sdk_check.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/api/test_auth.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/api/test_cleanup.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/api/test_config_defaults.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/api/test_contract.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/api/test_e2e.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/api/test_jobs.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/api/test_sdk.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/api/test_webhooks.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/assembly/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/assembly/evaluate.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/assembly/synth.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/assembly/test_assembly.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/assembly/test_real_documents.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/checks/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/checks/test_checks_stage.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/checks/test_complete.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/checks/test_htmlgrid.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/checks/test_numbers.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/conftest.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/cost/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/cost/test_r3b_cost.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/figures/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/figures/test_figures.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/forms/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/forms/test_fillable.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/forms/test_grid.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/forms/test_lines_crops.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/forms/test_rules.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/grounding/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/grounding/test_grounding.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/intake/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/intake/test_intake.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/judge/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/judge/test_judge.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/reading/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/reading/test_handwriting_route.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/reading/test_live_profile.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/reading/test_reading_pipeline.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/reading/test_reading_units.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/reading/test_robustness.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/regions/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/regions/test_fields.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/regions/test_furniture.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/regions/test_regions.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/shaping/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/shaping/test_chunking.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/shaping/test_round2_options.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/shaping/test_tables.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/tables/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/tables/test_tables_round2.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/tasks/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/tasks/conftest.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/tasks/live_notes.md +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/tasks/live_smoke.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/tasks/test_edit.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/tasks/test_extract.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/tasks/test_extract_extras.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/tasks/test_extract_robust.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/tasks/test_llm.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/tasks/test_reply_schema.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/tasks/test_schema.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/tasks/test_split_classify.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/test_bench.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/test_bench_suite.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/test_engine_final.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/test_integrations.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/test_library.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/test_localmodels.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/test_mcp_server.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/test_model.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/test_pipeline.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/test_readers.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/test_robust_fallbacks.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/test_serializer.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/test_star.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/test_ws4_ocr_prep.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/test_ws4_speed_batch.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/test_zoom_vote.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/typing/__init__.py +0 -0
- {readanydoc-0.4.2 → readanydoc-0.4.4}/tests/typing/test_typing.py +0 -0
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.4 (2026-11-19)
|
|
4
|
+
|
|
5
|
+
- Review flags values the output left out, by code with no model call: `printed_but_empty` (a field is empty but
|
|
6
|
+
the document prints a value for it that nothing took, for example a dropped billing contact) and
|
|
7
|
+
`row_not_extracted` (a list took some rows of a table and left another out). They replace
|
|
8
|
+
`list_may_be_incomplete`. On planted misses in 47 documents: 84-100% of emptied lists and 89-95% of blanked
|
|
9
|
+
fields caught, about 0.1 flags per document on real outputs. What it does not catch, and the model-based option
|
|
10
|
+
we did not build, are in the extraction guide ("Values the output left out").
|
|
11
|
+
|
|
12
|
+
## 0.4.3 (2026-11-19)
|
|
13
|
+
|
|
14
|
+
- `fill_required` (Python, CLI `--fill-required`, MCP, `settings.fill_required`): which required fields always get
|
|
15
|
+
a value. `"choices"` (default, as in 0.4.2): required yes/no and enum fields. `True`: also every required number
|
|
16
|
+
and text field. A list of field paths: the choices and those fields. `False`: none. Forced numbers and text may be
|
|
17
|
+
guesses: with `review`, each one not printed in the document is flagged `filled_because_required`. On a pack of 5
|
|
18
|
+
order forms, `True` scored 98.3% of fields right against 100% for the default (it filled end dates the answer
|
|
19
|
+
key leaves empty).
|
|
20
|
+
- Review: a total row whose label spans the columns ("Monthly recurring | USD 1,500.00") no longer counts as a
|
|
21
|
+
missing list item.
|
|
22
|
+
|
|
3
23
|
## 0.4.2 (2026-11-19)
|
|
4
24
|
|
|
5
25
|
From a user's test of 0.4.0 on a pack of 5 order forms (their scorer: 97.9% of fields right). After these fixes,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: readanydoc
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.4
|
|
4
4
|
Summary: Document parsing and extraction with vision models: an open engine around Claude (or any model), with a Reducto-compatible API
|
|
5
5
|
Project-URL: Homepage, https://arpitpatel25.github.io/ReadAnyDoc/
|
|
6
6
|
Project-URL: Repository, https://github.com/arpitpatel25/ReadAnyDoc
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "readanydoc",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "Parse PDFs, scans, photos and Office files into Markdown, and extract typed fields with a citation for every value. Open-source alternative to Reducto, on your own Anthropic key.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Unmute"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"mcpServers": {
|
|
3
3
|
"readanydoc": {
|
|
4
4
|
"command": "uvx",
|
|
5
|
-
"args": ["--from", "git+https://github.com/arpitpatel25/ReadAnyDoc@
|
|
5
|
+
"args": ["--from", "git+https://github.com/arpitpatel25/ReadAnyDoc@b461cec3f7849f74ab9b780e9aada5d5299ddd8f", "readanydoc", "mcp"]
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "readanydoc"
|
|
3
|
-
version = "0.4.
|
|
3
|
+
version = "0.4.4"
|
|
4
4
|
description = "Document parsing and extraction with vision models: an open engine around Claude (or any model), with a Reducto-compatible API"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [{ name = "readanydoc contributors" }]
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Use it as a library (``readanydoc.parse``, ``readanydoc.extract``) or run the server (``readanydoc serve``).
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
|
-
__version__ = "0.4.
|
|
6
|
+
__version__ = "0.4.4"
|
|
7
7
|
|
|
8
8
|
from .library import (Block, BoundingBox, Citation, ExtractResult, ParseResult, Usage, # noqa: E402
|
|
9
9
|
extract, parse)
|
|
@@ -69,6 +69,16 @@ def _parse_profile(args: argparse.Namespace) -> int:
|
|
|
69
69
|
return 0
|
|
70
70
|
|
|
71
71
|
|
|
72
|
+
def _fill(v):
|
|
73
|
+
if v is None:
|
|
74
|
+
return "choices"
|
|
75
|
+
if v == []:
|
|
76
|
+
return True
|
|
77
|
+
if v == ["none"]:
|
|
78
|
+
return False
|
|
79
|
+
return v
|
|
80
|
+
|
|
81
|
+
|
|
72
82
|
def _extract(args: argparse.Namespace) -> int:
|
|
73
83
|
from .library import extract
|
|
74
84
|
with open(args.schema) as f:
|
|
@@ -81,7 +91,7 @@ def _extract(args: argparse.Namespace) -> int:
|
|
|
81
91
|
alts = True if alts == [] else (alts or False)
|
|
82
92
|
result = extract(args.input, schema, instructions=instructions, citations=not args.no_citations,
|
|
83
93
|
extract_model=args.extract_model, review=args.review, alternatives=alts,
|
|
84
|
-
derived_values=not args.printed_only, **_common(args))
|
|
94
|
+
derived_values=not args.printed_only, fill_required=_fill(args.fill_required), **_common(args))
|
|
85
95
|
_warn(result.warnings)
|
|
86
96
|
out = {"data": result.data, "citations": {k: [c.model_dump() for c in v] for k, v in result.citations.items()},
|
|
87
97
|
**({"review": result.review} if args.review else {}),
|
|
@@ -206,6 +216,10 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
206
216
|
x.add_argument("--alternatives", nargs="*", metavar="FIELD",
|
|
207
217
|
help="also return other values the document gives for a field (a special term, an amendment); "
|
|
208
218
|
"for every field, or only the fields named")
|
|
219
|
+
x.add_argument("--fill-required", nargs="*", metavar="FIELD",
|
|
220
|
+
help="always give a value to required fields: alone, every required field (numbers and text "
|
|
221
|
+
"too: the model may guess, and each guess is flagged in --review); with FIELDs, only those; "
|
|
222
|
+
"'none' for no field. Default: required yes/no and enum fields only")
|
|
209
223
|
x.add_argument("--printed-only", action="store_true",
|
|
210
224
|
help="only values printed in the document: never one worked out or assumed")
|
|
211
225
|
_model_args(x)
|
|
@@ -108,7 +108,7 @@ class ExtractResult(BaseModel):
|
|
|
108
108
|
review: list[dict[str, Any]] = Field(default_factory=list,
|
|
109
109
|
description="with review=True: values to check, each {field, flag, detail} "
|
|
110
110
|
"(not_found_on_page, ambiguous_date, struck_through, "
|
|
111
|
-
"
|
|
111
|
+
"printed_but_empty, row_not_extracted, ...); found by code, no model call")
|
|
112
112
|
alternatives: dict[str, list[dict[str, Any]]] = Field(
|
|
113
113
|
default_factory=dict, description="with alternatives=True (or a list of field paths): other values the "
|
|
114
114
|
"document gives for a field, by path, each {value, note, citations}")
|
|
@@ -150,7 +150,8 @@ def extract(source: Source, schema: Union[dict[str, Any], type[BaseModel]], *, i
|
|
|
150
150
|
pages: Optional[list[int]] = None, filename: Optional[str] = None,
|
|
151
151
|
settings: Optional[dict[str, Any]] = None, timeout: Optional[float] = None, review: bool = False,
|
|
152
152
|
alternatives: Union[bool, list[str]] = False, derived_values: bool = True,
|
|
153
|
-
part_tokens: Optional[int] = None, parse: bool = True
|
|
153
|
+
part_tokens: Optional[int] = None, parse: bool = True,
|
|
154
|
+
fill_required: Union[bool, str, list[str]] = "choices") -> ExtractResult:
|
|
154
155
|
"""Extract the fields of ``schema`` (a JSON Schema dict or a pydantic model class) from a document.
|
|
155
156
|
|
|
156
157
|
``instructions`` is the system prompt for the extraction model. ``array_extract`` processes long documents in
|
|
@@ -164,6 +165,13 @@ def extract(source: Source, schema: Union[dict[str, Any], type[BaseModel]], *, i
|
|
|
164
165
|
extraction model): the pages are not parsed first; the model reads the file itself (a PDF, or the pages of an
|
|
165
166
|
image), and citations are found by code in the PDF's own words or, for scans and images, in local OCR words.
|
|
166
167
|
About half the cost and 2.5 times faster on a 43-page report, but less accurate: see docs/decisions.md.
|
|
168
|
+
|
|
169
|
+
``fill_required``: which required fields always get a value. ``"choices"`` (default): required yes/no and enum
|
|
170
|
+
fields (the document's terms decide them; "Net 30" means last day of month = false). ``True``: also every
|
|
171
|
+
required number and text field. A list of field paths (``["customer.tax_id", "items[].amount"]``): the choices
|
|
172
|
+
and these fields. ``False``: none, a value the document does not give stays null. Forcing numbers or text makes
|
|
173
|
+
the model guess when the document does not give the value: each such value not printed in the document is
|
|
174
|
+
flagged ``filled_because_required`` in ``review``. Not forced: a field stays null and is listed in ``warnings``.
|
|
167
175
|
"""
|
|
168
176
|
from .tasks import extract as extract_task
|
|
169
177
|
from .tasks.llm import get_llm
|
|
@@ -186,7 +194,8 @@ def extract(source: Source, schema: Union[dict[str, Any], type[BaseModel]], *, i
|
|
|
186
194
|
"settings": {**(settings or {}), "citations": {"enabled": citations}, "array_extract": array_extract,
|
|
187
195
|
**({"review": True} if review else {}), **({"alternatives": alternatives} if alternatives else {}),
|
|
188
196
|
**({} if derived_values else {"derived_values": False}),
|
|
189
|
-
**({"part_tokens": part_tokens} if part_tokens else {})
|
|
197
|
+
**({"part_tokens": part_tokens} if part_tokens else {}),
|
|
198
|
+
**({} if fill_required == "choices" else {"fill_required": fill_required})},
|
|
190
199
|
}
|
|
191
200
|
llm = get_llm(make_spec(extract_model or model, extract_effort or effort, extract_options))
|
|
192
201
|
if not parse and type(llm).__name__ != "AnthropicAPILLM":
|
|
@@ -47,7 +47,7 @@ def parse_document(path: str, mode: str = "engine", pages: Optional[list[int]] =
|
|
|
47
47
|
def extract_fields(path: str, schema: dict[str, Any], instructions: Optional[str] = None,
|
|
48
48
|
array_extract: bool = False, mode: str = "engine", review: bool = True,
|
|
49
49
|
alternatives: bool = False, part_tokens: Optional[int] = None,
|
|
50
|
-
parse_first: bool = True) -> dict[str, Any]:
|
|
50
|
+
parse_first: bool = True, fill_required: Any = "choices") -> dict[str, Any]:
|
|
51
51
|
"""Extract structured values from a local document into a JSON Schema, with citations.
|
|
52
52
|
|
|
53
53
|
schema: a JSON Schema object (type "object" with properties). instructions: optional guidance for the
|
|
@@ -55,13 +55,16 @@ def extract_fields(path: str, schema: dict[str, Any], instructions: Optional[str
|
|
|
55
55
|
check (found by code, no extra cost). alternatives: also return other values the document gives for a field
|
|
56
56
|
(a special term or an amendment that changes a price). part_tokens: largest document part per call, in tokens
|
|
57
57
|
(default 30,000). parse_first: false to skip parsing (the model reads the file itself: about half the cost and
|
|
58
|
-
faster, less accurate, fewer citations).
|
|
58
|
+
faster, less accurate, fewer citations). fill_required: which required fields always get a value: "choices"
|
|
59
|
+
(default, yes/no and enum fields), true (numbers and text too: the model may guess, each guess is flagged in
|
|
60
|
+
to_check as filled_because_required), a list of field paths, or false (nothing forced).
|
|
59
61
|
"""
|
|
60
62
|
import readanydoc
|
|
61
63
|
if isinstance(schema, str):
|
|
62
64
|
schema = json.loads(schema)
|
|
63
65
|
res = readanydoc.extract(_path(path), schema, instructions=instructions, array_extract=array_extract, mode=mode,
|
|
64
|
-
review=review, alternatives=alternatives, part_tokens=part_tokens, parse=parse_first
|
|
66
|
+
review=review, alternatives=alternatives, part_tokens=part_tokens, parse=parse_first,
|
|
67
|
+
fill_required=fill_required)
|
|
65
68
|
data = res.data.model_dump() if hasattr(res.data, "model_dump") else res.data
|
|
66
69
|
cites = {k: [c.model_dump(exclude_none=True) for c in v] for k, v in res.citations.items()}
|
|
67
70
|
return {"data": data, "citations": cites, "warnings": res.warnings,
|
|
@@ -30,8 +30,8 @@ NOTE = ('Answer as {"values": [...]} with one entry per value: "code" is the fie
|
|
|
30
30
|
"column, section or page (a unit, a scale such as \"in thousands\", a currency, a date or period in a "
|
|
31
31
|
"heading) applies to every item it covers: write it on each of those items. Leave out only a field the "
|
|
32
32
|
"document gives no value for and does not make clear; never write a guess. A field marked \"always answer\" is "
|
|
33
|
-
"required in every list item or section you write: never leave it out there
|
|
34
|
-
"document\'s terms mean (it never makes you write an item or section the document does not have). A value the document gives in "
|
|
33
|
+
"required in every list item or section you write: never leave it out there; write the choice or value "
|
|
34
|
+
"the document\'s terms mean (it never makes you write an item or section the document does not have). A value the document gives in "
|
|
35
35
|
"another form is not a guess: write it in the form the field asks for (a country name as its code). "
|
|
36
36
|
'Write numbers as plain digits ("4200.50", "-1200") and dates in the format the field asks for. '
|
|
37
37
|
'Copy names, titles and labels exactly as printed, every word of them, even when part of a name looks like '
|
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
"""Coverage: printed values the output did not take, found by code (no model call).
|
|
2
|
+
|
|
3
|
+
Two rules, built only from what the parser gives every document (form fields, table rows) and the output itself:
|
|
4
|
+
|
|
5
|
+
- ``printed_but_empty``: a field came back empty (null or []) while the document prints a label and value that no
|
|
6
|
+
output value used, and the label shares a word with that field's name, title or description;
|
|
7
|
+
- ``row_not_extracted``: a list took some rows of a table, but another item row of the same table was used by no
|
|
8
|
+
output value.
|
|
9
|
+
|
|
10
|
+
"Used" is decided per value, not per block: a printed value counts as used only if an output value matches it (as
|
|
11
|
+
text, number or date). Two fields printed in one box, or one value printed twice, are therefore told apart.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import re
|
|
17
|
+
from datetime import date
|
|
18
|
+
from typing import Any, Iterable, Optional
|
|
19
|
+
|
|
20
|
+
from ..textnorm import tokenize
|
|
21
|
+
from . import schema as S
|
|
22
|
+
|
|
23
|
+
_TAG = re.compile(r"<[^>]+>")
|
|
24
|
+
_ENTITY = re.compile(r"&(?:amp|lt|gt|quot|apos|nbsp|#3[49]|#160);", re.I)
|
|
25
|
+
_SKIP_TYPES = {"Header", "Footer", "Page Number", "Figure", "Signature", "Comment"}
|
|
26
|
+
_BASIC = {"the", "a", "an", "of", "to", "and", "or", "for", "in", "on", "at", "by", "is", "it", "its", "as",
|
|
27
|
+
"be", "this", "that", "with", "from", "e", "g", "eg", "if", "when", "any", "each", "all", "per", "not"}
|
|
28
|
+
_STOP = {"the", "a", "an", "of", "to", "and", "or", "for", "in", "on", "at", "by", "is", "it", "its", "as", "be",
|
|
29
|
+
"this", "that", "with", "from", "no", "number", "date", "value", "type", "name", "id", "code", "info",
|
|
30
|
+
"details", "detail", "total", "amount", "item", "items", "list", "field", "e", "g", "eg", "if", "when",
|
|
31
|
+
"any", "each", "all", "per", "not", "one", "who", "which", "what", "their", "they", "them", "has", "have"}
|
|
32
|
+
_MONTHS = {m: i + 1 for i, m in enumerate(["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct",
|
|
33
|
+
"nov", "dec"])}
|
|
34
|
+
_SUMMARY = re.compile(r"\b(sub-?\s?total|total|grand total|tax|vat|gst|balance|amount due|sum|carried forward|"
|
|
35
|
+
r"brought forward)\b", re.I)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _plain(s: str) -> str:
|
|
39
|
+
return " ".join(_ENTITY.sub(" ", _TAG.sub(" ", s or "")).replace("**", " ").split())
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _stem(w: str) -> str:
|
|
43
|
+
"""Singular of a plural word: parties -> party, taxes -> tax, lines -> line, contacts -> contact."""
|
|
44
|
+
w = w.lower()
|
|
45
|
+
if len(w) > 4 and w.endswith("ies"):
|
|
46
|
+
return w[:-3] + "y"
|
|
47
|
+
if len(w) > 4 and re.search(r"(s|x|z|ch|sh)es$", w):
|
|
48
|
+
return w[:-2]
|
|
49
|
+
if len(w) > 3 and w.endswith("s") and not w.endswith("ss"):
|
|
50
|
+
return w[:-1]
|
|
51
|
+
return w
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _words(s: str, stop: set = _STOP) -> set[str]:
|
|
55
|
+
s = re.sub(r"([a-z])([A-Z])", r"\1 \2", s or "").replace("_", " ")
|
|
56
|
+
return {_stem(t.norm) for t in tokenize(s) if len(t.norm) > 1 and not t.norm.isdigit()} - stop
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# ------------------------------------------------------------------------------------------- printed pieces
|
|
60
|
+
|
|
61
|
+
class Piece:
|
|
62
|
+
"""A printed label and value (a form field, a pair in a two-column table) or a table item row."""
|
|
63
|
+
|
|
64
|
+
def __init__(self, label: str, value: str, page: int, block: str, kind: str, table: Optional[int] = None):
|
|
65
|
+
self.label, self.value, self.page, self.block, self.kind, self.table = label, value, page, block, kind, table
|
|
66
|
+
|
|
67
|
+
def __repr__(self) -> str:
|
|
68
|
+
return f"Piece({self.kind}, {self.label!r}: {self.value[:50]!r}, p{self.page})"
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _rows(html: str) -> list[list[tuple[str, bool]]]:
|
|
72
|
+
out = []
|
|
73
|
+
for row in re.findall(r"<tr\b[^>]*>(.*?)</tr>", html, re.I | re.S):
|
|
74
|
+
out.append([(_plain(c), tag.lower() == "th")
|
|
75
|
+
for tag, c in re.findall(r"<(t[dh])\b[^>]*>(.*?)</t[dh]>", row, re.I | re.S)])
|
|
76
|
+
return out
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def pieces(pages: Iterable[dict]) -> list[Piece]:
|
|
80
|
+
"""Every printed label/value and table item row of the parsed pages (headers, footers, figures skipped)."""
|
|
81
|
+
out: list[Piece] = []
|
|
82
|
+
tid = 0
|
|
83
|
+
for p in pages:
|
|
84
|
+
for r in p["regions"]:
|
|
85
|
+
t, c = r["type"], r["content"] or ""
|
|
86
|
+
if t in _SKIP_TYPES:
|
|
87
|
+
continue
|
|
88
|
+
if t == "Table" and "<tr" in c.lower():
|
|
89
|
+
tid += 1
|
|
90
|
+
rows = [x for x in _rows(c) if any(v for v, _ in x)]
|
|
91
|
+
if not rows:
|
|
92
|
+
continue
|
|
93
|
+
width = max(len(x) for x in rows)
|
|
94
|
+
head = [v for v, th in rows[0]] if all(th for _, th in rows[0]) or _header_like(rows) else None
|
|
95
|
+
body = rows[1:] if head else rows
|
|
96
|
+
if _pair_table(rows, width): # label | value (| label | value): a form drawn as a table
|
|
97
|
+
for x in rows:
|
|
98
|
+
for i in range(0, len(x) - 1, 2):
|
|
99
|
+
lab, val = x[i][0].rstrip(":").strip(), x[i + 1][0]
|
|
100
|
+
if lab and val and not x[i + 1][1] and not _HEADER_WORDS.issuperset(_words(lab, _BASIC)):
|
|
101
|
+
out.append(Piece(lab, val, p["number"], r["label"], "pair"))
|
|
102
|
+
continue
|
|
103
|
+
for x in body:
|
|
104
|
+
cells = [v for v, _ in x]
|
|
105
|
+
if len(cells) == 2 and cells[0] and cells[1] and not re.search(r"\d", cells[0]) \
|
|
106
|
+
and len(cells[0].split()) <= 4:
|
|
107
|
+
out.append(Piece(cells[0].rstrip(":"), cells[1], p["number"], r["label"], "pair"))
|
|
108
|
+
# "TOTAL | 46,000": a label and its value; it may also be an item ("Y.B.BAT | 46,000")
|
|
109
|
+
if len(x) < width or not cells[0] or any(_SUMMARY.search(v) for v in cells if v):
|
|
110
|
+
continue # a total under the items, a spanned label
|
|
111
|
+
if any(v.endswith(":") for v in cells) or not any(re.search(r"\d", v) for v in cells):
|
|
112
|
+
continue # labels with their values ("Terms: | 60 days"), or a header row: not an item
|
|
113
|
+
label = " ".join(head) if head else ""
|
|
114
|
+
out.append(Piece(label, " | ".join(cells), p["number"], r["label"], "row", tid))
|
|
115
|
+
continue
|
|
116
|
+
if t == "Key Value" or t == "Text":
|
|
117
|
+
for line in re.split(r"\n| / |<br\s*/?>", c):
|
|
118
|
+
for seg in re.split(r"\s{3,}|\t", _TAG.sub(" ", line)): # side-by-side columns of a form
|
|
119
|
+
seg = _plain(seg)
|
|
120
|
+
m = re.match(r"^([A-Za-z][^:]{0,40}):\s+(.+)$", seg)
|
|
121
|
+
if m and (t == "Key Value" or len(m.group(1).split()) <= 4):
|
|
122
|
+
out.append(Piece(m.group(1).strip(), m.group(2).strip(), p["number"], r["label"], "pair"))
|
|
123
|
+
return out
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
_HEADER_WORDS = {"label", "value", "field", "key", "item", "description", "detail", "name"}
|
|
127
|
+
_FORM_HEADER = {"label", "value", "field", "key", "detail", "information", "info"}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def _pair_table(rows: list, width: int) -> bool:
|
|
131
|
+
"""A table of labels and their values: 2 or 4 columns, the label cells short text (or ending in ":")."""
|
|
132
|
+
if width not in (2, 4):
|
|
133
|
+
return False
|
|
134
|
+
if rows and all(th for _, th in rows[0]) and len(rows[0]) == width:
|
|
135
|
+
names = set().union(*(_words(v, _BASIC) for v, _ in rows[0]))
|
|
136
|
+
if names - _FORM_HEADER:
|
|
137
|
+
return False # a header naming columns ("Item | Amount"): an item table, not a form
|
|
138
|
+
body = [x for x in rows if not all(th for _, th in x) and len(x) == width] # a narrower row is a heading
|
|
139
|
+
if len(body) < 2:
|
|
140
|
+
return False
|
|
141
|
+
labels = [x[i][0] for x in body for i in range(0, len(x) - 1, 2) if x[i][0] or x[i + 1][0]]
|
|
142
|
+
if not labels:
|
|
143
|
+
return False
|
|
144
|
+
short = [v for v in labels if v and len(v.split()) <= 5 and not re.search(r"\d", v)]
|
|
145
|
+
colon = [v for v in labels if v.endswith(":")]
|
|
146
|
+
return len(short) >= 0.8 * len(labels) and (width == 2 or len(colon) >= 0.5 * len(labels) or
|
|
147
|
+
len(short) == len(labels))
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _header_like(rows: list) -> bool:
|
|
151
|
+
"""A first row of labels over rows of values (no amount or digit in it, more digits below)."""
|
|
152
|
+
if len(rows) < 2:
|
|
153
|
+
return False
|
|
154
|
+
first = [v for v, _ in rows[0]]
|
|
155
|
+
return not any(re.search(r"\d", v) for v in first) and any(re.search(r"\d", v) for x in rows[1:] for v, _ in x)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
# ------------------------------------------------------------------------------------------------ matching
|
|
159
|
+
|
|
160
|
+
_NUM = re.compile(r"\d{1,3}(?:[ ,.'\u00a0\u202f]\d{3})+(?:[.,]\d{1,2})?(?!\d)|\d+(?:[.,]\d+)?")
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def _numbers(s: str) -> set[float]:
|
|
164
|
+
"""Numbers as printed in any common form: 1,370.53, 1 370.53, 1.370,53, 1'370.53, 370.53."""
|
|
165
|
+
out = set()
|
|
166
|
+
for m in _NUM.finditer(s or ""):
|
|
167
|
+
t = m.group(0)
|
|
168
|
+
seps = re.findall(r"[ ,.'\u00a0\u202f]", t)
|
|
169
|
+
dec = ""
|
|
170
|
+
if seps and re.search(r"[.,]\d{1,2}$", t) and (len(seps) > 1 or len(t.split(seps[-1])[-1]) != 3):
|
|
171
|
+
dec = t[-3:] if t[-3] in ".," else t[-2:]
|
|
172
|
+
t = t[: -len(dec)]
|
|
173
|
+
dec = "." + dec[1:]
|
|
174
|
+
t = re.sub(r"[ ,.'\u00a0\u202f]", "", t) if len(seps) > (1 if dec else 0) or (seps and not dec and
|
|
175
|
+
len(t.split(seps[0])[-1]) == 3) else t.replace(",", ".")
|
|
176
|
+
try:
|
|
177
|
+
out.add(round(float(t + dec), 4))
|
|
178
|
+
except ValueError:
|
|
179
|
+
pass
|
|
180
|
+
return out
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def _dates(s: str) -> set[date]:
|
|
184
|
+
out = set()
|
|
185
|
+
for y, mo, d in re.findall(r"\b(\d{4})-(\d{1,2})-(\d{1,2})\b", s):
|
|
186
|
+
try:
|
|
187
|
+
out.add(date(int(y), int(mo), int(d)))
|
|
188
|
+
except ValueError:
|
|
189
|
+
pass
|
|
190
|
+
for a, b, c in re.findall(r"\b(\d{1,4})[/.](\d{1,2})[/.](\d{2,4})\b", s):
|
|
191
|
+
a, b, c = int(a), int(b), int(c)
|
|
192
|
+
for y, mo, d in ((a, b, c), (c, b, a), (c, a, b)) if a > 31 else ((c, b, a), (c, a, b)):
|
|
193
|
+
y = y + 2000 if y < 100 else y
|
|
194
|
+
try:
|
|
195
|
+
out.add(date(y, mo, d))
|
|
196
|
+
except ValueError:
|
|
197
|
+
pass
|
|
198
|
+
for mname, d, y in re.findall(r"\b([A-Za-z]{3,9})\.?\s+(\d{1,2}),?\s+(\d{4})\b", s):
|
|
199
|
+
mo = _MONTHS.get(mname[:3].lower())
|
|
200
|
+
if mo:
|
|
201
|
+
try:
|
|
202
|
+
out.add(date(int(y), mo, int(d)))
|
|
203
|
+
except ValueError:
|
|
204
|
+
pass
|
|
205
|
+
for d, mname, y in re.findall(r"\b(\d{1,2})\s+([A-Za-z]{3,9})\.?,?\s+(\d{4})\b", s):
|
|
206
|
+
mo = _MONTHS.get(mname[:3].lower())
|
|
207
|
+
if mo:
|
|
208
|
+
try:
|
|
209
|
+
out.add(date(int(y), mo, int(d)))
|
|
210
|
+
except ValueError:
|
|
211
|
+
pass
|
|
212
|
+
return out
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
class _Used:
|
|
216
|
+
"""The output's values, ready to test whether a printed value was taken."""
|
|
217
|
+
|
|
218
|
+
def __init__(self, value: Any, schema: Any):
|
|
219
|
+
self.tokens: list[list[str]] = []
|
|
220
|
+
self.nums: set[float] = set()
|
|
221
|
+
self.dates: set[date] = set()
|
|
222
|
+
for _, v, _s in S.iter_leaves(value, schema):
|
|
223
|
+
if v is None or isinstance(v, bool) or v == "":
|
|
224
|
+
continue
|
|
225
|
+
if isinstance(v, (int, float)):
|
|
226
|
+
self.nums.add(round(float(v), 4))
|
|
227
|
+
continue
|
|
228
|
+
s = str(v)
|
|
229
|
+
self.dates |= _dates(s)
|
|
230
|
+
if re.fullmatch(r"[^\w]*[A-Za-z.]{0,4}\s?[-(]?[\d ,.'\u00a0\u202f]+\)?[^\w]*", s.strip()):
|
|
231
|
+
self.nums |= {n for n in _numbers(s)} # a number written as text: "10,091", "Rp 46.000"
|
|
232
|
+
toks = [t.norm for t in tokenize(s)]
|
|
233
|
+
if toks:
|
|
234
|
+
self.tokens.append(toks)
|
|
235
|
+
|
|
236
|
+
def took(self, printed: str) -> bool:
|
|
237
|
+
"""An output value took this printed text: the same date, a distinctive number (10 or more, or with
|
|
238
|
+
decimals), or output words covering at least 40% of its words. A short common value ("USD", "1") alone
|
|
239
|
+
does not take a longer text."""
|
|
240
|
+
toks = [t.norm for t in tokenize(printed)]
|
|
241
|
+
if not toks:
|
|
242
|
+
return True # nothing to take
|
|
243
|
+
if _dates(printed) & self.dates:
|
|
244
|
+
return True
|
|
245
|
+
nums = {n for n in _numbers(printed) if abs(n) >= 10 or n != int(n)}
|
|
246
|
+
if nums & self.nums:
|
|
247
|
+
return True
|
|
248
|
+
covered = [False] * len(toks)
|
|
249
|
+
for t in self.tokens:
|
|
250
|
+
if len(t) == 1 and (t[0].isdigit() or len(t[0]) < 3):
|
|
251
|
+
continue
|
|
252
|
+
n = len(t)
|
|
253
|
+
for i in range(len(toks) - n + 1):
|
|
254
|
+
if toks[i:i + n] == t:
|
|
255
|
+
for j in range(i, i + n):
|
|
256
|
+
covered[j] = True
|
|
257
|
+
words = [i for i, w in enumerate(toks) if not w.isdigit()] or list(range(len(toks)))
|
|
258
|
+
return sum(covered[i] for i in words) >= max(1.0, 0.4 * len(words))
|
|
259
|
+
|
|
260
|
+
def took_row(self, cells: list[str]) -> bool:
|
|
261
|
+
"""A table row is taken when what identifies it was: its first cell, a text cell of two words or more,
|
|
262
|
+
a distinctive number (10 or more, or with decimals), or any two cells."""
|
|
263
|
+
cells = [c for c in cells if c.strip()]
|
|
264
|
+
if not cells:
|
|
265
|
+
return True
|
|
266
|
+
hits = 0
|
|
267
|
+
for i, c in enumerate(cells):
|
|
268
|
+
if not self.took(c):
|
|
269
|
+
continue
|
|
270
|
+
hits += 1
|
|
271
|
+
words = [w for w in tokenize(c) if not w.norm.isdigit()]
|
|
272
|
+
if i == 0 or len(words) >= 2 or {n for n in _numbers(c) if abs(n) >= 10 or n != int(n)}:
|
|
273
|
+
return True
|
|
274
|
+
return hits >= 2
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
# ---------------------------------------------------------------------------------------------- the checks
|
|
278
|
+
|
|
279
|
+
def _field_words(schema: Any) -> dict[str, set[str]]:
|
|
280
|
+
"""Normalised field path ("customer.contacts") -> words of its name, title and description, for every field
|
|
281
|
+
and list in the schema."""
|
|
282
|
+
out: dict[str, set[str]] = {}
|
|
283
|
+
|
|
284
|
+
def go(node: Any, path: tuple) -> None:
|
|
285
|
+
if not isinstance(node, dict):
|
|
286
|
+
return
|
|
287
|
+
n = S.branch_for(node, {}) if (node.get("anyOf") or node.get("oneOf")) else node
|
|
288
|
+
if not isinstance(n, dict):
|
|
289
|
+
return
|
|
290
|
+
if path:
|
|
291
|
+
words = _words(path[-1], _BASIC) | _words(str(n.get("title") or node.get("title") or ""), _BASIC)
|
|
292
|
+
words |= _words(str(n.get("description") or node.get("description") or ""))
|
|
293
|
+
out[".".join(path)] = out.get(".".join(path), set()) | words
|
|
294
|
+
if S.is_object(n):
|
|
295
|
+
for k, v in (n.get("properties") or {}).items():
|
|
296
|
+
go(v, path + (k,))
|
|
297
|
+
elif S.is_array(n):
|
|
298
|
+
items = S.branch_for(n.get("items") or {}, {})
|
|
299
|
+
if path and isinstance(items, dict) and S.is_object(items): # a list is also named by its items' fields
|
|
300
|
+
for k, v in (items.get("properties") or {}).items():
|
|
301
|
+
out[".".join(path)] |= _words(k, _BASIC) | _words(str((v or {}).get("title") or ""), _BASIC)
|
|
302
|
+
go(n.get("items") or {}, path)
|
|
303
|
+
|
|
304
|
+
go(schema, ())
|
|
305
|
+
return out
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def _output_lists(value: Any, schema: Any) -> list[tuple[str, "_Used"]]:
|
|
309
|
+
"""(path, its values) for every list of objects in the output: to name the list a table's rows belong to."""
|
|
310
|
+
out: list = []
|
|
311
|
+
|
|
312
|
+
def go(v: Any, s: Any, path: tuple) -> None:
|
|
313
|
+
s = S.branch_for(s, v) if isinstance(s, dict) else s
|
|
314
|
+
if isinstance(v, dict) and isinstance(s, dict) and S.is_object(s):
|
|
315
|
+
for k, x in v.items():
|
|
316
|
+
go(x, (s.get("properties") or {}).get(k, {}), path + (k,))
|
|
317
|
+
elif isinstance(v, list) and isinstance(s, dict) and S.is_array(s) and v and all(isinstance(i, dict) for i in v):
|
|
318
|
+
out.append((".".join(path), _Used(v, s)))
|
|
319
|
+
|
|
320
|
+
go(value, schema, ())
|
|
321
|
+
return out
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def _list_paths(schema: Any) -> set[str]:
|
|
325
|
+
out: set = set()
|
|
326
|
+
|
|
327
|
+
def go(node: Any, path: tuple) -> None:
|
|
328
|
+
n = S.branch_for(node, {}) if isinstance(node, dict) and (node.get("anyOf") or node.get("oneOf")) else node
|
|
329
|
+
if not isinstance(n, dict):
|
|
330
|
+
return
|
|
331
|
+
if S.is_object(n):
|
|
332
|
+
for k, v in (n.get("properties") or {}).items():
|
|
333
|
+
go(v, path + (k,))
|
|
334
|
+
elif S.is_array(n):
|
|
335
|
+
out.add(".".join(path))
|
|
336
|
+
go(n.get("items") or {}, path)
|
|
337
|
+
|
|
338
|
+
go(schema, ())
|
|
339
|
+
return out
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
def _empty_fields(value: Any, schema: Any) -> list[str]:
|
|
343
|
+
"""Normalised paths of fields that came back null or [] (inside a list item: per item, path without index)."""
|
|
344
|
+
out: list[str] = []
|
|
345
|
+
|
|
346
|
+
def go(v: Any, s: Any, path: tuple) -> None:
|
|
347
|
+
s = S.branch_for(s, v) if isinstance(s, dict) else s
|
|
348
|
+
if not isinstance(s, dict):
|
|
349
|
+
return
|
|
350
|
+
if S.is_object(s):
|
|
351
|
+
if not isinstance(v, dict):
|
|
352
|
+
if v is None and path:
|
|
353
|
+
out.append(".".join(path))
|
|
354
|
+
return
|
|
355
|
+
for k, sub in (s.get("properties") or {}).items():
|
|
356
|
+
go(v.get(k), sub, path + (k,))
|
|
357
|
+
elif S.is_array(s):
|
|
358
|
+
if not v:
|
|
359
|
+
out.append(".".join(path))
|
|
360
|
+
return
|
|
361
|
+
for item in v:
|
|
362
|
+
go(item, s.get("items") or {}, path)
|
|
363
|
+
elif v is None or v == "":
|
|
364
|
+
out.append(".".join(path))
|
|
365
|
+
|
|
366
|
+
go(value, schema, ())
|
|
367
|
+
return list(dict.fromkeys(out))
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def _shape(v: str) -> Optional[str]:
|
|
371
|
+
"""The kind of value a printed text is, when its form says so: "email", "phone", "url"."""
|
|
372
|
+
if re.search(r"[\w.+-]+@[\w-]+\.[\w.]+", v):
|
|
373
|
+
return "email"
|
|
374
|
+
if re.search(r"https?://|www\.", v):
|
|
375
|
+
return "url"
|
|
376
|
+
if _dates(v):
|
|
377
|
+
return "date"
|
|
378
|
+
if re.fullmatch(r"[+()\d\s.-]{7,}", v.strip()) and len(re.sub(r"\D", "", v)) >= 7:
|
|
379
|
+
return "phone"
|
|
380
|
+
return None
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
def check(value: Any, schema: Any, pages: list[dict]) -> list[dict]:
|
|
384
|
+
"""[{"field", "flag", "detail"}]: printed values the output did not take (see the module docstring)."""
|
|
385
|
+
found = pieces(pages)
|
|
386
|
+
used = _Used(value, schema)
|
|
387
|
+
taken = {id(p): (used.took_row(p.value.split(" | ")) if p.kind == "row" else used.took(p.value)) for p in found}
|
|
388
|
+
free = [p for p in found if not taken[id(p)]]
|
|
389
|
+
words = _field_words(schema)
|
|
390
|
+
out: list[dict] = []
|
|
391
|
+
|
|
392
|
+
# A. printed_but_empty: the most specific empty field whose words the free label shares
|
|
393
|
+
empty = _empty_fields(value, schema)
|
|
394
|
+
lists_ = _list_paths(schema)
|
|
395
|
+
flagged_tables: set = set()
|
|
396
|
+
for p in free:
|
|
397
|
+
if p.kind == "row" and (p.table in flagged_tables or not p.label):
|
|
398
|
+
continue
|
|
399
|
+
lw = _words(p.label, _BASIC if p.kind == "row" else _STOP)
|
|
400
|
+
shape = _shape(p.value)
|
|
401
|
+
best, score = None, 0
|
|
402
|
+
for f in empty:
|
|
403
|
+
if p.kind == "row" and f not in lists_:
|
|
404
|
+
continue # a table's rows are the items of a list, never one single value
|
|
405
|
+
fw = words.get(f, set())
|
|
406
|
+
own = _words(f.rsplit(".", 1)[-1], _BASIC)
|
|
407
|
+
hit = len(lw & fw) + len(_words(p.label, _BASIC) & own) # the field's own name counts twice, and
|
|
408
|
+
# there a common word ("Total", "Date") counts: the field is empty and is named exactly that
|
|
409
|
+
if lw and not lw & (fw | own) and not (shape in ("email", "url", "phone") and shape in own):
|
|
410
|
+
continue # "Credit Date" is not the due date: the label's own words name something else
|
|
411
|
+
if p.kind == "pair" and shape and shape in own:
|
|
412
|
+
hit += 2 # an email printed, an email field empty: matched by the value's shape
|
|
413
|
+
if f in lists_ and p.kind == "pair" and hit < 2:
|
|
414
|
+
continue # a list is named by all its items' fields: one shared word is not enough
|
|
415
|
+
if hit > score:
|
|
416
|
+
best, score = f, hit
|
|
417
|
+
if best and p.kind == "row":
|
|
418
|
+
need = 2 # a table header shares at least two words with the list, or it is not that list's table
|
|
419
|
+
if score >= need:
|
|
420
|
+
flagged_tables.add(p.table)
|
|
421
|
+
out.append({"field": best, "flag": "printed_but_empty",
|
|
422
|
+
"detail": f'a table with "{p.label[:60]}" (page {p.page}) has rows such as '
|
|
423
|
+
f'"{p.value[:60]}", and {best} is empty'})
|
|
424
|
+
elif best:
|
|
425
|
+
out.append({"field": best, "flag": "printed_but_empty",
|
|
426
|
+
"detail": f'"{p.label}: {p.value[:80]}" is printed on page {p.page}, and {best} is empty'})
|
|
427
|
+
|
|
428
|
+
# B. row_not_extracted: a table some of whose item rows were taken, and another row not
|
|
429
|
+
tables: dict[int, list[Piece]] = {}
|
|
430
|
+
for p in found:
|
|
431
|
+
if p.kind == "row" and p.table is not None:
|
|
432
|
+
tables.setdefault(p.table, []).append(p)
|
|
433
|
+
lists_out = _output_lists(value, schema)
|
|
434
|
+
for rows in tables.values():
|
|
435
|
+
took = [r for r in rows if taken[id(r)]]
|
|
436
|
+
if not took or len(took) == len(rows) or (len(took) < 2 and len(rows) > 3):
|
|
437
|
+
continue # one row matching by chance in a long table says nothing about that table
|
|
438
|
+
owner = max(lists_out, key=lambda kv: sum(kv[1].took_row(r.value.split(" | ")) for r in took),
|
|
439
|
+
default=(None, None))[0]
|
|
440
|
+
for r in rows:
|
|
441
|
+
if r not in took:
|
|
442
|
+
out.append({"field": owner, "flag": "row_not_extracted",
|
|
443
|
+
"detail": f'table row "{r.value[:80]}" (page {r.page}) is not in the output, though '
|
|
444
|
+
f"{len(took)} other rows of its table are"})
|
|
445
|
+
return out
|