How to run multiple files together on Refextract

Viewed 160

I'm a novice in python and I need to extract references from scientific literature. Following is the code I'm using

from refextract import extract_references_from_file

import pandas as pd

references = extract_references_from_file('1503.07589.pdf')

dfref = pd.DataFrame(references)

dfref.to_excel('./refs.xlsx')

I can only extract references from a single file at a time using this command but I need to extract references from numerous files together. So, Please guide me whether is it possible and how to do it. Thank you so much!

1 Answers

The docs claim that extracted references are returned as a dict.

Returns a dictionary with extracted references and stats.

This is not quite accurate; a list of dicts is returned, one dictionary per reference.

So you simply need to build up a longer list.

from refextract import extract_references_from_file

higgs_papers = ['1503.07589', '2008.05492']
references = []
for paper in higgs_papers:
    references.extend(extract_references_from_file(f'/tmp/{paper}.pdf'))

Now you have a bigger list, references, that you can turn into a bigger df.


You might also find glob convenient:

import glob

files = glob.glob('/tmp/*.pdf')
Related