Examples¶
Each example is a recipe in pdfexorcist/recipes/, shipped in the wheel, and runs on a fixture in tests/fixtures/. The NCVBDC line charts use the charts command; its charts in pictures use the recipe ncvbdc_charts.
Document |
The table |
What the recipe does |
|---|---|---|
Deaths by cause, sex and State: M/F/T blocks under rotated State names. |
Pages found by title regex; a custom parser; State names read from the rotated headers after the vote. |
|
The same M/F/T blocks by chapter, with States, age groups or years for columns. |
Table 2 reuses Table 4’s parser; Tables 5 and 9 share one keyed by Roman numeral, with column names read from the flat header. |
|
One State a page: Total, Rural and Urban blocks of 19 ages x 12 values. |
The State kept out of the key, so camelot (which drops the title) still votes; a survivorship check in Python. |
|
Two blocks a page: five years of Males and Females by single age. |
Keyed by block position and printed year; the district from the table title, since some “District:” headers are wrong. |
|
Person, Male and Female by age for six years, in thousands. |
Keyed by year, age and sex only (one table crosses a page, one is titled PUNJAB); TOML checks with a rounding tolerance. |
|
A row per State/UT, age group or district: Rural, Urban and Total by Male, Female and Person. |
Fake bold, slanted “Not Available”, Type3 fonts without a Unicode map; |
|
State/UT rows of counts and rates, then total rows. |
The generic parser, cleaned numbers, totals that must add up. |
|
A phone photo: seven lakes, this year and the two before. |
OCR engines only, with your own parser. |
|
Key Indicators by State and district. |
|
|
Key Indicators by State and district, 2019-21. |
|
|
Nine tables on five pages: highlights by year, language, gender, category, State. |
One recipe for every table: cells keyed by table, row and column; a check fails on a misprinted count. |
|
NCVBDC’s monthly report: a small table of months under each trend graph, by State and indicator. |
Cells keyed by the graph’s place on the page; area and indicator from the graph title as extra columns; a TPR check and a check that fails on a table under the wrong graph. |
|
NCVBDC’s monthly report: Excel line charts of Tested, Positive, TPR and Pf by month, drawn as paths or pasted as pictures. |
|
|
NCRB’s capacity, inmates and occupancy by State/UT, by sex and by jail type; one table runs over three pages by column. |
Cells keyed by printed column number, so the three pages join; totals, Table 1.3 against Table 1.2, and an occupancy check. |
|
Table 1: percent distribution of the population by age, sex and residence, one or two State blocks a page. |
Keyed by block on the page, the State an extra column; age groups add up to 100 and a total lies between its parts. |
|
KI 75/25.0 Appendix A: spending, childbirth and the aged, in Rural, Urban and Rural + Urban blocks. |
The sector side label dropped wherever an engine puts it; rows keyed by block and a space-free label. |
|
MMR by State with its 95% CI, deaths by age, and the Cause of Death report’s top 10 causes. |
Intervals split into lower and upper columns, percents made numbers; CI, lifetime-risk and sum-to-100 checks. |
|
MoRTH’s State/UT accidents, killed and injured, printed sideways, with three-level headers and Indian comma grouping. |
Pages turned upright, |
|
CBHI National Health Profile: State/UT malaria cases and deaths for five years, the last provisional. |
Years read from the header; a wrapped name joined; States/UTs add up to India. |
|
Maharashtra’s daily report: a row per dam, grouped by region and district. |
Rows keyed by dam name, wrapped names joined, region and district carried from the headings; capacity and % checks. |
|
The Central Water Commission’s weekly bulletin: 91 reservoirs, grouped by region and state. |
Rows keyed by reservoir name, region and state carried from the headings; a total and a storage % check. |
|
A scanned list: Sr. No., application number, name, gender, category, percentile, rank, State. |
OCR engines only; rows keyed by Sr. No., wrapped cells joined to their row; rank and percentile order checks. |
|
Pages of the documents above. |
Small recipes for the settings the others leave at their defaults: the columns parser, column totals, tolerances, page boxes, voting rules, families, a cleaning function, the cells layout and the xlsx, parquet and json formats. |
The Python library page has short examples for each function, and Command line for each command.
tests/test_examples_gallery.py, tests/test_nfhs6_examples.py, tests/test_nfhs5_examples.py, tests/test_recipe_docs_examples.py and tests/test_recipe.py run the commands on these pages; test_recipe.py also checks that every recipe in pdfexorcist/recipes/ is valid.
Regression tests¶
Each test pairs a document parser with values checked against the printed page. It fails on a wrong voted value, a drop in coverage, or broken table arithmetic.
Test |
Document |
|---|---|
|
BMC daily lake levels (photos, OCR) |
|
MCCD Table 4, cause x State x sex (2009, 2011, 2014) |
|
MCCD Tables 2, 5 and 9: chapter x State, age group or year x sex (2018, 2019) |
|
SRS abridged life tables |
|
NCRB ADSI State/UT tables (2023, 2024; a 1995 scan with OCR) |
|
NCRB Crime in India State/UT tables (2021, 2023, 2024) |
|
MoHFW population projections by age and sex |
|
IIPS district projections by single age and sex |
|
NCVBDC Monthly Malaria Situation, Category II (October 2023) |
|
NCVBDC Monthly Malaria Situation line charts: national and Category III (August 2026) |
|
NCVBDC Monthly Malaria Situation charts in pictures, read by OCR (December 2020) |
|
NCRB Prison Statistics India 2023, Tables 1.2 and 1.3 |
|
SRS Statistical Report 2024, Table 1: age distribution by State |
|
NSS KI 75/25.0 (Health), Appendix A Tables A23-A32 |
|
SRS maternal mortality bulletin 2021-23 and Cause of Death Table 2.3A |
|
MoRTH Road Accidents in India 2022, Annexures 2-4 (sideways) |
|
CBHI National Health Profile 2023, Table 3.1.1: malaria by State/UT |
|
Maharashtra WRD Pravah daily dam storage |
|
CWC weekly storage bulletin of 91 reservoirs (1 February 2018) |
|
NTA NEET (UG) 2026 toppers list (a scan, OCR) |
|
NTA NEET (UG) 2024 press release: nine tables in one recipe |
|
CRS State Tables 1, 4 and 6: births, still births and deaths by age, by State, sex and residence (2010, 2011, 2023) |
|
CRS District Tables 7 and 8: births and deaths by district (2016, 2017) |
|
The CRS cases behind slanted text, fake bold, joined pdftotext values, Excel rounding, placement and Type3 fonts |
|
NFHS-6 Key Indicators fact sheets, India, States and districts (an outlined page, OCR) |
|
NFHS-5 Key Indicators fact sheets, India, States and districts (2019-21) |
The OCR tests are slow, so they run on request:
PDFEXORCIST_OCR_TESTS=1 python -m pytest tests/test_bmc_lake_report.py -s