|
| 1 | +# Fetching Full Text and PDFs |
| 2 | + |
| 3 | +This guide explains how the validator obtains the **full text** of a reference |
| 4 | +(not just its abstract or metadata) by trying a chain of full-text providers, |
| 5 | +optionally downloading and extracting text from PDFs. |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +When a metadata source (Crossref, PubMed, DataCite, etc.) returns only an |
| 10 | +abstract or title, the validator can fall through to a **full-text provider |
| 11 | +chain**. Each provider attempts to *locate* an open-access copy of the |
| 12 | +reference. The first provider that yields usable full text wins; the located |
| 13 | +resource is downloaded and, if it is a PDF, the text is extracted and cached |
| 14 | +alongside the reference. |
| 15 | + |
| 16 | +This behaviour is **on by default**. |
| 17 | + |
| 18 | +## The provider chain |
| 19 | + |
| 20 | +The validator tries providers in order until one returns usable full text. |
| 21 | +The default order is: |
| 22 | + |
| 23 | +``` |
| 24 | +pmc → unpaywall → openalex |
| 25 | +``` |
| 26 | + |
| 27 | +- **`pmc`** — PubMed Central open-access subset (XML/HTML full text for many |
| 28 | + biomedical articles). |
| 29 | +- **`unpaywall`** — Unpaywall open-access lookup by DOI (often a publisher or |
| 30 | + repository PDF). |
| 31 | +- **`openalex`** — OpenAlex open-access location (PDF/HTML). |
| 32 | + |
| 33 | +Providers are skipped silently if they have nothing for a given reference, so |
| 34 | +the chain degrades gracefully: a miss in `pmc` simply moves on to `unpaywall`, |
| 35 | +and so on. If no provider yields full text, the reference keeps whatever |
| 36 | +metadata-only content it already had. |
| 37 | + |
| 38 | +## Configuration |
| 39 | + |
| 40 | +Full-text fetching is controlled by the following configuration keys (set in |
| 41 | +your config YAML or on the `ReferenceValidationConfig` object): |
| 42 | + |
| 43 | +| Key | Default | Description | |
| 44 | +|-----|---------|-------------| |
| 45 | +| `fetch_full_text` | `true` | Attempt to obtain full text via the provider chain when a metadata source does not already return full text. | |
| 46 | +| `full_text_providers` | `[pmc, unpaywall, openalex]` | Ordered list of provider names to try until one yields usable full text. | |
| 47 | +| `pdf_backend` | `pypdf` | Name of the PDF text-extraction backend. | |
| 48 | +| `download_pdfs` | `true` | If true, persist downloaded PDFs to the files cache directory. | |
| 49 | +| `full_text_providers_file` | `null` | Optional path to a YAML file defining custom full-text providers. | |
| 50 | + |
| 51 | +Two existing keys are also reused by the full-text machinery: |
| 52 | + |
| 53 | +| Key | Description | |
| 54 | +|-----|-------------| |
| 55 | +| `email` | Used for "polite pool" access to providers such as Unpaywall and OpenAlex (and for Crossref/Entrez). Set this for more reliable access. | |
| 56 | +| `max_supplementary_file_size` | Upper bound (in bytes) on individual file downloads; a downloaded full-text PDF larger than this limit is not persisted. | |
| 57 | + |
| 58 | +Example config YAML: |
| 59 | + |
| 60 | +```yaml |
| 61 | +email: you@example.org |
| 62 | +fetch_full_text: true |
| 63 | +full_text_providers: |
| 64 | + - pmc |
| 65 | + - unpaywall |
| 66 | + - openalex |
| 67 | +pdf_backend: pypdf |
| 68 | +download_pdfs: true |
| 69 | +``` |
| 70 | + |
| 71 | +## CLI flag |
| 72 | + |
| 73 | +Every `validate` subcommand accepts a `--full-text/--no-full-text` flag that |
| 74 | +toggles `fetch_full_text` for that run (default: on): |
| 75 | + |
| 76 | +```bash |
| 77 | +# Default: full-text chain is tried |
| 78 | +linkml-reference-validator validate data data.yaml \ |
| 79 | + --schema schema.yaml --target-class Statement |
| 80 | + |
| 81 | +# Disable full-text fetching (metadata only) |
| 82 | +linkml-reference-validator validate data data.yaml \ |
| 83 | + --schema schema.yaml --target-class Statement --no-full-text |
| 84 | +``` |
| 85 | + |
| 86 | +## Custom providers |
| 87 | + |
| 88 | +You can declare your own JSON-API-backed provider in a YAML file and point |
| 89 | +`full_text_providers_file` at it. Each entry under `full_text_providers` is |
| 90 | +keyed by the provider name and must supply a `url_template`. The template may |
| 91 | +reference `{doi}`, `{pmid}`, or `{pmcid}`. `location_field` is a JSONPath into |
| 92 | +the response that holds the URL of the full-text resource; `format_hint` tells |
| 93 | +the validator how to treat it; and `headers` are sent with the request, with |
| 94 | +`${ENV_VAR}` placeholders interpolated from the environment. |
| 95 | + |
| 96 | +```yaml |
| 97 | +full_text_providers: |
| 98 | + myrepo: |
| 99 | + url_template: https://api.example.org/fulltext/{doi} |
| 100 | + location_field: $.links.pdf |
| 101 | + format_hint: pdf |
| 102 | + headers: |
| 103 | + Authorization: Bearer ${MYREPO_TOKEN} |
| 104 | +``` |
| 105 | + |
| 106 | +To actually use a custom provider, add its name to the `full_text_providers` |
| 107 | +chain (it is not enabled merely by being defined), for example: |
| 108 | + |
| 109 | +```yaml |
| 110 | +full_text_providers_file: providers.yaml |
| 111 | +full_text_providers: |
| 112 | + - myrepo |
| 113 | + - pmc |
| 114 | + - unpaywall |
| 115 | + - openalex |
| 116 | +``` |
| 117 | + |
| 118 | +## Provenance fields |
| 119 | + |
| 120 | +When a reference is enriched with full text, the cached reference records where |
| 121 | +the text came from. These provenance fields are written alongside the content: |
| 122 | + |
| 123 | +| Field | Description | |
| 124 | +|-------|-------------| |
| 125 | +| `full_text_provider` | Name of the provider that supplied the full text (e.g. `pmc`, `unpaywall`, or a custom name). | |
| 126 | +| `oa_status` | Open-access status reported by the provider (e.g. `gold`, `green`, `bronze`). | |
| 127 | +| `license` | License of the open-access copy, when known. | |
| 128 | +| `local_pdf_path` | Path (relative to the cache directory) to the downloaded PDF, when one was persisted. | |
| 129 | + |
| 130 | +When full text from a PDF is obtained, the reference's `content_type` becomes |
| 131 | +`full_text_pdf` and the extracted text replaces the abstract-only content. The |
| 132 | +downloaded PDF lives under the cache directory and can be located at |
| 133 | +`cache_dir / local_pdf_path`. |
| 134 | + |
| 135 | +## See Also |
| 136 | + |
| 137 | +- [Validating DOIs](validate-dois.md) — DOI metadata sources and supplementary files |
| 138 | +- [Validating Entrez Accessions](validate-entrez.md) — PubMed/PMC references |
| 139 | +- [CLI Reference](../reference/cli.md) — complete command documentation |
0 commit comments