Recommendations
client.recommendations talks to the /recommendations/v1 routes and returns Paper models. Both routes answer {"recommendedPapers": [...]} and work without an API key. Later blocks on this page reuse the client created here.
import asyncio
from bibliofabric.semanticscholar import SemanticScholarClient
client = SemanticScholarClient()
Recommendations for one paper
for_paper(id) returns papers related to one paper. The id takes the same forms as a paper get (DOI:, ARXIV:, a bare S2 id, and so on):
papers = await client.recommendations.for_paper(
"DOI:10.1038/nature12373", select=["title", "year"], page_size=3
)
print(len(papers), papers[0].title[:50])
3 Spin-Uniform Nanodiamond Quantum Sensors for Repro
params={"from": "all-cs"} widens the candidate pool from the default recent papers to all of computer science.
Recommendations for a list of papers
for_list() takes papers to steer toward and papers to steer away from; at least one id is required. The route is a read-only POST and is sent with retries:
papers = await client.recommendations.for_list(
positive_paper_ids=["ARXIV:2106.15928"],
negative_paper_ids=["DOI:10.1038/nature12373"],
select=["title", "year"],
page_size=3,
)
print(len(papers), papers[0].title[:50])
3 Estimating SARS-CoV-2 reinfection frequency and in
The list route is more restricted upstream than the single-paper route and may answer HTTP 400 on the anonymous pool.
Point the recommendations API elsewhere
The recommendations service lives on its own base URL. SemanticScholarClient(recommendations_base_url=...) points it at another host:
client = SemanticScholarClient(
recommendations_base_url="https://mirror.example.org/recommendations/v1"
)
Where to go next
- Papers for the paper model and its fields.
- Upstream quirks for the recommendation routes' base URL.