Skip to content

Check if a journal name starts with the #320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 paperqa/clients/journal_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ async def _process(
# remember, if both have docnames (i.e. key) they are
# wiped and re-generated with resultant data
return doc_details + DocDetails( # type: ignore[call-arg]
source_quality=self.data.get(query.journal.casefold(), -1) # type: ignore[union-attr]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be using casefold?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so? just to be more robust with journal names. @mskarlin thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup that's what we've been using on title comparisons!

source_quality=max(
[
self.data.get(query.journal.casefold(), DocDetails.UNDEFINED_JOURNAL_QUALITY), # type: ignore[union-attr]
self.data.get("the " + query.journal.casefold(), DocDetails.UNDEFINED_JOURNAL_QUALITY), # type: ignore[union-attr]
]
)
)

def query_creator(self, doc_details: DocDetails, **kwargs) -> JournalQuery | None:
Expand Down
19 changes: 18 additions & 1 deletion tests/test_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ async def test_s2_only_fields_filtering():
assert not s2_details.source_quality, "No source quality data should exist" # type: ignore[union-attr]


@pytest.mark.vcr
@pytest.mark.vcr(record_mode="new_episodes")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think you need this - I was wrong

Suggested change
@pytest.mark.vcr(record_mode="new_episodes")
@pytest.mark.vcr

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should let the VCR config in conftest.py be the one source of truth. So I vote we do actually commit this change

@pytest.mark.asyncio
async def test_crossref_journalquality_fields_filtering():
async with aiohttp.ClientSession() as session:
Expand Down Expand Up @@ -327,6 +327,23 @@ async def test_crossref_journalquality_fields_filtering():
"doi:10.1038/s42256-024-00832-8."
), "Citation should be populated"

async with aiohttp.ClientSession() as session:
crossref_client = DocMetadataClient(
session,
clients=cast(
Collection[
type[MetadataPostProcessor[Any]] | type[MetadataProvider[Any]]
],
[CrossrefProvider, JournalQualityPostProcessor],
),
)
nejm_crossref_details = await crossref_client.query(
title="Beta-Blocker Interruption or Continuation after Myocardial Infarction", # codespell:ignore
fields=["title", "doi", "authors", "journal"],
)

assert nejm_crossref_details.source_quality == 3, "Should have source quality data" # type: ignore[union-attr]


@pytest.mark.vcr
@pytest.mark.asyncio
Expand Down