paperminertoolkit 1.0.0__py3-none-any.whl
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.
- paperminertoolkit/__init__.py +10 -0
- paperminertoolkit/_version.py +11 -0
- paperminertoolkit/cli.py +1053 -0
- paperminertoolkit/corpus/__init__.py +1 -0
- paperminertoolkit/corpus/database.py +1542 -0
- paperminertoolkit/corpus/documents.py +313 -0
- paperminertoolkit/corpus/filtering.py +1390 -0
- paperminertoolkit/corpus/metadata.py +532 -0
- paperminertoolkit/extraction/__init__.py +1 -0
- paperminertoolkit/extraction/compression.py +486 -0
- paperminertoolkit/extraction/extract.py +573 -0
- paperminertoolkit/extraction/models.py +784 -0
- paperminertoolkit/extraction/recipes.py +241 -0
- paperminertoolkit/extraction/scrape.py +737 -0
- paperminertoolkit/extraction/store.py +244 -0
- paperminertoolkit/extraction/tokenizer.py +313 -0
- paperminertoolkit/providers/__init__.py +1 -0
- paperminertoolkit/providers/arxiv.py +760 -0
- paperminertoolkit/providers/base.py +514 -0
- paperminertoolkit/providers/biorxiv.py +561 -0
- paperminertoolkit/providers/chemrxiv.py +1115 -0
- paperminertoolkit/providers/core.py +423 -0
- paperminertoolkit/providers/crossref.py +649 -0
- paperminertoolkit/providers/elsevier.py +455 -0
- paperminertoolkit/providers/medrxiv.py +548 -0
- paperminertoolkit/providers/openalex.py +471 -0
- paperminertoolkit/providers/pubmed.py +1272 -0
- paperminertoolkit/providers/registry.py +521 -0
- paperminertoolkit/providers/rxiv.py +936 -0
- paperminertoolkit/providers/unpaywall.py +162 -0
- paperminertoolkit/resources/recipes.json +1670 -0
- paperminertoolkit/settings.py +661 -0
- paperminertoolkit/workflows/__init__.py +1 -0
- paperminertoolkit/workflows/download.py +1748 -0
- paperminertoolkit/workflows/enrichment.py +1906 -0
- paperminertoolkit/workflows/imports.py +121 -0
- paperminertoolkit/workflows/search.py +877 -0
- paperminertoolkit/workflows/topics.py +2837 -0
- paperminertoolkit/workflows/utilities.py +73 -0
- paperminertoolkit-1.0.0.dist-info/METADATA +126 -0
- paperminertoolkit-1.0.0.dist-info/RECORD +45 -0
- paperminertoolkit-1.0.0.dist-info/WHEEL +5 -0
- paperminertoolkit-1.0.0.dist-info/entry_points.txt +2 -0
- paperminertoolkit-1.0.0.dist-info/licenses/LICENSE +21 -0
- paperminertoolkit-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
"""Request helpers for the bioRxiv API used by PaperMinerToolkit.
|
|
2
|
+
|
|
3
|
+
This module gives bioRxiv its own names and constants over the shared
|
|
4
|
+
bioRxiv-family client in :mod:`paperminertoolkit.providers.rxiv`, which documents the paging,
|
|
5
|
+
error, and versioning rules the two archives have in common. What follows is
|
|
6
|
+
what is particular to bioRxiv.
|
|
7
|
+
|
|
8
|
+
The service needs neither an API key nor a contact address, so there is nothing
|
|
9
|
+
to configure before using it. It publishes no rate limit either, so requests
|
|
10
|
+
are paced through one module-level limiter at a rate chosen to be unobtrusive
|
|
11
|
+
rather than to satisfy a documented rule.
|
|
12
|
+
|
|
13
|
+
bioRxiv has been accepting preprints since November 2013 and holds several
|
|
14
|
+
times what medRxiv does, so an unscoped walk is correspondingly longer and
|
|
15
|
+
:data:`MAX_SCAN_RECORDS` is correspondingly likelier to be what ends it.
|
|
16
|
+
Naming a category or a date range is the difference between a search of a
|
|
17
|
+
subject and a read of the archive.
|
|
18
|
+
|
|
19
|
+
bioRxiv DOIs carry the ``10.1101`` prefix up to late 2025 and ``10.64898``
|
|
20
|
+
afterwards. Both prefixes are shared with medRxiv, so a prefix says nothing
|
|
21
|
+
about which archive holds a preprint; what separates them is the accession
|
|
22
|
+
number, which runs six digits here and eight on medRxiv, whose counter is
|
|
23
|
+
prefixed with the two-digit year.
|
|
24
|
+
|
|
25
|
+
Two suffix shapes have to be recognized, not one. Preprints posted before 2018
|
|
26
|
+
were issued a bare accession number, as in ``10.1101/060400``, rather than the
|
|
27
|
+
dated ``10.1101/2023.12.01.569634`` in use since. Those identifiers were never
|
|
28
|
+
reissued, and a preprint that old can still be revised, so the old shape turns
|
|
29
|
+
up in a walk of last week's postings as readily as in one of 2014's. medRxiv
|
|
30
|
+
opened in 2019 and so has only ever used the dated form, which is why the bare
|
|
31
|
+
one is accepted here alone.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
from __future__ import annotations
|
|
35
|
+
|
|
36
|
+
import re
|
|
37
|
+
from collections.abc import Iterator, Mapping, Sequence
|
|
38
|
+
from typing import Any, TypeAlias
|
|
39
|
+
|
|
40
|
+
from paperminertoolkit.providers import base as provider, rxiv as _rxiv
|
|
41
|
+
|
|
42
|
+
BASE_URL = _rxiv.BASE_URL
|
|
43
|
+
CATEGORY_BASE_URL = _rxiv.CATEGORY_BASE_URL
|
|
44
|
+
WEB_URL = 'https://www.biorxiv.org'
|
|
45
|
+
SERVER = 'biorxiv'
|
|
46
|
+
PAGE_SIZE = _rxiv.PAGE_SIZE
|
|
47
|
+
CATEGORY_PAGE_SIZE = _rxiv.CATEGORY_PAGE_SIZE
|
|
48
|
+
CORPUS_START = '2013-11-01'
|
|
49
|
+
BIORXIV_MIN_INTERVAL = _rxiv.RXIV_MIN_INTERVAL
|
|
50
|
+
MAX_SCAN_RECORDS = _rxiv.MAX_SCAN_RECORDS
|
|
51
|
+
QUERY_PREFIXES = _rxiv.QUERY_PREFIXES
|
|
52
|
+
OK_STATUS = _rxiv.OK_STATUS
|
|
53
|
+
EMPTY_STATUSES = _rxiv.EMPTY_STATUSES
|
|
54
|
+
# Two suffix shapes, because bioRxiv changed the scheme in 2018 and kept the
|
|
55
|
+
# old identifiers: a dated accession, and the bare accession used before it.
|
|
56
|
+
# Six digits either way, against medRxiv's eight, which is the only part of a
|
|
57
|
+
# dated DOI that tells the two archives apart; the upper bound leaves room for
|
|
58
|
+
# a seventh without reaching medRxiv's width, and the trailing lookahead stops
|
|
59
|
+
# a shorter run from matching inside a longer one. The bare form is tied to
|
|
60
|
+
# ``10.1101`` because that is the only prefix that ever issued it, and it is
|
|
61
|
+
# too plain to recognize safely under any prefix.
|
|
62
|
+
_BIORXIV_DOI = re.compile(
|
|
63
|
+
r'(?P<doi>10\.\d{4,9}/\d{4}\.\d{2}\.\d{2}\.\d{6,7}(?!\d)'
|
|
64
|
+
r'|10\.1101/\d{6,7}(?!\d))(?:v(?P<version>\d+))?',
|
|
65
|
+
re.IGNORECASE,
|
|
66
|
+
)
|
|
67
|
+
_BiorxivRecord: TypeAlias = dict[str, Any]
|
|
68
|
+
LIMITER = provider.RateLimiter(BIORXIV_MIN_INTERVAL)
|
|
69
|
+
SERVER_CONFIG = _rxiv.RxivServer(
|
|
70
|
+
name=SERVER,
|
|
71
|
+
label='bioRxiv',
|
|
72
|
+
web_url=WEB_URL,
|
|
73
|
+
web_host='biorxiv.org',
|
|
74
|
+
corpus_start=CORPUS_START,
|
|
75
|
+
doi_pattern=_BIORXIV_DOI,
|
|
76
|
+
limiter=LIMITER,
|
|
77
|
+
max_scan_records=MAX_SCAN_RECORDS,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def request_headers() -> dict[str, str]:
|
|
82
|
+
"""Build bioRxiv request headers.
|
|
83
|
+
|
|
84
|
+
Returns
|
|
85
|
+
-------
|
|
86
|
+
dict[str, str]
|
|
87
|
+
Headers containing the PaperMinerToolkit user agent.
|
|
88
|
+
"""
|
|
89
|
+
return provider.default_headers()
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def details_url(doi: str, version: str = 'na') -> str:
|
|
93
|
+
"""Build the URL for a bioRxiv details request.
|
|
94
|
+
|
|
95
|
+
Parameters
|
|
96
|
+
----------
|
|
97
|
+
doi : str
|
|
98
|
+
Bare bioRxiv DOI.
|
|
99
|
+
version : str, default='na'
|
|
100
|
+
Posted version to request, or ``'na'`` for every version.
|
|
101
|
+
|
|
102
|
+
Returns
|
|
103
|
+
-------
|
|
104
|
+
str
|
|
105
|
+
Details endpoint URL.
|
|
106
|
+
"""
|
|
107
|
+
return _rxiv.details_url(SERVER_CONFIG, doi, version)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def endpoint(category: str = '') -> tuple[str, int]:
|
|
111
|
+
"""Choose the interval host for a scan and report its page length.
|
|
112
|
+
|
|
113
|
+
See :func:`paperminertoolkit.providers.rxiv.endpoint` for why the two hosts differ and
|
|
114
|
+
which is cheaper for which scan.
|
|
115
|
+
|
|
116
|
+
Parameters
|
|
117
|
+
----------
|
|
118
|
+
category : str, default=''
|
|
119
|
+
bioRxiv subject category the scan is restricted to, if any.
|
|
120
|
+
|
|
121
|
+
Returns
|
|
122
|
+
-------
|
|
123
|
+
tuple[str, int]
|
|
124
|
+
Base URL to walk, and the number of records that host returns per page.
|
|
125
|
+
"""
|
|
126
|
+
return _rxiv.endpoint(category)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def page_size(payload: Mapping[str, Any] | None, default: int = PAGE_SIZE) -> int:
|
|
130
|
+
"""Read how many records a bioRxiv payload actually returned.
|
|
131
|
+
|
|
132
|
+
Parameters
|
|
133
|
+
----------
|
|
134
|
+
payload : Mapping[str, Any] or None
|
|
135
|
+
Parsed bioRxiv payload.
|
|
136
|
+
default : int, default=PAGE_SIZE
|
|
137
|
+
Page length assumed when the payload reports none.
|
|
138
|
+
|
|
139
|
+
Returns
|
|
140
|
+
-------
|
|
141
|
+
int
|
|
142
|
+
Records on this page, or ``default`` when the payload reports none.
|
|
143
|
+
"""
|
|
144
|
+
return _rxiv.page_size(payload, default)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def interval_url(start_date: str, end_date: str, cursor: int = 0, category: str = '') -> str:
|
|
148
|
+
"""Build the URL for one page of a bioRxiv date interval.
|
|
149
|
+
|
|
150
|
+
Parameters
|
|
151
|
+
----------
|
|
152
|
+
start_date : str
|
|
153
|
+
Inclusive interval start as ``YYYY-MM-DD``.
|
|
154
|
+
end_date : str
|
|
155
|
+
Inclusive interval end as ``YYYY-MM-DD``.
|
|
156
|
+
cursor : int, default=0
|
|
157
|
+
Zero-based index of the first record requested.
|
|
158
|
+
category : str, default=''
|
|
159
|
+
bioRxiv subject category the scan is restricted to, if any.
|
|
160
|
+
|
|
161
|
+
Returns
|
|
162
|
+
-------
|
|
163
|
+
str
|
|
164
|
+
Interval endpoint URL.
|
|
165
|
+
|
|
166
|
+
Raises
|
|
167
|
+
------
|
|
168
|
+
ValueError
|
|
169
|
+
If either bound is not an ISO ``YYYY-MM-DD`` date.
|
|
170
|
+
"""
|
|
171
|
+
return _rxiv.interval_url(SERVER_CONFIG, start_date, end_date, cursor, category)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def pdf_url(doi: str, version: str = '') -> str:
|
|
175
|
+
"""Build the public PDF location for a bioRxiv preprint.
|
|
176
|
+
|
|
177
|
+
Parameters
|
|
178
|
+
----------
|
|
179
|
+
doi : str
|
|
180
|
+
bioRxiv DOI, with or without a version suffix.
|
|
181
|
+
version : str, default=''
|
|
182
|
+
Posted version number. Defaults to the version carried by ``doi``, and
|
|
183
|
+
then to the first version.
|
|
184
|
+
|
|
185
|
+
Returns
|
|
186
|
+
-------
|
|
187
|
+
str
|
|
188
|
+
PDF URL, or an empty string when no DOI is present.
|
|
189
|
+
"""
|
|
190
|
+
return _rxiv.pdf_url(SERVER_CONFIG, doi, version)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def request(
|
|
194
|
+
url: str,
|
|
195
|
+
params: Mapping[str, object] | None = None,
|
|
196
|
+
session: provider.HTTPClient | None = None,
|
|
197
|
+
timeout: float = provider.DEFAULT_TIMEOUT,
|
|
198
|
+
attempts: int = provider.DEFAULT_ATTEMPTS,
|
|
199
|
+
) -> provider.ResponseLike | None:
|
|
200
|
+
"""Request a bioRxiv endpoint with courtesy pacing and bounded retries.
|
|
201
|
+
|
|
202
|
+
Parameters
|
|
203
|
+
----------
|
|
204
|
+
url : str
|
|
205
|
+
bioRxiv endpoint URL.
|
|
206
|
+
params : Mapping[str, object] or None, optional
|
|
207
|
+
Query parameters for the request.
|
|
208
|
+
session : provider.HTTPClient or None, optional
|
|
209
|
+
HTTP client exposing a ``get`` method. Defaults to :mod:`requests`.
|
|
210
|
+
timeout : float, default=60.0
|
|
211
|
+
Request timeout in seconds.
|
|
212
|
+
attempts : int, default=4
|
|
213
|
+
Maximum number of request attempts.
|
|
214
|
+
|
|
215
|
+
Returns
|
|
216
|
+
-------
|
|
217
|
+
provider.ResponseLike or None
|
|
218
|
+
Successful response, or ``None`` for a 404 response.
|
|
219
|
+
|
|
220
|
+
Raises
|
|
221
|
+
------
|
|
222
|
+
RuntimeError
|
|
223
|
+
If the request is rejected, or all request attempts fail.
|
|
224
|
+
"""
|
|
225
|
+
return _rxiv.request(SERVER_CONFIG, url, params=params, session=session,
|
|
226
|
+
timeout=timeout, attempts=attempts)
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def request_json(
|
|
230
|
+
url: str,
|
|
231
|
+
params: Mapping[str, object] | None = None,
|
|
232
|
+
session: provider.HTTPClient | None = None,
|
|
233
|
+
timeout: float = provider.DEFAULT_TIMEOUT,
|
|
234
|
+
attempts: int = provider.DEFAULT_ATTEMPTS,
|
|
235
|
+
) -> _BiorxivRecord | None:
|
|
236
|
+
"""Request a bioRxiv endpoint and parse its JSON payload.
|
|
237
|
+
|
|
238
|
+
Parameters
|
|
239
|
+
----------
|
|
240
|
+
url : str
|
|
241
|
+
bioRxiv endpoint URL.
|
|
242
|
+
params : Mapping[str, object] or None, optional
|
|
243
|
+
Query parameters for the request.
|
|
244
|
+
session : provider.HTTPClient or None, optional
|
|
245
|
+
HTTP client exposing a ``get`` method.
|
|
246
|
+
timeout : float, default=60.0
|
|
247
|
+
Request timeout in seconds.
|
|
248
|
+
attempts : int, default=4
|
|
249
|
+
Maximum number of request attempts.
|
|
250
|
+
|
|
251
|
+
Returns
|
|
252
|
+
-------
|
|
253
|
+
dict[str, Any] or None
|
|
254
|
+
Parsed payload, or ``None`` when bioRxiv holds no matching records.
|
|
255
|
+
|
|
256
|
+
Raises
|
|
257
|
+
------
|
|
258
|
+
RuntimeError
|
|
259
|
+
If the request fails, the payload is not well-formed JSON, or bioRxiv
|
|
260
|
+
reports the request as invalid.
|
|
261
|
+
"""
|
|
262
|
+
return _rxiv.request_json(SERVER_CONFIG, url, params=params, session=session,
|
|
263
|
+
timeout=timeout, attempts=attempts)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def total_results(payload: Mapping[str, Any] | None) -> int:
|
|
267
|
+
"""Read the total record count a bioRxiv interval payload reports.
|
|
268
|
+
|
|
269
|
+
Parameters
|
|
270
|
+
----------
|
|
271
|
+
payload : Mapping[str, Any] or None
|
|
272
|
+
Parsed bioRxiv payload.
|
|
273
|
+
|
|
274
|
+
Returns
|
|
275
|
+
-------
|
|
276
|
+
int
|
|
277
|
+
Total number of records in the interval, or ``0`` when none is
|
|
278
|
+
reported.
|
|
279
|
+
"""
|
|
280
|
+
return _rxiv.total_results(payload)
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def normalize_biorxiv_doi(value: object) -> str:
|
|
284
|
+
"""Normalize a bioRxiv identifier to its bare, unversioned DOI.
|
|
285
|
+
|
|
286
|
+
A DOI, a ``doi:`` or ``biorxiv:`` paper identifier, a resolver URL, and a
|
|
287
|
+
bioRxiv content or PDF URL are all accepted. Both the dated accession scheme and
|
|
288
|
+
the bare one bioRxiv used before 2018 are recognized. Case is
|
|
289
|
+
folded, because DOIs are case-insensitive and the corpus compares them as
|
|
290
|
+
strings. A medRxiv DOI is rejected rather than returned, because it names
|
|
291
|
+
a preprint this API cannot answer for.
|
|
292
|
+
|
|
293
|
+
Parameters
|
|
294
|
+
----------
|
|
295
|
+
value : object
|
|
296
|
+
bioRxiv DOI, paper identifier, or content URL.
|
|
297
|
+
|
|
298
|
+
Returns
|
|
299
|
+
-------
|
|
300
|
+
str
|
|
301
|
+
Bare bioRxiv DOI, or an empty string when none is present.
|
|
302
|
+
"""
|
|
303
|
+
return _rxiv.normalize_doi(SERVER_CONFIG, value)
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def biorxiv_version(value: object) -> str:
|
|
307
|
+
"""Extract the posted version number from a versioned bioRxiv identifier.
|
|
308
|
+
|
|
309
|
+
Parameters
|
|
310
|
+
----------
|
|
311
|
+
value : object
|
|
312
|
+
bioRxiv DOI or content URL, such as ``10.1101/2023.12.01.569634v2``.
|
|
313
|
+
|
|
314
|
+
Returns
|
|
315
|
+
-------
|
|
316
|
+
str
|
|
317
|
+
Version number such as ``2``, or an empty string when unversioned.
|
|
318
|
+
"""
|
|
319
|
+
return _rxiv.version_of(SERVER_CONFIG, value)
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def record_to_paper(record: Mapping[str, Any]) -> _BiorxivRecord:
|
|
323
|
+
"""Map one bioRxiv API record onto PaperMinerToolkit's paper schema.
|
|
324
|
+
|
|
325
|
+
Parameters
|
|
326
|
+
----------
|
|
327
|
+
record : Mapping[str, Any]
|
|
328
|
+
bioRxiv API record.
|
|
329
|
+
|
|
330
|
+
Returns
|
|
331
|
+
-------
|
|
332
|
+
dict[str, Any]
|
|
333
|
+
Normalized paper metadata plus the ``abstract``, ``categories``,
|
|
334
|
+
``category``, ``primary_category``, ``license``, ``version``,
|
|
335
|
+
``published_doi``, and ``jatsxml`` extras that the corpus schema does
|
|
336
|
+
not store directly.
|
|
337
|
+
"""
|
|
338
|
+
return _rxiv.record_to_paper(SERVER_CONFIG, record)
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def parse_records(payload: Mapping[str, Any] | None) -> list[_BiorxivRecord]:
|
|
342
|
+
"""Map every record in a bioRxiv payload onto the paper schema.
|
|
343
|
+
|
|
344
|
+
Parameters
|
|
345
|
+
----------
|
|
346
|
+
payload : Mapping[str, Any] or None
|
|
347
|
+
Parsed bioRxiv payload, or ``None``.
|
|
348
|
+
|
|
349
|
+
Returns
|
|
350
|
+
-------
|
|
351
|
+
list[dict[str, Any]]
|
|
352
|
+
Normalized paper metadata, one mapping per record, in payload order.
|
|
353
|
+
"""
|
|
354
|
+
return _rxiv.parse_records(SERVER_CONFIG, payload)
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
def latest_versions(entries: Sequence[Mapping[str, Any]]) -> list[_BiorxivRecord]:
|
|
358
|
+
"""Reduce parsed bioRxiv records to one entry per preprint, newest kept.
|
|
359
|
+
|
|
360
|
+
Parameters
|
|
361
|
+
----------
|
|
362
|
+
entries : Sequence[Mapping[str, Any]]
|
|
363
|
+
Parsed records from :func:`parse_records`.
|
|
364
|
+
|
|
365
|
+
Returns
|
|
366
|
+
-------
|
|
367
|
+
list[dict[str, Any]]
|
|
368
|
+
One record per preprint, in first-appearance order.
|
|
369
|
+
"""
|
|
370
|
+
return _rxiv.latest_versions(SERVER_CONFIG, entries)
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
def page_cursors(total: int, step: int = PAGE_SIZE) -> Iterator[int]:
|
|
374
|
+
"""Yield bioRxiv interval page cursors newest first.
|
|
375
|
+
|
|
376
|
+
Parameters
|
|
377
|
+
----------
|
|
378
|
+
total : int
|
|
379
|
+
Total record count the interval reports.
|
|
380
|
+
step : int, default=PAGE_SIZE
|
|
381
|
+
Records per page, from :func:`page_size`.
|
|
382
|
+
|
|
383
|
+
Yields
|
|
384
|
+
------
|
|
385
|
+
int
|
|
386
|
+
Zero-based cursor of each page, from the last page down to zero.
|
|
387
|
+
"""
|
|
388
|
+
yield from _rxiv.page_cursors(total, step)
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
def interval_page(start_date: str,
|
|
392
|
+
end_date: str,
|
|
393
|
+
cursor: int = 0,
|
|
394
|
+
category: str = '',
|
|
395
|
+
session: provider.HTTPClient | None = None) -> _BiorxivRecord | None:
|
|
396
|
+
"""Fetch one page of bioRxiv records posted within a date interval.
|
|
397
|
+
|
|
398
|
+
Parameters
|
|
399
|
+
----------
|
|
400
|
+
start_date : str
|
|
401
|
+
Inclusive interval start as ``YYYY-MM-DD``.
|
|
402
|
+
end_date : str
|
|
403
|
+
Inclusive interval end as ``YYYY-MM-DD``.
|
|
404
|
+
cursor : int, default=0
|
|
405
|
+
Zero-based index of the first record requested.
|
|
406
|
+
category : str, default=''
|
|
407
|
+
bioRxiv subject category to restrict the interval to.
|
|
408
|
+
session : provider.HTTPClient or None, optional
|
|
409
|
+
HTTP client exposing a ``get`` method.
|
|
410
|
+
|
|
411
|
+
Returns
|
|
412
|
+
-------
|
|
413
|
+
dict[str, Any] or None
|
|
414
|
+
Parsed payload, or ``None`` once the cursor is past the last record.
|
|
415
|
+
|
|
416
|
+
Raises
|
|
417
|
+
------
|
|
418
|
+
ValueError
|
|
419
|
+
If either bound is not an ISO ``YYYY-MM-DD`` date.
|
|
420
|
+
RuntimeError
|
|
421
|
+
If the request cannot be completed or bioRxiv rejects the interval.
|
|
422
|
+
"""
|
|
423
|
+
return _rxiv.interval_page(SERVER_CONFIG, start_date, end_date, cursor, category,
|
|
424
|
+
session=session)
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
def details(doi: str,
|
|
428
|
+
version: str = 'na',
|
|
429
|
+
session: provider.HTTPClient | None = None) -> _BiorxivRecord | None:
|
|
430
|
+
"""Fetch the posted versions of one bioRxiv preprint.
|
|
431
|
+
|
|
432
|
+
Parameters
|
|
433
|
+
----------
|
|
434
|
+
doi : str
|
|
435
|
+
bioRxiv DOI, with or without a version suffix.
|
|
436
|
+
version : str, default='na'
|
|
437
|
+
Posted version to request, or ``'na'`` for every version.
|
|
438
|
+
session : provider.HTTPClient or None, optional
|
|
439
|
+
HTTP client exposing a ``get`` method.
|
|
440
|
+
|
|
441
|
+
Returns
|
|
442
|
+
-------
|
|
443
|
+
dict[str, Any] or None
|
|
444
|
+
Parsed payload, or ``None`` when bioRxiv holds no such preprint.
|
|
445
|
+
|
|
446
|
+
Raises
|
|
447
|
+
------
|
|
448
|
+
RuntimeError
|
|
449
|
+
If the request cannot be completed or bioRxiv rejects the DOI.
|
|
450
|
+
"""
|
|
451
|
+
return _rxiv.details(SERVER_CONFIG, doi, version, session=session)
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
def fetch_doi(doi: str, session: provider.HTTPClient | None = None) -> _BiorxivRecord | None:
|
|
455
|
+
"""Fetch the newest posted version of one bioRxiv preprint.
|
|
456
|
+
|
|
457
|
+
Parameters
|
|
458
|
+
----------
|
|
459
|
+
doi : str
|
|
460
|
+
bioRxiv DOI, with or without a version suffix.
|
|
461
|
+
session : provider.HTTPClient or None, optional
|
|
462
|
+
HTTP client exposing a ``get`` method.
|
|
463
|
+
|
|
464
|
+
Returns
|
|
465
|
+
-------
|
|
466
|
+
dict[str, Any] or None
|
|
467
|
+
Normalized paper metadata, or ``None`` when bioRxiv holds no such
|
|
468
|
+
preprint.
|
|
469
|
+
|
|
470
|
+
Raises
|
|
471
|
+
------
|
|
472
|
+
RuntimeError
|
|
473
|
+
If the request cannot be completed or bioRxiv rejects the DOI.
|
|
474
|
+
"""
|
|
475
|
+
return _rxiv.fetch_doi(SERVER_CONFIG, doi, session=session)
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
def resolve_biorxiv_doi(paper: Mapping[str, Any]) -> str:
|
|
479
|
+
"""Resolve one paper row's bioRxiv DOI from values it already holds.
|
|
480
|
+
|
|
481
|
+
This never issues a request. bioRxiv publishes no title search, so a row
|
|
482
|
+
that carries neither a bioRxiv DOI nor a bioRxiv URL cannot be reached at
|
|
483
|
+
all; a published DOI on the row belongs to the journal version and is not
|
|
484
|
+
a bioRxiv identifier.
|
|
485
|
+
|
|
486
|
+
Parameters
|
|
487
|
+
----------
|
|
488
|
+
paper : Mapping[str, Any]
|
|
489
|
+
Corpus paper row.
|
|
490
|
+
|
|
491
|
+
Returns
|
|
492
|
+
-------
|
|
493
|
+
str
|
|
494
|
+
Bare bioRxiv DOI, or an empty string when the row stores none.
|
|
495
|
+
"""
|
|
496
|
+
return _rxiv.resolve_doi(SERVER_CONFIG, paper)
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
def full_text(entry: Mapping[str, Any], session: provider.HTTPClient | None = None) -> str:
|
|
500
|
+
"""Fetch and flatten a bioRxiv preprint's JATS full text.
|
|
501
|
+
|
|
502
|
+
Parameters
|
|
503
|
+
----------
|
|
504
|
+
entry : Mapping[str, Any]
|
|
505
|
+
Normalized record from :func:`record_to_paper`.
|
|
506
|
+
session : provider.HTTPClient or None, optional
|
|
507
|
+
HTTP client exposing a ``get`` method.
|
|
508
|
+
|
|
509
|
+
Returns
|
|
510
|
+
-------
|
|
511
|
+
str
|
|
512
|
+
Article text, or an empty string when no body is available.
|
|
513
|
+
|
|
514
|
+
Raises
|
|
515
|
+
------
|
|
516
|
+
RuntimeError
|
|
517
|
+
If the request cannot be completed or the payload is not well-formed.
|
|
518
|
+
"""
|
|
519
|
+
return _rxiv.full_text(SERVER_CONFIG, entry, session=session)
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
def parse_query(query: str) -> tuple[list[str], dict[str, str]]:
|
|
523
|
+
"""Split a bioRxiv search phrase into match terms and interval scope.
|
|
524
|
+
|
|
525
|
+
Parameters
|
|
526
|
+
----------
|
|
527
|
+
query : str
|
|
528
|
+
Search phrase, optionally carrying ``category:``, ``from:``, or ``to:``
|
|
529
|
+
scope terms.
|
|
530
|
+
|
|
531
|
+
Returns
|
|
532
|
+
-------
|
|
533
|
+
tuple[list[str], dict[str, str]]
|
|
534
|
+
Match terms, and the scope mapping with ``category``, ``from``, and
|
|
535
|
+
``to`` keys for whichever were supplied.
|
|
536
|
+
|
|
537
|
+
Raises
|
|
538
|
+
------
|
|
539
|
+
ValueError
|
|
540
|
+
If ``from:`` or ``to:`` is not an ISO ``YYYY-MM-DD`` date.
|
|
541
|
+
"""
|
|
542
|
+
return _rxiv.parse_query(query)
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
def matches(entry: Mapping[str, Any], terms: Sequence[str]) -> bool:
|
|
546
|
+
"""Report whether a bioRxiv record matches every term of a query.
|
|
547
|
+
|
|
548
|
+
Parameters
|
|
549
|
+
----------
|
|
550
|
+
entry : Mapping[str, Any]
|
|
551
|
+
Normalized record from :func:`record_to_paper`.
|
|
552
|
+
terms : Sequence[str]
|
|
553
|
+
Match terms from :func:`parse_query`. An empty sequence matches every
|
|
554
|
+
record.
|
|
555
|
+
|
|
556
|
+
Returns
|
|
557
|
+
-------
|
|
558
|
+
bool
|
|
559
|
+
Whether the record matches all terms.
|
|
560
|
+
"""
|
|
561
|
+
return _rxiv.matches(entry, terms)
|