Skip to content

Commit

Permalink
refactor: Num_citations also supports recent scholarly
Browse files Browse the repository at this point in the history
  • Loading branch information
jannisborn committed Jun 23, 2024
1 parent 397b730 commit de81def
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion paperscraper/scholar/scholar.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def get_citations_from_title(title: str) -> int:
title = '"' + title.strip() + '"'

matches = scholarly.search_pubs(title)
counts = list(map(lambda p: int(p.bib["cites"]), matches))
counts = list(map(lambda p: int(p["num_citations"]), matches))
if len(counts) == 0:
logger.warning(f"Found no match for {title}.")
return 0
Expand Down
18 changes: 16 additions & 2 deletions paperscraper/scholar/tests/test_scholar.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import logging
import pandas as pd

import pytest

from paperscraper.scholar import get_scholar_papers
from paperscraper.scholar import (
get_and_dump_scholar_papers,
get_citations_from_title,
get_scholar_papers,
)

logging.disable(logging.INFO)


class TestScholar:

def test_citations(self):
num = get_citations_from_title("GT4SD")
assert isinstance(num, int)
assert num > 0

def test_dump_search(self, tmpdir):
temp_dir = tmpdir.mkdir("scholar_papers")
output_filepath = temp_dir.join("results.jsonl")
get_and_dump_scholar_papers("GT4SD", str(output_filepath))
assert output_filepath.check(file=1)

def test_basic_search(self):
results = get_scholar_papers("GT4SD")
assert len(results) > 0 # Ensure we get some results
Expand Down

0 comments on commit de81def

Please sign in to comment.