Package: article-dataset-builder
Open Access scholar PDF harvester and ingesterPython utility for harvesting efficiently a large Open Access collection of scholar PDF (fault tolerant, can be resumed, parallel download and ingestion) and for transforming them into structured XML adapted to text mining and information retrieval applications.Input currently supported:list of DOI in a file, one DOI per linelist of PMID in a file, one DOI per linelist of PMC ID in a file, one DOI per linemetadata csv input file fromCORD-19 dataset, see the CORD-19 result section below to see the capacity of the tool to get more full texts and better data quality that the official datasetThe harvesting is following fair-use (which means that it covers non re-sharable articles) and it is exploiting various Open Access sources. The harvesting thus should result in a close-to-optimal discovery of OA full texts. For instance, from the same CORD-19 metadata file, the tool can harvest 35.5% more usable full text than available in the CORD-19 dataset (140,322 articles with at least one usable full text versus 103,587 articles with at least one usable full text for the CORD-19 dataset version 2020-09-11), see statisticshere.To do:Apache Airflow for more complex task workflow and automated periodic incremental harvestingConsolidate/resolve bibliographical references obtained via Pub2TEIUpload harvested resources on SWIFT object storage (OpenStack) in addition to local and S3 storageWhat this doing is doingPerform some metadata enrichment/agregation viabiblio-glutton&CrossRef web APIand output consolidated metadata in a json fileHarvest PDF from the specification of the article set (list of strong identifiers or basic metadata provided in a csv file), typically PDF available in Open Access PDF via theUnpaywall APIand some heuristicsOptionally, performGrobidfull processing of PDF (including bibliographical reference consolidation and OA access resolution of the cited references), converting them into structured XML TEIFor PMC files (Open Access set only), harvest also XML JATS (NLM) files and perform optionally a conversion into XML TEI (same TEI customization as Grobid) viaPub2TEIIn addition, optionally:Generate thumbnails for article (based on the first page of the PDF), small/medium/largeUpload the generated dataset on S3, instead of the local file systemGenerate json PDF annotations (with coordinates) for inline reference markers and bibliographical references (seehere)RequirementsThe utility has been tested with Python 3.5+. It is developed for a deployment on a POSIX/Linux server (it usesimagemagickas external process to generate thumbnails andwget). An S3 account and bucket must have been created for non-local storage of the data collection.If you wish to generate thumbnails for article as they are harvested, installimagemagick:on Linux Ubuntu:sudo apt updatesudo apt build-dep imagemagickon macos:brew install libmagicInstallationArticle dataset builderLocal installFor installing the tool locally and use the current master version, get the github repo:gitclonehttps://github.com/kermitt2/article_dataset_buildercddelftCreate a virtual environment and install the Python mess:virtualenv --system-site-packages -p python3.8 envsource env/bin/activatepython3 -m pip install -r requirements.txtFinally install the project, preferably in editable statepython3-mpipinstall-e.Using PyPI packagePyPI packages are available for stable versions. Latest stable version is normally0.2.4, but double checkhere:python3 -m pip install article-dataset-builder==0.2.4Third party web servicesDepending on the process you are interested to apply to the articles as they are harvested, the following tools need to be installed/accessed and running, with access information specified in the configuration file (config.json):biblio-glutton, for metadata retrieval and aggregationIt should be possible to use the public demo instance ofbiblio-glutton, as default configured in theconfig.jsonfile (the tool scale at more than 6000 queries per second). However in combaination withGrobid, we strongly recommand to install a local instance, because the online public demo will not be able to scale and won't be reliable given that it is more or less always overloaded.Grobid, for converting PDF into XML TEIThis tool requires Java 8 to 11.Pub2TEI, for converting PMC XML files into XML TEIAsbiblio-gluttonis using dataset dumps, there is a gap of several months in term of bibliographical data freshness. So, complementary, theCrossRef web APIandUnpaywall APIservices are used to cover the gap. For these two services, you need to indicate your email in the config file (config.json) to follow the etiquette policy of these two services. If the configuration parameters forbiblio-gluttonare empty, only the CrossRef REST API will be used.An important parameter in theconfig.jsonfile is the number of parallel document processing that is allowed, this is specified by the attributebatch_size, default value being10(so 10 documents max downloaded in parallel with distinct threads/workers and processed by Grobid in parallel). You can set this number according to your available number of threads. If you do not apply Grobid on the downloaded PDF, you can raise thebatch_sizeparameter significantly, for example to50, which means then 100 paralell download. Be careful that parallel download from the same source might be blocked or might result in black-listing for some OA publisher sites, so it might be better to keepbatch_sizereasonable even when only donwloading.For downloading preferably the fulltexts available at PubMed Central from the NIH site (PDF and JATS XML files) rather than on publisher sites, the Open Access list file from PMC that maps PMC identifiers to PMC resource archive URL will be downloaded automatically. You can also download it manually as follow:cd resourceswget https://ftp.ncbi.nlm.nih.gov/pub/pmc/oa_file_list.txtWhen this file is available underresources/oa_file_list.txt, an index will be built at first launch and the harvester will prioritize the access to the NIH resources.DockerTBDUsagepython3 article_dataset_builder/harvest.py --help
usage: harvest.py [-h] [--dois DOIS] [--cord19 CORD19] [--pmids PMIDS] [--pmcids PMCIDS]
                  [--config CONFIG] [--reset] [--reprocess] [--thumbnail] [--annotation]
                  [--diagnostic] [--dump] [--grobid]
Scholar PDF harvester and converter

optional arguments:
  -h, --help       show this help message and exit
  --dois DOIS      path to a file describing a dataset articles as a simple list of DOI (one per
                   line)
  --cord19 CORD19  path to the csv file describing the CORD-19 dataset articles
  --pmids PMIDS    path to a file describing a dataset articles as a simple list of PMID (one
                   per line)
  --pmcids PMCIDS  path to a file describing a dataset articles as a simple list of PMC ID (one
                   per line)
  --config CONFIG  path to the config file, default is ./config.json
  --reset          ignore previous processing states, and re-init the harvesting process from
                   the beginning
  --reprocess      reprocessed existing failed entries
  --thumbnail      generate thumbnail files for the front page of the harvested PDF
  --annotation     generate bibliographical annotations with coordinates for the harvested PDF
  --diagnostic     perform a full consistency diagnostic on the harvesting and transformation
                   process
  --dump           write all the consolidated metadata in json in the file
                   consolidated_metadata.json
  --grobid         process downloaded files with Grobid to generate full text XMLFill the fileconfig.jsonwith relevant service and parameter url.For example to harvest a list of DOI (one DOI per line):python3 article_dataset_builder/harvest.py --dois test/dois.txtSimilarly for a list of PMID or PMC ID with Grobid conversion of the PDF as the are downloaded:python3 article_dataset_builder/harvest.py --pmids test/pmids.txt --grobidpython3 article_dataset_builder/harvest.py --pmcids test/pmcids.txt --grobidFor example for theCORD-19 dataset, you can use themetadata.csv(last tested version from 2020-06-29) file by running:python3 harvest.py --cord19 metadata.csvAn harvesting will generate a JSONL mapping file with the UUID associated with to the Open Access full text resource and the main identifiers of the entries under the data path specified in the configuration file and namedmap.json. The harvesting uploads full text files, converted tei.xml files and other optional files either in the local file system (under data_path indicated in theconfig.jsonfile) or on a S3 bucket if the fields are filled inconfig.json.You can set a specific config file name with--config:python3 harvest.py --cord19 metadata.csv --config my_config.jsonTo resume an interrupted processing,simply re-run the same command.To re-process the failed articles of an harvesting, use:python3 harvest.py --reprocess --config my_config.jsonTo reset entirely an existing harvesting and re-start an harvesting from zero (it means all the already harvested PDF will be deleted!):python3 harvest.py --cord19 metadata.csv --reset --config my_config.jsonTo download full texts (PDF and JATS/NLM) with GROBID processing, use--grobidparameter:python3 harvest.py --cord19 metadata.csv --config my_config.json --grobidTo create a full dump of the consolidated metadata for all the scholar articles (including the UUID identifier and the state of processing), add the parameter--dump:python3 harvest.py --dump --config my_config.jsonThe generated metadata file is namedconsolidated_metadata.json.For producing the thumbnail images of the article first page, use--thumbnailargument. This option requiresimagemagickinstalled on your system and will produce 3 PNG files of size height x150, x300 and x500. These thumbnails can be interesting for offering a preview to an article for an application using these data.python3 harvest.py --cord19 metadata.csv --thumbnail --config my_config.jsonFor producing PDF annotations in JSON format corresponding to the bibliographical information (reference markers in the article and bibliographical references in the bibliographical section), use the argument--annotation. See more information about these annotationshere. They allow to enrich the display of PDF, and make them more interactive.python3 harvest.py --cord19 metadata.csv --annotation --config my_config.jsonFinally you can run a short diagnostic/reporting on the latest harvesting by adding--diagnostic(combined to any previous harvesting command line, or just as unique parameter, to make a diagnostic to the realized harvesting):python3 harvest.py --diagnostic --config my_config.jsonGenerated filesDefaultStructure of the generated files for an article having as UUID identifier98da17ff-bf7e-4d43-bdf2-4d8d831481e598/da/17/ff/98da17ff-bf7e-4d43-bdf2-4d8d831481e5/98da17ff-bf7e-4d43-bdf2-4d8d831481e5.pdf
98/da/17/ff/98da17ff-bf7e-4d43-bdf2-4d8d831481e5/98da17ff-bf7e-4d43-bdf2-4d8d831481e5.json
98/da/17/ff/98da17ff-bf7e-4d43-bdf2-4d8d831481e5/98da17ff-bf7e-4d43-bdf2-4d8d831481e5.grobid.tei.xmlThe*.jsonfile above gives the consolidated metadata of the harvested item, based on CrossRef entries, with additional information provided bybiblio-glutton, status of the harvesting and GROBID processing and UUID (fieldid).Optional additional files:98/da/17/ff/98da17ff-bf7e-4d43-bdf2-4d8d831481e5/98da17ff-bf7e-4d43-bdf2-4d8d831481e5.nxml
98/da/17/ff/98da17ff-bf7e-4d43-bdf2-4d8d831481e5/98da17ff-bf7e-4d43-bdf2-4d8d831481e5.pub2tei.tei.xml
98/da/17/ff/98da17ff-bf7e-4d43-bdf2-4d8d831481e5/98da17ff-bf7e-4d43-bdf2-4d8d831481e5-ref-annotations.json
98/da/17/ff/98da17ff-bf7e-4d43-bdf2-4d8d831481e5/98da17ff-bf7e-4d43-bdf2-4d8d831481e5-thumb-small.png
98/da/17/ff/98da17ff-bf7e-4d43-bdf2-4d8d831481e5/98da17ff-bf7e-4d43-bdf2-4d8d831481e5-thumb-medium.png
98/da/17/ff/98da17ff-bf7e-4d43-bdf2-4d8d831481e5/98da17ff-bf7e-4d43-bdf2-4d8d831481e5-thumb-large.pngFile with extension*.nxmlare JATS XML files downloaded from PubMed Central (Open Access set only). File with extension*.pub2tei.tei.xmlare converted JATS file into TEI XML (same XML full text format as Grobid TEI) with Pub2TEI. File with suffix*-ref-annotations.jsonare JSON PDF coordinates of structures recognized by GROBID. Files with extension*.pngare thumbnail images of the first page of the harvested PDF.The UUID identifier for a particular article is given in the generatedmap.jsonfile under the data path, associated to the every document identifiers. The UUID is also given in theconsolidated_metadata.csvfile (obtained with option--dump, see above).CORD-19 exampleThe tool can realize its own harvesting and ingestion of CORD-19 papers based on an official version of themetadata.csvfile of CORD-19. It provides two main advantages as compared to the official CORD-19 dataset:Harvest around 35% more usable full texts for the CORD-192020-09-11version, around 25% more for the CORD-192021-07-26versionStructure the full texts into high quality TEI format (both from PDF and from JATS), with much more information than the JSON format of the CORD-19 dataset. The JATS conversion into TEI in particular does not lose any information from the original XML file.Be sure to install the latest available version of GROBID, many improvements have been added to the tool regarding the support of bioRxiv and medRxiv preprints.To launch the harvesting (see above for more details):python3 harvest.py --cord19 metadata.csv --grobidFor the CORD-19 dataset, for simplification and clarity, we reuse thecord idwhich is a random string 8 characters in[0-9a-z]:00/0a/je/vz/000ajevz/000ajevz.pdf
00/0a/je/vz/000ajevz/000ajevz.json
00/0a/je/vz/000ajevz/000ajevz.grobid.tei.xmlOptional additional files:00/0a/je/vz/000ajevz/000ajevz.nxml
00/0a/je/vz/000ajevz/000ajevz.pub2tei.tei.xml
00/0a/je/vz/000ajevz/000ajevz-ref-annotations.json
00/0a/je/vz/000ajevz/000ajevz-thumb-small.png
00/0a/je/vz/000ajevz/000ajevz-thumb-medium.png
00/0a/je/vz/000ajevz/000ajevz-thumb-large.pngFor harvesting and structuring, you only need the metadata file of the CORD-19 dataset, available at:https://ai2-semanticscholar-cord-19.s3-us-west-2.amazonaws.com/<date_iso_str>/metadata.csvwhere<date_iso_str>should match a release date indicated on theCORD-19 release page.For running the coverage script, which compares the full text coverage of the official CORD-19 dataset with the one produced by the present tool, you will need the full CORD-19 dataset.On harvesting and ingesting the CORD-19 datasetAdding a local PDF repository for Elsevier OA COVID papersTheCORD-19 datasetincludes more than 19k articles corresponding to a set of Elsevier articles on COVID-19recently put in Open Access. As Unpaywall does not cover these OA articles (on 2020-03-23 at least), you will need to download first these PDF and indicates to the harvesting tool where the local repository of PDF is located:download the PDF files on the COVID-19 FTP server:sftp public@coronacontent.np.elsst.comIndicatebeat_coronaas password. See theinstruction pagein case of troubles.cd pdfmget *indicate the local repository where you have downloaded the dataset in theconfig.jsonfile:"cord19_elsevier_pdf_path":"/the/path/to/the/pdf"That's it. The file./elsevier_covid_map_28_06_2020.csv.gzcontains a map of DOI and PII (the Elsevier article identifiers) for these OA articles.Incremental harvestingCORD-19 is updated regularly. Suppose that you have harvested one release of the CORD-19 full texts and a few weeks later you would like to refresh your local corpus. Incremental harvesting is supported, so only the new entries will be uploaded and ingested.If the harvesting was done with one version of the metadata filemetadata-2020-09-11.csv(from the2020-09-11release):python3 article_dataset_builder/harvest.py --cord19 metadata-2020-09-11.csv --config my_config.json --grobidThe incremental update will be realized with a new version of the metadata file simply by specifying it:python3 article_dataset_builder/harvest.py --cord19 metadata-2021-03-22.csv --config my_config.json --grobidThe constraint is that the same data repository path is kept in the config file. The repository and its state will be reused to check if an entry has already been harvested or not.As an alternative, it is also possible to point to a local old data directory in the config file, with parameterlegacy_data_path. Before trying to download a file from the internet, the harvester will first check in this older data directory if the PDF files are not already locally available based on the same identifiers.Results with CORD-19Here are the results regarding the CORD-19 from2020-09-11(cord-19_2020-09-11.tar.gz) (4.6GB) to illustrate the interest of this harvester tool. We used the present tool using the CORD-19 metadata file (metadata.csv), re-harvested the full texts and converted all into the same target TEI XML format (without information loss with respect to the available publisher XML and GROBID PDF-to-XML conversion).official CORD-19this harvestertotal entries253,454253,454withoutcord idduplicates241,335241,335without duplicates-161,839entries with valid OA URL-141,142entries with successfully downloaded PDF-139,565entries with structured full texts via GROBID94,541 (PDF JSON)138,440 (TEI XML)entries with structured full texts via PMC JATS77,115 (PMC JSON)104,288 (TEI XML)total entries with at least one structured full text103,587 (PDF JSON or PMC JSON)140,322 (TEI XML)Other information for this harvester:total OA URL not found or invalid: 20,697 (out of the 161,839 distinct articles)760 GROBID PDF to TEI XML conversion failures (the average failure on random downloaded scholar PDF is normally around 1%, so we are at 0.5% and this is good)45 Pub2TEI tranformations (NLM (JATS) -> TEI XML) reported as containing some kind of failureOther main differences include:the XML TEI contain richer structured full text (section titles, notes, formulas, etc.),usage of up-to-date GROBID models for PDF conversion (with extra medRxiv and bioRxiv training data),PMC JATS files conversion withPub2TEI(normally without information loss because the TEI custumization we are using superseeds the structures covered by JATS). Note that a conversion from PMC JATS files has been introduced in CORD-19 from version 6.full consolidation of the bibliographical references with publisher metadata, DOI, PMID, PMC ID, etc. when available (if you are into citation graphs)consolidation of article metadata with CrossRef and PubMed aggregations for the entriesoptional coordinates of structures on the original PDFoptional thumbnails for article previewSomenotes on CORD-19 harvesting, including numbers for update version2021-07-26.Converting the PMC XML JATS files into XML TEIAfter the harvesting and processing realised byarticle_dataset_builder/harvest.py, it is possible to convert of PMC XML JATS files into XML TEI. This will provide better XML quality than what can be extracted automatically by Grobid from the PDF. This conversion allows to have all the documents in the same XML TEI customization format. As the TEI format superseeds JATS, there is no loss of information from the JATS file. It requiresPub2TEIto be installed and the path to Pub2TEIpub2tei_pathto be set in theconfig.jsonfile of thearticle_dataset_builderproject.To launch the conversion under the defaultdata/directory:python3 article_dataset_builder/nlm2tei.pyIf a custom config file and customdata/path are used:python3 article_dataset_builder/nlm2tei.py --config ./my_config.jsonThis will apply Pub2TEI (a set of XSLT) to all the harvested*.nxmlfiles and add to the document repository a new file TEI file, for instance for a CORD-19 entry:00/0a/je/vz/000ajevz/000ajevz.pub2tei.tei.xmlNote that Pub2TEI supports a lot of other publisher's XML formats (and variants of these formats), so the principle and current tool could be used to transform different publisher XML formats into a single one (TEI) - not just NLM/JATS, facilitating and centralizing further ingestion and process by avoiding to write complicated XML parsers for each case.Checking CORD-19 dataset coverageThe following script checks the number of duplicatedcord id(also done by the normal harvester), but also count the number of articles with at least one JSON full text file:usage: article_dataset_builder/check_cord19_coverage.py [-h] [--documents DOCUMENTS]
                                [--metadata METADATA]

COVIDataset harvester

optional arguments:
  -h, --help            show this help message and exit
  --documents DOCUMENTS
                        path to the official CORD-19 uncompressed document dataset
  --metadata METADATA   path to the CORD-19 CSV metadata fileFor example:python3 article_dataset_builder/check_cord19_coverage.py --metadata cord-19/2021-03-22/metadata.csv --documents cord-19/2021-03-22/ --config my_config.jsonThe path for--documentsis the path where the folderdocument_parsesis located.Troubleshooting with imagemagickRecent update (end of October 2018) of imagemagick is breaking the normal conversion usage. Basically the converter does not convert by default for security reason related to server usage. For non-server mode as involved in our module, it is not a problem to allow PDF conversion. For this, simply edit the file/etc/ImageMagick-6/policy.xml(or/etc/ImageMagick/policy.xml) and put into comment the following line:<!-- <policy domain="coder" rights="none" pattern="PDF" /> -->How to citeFor citing this software work, please refer to the present GitHub project, together with theSoftware Heritageproject-level permanent identifier. For example, with BibTeX:@misc{articledatasetbuilder,title={Article Dataset Builder},howpublished={\url{https://github.com/kermitt2/article_dataset_builder}},publisher={GitHub},year={2020--2023},archivePrefix={swh},eprint={1:dir:adc1581a092560c0ac4a82256c0c905859ec15fc}}License and contactDistributed underApache 2.0 license.Main author and contact: Patrice Lopez (patrice.lopez@science-miner.com)