Datasets:

Languages:
English
ArXiv:
License:
File size: 10,896 Bytes
6b9aad3
 
 
7527970
 
 
6b9aad3
7527970
 
6b9aad3
7527970
 
6b9aad3
7527970
6b9aad3
 
7527970
 
6b9aad3
7527970
 
 
6b9aad3
 
 
 
 
 
 
 
7527970
6b9aad3
7527970
 
6b9aad3
 
7527970
 
6b9aad3
 
 
7527970
 
 
 
 
 
 
 
6b9aad3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7527970
6b9aad3
7527970
 
 
 
 
6b9aad3
 
7527970
 
 
6b9aad3
7527970
 
 
 
6b9aad3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7527970
6b9aad3
7527970
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45fb80e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b9aad3
7527970
 
 
5cbe47d
fd7e968
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# 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`](../README.md) for the high‑level overview and examples.

## Requirements

- Python 3.10+
- A running GROBID server (default: `http://localhost:8070`).

  Example Docker run:

  ```bash
  docker run --rm -p 8070:8070 grobid/grobid:0.8.0
  ```

- Python 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:

```bash
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)

1) Place your PDFs in `pdfs/`.
2) Hydrate (runs GROBID unless `--skip-grobid`):

```bash
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`:

```bash
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` (the `paper_id` in 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.py` generates a temporary config that points to `http://localhost:8070`.
- Use `--grobid-config config.json` to 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-mismatch` to continue anyway (use only after manual inspection).

## Interpretation of warnings

- `Error initializing GROBID client` or `GROBID server ... does not appear up and running`:
  GROBID is not reachable. Start the server (or Docker) or pass `--grobid-config` with the correct URL. If you already have TEI files, rerun with `--skip-grobid`.

- `Processing failed ... [BAD_INPUT_DATA] ... error code: 139` or `pdfalto` errors:
  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-mismatch` and 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 pointer` or 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`/`missing` indicating 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 like `bias4`.
- `definition_end_punct`, `context_end_punct`:
  trailing punctuation marker captured from the manual copy.

## Legal CSV columns (full)

| Column | Description |
| --- | --- |
| `paper_id` | Paper identifier (often a Semantic Scholar ID, DOI, or arXiv ID). |
| `paper_title` | Paper title. |
| `paper_doi` | DOI (if available). |
| `paper_arxiv` | arXiv ID or URL (if available). |
| `concept` | Term / concept being defined. |
| `definition_type` | Definition type (e.g., explicit / implicit). |
| `source_file` | Source JSON filename used during curation. |
| `is_out_of_domain` | Boolean flag for out‑of‑domain papers. |
| `definition_preserve_linebreaks` | Whether line breaks should be preserved in the definition. |
| `context_preserve_linebreaks` | Whether line breaks should be preserved in the context. |
| `definition_preserve_hyphenation` | Whether hyphenation should be preserved in the definition. |
| `context_preserve_hyphenation` | Whether hyphenation should be preserved in the context. |
| `definition_has_bracket_citation` | Definition contains bracket‑style citations (e.g., `[12]`). |
| `definition_has_paren_citation` | Definition contains parenthetical citations (e.g., `(Smith, 2020)`). |
| `definition_has_letter_digit` | Definition contains letter–digit patterns (e.g., `bias4`). |
| `context_has_bracket_citation` | Context contains bracket‑style citations. |
| `context_has_paren_citation` | Context contains parenthetical citations. |
| `context_has_letter_digit` | Context contains letter–digit patterns. |
| `definition_end_punct` | Expected trailing punctuation for definition. |
| `context_end_punct` | Expected trailing punctuation for context. |
| `marker_version` | Marker format version. |
| `hash_version` | Hashing scheme version. |
| `definition_char_start` | Character start offset (TEI) for definition (if available). |
| `definition_char_end` | Character end offset (TEI) for definition (if available). |
| `definition_match` | Debug marker: reference string used to compute definition hashes. |
| `definition_hash64` | 64‑bit hash of definition token sequence. |
| `definition_sha256` | SHA‑256 hash of definition token sequence. |
| `definition_token_count` | Token count for definition span. |
| `definition_head_hash64` | Head‑anchor 64‑bit hash for definition. |
| `definition_head_sha256` | Head‑anchor SHA‑256 hash for definition. |
| `definition_head_token_count` | Head‑anchor token count for definition. |
| `definition_mid_hash64` | Mid‑anchor 64‑bit hash for definition. |
| `definition_mid_sha256` | Mid‑anchor SHA‑256 hash for definition. |
| `definition_mid_token_count` | Mid‑anchor token count for definition. |
| `definition_tail_hash64` | Tail‑anchor 64‑bit hash for definition. |
| `definition_tail_sha256` | Tail‑anchor SHA‑256 hash for definition. |
| `definition_tail_token_count` | Tail‑anchor token count for definition. |
| `definition_head_alt_hash64` | Alternate head‑anchor 64‑bit hash for definition. |
| `definition_head_alt_sha256` | Alternate head‑anchor SHA‑256 hash for definition. |
| `definition_head_alt_token_count` | Alternate head‑anchor token count for definition. |
| `definition_mid_alt_hash64` | Alternate mid‑anchor 64‑bit hash for definition. |
| `definition_mid_alt_sha256` | Alternate mid‑anchor SHA‑256 hash for definition. |
| `definition_mid_alt_token_count` | Alternate mid‑anchor token count for definition. |
| `definition_tail_alt_hash64` | Alternate tail‑anchor 64‑bit hash for definition. |
| `definition_tail_alt_sha256` | Alternate tail‑anchor SHA‑256 hash for definition. |
| `definition_tail_alt_token_count` | Alternate tail‑anchor token count for definition. |
| `context_char_start` | Character start offset (TEI) for context (if available). |
| `context_char_end` | Character end offset (TEI) for context (if available). |
| `context_match` | Debug marker: reference string used to compute context hashes. |
| `context_hash64` | 64‑bit hash of context token sequence. |
| `context_sha256` | SHA‑256 hash of context token sequence. |
| `context_token_count` | Token count for context span. |
| `context_head_hash64` | Head‑anchor 64‑bit hash for context. |
| `context_head_sha256` | Head‑anchor SHA‑256 hash for context. |
| `context_head_token_count` | Head‑anchor token count for context. |
| `context_mid_hash64` | Mid‑anchor 64‑bit hash for context. |
| `context_mid_sha256` | Mid‑anchor SHA‑256 hash for context. |
| `context_mid_token_count` | Mid‑anchor token count for context. |
| `context_tail_hash64` | Tail‑anchor 64‑bit hash for context. |
| `context_tail_sha256` | Tail‑anchor SHA‑256 hash for context. |
| `context_tail_token_count` | Tail‑anchor token count for context. |
| `context_head_alt_hash64` | Alternate head‑anchor 64‑bit hash for context. |
| `context_head_alt_sha256` | Alternate head‑anchor SHA‑256 hash for context. |
| `context_head_alt_token_count` | Alternate head‑anchor token count for context. |
| `context_mid_alt_hash64` | Alternate mid‑anchor 64‑bit hash for context. |
| `context_mid_alt_sha256` | Alternate mid‑anchor SHA‑256 hash for context. |
| `context_mid_alt_token_count` | Alternate mid‑anchor token count for context. |
| `context_tail_alt_hash64` | Alternate tail‑anchor 64‑bit hash for context. |
| `context_tail_alt_sha256` | Alternate tail‑anchor SHA‑256 hash for context. |
| `context_tail_alt_token_count` | Alternate tail‑anchor token count for context. |

## 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.md`](mismatch_examples.md) for concrete mismatch types with short excerpts.