-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
affiliations: added custom scheme for edmo
- Loading branch information
1 parent
5ffb2ce
commit 59709c7
Showing
3 changed files
with
92 additions
and
56 deletions.
There are no files selected for viewing
This file contains 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 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 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,57 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2024 CERN. | ||
# | ||
# ZenodoRDM is free software; you can redistribute it and/or modify it | ||
# under the terms of the MIT License; see LICENSE file for more details. | ||
|
||
"""Custom scheme config.""" | ||
|
||
import re | ||
|
||
# Regular expression to validate EDMO identifiers in the format "edmo:<ID>" | ||
edmo_regexp = re.compile(r"^edmo:(\d+)$") | ||
|
||
# Regular expression to match the EDMO URL format | ||
edmo_url_regexp = re.compile( | ||
r"(?:https?://)?(?:edmo\.seadatanet\.org/report/)?(\d+)$", re.IGNORECASE | ||
) | ||
|
||
|
||
def is_edmo(val): | ||
""" | ||
Validate and normalize an EDMO identifier or URL. | ||
Returns the normalized 'edmo:<ID>' format if valid, otherwise None. | ||
""" | ||
# Match against the URL or the edmo:<ID> format | ||
match = edmo_url_regexp.match(val) or edmo_regexp.match(val) | ||
if match: | ||
# Extract the numeric ID from the matched group | ||
return f"edmo:{match.group(1)}" | ||
return None | ||
|
||
|
||
def normalize_edmo(val): | ||
"""Normalize an EDMO identifier or URL to the 'edmo:<ID>' format.""" | ||
return is_edmo(val) | ||
|
||
|
||
def generate_edmo_url(_, normalized_pid): | ||
""" | ||
Generate a URL for a given normalized EDMO identifier. | ||
Assumes the input is in the form 'edmo:<ID>'. | ||
""" | ||
edmo_id = normalized_pid.split(":")[1] | ||
return f"https://edmo.seadatanet.org/report/{edmo_id}" | ||
|
||
|
||
def get_scheme_config_func(): | ||
"""Return the configuration for the EDMO custom scheme.""" | ||
return { | ||
"validator": is_edmo, | ||
"normalizer": normalize_edmo, | ||
"filter": [], | ||
"url_generator": generate_edmo_url, | ||
} |