Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/paperqa/clients/openalex.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ async def get_doc_details_from_openalex(

if fields:
params["select"] = ",".join(fields)

response = await client.get(
url, params=params, timeout=OPENALEX_API_REQUEST_TIMEOUT
)
Expand All @@ -104,6 +103,7 @@ async def get_doc_details_from_openalex(
raise DOINotFoundError("OpenAlex API returned a failed status for the query.")

results_data = response_data

if params.get("filter") is not None:
results_data = results_data["results"]
if len(results_data) == 0:
Expand All @@ -112,13 +112,18 @@ async def get_doc_details_from_openalex(
)
results_data = results_data[0]

# openalex keeps the DOI prefix on (we remove)
if results_data.get("doi"):
results_data["doi"] = results_data["doi"].removeprefix("https://doi.org/")

if (
doi is None
and title
and strings_similarity(results_data.get("title", ""), title)
< title_similarity_threshold
):
raise DOINotFoundError(f"OpenAlex results did not match for title {title!r}.")

if doi and results_data.get("doi") != doi:
raise DOINotFoundError(f"DOI {doi!r} not found in OpenAlex.")

Expand Down
144 changes: 144 additions & 0 deletions tests/cassettes/test_does_openalex_work[10.1021-acs.jctc.5b00178].yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion tests/test_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)
from paperqa.clients.client_models import MetadataPostProcessor, MetadataProvider
from paperqa.clients.journal_quality import JournalQualityPostProcessor
from paperqa.clients.openalex import reformat_name
from paperqa.clients.openalex import OpenAlexProvider, reformat_name
from paperqa.clients.retractions import RetractionDataPostProcessor
from paperqa.types import DocDetails

Expand Down Expand Up @@ -793,3 +793,24 @@ async def test_tricky_journal_quality_results(doi: str, score: int) -> None:
assert (
crossref_details.source_quality == score
), "Should have source quality data"


@pytest.mark.vcr
@pytest.mark.parametrize(
("doi"),
[
("10.1021/acs.jctc.5b00178"),
],
)
@pytest.mark.asyncio
async def test_does_openalex_work(doi: str):
async with httpx_aiohttp.HttpxAiohttpClient() as http_client:
openalex_client = DocMetadataClient(
http_client,
metadata_clients=[OpenAlexProvider],
)
openalex_details = await openalex_client.query(
doi=doi,
fields=["open_access"],
)
assert openalex_details, "Failed to query OpenAlex"
Loading