Skip to main content

Semantic Scholar paper api consuming

Project description

How to install

pip install S2query

S2query

Sematic Scholar paper search developed by BecomeAllan (c) 2020 is library that can search papers on Semantic Scholar page or in the API provided by them.

S2query is an request http library, written in Python, to retrieve papers available in Semantic Scholar.

Examples

We have two main classes, that can handle the paper data. To make a query about more than one topic, title, etc... The parameter search, have to be a string like:

to add some, use +:

  • search = "artificial intelligence+Deep Learning"

or if you want to exclude some, use the - to exclude:

  • search = "artificial intelligence-application"

S2paperAPI()

The S2paperAPI(), consume the API of Semantic Scholar. See the Link to understand more about the API.

The return in .all is a Pandas DataFrame.

   >>> from S2query import S2paperAPI
   >>> m = S2paperAPI()
   >>> m.get("artificial intelligence", n=2)
   >>> m.all.shape
   (2, 12)
   >>> m.all['title']
   0    Explainable Artificial Intelligence (XAI): Con...
   1    Explanation in Artificial Intelligence: Insigh...
   Name: title, dtype: object

S2paperWeb()

The S2paperWeb(), consume the content in the page in Semantic Scholar.

The return in .all is a dictionary arranged about the pages founded.

   >>> from S2query import S2paperWeb
   >>> m = S2paperWeb()
   >>> m.get("artificial intelligence+Deep Learning", n=3, sort = "total-citations", fieldsOfStudy = ['biology'])
   >>> len(m.all['Results'][0]['Page']['Papers'])
   3
   >>> m.all['Results'][0]['Page']['Papers'][0].keys()
   dict_keys(['authors', 'id', 'socialLinks', 'title', 'paperAbstract', 'year',
    'venue', 'citationContexts', 'citationStats', 'sources', 'externalContentStats',
    'journal', 'presentationUrls', 'links', 'primaryPaperLink', 'alternatePaperLinks',
    'entities', 'entityRelations', 'blogs', 'videos', 'githubReferences',
    'scorecardStats', 'fieldsOfStudy', 'pubDate', 'pubUpdateDate',
    'badges', 'tldr'])

Parameters

These classes have an optimization with CPU cores that make multiple requests at the same time, which is passed as a parameter like the number of cores pass as parameter poolCPU. Because of this fact, the Semantic Scholar server may stop receiving requests for a while, so we have defined a timeout in seconds so that we can continue these requests, the parameter is sleeptry.

Example

   >>> from S2query import S2paperWeb, S2paperAPI
   >>> m = S2paperWeb(poolCPU = 2, sleeptry = 60)
   >>> k = S2paperAPI(poolCPU = 4, sleeptry = 5)

To more specific search, this classes have a main function .get() with can hame some parameters that can help.

  • S2paperAPI().get(search, n = 10, offset = 0, papers = [], save = False, saveName = Data, fields = ["title","abstract","isOpenAccess","fieldsOfStudy"])

    • Parameters:
      • search : (str) | The main query in Semantic Scholar API about the papers.
      • n : (int) | The number of papers to get, the maximum is 10.000.
      • offset : (int) | Where start to return the papers, the default is 0, that is the first paper found.
      • papers : list(int) | A list of positions of the papers (0 is the first one), if pass a list, the parameters (n, offset) have no effect in the main query (search). The default is a empty list [].
      • save : (bool) | If true, will save the data set in a file csv at the current directory. the default is False.
      • saveName : (str) | The name of the file when the save is set True.
      • fields : list(str) | The dataframe columns that the Semantic Scholar API returns, see the documentation in Semantic Scholar API Doc..
  • S2paperWeb().get(search, n = 10, offset = 0, papers = [], save = False, saveName = Data, **kwargs)

    • Parameters:
      • search : (str) | The main query in Semantic Scholar API about the papers.
      • n : (int) | The number of papers to get.
      • save : (bool) | If true, will save the data set in a file csv at the current directory. the default is False.
      • saveName : (str) | The name of the file when the save is set True.
      • page : (int) | Where start to return of the papers, the default is 1, that is the first paper found.
      • sort : (str) | The order of the return paper, the options are ("total-citations", "influence", "pub-date", "relevance"). The default is "relevance".
      • authors : list(str) | The filter of authors. The default is [].
      • coAuthors : list(str) | The filter of cothors. The default is [].
      • venues : list(str) | The filter of venues. The options are ["PloS one", "AAAI", "Scientific reports", "IEEE Access", "ArXiv", "Expert Syst. Appl.""ICML", "Neurocomputing", "Sensors", "Remote. Sens."]. The default is [].
      • yearFilter : dict({"min": int, "max": int}) | The filter of year. Ex. {"min": 1999, "max": 2021}. The default is None.
      • requireViewablePdf : (bool) | If the paper have pdf.
      • publicationTypes : list(str) | The filter of type publication, the options are ["ClinicalTrial","CaseReport","Editorial","Study", "Book","News","Review","Conference","LettersAndComments","JournalArticle"]. The default is []
      • fieldsOfStudy : list(str) | The filter of fields of study, the options are [ "agricultural-and-food-sciences","art","biology","business","computer-science","chemistry","economics","education","engineering","environmental-science","geography","geology","history","law","linguistics","materials-science","mathematics","medicine","philosophy","physics","political-science","sociology","psychology"]. The default is [].
      • useFallbackRankerService : (bool) | Fall back to rank the match papers. The defalt is False.
      • useFallbackSearchCluster : (bool) | Fall back to cluster the match papers. The defalt is False.
      • hydrateWithDdb : (bool) | The defalt is True.
      • includeTldrs : (bool) | AI based summary abstracts of papers. The defalt is True.
      • "tldrModelVersion" : (str) | The AI version. The default is "v2.0.0"
      • performTitleMatch: (bool) | Match papers about title. The defalt is True.
      • includeBadges: (bool) | Some bagdes about the papers. The defalt is True.
      • getQuerySuggestions: (bool) | Some query suggestions. The defalt is True.
      • papers : list(int) | A list of positions of the papers (0 is the first one), if pass a list, the parameters (n, offset) have no effect in the main query (search). The default is a empty list [].

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

S2query-1.0.3.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

S2query-1.0.3-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file S2query-1.0.3.tar.gz.

File metadata

  • Download URL: S2query-1.0.3.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.13

File hashes

Hashes for S2query-1.0.3.tar.gz
Algorithm Hash digest
SHA256 4490323c85ba68cc230e89d6013c0f43604922e5c2260a341e32c2a7f7d8c3db
MD5 57fb1d8129e1c0ad6e0b24e35dc371e7
BLAKE2b-256 2ca272b52c3f706f722ff68be66c46d72da1fe9338b77e410fafe8205ae53fc0

See more details on using hashes here.

File details

Details for the file S2query-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: S2query-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.13

File hashes

Hashes for S2query-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f5b74060812e366af14c2805018ab16622c2099d5bb6ef23e0a4e6053d886607
MD5 f1945bc5688318bb6498d72aba2d7422
BLAKE2b-256 2b81ca2b420c0d406df296f498115732ab8696f82589ac510a4c2384aa32996c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page