MCPcopy Create free account
hub / github.com/HzaCode/OneCite / _search_semantic_scholar

Method _search_semantic_scholar

onecite/pipeline/identifier.py:719–788  ·  view source on GitHub ↗

Search Semantic Scholar for academic papers

(self, query: str, limit: int = 5)

Source from the content-addressed store, hash-verified

717 return []
718
719 def _search_semantic_scholar(self, query: str, limit: int = 5) -> List[Dict]:
720 """Search Semantic Scholar for academic papers"""
721 try:
722 url = f"{self.semantic_scholar_base}/paper/search"
723 params = {
724 'query': query,
725 'limit': limit,
726 'fields': 'title,authors,year,venue,citationCount,publicationDate,externalIds,journal,url,abstract'
727 }
728
729 response = requests.get(url, params=params, timeout=10)
730
731 if response.status_code == 429:
732 self.logger.debug("Semantic Scholar rate-limited (429); skipping for this query.")
733 return []
734
735 if response.status_code == 200:
736 data = response.json()
737 papers = data.get('data', [])
738
739 results = []
740 for paper in papers:
741 external_ids = paper.get('externalIds') or {}
742 doi = external_ids.get('DOI') if external_ids else None
743 arxiv_id = external_ids.get('ArXiv') if external_ids else None
744
745 authors = []
746 author_list = paper.get('authors') or []
747 for author in author_list:
748 if author and isinstance(author, dict):
749 name = author.get('name', '')
750 if name:
751 authors.append(name)
752
753 venue = paper.get('venue') or ''
754 if not venue:
755 journal_obj = paper.get('journal')
756 if journal_obj and isinstance(journal_obj, dict):
757 venue = journal_obj.get('name', '')
758
759 paper_url = paper.get('url')
760 if not paper_url and paper.get('paperId'):
761 paper_url = f"https://www.semanticscholar.org/paper/{paper.get('paperId')}"
762
763 result = {
764 'source': 'semantic_scholar',
765 'doi': doi,
766 'arxiv_id': arxiv_id,
767 'title': paper.get('title', ''),
768 'authors': authors,
769 'year': paper.get('year'),
770 'journal': venue,
771 'citations': paper.get('citationCount', 0),
772 'url': paper_url,
773 'abstract': paper.get('abstract'),
774 'type': 'article'
775 }
776

Callers 3

test_url_fallbackMethod · 0.95
_fuzzy_searchMethod · 0.95

Calls 1

jsonMethod · 0.45

Tested by 2

test_url_fallbackMethod · 0.76