import pandas as pd import requests def import_data(pages, start_year, end_year, search_terms): """ This function is used to use the OpenAlex API, conduct a search on works, a return a dataframe with associated works. Inputs: - pages: int, number of pages to loop through - search_terms: str, keywords to search for (must be formatted according to OpenAlex standards) - start_year and end_year: int, years to set as a range for filtering works """ #create an empty dataframe search_results = pd.DataFrame() for page in range(1, pages): #use paramters to conduct request and format to a dataframe response = requests.get(f'https://api.openalex.org/works?page={page}&per-page=200&filter=publication_year:{start_year}-{end_year},type:article&search={search_terms}') data = pd.DataFrame(response.json()['results']) #append to empty dataframe search_results = pd.concat([search_results, data]) #subset to relevant features search_results = search_results[["id", "title", "display_name", "publication_year", "publication_date", "type", "countries_distinct_count","institutions_distinct_count", "has_fulltext", "cited_by_count", "keywords", "referenced_works_count", "abstract_inverted_index"]] return(search_results) #search for AI-related research ai_search = import_data(30, 2018, 2025, "'artificial intelligence' OR 'deep learn' OR 'neural net' OR 'natural language processing' OR 'machine learn' OR 'large language models' OR 'small language models'")