# Initialize author with uri URI = "https://krr.cs.vu.nl/" data = {"data": "24.3"} data_json = json.dumps(data) headers = {'Accept': 'application/json'} my_auth = ElsAuthor( uri='https://api.elsevier.com/content/author/author_id/7004322609') #data from Elsevier # resp = client.exec_request('https://api.elsevier.com/content/search/scopus?query=all(7004322609)&apiKey=ff61921fc97787106a446daa9dc3827b') resp = client.exec_request( 'https://api.elsevier.com/content/search/author?query=authlast(Harmelen)&apiKey=7f59af901d2d86f78a1fd60c1bf9426a' ) data = resp #data from scopus #data from JSON file # with open('data_scopus_author.json') as json_file: # data_json_file = json.load(json_file) # data = data_json_file #data from JSON file with open('data_scopus_author.json', 'w') as outfile: json.dump(resp, outfile) pprint.pprint(data)
class ElsevierSearcher: __base_url = u'https://api.elsevier.com/content/search/' __api_key = u'e7882eed968063f188d6c53a919528a7' def __init__(self, index: str, apikey: str = __api_key): self.articles_found = [] self.apikey = apikey self.index = index self.els_client = ElsClient(self.apikey) self._uri = self.__base_url + index + '?' def search(self, queryterms: list = None, start_year: int = None, end_year: int = None, content_type: str = 'journals', start_record: int = None, sort_field: str = None, sort_order: int = None, max_records: int = None, article_title: str = None, author: list = None, journal: list = None): """ @param queryterms: list of lists. Terms within the same list are separated by an OR. Lists are separated by an AND @param search_type: meta_data or querytext. meta_data: This field enables a free-text search of all configured metadata fields and the abstract. Accepts complex queries involving field names and boolean operators. querytext: This field enables a free-text search of all configured metadata fields, abstract and document text. Accepts complex queries involving field names and boolean operators. @param start_year: Start value of Publication Year to restrict results by. @param end_year: End value of Publication Year to restrict results by. @param content_type: Note: these are case sensitive and must be spelled as presented here to get a result: Journals, Conference, Early Access, Standards, Books, Courses @param start_record: Sequence number of first record to fetch. Default: 1 @param sort_field: Field name on which to sort. Choose from: article_number article_title, author, publication_title, publication_year @param sort_order: asc (for ascending sort) or desc (for descending sort) @param max_records: The number of records to fetch. Maximum: 200 @return the data fields returned by the search are described by the following link https://developer.ieee.org/docs/read/Metadata_API_responses """ formated_query = '' if self.index == 'scopus': formated_query = "TITLE-ABS-KEY((" if self.index == 'scidir': formated_query = "tak((" for index_group, group in enumerate(queryterms): if index_group > 0: formated_query += ' AND (' # else: # # formated_query += '(' for index_term, term in enumerate(group): if index_term > 0: formated_query += ' OR ' formated_query += f'"{term}"' if (index_term + 1) == len(group): formated_query += ')' formated_query += ')' if author: str_author = ' AND '.join([f'"{x}"' for x in author]) if self.index == 'scopus': formated_query += f' AND AUTHOR-NAME({str_author})' if self.index == 'scidir': formated_query += f' AND aut({str_author})' if article_title: if self.index == 'scopus': formated_query += f' AND TITLE("{article_title}")' if self.index == 'scidir': formated_query += f' AND ttl("{article_title}")' if journal: str_journal = ' AND '.join([f'"{x}"' for x in journal]) if self.index == 'scopus': formated_query += f' AND SRCTITLE({str_journal})' if self.index == 'scidir': formated_query += f' AND src({str_journal})' query_params = dict() print(formated_query) query_params['query'] = formated_query # query_params['view'] = 'STANDARD' if start_year: start_year = str(start_year) date = start_year if end_year: end_year = str(end_year) date += f'-{end_year}' query_params['date'] = date if content_type: query_params['content'] = content_type if start_record: query_params['start'] = start_record if max_records: query_params['count'] = max_records get_all = True url = self._uri + urlencode(query_params, quote_via=quote_plus) print(url) self._api_response = self.els_client.exec_request(url) self._tot_num_res = int( self._api_response['search-results']['opensearch:totalResults']) self.results = self._api_response['search-results']['entry'] print("a request completed...") if get_all is True: while (len(self.results) < self._tot_num_res) and (len( self.results) < 5000): for e in self._api_response['search-results']['link']: if e['@ref'] == 'next': next_url = e['@href'] self._api_response = self.els_client.exec_request(next_url) self.results += self._api_response['search-results']['entry'] print("a request completed...") return self.results
client = ElsClient(config['apikey']) # client.inst_token = config['insttoken'] ## Author example # Initialize author with uri data = {"data" : "24.3"} data_json = json.dumps(data) headers = {'Accept': 'application/json'} my_auth = ElsAuthor( uri = 'https://api.elsevier.com/content/author/author_id/7004322609') resp = client.exec_request('https://api.elsevier.com/content/author/author_id/7004322609?apiKey=2af6a3b4ba3f250031381ec4c63c1c5e') import pprint pprint.pprint(resp) # print("Scopus") # #ID of the Author? # print("Personal ID: " + resp['author-retrieval-response'][0]['author-profile']['affiliation-current']['affiliation']['@affiliation-id']) # #different kind of names used # print(resp['author-retrieval-response'][0]['author-profile']['name-variant']) # #preferred-name # print(resp['author-retrieval-response'][0]['author-profile']['preferred-name']) # #Author ID # print(resp['author-retrieval-response'][0]['coredata']['dc:identifier']) # #Total document-count
has_scopus_id = transformToRDF('hasScopusID') has_description = transformToRDF('hasDescription') has_isbn = transformToRDF('hasISBN') has_issn = transformToRDF('hasISSN') has_publication_name = transformToRDF('hasPublicationName') has_page_range = transformToRDF('hasPageRange') has_publication_year = transformToRDF('hasPublicationYear') has_doi = transformToRDF('hasDoi') for doi in doi_list: print(doi) #data from Elsevier url = 'https://api.elsevier.com/content/abstract/doi/'+ doi +'?apiKey=ff61921fc97787106a446daa9dc3827b' resp = client.exec_request(url) data = resp #======================= # Publications #======================= #Title if 'dc:title' in data['abstracts-retrieval-response']['coredata']: title_pub = transformToRDF(data['abstracts-retrieval-response']['coredata']['dc:title']) titles = transformToRDF('Titles') g.add((titles, RDF.type, OWL.Class)) g.add((titles, RDFS.label, title_pub)) g.add((titles, RDFS.subClassOf, OWL.Thing)) g.add((title_pub, RDF.type, FOAF.Document))