Repository navigation
add(hse): new model and transformation rules #393
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
zzacharo
merged 3 commits into
CERNDocumentServer:master
from
zubeydecivelek:hse-metadata
Nov 5, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # -*- 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. | ||
|
|
||
| """CDS-RDM HSE model.""" | ||
| from cds_migrator_kit.rdm.records.transform.models._config import IGNORE_SYSTEM_KEYS | ||
| from cds_migrator_kit.rdm.records.transform.models.base_publication_record import ( | ||
| rdm_base_publication_model, | ||
| ) | ||
| from cds_migrator_kit.transform.overdo import CdsOverdo | ||
|
|
||
|
|
||
| class HseModel(CdsOverdo): | ||
| """Translation model for HSE records.""" | ||
|
|
||
| __query__ = """595__:CERN-HSE""" | ||
|
|
||
| __ignore_keys__ = IGNORE_SYSTEM_KEYS | { | ||
| "100__j", | ||
| "300__c", # value only '9 p': 2712787, 2789695 | ||
| "506__a", # Access note restrictions, only 2 records have "Free" but they are restricted | ||
| "595__a", # Unneeded: CERN-HSE or "To be check by ..." | ||
| "690C_a", # Duplicate of 980__a resource type | ||
| # "6531_9", # keyword scheme | ||
| "700__j", | ||
| "720__a", # Author's duplicate | ||
| "7870_r", # detailed description of record relation (2862345) | ||
| # Drop citation field https://cds.cern.ch/record/202927/ | ||
| "913__t", # Citation field | ||
| "913__y", # Citation field | ||
| "913__v", # Citation field | ||
| "913__c", # Citation field | ||
| } | ||
|
|
||
| _default_fields = { | ||
| "custom_fields": {}, | ||
| "record_restriction": "public", # All HSE papers are public, but some of them are missing 963:PUBLIC | ||
| } | ||
|
|
||
|
|
||
| hse_model = HseModel( | ||
| bases=(rdm_base_publication_model,), | ||
| entry_point_group="cds_migrator_kit.migrator.rules.hse", | ||
| ) |
28 changes: 28 additions & 0 deletions
28
cds_migrator_kit/rdm/records/transform/models/radio_protection.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,28 @@ | ||
| # -*- 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. | ||
|
|
||
| """CDS-RDM Radio Protection model.""" | ||
| from cds_migrator_kit.rdm.records.transform.models.hse import HseModel, hse_model | ||
|
|
||
|
|
||
| class RadioProtectionModel(HseModel): | ||
| """Translation model for Radio Protection records.""" | ||
|
|
||
| __query__ = """980__:RP_RESTRICTED""" | ||
|
|
||
| _default_fields = { | ||
| "resource_type": { | ||
| "id": "publication-preprint" | ||
| }, # Default (only 2 articles which the rules will update) | ||
| "custom_fields": {}, | ||
| } | ||
|
|
||
|
|
||
| radio_protection_model = RadioProtectionModel( | ||
| bases=(hse_model,), # inherits the HSE rules | ||
| entry_point_group="cds_migrator_kit.migrator.rules.radio_protection", | ||
| ) |
96 changes: 96 additions & 0 deletions
96
cds_migrator_kit/rdm/records/transform/xml_processing/rules/hse.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,96 @@ | ||
| # -*- 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. | ||
|
|
||
| """CDS-RDM HSE rules.""" | ||
|
|
||
| from dojson.errors import IgnoreKey | ||
|
|
||
| from cds_migrator_kit.errors import UnexpectedValue | ||
| from cds_migrator_kit.transform.xml_processing.quality.decorators import ( | ||
| for_each_value, | ||
| ) | ||
|
|
||
| from ...models.hse import hse_model as model | ||
|
|
||
| # from .base import copyrights as base_copyright | ||
| # from .base import licenses as base_licenses | ||
| from .base import note as base_note | ||
| from .hr import corpo_author | ||
| from .it import imprint | ||
| from .research import resource_type as research_resource_type | ||
|
|
||
| # from dojson.utils import filter_values, force_list | ||
|
|
||
|
|
||
| # from cds_migrator_kit.transform.xml_processing.rules.base import ( | ||
| # description as base_description, | ||
| # ) | ||
|
|
||
|
|
||
| model.over("creators", "(^110__)")(corpo_author) | ||
| model.over("imprint_info", "(^250__)")(imprint) # Only one record: 156663 | ||
|
|
||
|
|
||
| @model.over("physical_copies", "^964__", override=True) | ||
| @for_each_value | ||
| def physical_copies(self, key, value): | ||
| """Translates physical copies field.""" | ||
| number_of_copies = value.get("a").strip() | ||
| if number_of_copies and number_of_copies not in [ | ||
| "0002", | ||
| "0001", | ||
| "0004", | ||
| "0003", | ||
| "0005", | ||
| ]: | ||
| raise UnexpectedValue(subfield="a", value=number_of_copies, field=key) | ||
| raise IgnoreKey("physical_copies") | ||
|
|
||
|
|
||
| @model.over("internal_notes", "^595__") | ||
| @for_each_value | ||
| def note_hse(self, key, value): | ||
| """Translates notes. HSE Articles query is 595__:CERN-HSE.""" | ||
| _note = (value.get("a") or "").strip() | ||
| if _note in ("CERN-HSE", "To be check by Salome"): | ||
| raise IgnoreKey("internal_notes") | ||
| else: | ||
| return base_note(self, key, value) | ||
|
|
||
|
|
||
| # Reuse the generic 980__/697C_ resource type rule. HSE papers have no default, | ||
| # a record without a match is rejected by ``ResourceTypeMapper``. | ||
| model.over("resource_type", "(^980__)|(^697C_)", override=True)(research_resource_type) | ||
|
|
||
|
|
||
| # @model.over("rights", "^540__", override=True) | ||
|
sakshamarora1 marked this conversation as resolved.
Resolved
|
||
| # @for_each_value | ||
| # @filter_values | ||
| # def licenses(self, key, value): | ||
| # """Translates rights.""" | ||
| # material = value.get("3") | ||
| # if material and material.lower() not in ["publication"]: | ||
| # raise UnexpectedValue(subfield="3", value=material, field=key) | ||
| # license = base_licenses(self, key, value) | ||
| # return license[0] | ||
|
|
||
|
|
||
| # @model.over("copyright", "^542__", override=True) | ||
| # def copyrights(self, key, value): | ||
| # """Translates copyright.""" | ||
| # material = value.get("3") | ||
| # if material and material.lower() not in ["publication"]: | ||
| # raise UnexpectedValue(subfield="3", value=material, field=key) | ||
| # return base_copyright(self, key, value) | ||
| # @model.over("description", "^520__", override=True) | ||
| # def description(self, key, value): | ||
| # """Translates description.""" | ||
| # abstract_number = value.get("9") | ||
| # # TODO: can we ignore? | ||
| # if abstract_number and abstract_number not in ["JACoW", "submitter"]: | ||
| # raise UnexpectedValue(subfield="9", value=abstract_number, field=key) | ||
| # return base_description(self, key, value) | ||
35 changes: 35 additions & 0 deletions
35
cds_migrator_kit/rdm/records/transform/xml_processing/rules/radio_protection.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,35 @@ | ||
| # -*- 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. | ||
|
|
||
| """CDS-RDM Radio Protection rules.""" | ||
|
|
||
| from ...models.radio_protection import radio_protection_model as model | ||
| from .research import resource_type as research_resource_type | ||
|
|
||
| # The rules (including the 980__/697C_ resource type) are inherited from the HSE | ||
| # model, only the model defaults differ (resource_type: publication-preprint). | ||
|
|
||
| # Radio Protection also has the document type in the 490__a series. Clean the | ||
| # value to the legacy document types known by the generic rule, it shares the | ||
| # rank with 980__ so the highest priority value wins. Replaces the inherited | ||
| # series rule. | ||
| SERIES_TO_DOCUMENT_TYPE = { | ||
| "internal report": "report", | ||
| "rp annual report": "report", | ||
| "divisionnal report": "report", | ||
| "technical inspection": "report", | ||
| "technical notes": "technical note", | ||
| "technical memorandum": "technical note", | ||
| } | ||
|
|
||
|
|
||
| @model.over("resource_type", "^490__", override_tag=True) | ||
| def series_resource_type(self, key, value): | ||
| """Translates resource_type from the 490__a series.""" | ||
| series = (value.get("a") or "").strip().lower() | ||
| cleaned = {"a": SERIES_TO_DOCUMENT_TYPE.get(series, series)} | ||
| return research_resource_type(self, key, cleaned) |
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,6 @@ | ||
| name: hse | ||
| queries: | ||
| - q: "595__:CERN-HSE" | ||
| dump_file_prefix: hse | ||
| communities: | ||
| - hse |
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,8 @@ | ||
| name: radio_protection | ||
| queries: | ||
| - q: "980__:RP_RESTRICTED" | ||
| dump_file_prefix: radio_protection | ||
| flags: | ||
| restricted: true | ||
| communities: | ||
| - radio-protection |
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
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.
Uh oh!
There was an error while loading. Please reload this page.