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.2.tar.gz (11.3 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.2-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: S2query-1.0.3.2.tar.gz
  • Upload date:
  • Size: 11.3 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.2.tar.gz
Algorithm Hash digest
SHA256 770869360935218d6a5ec4ba567ca653b30f60b83035533670e3ee265bdc1ff4
MD5 c9de347b703d0212d85e89f929a3fd51
BLAKE2b-256 a075d33bffbe73ab318313c9f67dcee87f3b956d18999db2cc417dfcdf59b985

See more details on using hashes here.

File details

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

File metadata

  • Download URL: S2query-1.0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 13.7 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d4f255741fe8df761dd099b6ad4c5f6f0ccd1aa80de6b70c0361ac8e33713d6f
MD5 35e0966a2195fd3a47ff59ccf7802265
BLAKE2b-256 c4d7850287383d3d41c6922be0bb2b62b1b2b7cd1c121668e975ac8533f13138

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