Skip to content

Commit

Permalink
feat: ✨ Add pool_from parameter in get_recommended_papers()
Browse files Browse the repository at this point in the history
Represents which pool of papers to recommend from (the `from` query parameter).
  • Loading branch information
danielnsilva committed Aug 20, 2023
1 parent 4dead91 commit d245515
Show file tree
Hide file tree
Showing 4 changed files with 2,531 additions and 528 deletions.
14 changes: 10 additions & 4 deletions semanticscholar/SemanticScholar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import warnings
from typing import List
from typing import List, Literal

from semanticscholar.ApiRequester import ApiRequester
from semanticscholar.Author import Author
Expand Down Expand Up @@ -512,7 +511,8 @@ def get_recommended_papers(
self,
paper_id: str,
fields: list = None,
limit: int = 100
limit: int = 100,
pool_from: Literal["recent", "all-cs"] = "recent"
) -> List[Paper]:
'''Get recommended papers for a single positive example.
Expand All @@ -532,10 +532,16 @@ def get_recommended_papers(
:param list fields: (optional) list of the fields to be returned.
:param int limit: (optional) maximum number of recommendations to \
return (must be <= 500).
:param str pool_from: (optional) which pool of papers to recommend \
from. Must be either "recent" or "all-cs".
:returns: list of recommendations.
:rtype: :class:`List` of :class:`semanticscholar.Paper.Paper`
'''

if pool_from not in ["recent", "all-cs"]:
raise ValueError(
'The pool_from parameter must be either "recent" or "all-cs".')

if limit < 1 or limit > 500:
raise ValueError(
'The limit parameter must be between 1 and 500 inclusive.')
Expand All @@ -547,7 +553,7 @@ def get_recommended_papers(
url = f'{base_url}/papers/forpaper/{paper_id}'

fields = ','.join(fields)
parameters = f'&fields={fields}&limit={limit}'
parameters = f'&fields={fields}&limit={limit}&from={pool_from}'

data = self._requester.get_data(url, parameters, self.auth_header)
papers = [Paper(item) for item in data['recommendedPapers']]
Expand Down
Loading

0 comments on commit d245515

Please sign in to comment.