-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathopenalex_search.py
More file actions
64 lines (54 loc) · 1.89 KB
/
openalex_search.py
File metadata and controls
64 lines (54 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from decode_abstract import decode_abstract
from pyalex import config
import pyalex as px
import pandas as pd
px.config.email = "idiayeifeanyi@yahoo.com"
config.max_retries = 5
config.retry_backoff_factor = 0.1
config.retry_http_codes = [429, 500, 503]
def replication_doi_search(doi: str) -> pd.DataFrame:
"""
Search for a replication DOI in OpenAlex and return the results as a Pandas DataFrame.
Args:
doi (str): The DOI to search for.
Returns:
pd.DataFrame: A Pandas DataFrame containing the search results.
"""
try:
search = px.Works().search(doi).get()
title = []
abstract = []
authorships = []
publication_year = []
publication_date = []
related_works = []
referenced_works = []
dois = []
# extract the publication's metadata
for s in search:
title.append(s['title'])
abstract.append(decode_abstract(s['abstract_inverted_index']))
authorships.append(s['authorships'])
publication_year.append(s['publication_year'])
publication_date.append(s['publication_date'])
related_works.append(s['related_works'])
referenced_works.append(s['referenced_works'])
dois.append(s['doi'])
# store the metadata in a dictionary
pubs = {
"Title": title,
"Abstract": abstract,
"Authorships": authorships,
"Publication Year": publication_year,
"Publication Date": publication_date,
"Related Works": related_works,
"Referenced Works": referenced_works,
"DOI": dois
}
# turn the dictionary into a pandas dataframe
pubs_df = pd.DataFrame(pubs)
return pubs_df
except Exception as e:
print(e)
if __name__ == "__main__":
replication_doi_search("10.1002/acp.1376")