extract_dois()
Find the DOI and the title of each paper in one PDF, or in every PDF in a folder.
extract_dois(
source: str,
save: str | None = None,
first_pages: int = FIRST_PAGES,
cache: bool = True,
) -> list[dict]
Source: theoryminer/prepare/dois.py
The DOI rule: the first DOI on page 1, else the first DOI on the next pages, up to
first_pages. The title rule: the largest font on page 1 with at least MIN_TITLE_WORDS
words, else the title in the PDF metadata. A bad file does not stop the run: it gets a
row with the status “not_pdf” or “unreadable_pdf”. The function reads the same page
cache as harvest(). It writes a CSV file only when you give save.
Arguments
source
The PDF file, or the folder of PDF files, to read.
- Values: the path of one PDF file, or the path of a folder. The function looks in the folder only, not in its subfolders.
- Default: none. Give a path.
save
Where to write the rows as a CSV file.
- Values: None, a path that ends with “.csv”, or a folder (then <folder>/dois.csv). A missing folder is made.
- Default
None: write no file.
first_pages
The last page on which to look for the DOI.
- Values: a whole number, 1 or more. A larger value can find a DOI that is not on the first pages, but also the DOI of a cited paper in the reference list.
- Default
2: look on page 1, then on page 2 (page 1 is sometimes a cover page).
cache
Whether to use the page cache <pdf>.pages.json beside each PDF.
- Values: True or False.
- Default
True: read the cache when it exists, else read the PDF and write the cache. False reads every PDF again and writes no cache.
Returns
A list of dicts, one per file, in file-name order, with the keys
| key | meaning |
|---|---|
doc_id | the file name without “.pdf”, as in harvest() |
file | the path of the file |
doi | the DOI in lowercase, or “” when none was found |
title | the title, or “” when none was found |
page | the page of the DOI, or 0 when none was found |
status | “found”, “not_found”, “not_pdf” or “unreadable_pdf” |
note | why a file has no DOI, else “” |
Raises
ValueError: The source does not exist, or the folder has no PDF.
Example
>>> rows = extract_dois("sample_files/alrabai_2021_autonomy_supportive_teaching.pdf")
>>> rows[0]["doi"], rows[0]["status"]
('10.3389/fpsyg.2021.728657', 'found')