DefExtra hydration
Overview
This dataset cannot ship excerpts. We ship markers only. Users supply PDFs and run hydration to reconstruct the definitions and contexts.
See README.md for the high‑level overview and examples.
Requirements
Python 3.10+
A running GROBID server (default:
http://localhost:8070).Example Docker run:
docker run --rm -p 8070:8070 grobid/grobid:0.8.0Python packages used by scripts:
grobid-client-python,lxml,pdfplumber,pdfminer.six,PyPDF2,pyarrow
UV usage
This repo ships a pyproject.toml, so you can run:
uv run python scripts/hydrate_defextra.py ...
Getting PDFs
See docs/get_pdfs.md for sources and a helper script that lists required PDFs.
Quickstart (run GROBID)
- Place your PDFs in
pdfs/. - Hydrate (runs GROBID unless
--skip-grobid):
uv run python scripts/hydrate_defextra.py \
--legal-csv data/defextra_legal.csv \
--pdf-dir pdfs \
--grobid-out grobid_out \
--output-csv defextra_hydrated.csv \
--report defextra_hydrated_report.txt \
--require-complete
Quickstart (skip GROBID, use existing TEI)
If you already have TEI XML files (e.g., produced by your own GROBID run), point
--grobid-out to that TEI folder and add --skip-grobid:
uv run python scripts/hydrate_defextra.py \
--legal-csv data/defextra_legal.csv \
--pdf-dir pdfs \
--grobid-out /path/to/tei_xml_dir \
--output-csv defextra_hydrated.csv \
--report defextra_hydrated_report.txt \
--require-complete \
--skip-grobid
File naming expectations
- Preferred:
<paper_id>.pdf(thepaper_idin the CSV). - DOI/arXiv/PII aliases are supported for common cases.
- Hash IDs are often Semantic Scholar IDs; many PDFs can be downloaded from there.
GROBID configuration
- By default,
scripts/pdf_to_grobid.pygenerates a temporary config that points tohttp://localhost:8070. - Use
--grobid-config config.jsonto override the URL/timeout/batch size.
Hash mismatch behavior
- The legal CSV includes hash markers to verify that the PDF content matches the paper version.
- Default: skip PDFs with hash mismatches and report them.
- Optional:
--allow-pdf-hash-mismatchto continue anyway (use only after manual inspection).
Interpretation of warnings
Error initializing GROBID clientorGROBID server ... does not appear up and running: GROBID is not reachable. Start the server (or Docker) or pass--grobid-configwith the correct URL. If you already have TEI files, rerun with--skip-grobid.Processing failed ... [BAD_INPUT_DATA] ... error code: 139orpdfaltoerrors: GROBID could not parse a PDF (often a damaged or unusual file). Hydration may still succeed via PDF text fallback, but TEI will be missing. Try a different PDF version.Warning: PDF hash markers did not match ... skipping PDF: The PDF content differs from the expected version. Replace the PDF with the correct version or rerun with--allow-pdf-hash-mismatchand manually inspect outputs.Warning: PDF text extraction failed ...: The PDF text fallback failed (pdfplumber/pdfminer/PyPDF2). Hydration then relies on TEI only. Try a different PDF or a different extraction backend.incorrect startxref pointeror similar PDF syntax warnings: The PDF appears malformed. Often recoverable, but if hydration fails, obtain a clean copy.Summary lines:
Missing TEI for N papers: GROBID output missing for those PDFs.Missing definition spans/Missing context spans: nothing matched after TEI + hash + anchor + PDF fallback.Hydrated from PDF fallback: spans were reconstructed from PDF text (not TEI).
Legal CSV schema (marker columns)
definition_char_start,definition_char_end: exact TEI substring span (optional).definition_match:exact/hash/missingindicating how the TEI span was found.definition_hash64,definition_sha256,definition_token_count: full span hash.definition_head_*,definition_mid_*,definition_tail_*: anchor hashes (window size 12).definition_head_alt_*,definition_mid_alt_*,definition_tail_alt_*: anchor hashes (window size 6).- Same fields exist for
context_*. definition_preserve_linebreaks,context_preserve_linebreaks: keep line breaks when present in the manual copy (tables).definition_preserve_hyphenation,context_preserve_hyphenation: preserve line-break hyphenation when present.definition_has_bracket_citation,context_has_bracket_citation: whether the manual copy included[12]‑style citations.definition_has_paren_citation,context_has_paren_citation: whether the manual copy included(Author, 2019)‑style citations.definition_has_letter_digit,context_has_letter_digit: whether the manual copy contained letter‑digit runs likebias4.definition_end_punct,context_end_punct: trailing punctuation marker captured from the manual copy.
Notes
- Small mismatches are expected due to PDF/GROBID text normalization.
- Missing exact TEI spans do not block hydration; hash/anchor markers are used as fallback.
- Exact TEI spans are validated against stored hashes; if they do not match, citation‑stripped hash/anchor matching is used instead.
- See
docs/mismatch_examples.mdfor concrete mismatch types with short excerpts.