A fluent, elegant, and modern wrapper for the Semantic Scholar Academic Graph API, built for Laravel.
- Fluent API Design: Intuitive, chainable query methods
- Rich Data Transfer Objects: Strongly-typed responses with helper methods
- Advanced Caching: Built-in caching with configurable TTL
- Memory Efficient: Cursor-based pagination for large datasets
- Academic Utilities: BibTeX generation, citation analysis, impact metrics
- Multiple ID Support: DOI, ArXiv, PubMed, ORCID, and more
- Rate Limit Handling: Automatic retry with exponential backoff
- Laravel Integration: Service provider, facade, and configuration
You can install the package via Composer:
composer require mbsoft31/laravel-semantic-scholarPublish the configuration file:
php artisan vendor:publish --provider="Mbsoft\SemanticScholar\SemanticScholarServiceProvider" --tag="config"Optionally, set your API key in your .env file for increased rate limits:
SEMANTIC_SCHOLAR_API_KEY=your-api-key-hereuse Mbsoft\SemanticScholar\Facades\SemanticScholar;
// Search for papers
$papers = SemanticScholar::papers()
->search('machine learning')
->byYear(2024)
->minCitations(10)
->openAccess()
->limit(50)
->get();
// Find a specific paper
$paper = SemanticScholar::papers()->find('649def34f8be52c8b66281af98ae884c09aef38b');
echo $paper->title;
echo $paper->toBibTeX();
// Search authors
$authors = SemanticScholar::authors()
->search('Geoffrey Hinton')
->get();
// Find author by ORCID
$author = SemanticScholar::authors()->findByOrcid('0000-0002-1825-0097');
echo "H-Index: " . $author->hIndex;
echo "Total Papers: " . $author->paperCount;$paper = SemanticScholar::papers()->findByDoi('10.1038/nature14539');
// Academic metrics
echo $paper->getCitationVelocity(); // Citations per year
echo $paper->getInfluentialCitationRatio(); // Quality metric
echo $paper->isHighlyInfluential(); // Boolean flag
echo $paper->getTldr(); // AI-generated summary
// Citation formats
echo $paper->toBibTeX();
echo $paper->toApa();
echo $paper->toMla();
// Access metadata
echo $paper->getDoi();
echo $paper->getOpenAccessUrl();
echo implode(', ', $paper->getAuthorNames());$author = SemanticScholar::authors()->find('1741101');
// Career analysis
$careerSpan = $author->getCareerSpan();
echo "Active from {$careerSpan['start_year']} to {$careerSpan['end_year']}";
// Productivity metrics
echo $author->getProductivityLevel(); // 'highly_productive', 'productive', etc.
echo $author->getProductivityTrend(); // 'increasing', 'stable', 'decreasing'
echo $author->getPeakProductivityYear();
// Impact analysis
echo $author->getImpactLevel(); // 'exceptional', 'high', 'significant', etc.
echo $author->getAverageCitationsPerPaper();
echo $author->getCollaborationNetworkSize();// Process large datasets without memory issues
SemanticScholar::papers()
->search('deep learning')
->byYear(2023)
->cursor()
->chunk(1000)
->each(function ($papers) {
foreach ($papers as $paper) {
echo $paper->title . "\n";
}
});// Cache for 10 minutes
$papers = SemanticScholar::papers()
->search('neural networks')
->cacheFor(600)
->get();
// Cache forever
$author = SemanticScholar::authors()
->find('1741101')
->cacheForever()
->get();// Automatic pagination
$paginatedPapers = SemanticScholar::papers()
->search('computer vision')
->paginate(perPage: 25, page: 2);
echo "Total papers: " . $paginatedPapers->total();
echo "Current page: " . $paginatedPapers->currentPage();// Only fetch specific fields to improve performance
$papers = SemanticScholar::papers()
->search('artificial intelligence')
->fields(['paperId', 'title', 'year', 'citationCount', 'authors'])
->get();The configuration file allows you to customize various aspects of the package:
return [
'api_key' => env('SEMANTIC_SCHOLAR_API_KEY'),
'base_url' => env('SEMANTIC_SCHOLAR_BASE_URL', 'https://api.semanticscholar.org/graph/v1'),
'timeout' => env('SEMANTIC_SCHOLAR_TIMEOUT', 30),
'cache_ttl' => env('SEMANTIC_SCHOLAR_CACHE_TTL', 300),
'default_fields' => [
'papers' => [
'paperId', 'title', 'year', 'abstract',
'citationCount', 'authors', 'venue', 'openAccessPdf'
],
'authors' => [
'authorId', 'name', 'paperCount', 'citationCount',
'hIndex', 'affiliations'
]
],
'rate_limit' => [
'requests_per_second' => 1,
'burst_limit' => 10,
],
];use Mbsoft\SemanticScholar\Exceptions\SemanticScholarException;
try {
$papers = SemanticScholar::papers()
->search('quantum computing')
->get();
} catch (SemanticScholarException $e) {
logger()->error('Semantic Scholar API error: ' . $e->getMessage());
// Handle specific error types
if ($e->getCode() === 429) {
// Rate limit exceeded
}
}papers()- Start a papers querysearch(string $query)- Search papers by textfind(string $id)- Find paper by Semantic Scholar IDfindByDoi(string $doi)- Find paper by DOIfindByArxiv(string $arxivId)- Find paper by ArXiv IDfindByPubmed(string $pubmedId)- Find paper by PubMed IDbyYear(int $year)- Filter by publication yearbyYearRange(int $start, int $end)- Filter by year rangeminCitations(int $count)- Minimum citation countopenAccess(bool $required = true)- Open access papers onlybyFieldOfStudy(string $field)- Filter by field of studybyVenue(string $venue)- Filter by publication venue
authors()- Start an authors querysearch(string $query)- Search authors by namefind(string $id)- Find author by Semantic Scholar IDfindByOrcid(string $orcid)- Find author by ORCID
fields(array $fields)- Select specific fieldslimit(int $limit)- Limit number of resultsoffset(int $offset)- Skip number of resultsget()- Execute query and get Collectionpaginate(int $perPage, int $page)- Get paginated resultscursor()- Get LazyCollection for memory efficiencycacheFor(int $seconds)- Cache resultscacheForever()- Cache results indefinitely
composer testPlease see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.