-
Notifications
You must be signed in to change notification settings - Fork 27
fix(harvester): merge new abstracts and author identifiers on update #950
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
Open
TahaKhan998
wants to merge
1
commit into
CERNDocumentServer:master
Choose a base branch
from
TahaKhan998:fix/harvester-update-strategies
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
site/tests/inspire_harvester/test_creatibutors_update.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright (C) 2026 CERN. | ||
| # | ||
| # CDS-RDM is free software; you can redistribute it and/or modify it under | ||
| # the terms of the MIT License; see LICENSE file for more details. | ||
|
|
||
| """CreatibutorsFieldUpdate matching tests.""" | ||
|
|
||
| from cds_rdm.inspire_harvester.update.fields.creatibutors import CreatibutorsFieldUpdate | ||
|
|
||
| PATH = "metadata.creators" | ||
|
|
||
|
|
||
| def _person(family="", given="", name="", orcid=None): | ||
| """Build a creator entry.""" | ||
| person = { | ||
| "type": "personal", | ||
| "family_name": family, | ||
| "given_name": given, | ||
| "name": name or ", ".join(part for part in (family, given) if part), | ||
| } | ||
| if orcid: | ||
| person["identifiers"] = [{"scheme": "orcid", "identifier": orcid}] | ||
| return {"person_or_org": person} | ||
|
|
||
|
|
||
| def _merge(current_creators, incoming_creators): | ||
| strategy = CreatibutorsFieldUpdate(strict=True) | ||
| return strategy.update( | ||
| {"metadata": {"creators": current_creators}}, | ||
| {"metadata": {"creators": incoming_creators}}, | ||
| PATH, | ||
| ctx=None, | ||
| ) | ||
|
|
||
|
|
||
| def test_name_key_uses_family_given_and_full_name(): | ||
| """Matching is on the full name tuple, not given name alone.""" | ||
| keys = CreatibutorsFieldUpdate()._keys( | ||
| _person(family="Rossi", given="Anna", name="Rossi, Anna") | ||
| ) | ||
|
|
||
| assert ("name", "rossi", "anna", "rossi, anna") in keys | ||
|
|
||
|
|
||
| def test_same_given_name_different_family_is_not_merged(): | ||
| """Two people who share a given name are not treated as one person.""" | ||
| result = _merge( | ||
| [_person(family="Rossi", given="Anna", name="Rossi, Anna")], | ||
| [_person(family="Bianchi", given="Anna", name="Bianchi, Anna")], | ||
| ) | ||
|
|
||
| stored = result.updated["metadata"]["creators"][0]["person_or_org"] | ||
| assert stored["family_name"] == "Rossi" | ||
| assert [w.kind for w in result.warnings] == ["new_creator"] | ||
|
|
||
|
|
||
| def test_stored_name_only_gains_orcid_from_inspire(): | ||
| """Stored author keyed by name still matches incoming ORCID.""" | ||
| result = _merge( | ||
| [_person(family="Doe", given="John", name="Doe, John")], | ||
| [ | ||
| _person( | ||
| family="Doe", | ||
| given="John", | ||
| name="Doe, John", | ||
| orcid="0000-0002-1825-0097", | ||
| ) | ||
| ], | ||
| ) | ||
|
|
||
| assert result.warnings == [] | ||
| assert result.updated["metadata"]["creators"][0]["person_or_org"]["identifiers"] == [ | ||
| {"scheme": "orcid", "identifier": "0000-0002-1825-0097"} | ||
| ] | ||
|
|
||
|
|
||
| def test_same_name_different_orcids_are_not_merged(): | ||
| """Two people with the same name and different ORCIDs stay separate.""" | ||
| result = _merge( | ||
| [ | ||
| _person( | ||
| family="Smith", | ||
| given="John", | ||
| name="Smith, John", | ||
| orcid="0000-0001-0000-0001", | ||
| ) | ||
| ], | ||
| [ | ||
| _person( | ||
| family="Smith", | ||
| given="John", | ||
| name="Smith, John", | ||
| orcid="0000-0002-0000-0002", | ||
| ) | ||
| ], | ||
| ) | ||
|
|
||
| assert [w.kind for w in result.warnings] == ["new_creator"] | ||
| stored = result.updated["metadata"]["creators"][0]["person_or_org"] | ||
| assert stored["identifiers"] == [ | ||
| {"scheme": "orcid", "identifier": "0000-0001-0000-0001"} | ||
| ] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I understand how this part will behave - we can't be relying on matching only family name or only given name because it will lead to false positives, no?
ex.
Karolina ABCandKarolina EDFare different names but if you use given name as matching key, they will be matched incorrectly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So for your examples if INSPIRE sends Karolina ABC and Karolina EDF, theres no comma in the name so the mapper cant split it and the whole string just goes into family name. That gives you keys like ("name", "karolina abc", "", "") and ("name", "karolina edf", "", "") . Different keys so they dont match. If INSPIRE sends first name and last name separately instead you get ("name", "abc", "karolina", "abc, karolina") and ("name", "edf", "karolina", "edf, karolina"). Still different because the family name part is different even though given name is the same both times. So we are not matching on given name alone, the whole tuple has to match.
What happens is it first tries to match on ORCID if there is one and only if that doesnt work it tries the name key. The case we're fixing is CDS has the author keyed by name only INSPIRE now has an ORCID and the ORCID lookup finds nothing but the name key matches so we merge and the ORCID gets added. But if both sides already have an ORCID and theyre different we dont fall back to the name even if it would match so two different people called Karolina dont get merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have tests covering different possible corner cases?