Package: openalexnet
OpenAlex Networks (openalexnet)OpenAlex Networks is a helper library and standalone command-line application to process and obtain data from theOpenAlexdataset via API. It also provides functionality to generate citation and coauthorship networks from queries.InstallationInstall using pippipinstallopenalexnetor from source:pipgit+https://github.com/filipinascimento/openalexnet.gitUsage as command-line applicationAfter installing openalexnet, you can use the command:python-mopenalexnetor simplyopenalexnetThis should print a help message with the available commands and options.You can make your first query by using:openalexnet-tworks-f"author.id:A2420755856,is_paratext:false,type:journal-article"-s"complex"-r"cited_by_count:desc"-oworks.jsonl-ccitation_network.gml-acoauthorship_network.gmlThis will get all the journal articles from H. Eugene Stanley (A2420755856) with the word "complex" and sorted by the number of citations (in descending order).For more details about the interface, check the following sections.Querying the OpenAlex APIThe queries have four main parameters:entitytype(-t): Type of entity to be retrieved from the OpenAlex API. Can be one of the following:works,institutions,authors,conceptsorvenuesfilter(-f): Comma-separated filter entries formatted as<key>:<value>to be used in the OpenAlex API call. Only results passing the filter will be retrieved. Seehttps://docs.openalex.org/how-to-use-the-api/get-lists-of-entities/filter-entity-listsfor more information. Defaults to""(or no filter). Example:-f "type:journal-article,author.id:A2420755856".search(-s): Search string to be used in the OpenAlex API call. Only results matching the search string (in the title, abstract, or fulltext) will be retrieved. Seehttps://docs.openalex.org/how-to-use-the-api/get-lists-of-entities/search-entitiesfor more information. Defaults to""(or no search). Example:-s "complex networks".sort(-r): Comma-separated sort entries formatted as<key>[:desc]to be used in the OpenAlex API call. Seehttps://docs.openalex.org/how-to-use-the-api/get-lists-of-entities/sort-entity-listsfor more information. Defaults to""(or no sort). Example:-r "cited_by_count:desc".In addition to the query parameters, the user can provide the maximum number of entities to be retrieved by using the parametermaxentities(-m), set to 10000 by default. Use -1 to retrieve all entities. Example:-m 100or-m -1.Note that OpenAlex API recommends downloading and processing the snapshots of the dataset instead of using the API if you plan to download a large chunk of the complete dataset.JSON Lines outputThe output can be saved to a JSON Lines file (each line containing a JSON entry) by passing the argument--outputfile(-o). Example:-o works.jsonl.Aggregating queriesIt is also possible to combine several queries by providing a.csvor.tsvfile with the queries. The file should have the following columns:filter,search,sortandmaxentities. Missing columns will be filled with the default values. The output will have all the aggregated queries. Example:openalexnet -i queries.csvfor a filequeries.csvwith the following content:filter,search,sort,maximum_entities
"type:journal-article","""complex networks""","cited_by_count:desc",10000
"type:journal-article","""network science""","cited_by_count:desc",10000This should retrieve the 10000 most cited works with the terms "complex networks" or "network science" using two different queries. The folderExamples/query_files/provides more examples of query files.Generating networksThe command-line application can also generate citation and coauthorship networks from the retrieved entities. The networks can be saved in 3 different formats:.edgelist,.gml, or.xnet.
The citation network can be generated by providing the argument--citationfile(-c), with the parameter being the file path where the network should be saved. The extension of the file will determine the format. Example:-c citation_network.gml. Similarly, the coauthorship network can be generated by providing the argument--coauthorfile(-a). Example:-c citation_network.gml -a coauthorship_network.gml.Attributes of works can be selected to be exported in the network by providing the argument--keptattributes(-k). The attributes should be comma-separated. Example:-n "id,title,doi".By default the following properties are exported in the network:id, doi, title, display_name, publication_year, publication_date, type, authorships, concepts, host_venueThe parameter --ignoreattributes (-g) can be used to ignore some of the default attributes. Example:-i "authorships,concepts,host_venue".For the case of coauthorship networks, the user can provide two extra parameters:--no_simplenetworks(-n): If enabled, the coauthorship network edges will not be aggregated, resulting in multiple edges. The default is disabled.--countweights(-w) If enabled the coauthorship network will have non-normalized weights, i.e., the contribution of a paper to a connection weight is 1.0, otherwise the contribution is the inverse of the number of authors in the paper. The default is disabled.if.edgelistformat is used, extracsvfiles with the nodes and edges attributes will be generated with the same name as the network file, but with the extension_nodes.csvand_edges.csv.Loading from saved JSON Lines filesThe command-line application can also load the JSON Lines files generated by the API and generate the networks. This can be done by providing the argument--inputfile(-i). Example:-i works.jsonl -c citation_network.gml -a coauthorship_network.gml.Polite modeFinally, users can use the polite mode by providing an email address using--email(-e). Seehttps://docs.openalex.org/how-to-use-the-api/for more information.Example usageTo obtain the works with the term"complex networks"(in abstracts, titles or fulltexts) sorted by the number of citations. This also generates gml files for the citation and coauthorship networks.openalexnet-tworks-f"type:journal-article"-s"complex networks"-r"cited_by_count:desc"-oworks.jsonl-ccitation_network.gml-acoauthorship_network.gmlNote that becausemaxentitiesis not provided, only the 10000 most cited works will be obtained.To load the saved works.jsonl file and generate the networks:openalexnet-tworks-iworks.jsonl-ccitation_network.edgelist-acoauthorship_network.edgelistUse a query file to retrieve works and save them to a JSON Lines file:openalexnet-tworks-qquery.csv-oworks.jsonlPython Library UsageObtaining works from a specific author:filterData={"author.id":"A2420755856",# Eugene H. Stanley"is_paratext":"false",# Only works, no paratexts (https://en.wikipedia.org/wiki/Paratext)"type":"journal-article",# Only journal articles"from_publication_date":"2000-01-01"# Published after 2000}entityType="works"openalex=oanet.OpenAlexAPI()# add your email to accelerate the API calls. See https://openalex.org/apientities=openalex.getEntities(entityType,filter=filterData)entitiesList=[]forentityintqdm(entities,desc="Retrieving entries"):entitiesList.append(entity)# Saving data as json lines (each line is a json object)oanet.saveJSONLines(entitiesList,"works_filtered.jsonl")CheckExamplesfolder for more examples.Coming soonFull API documentationMore examplesUnit testsGroup countGoogle Colaboratory Demo/TutorialYou can access a Google Colab demo and tutorial by using the following link.ThanksRemember to cite the OpenAlex work:@article{priem2022openalex,title={OpenAlex: A fully-open index of scholarly works, authors, venues, institutions, and concepts},author={Priem, Jason and Piwowar, Heather and Orr, Richard},journal={arXiv preprint arXiv:2205.01833},year={2022}}If you use this code, please give it a star and share with your coleagues. Also stay tuned as I plan to develop a web-based interface for dynamic visualization of openalex networks. Check outHelios-Webto see the development progress of our network visualization tools.