Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/metadata_dictionary/citation.py
- This file was added.
import yaml | |||||
from swh.indexer.codemeta import CROSSWALK_TABLE | |||||
from .base import DictMapping, SingleFileMapping | |||||
yaml.SafeLoader.yaml_implicit_resolvers = { | |||||
k: [r for r in v if r[0] != "tag:yaml.org,2002:timestamp"] | |||||
for k, v in yaml.SafeLoader.yaml_implicit_resolvers.items() | |||||
} | |||||
class CitationMapping(DictMapping, SingleFileMapping): | |||||
"""Dedicated class for Citation (CITATION.cff) mapping and translation""" | |||||
name = "citation" | |||||
filename = b"CITATION.cff" | |||||
mapping = CROSSWALK_TABLE["Citation File Format Core (CFF-Core) 1.0.2"] | |||||
string_fields = [ | |||||
"date-released", | |||||
"keywords", | |||||
"license", | |||||
"abstract", | |||||
"version", | |||||
"doi", | |||||
"repository-code", | |||||
"authors", | |||||
] | |||||
def translate(self, raw_content): | |||||
raw_content = raw_content.decode() # bytes to str | |||||
content_dict = yaml.load(raw_content, Loader=yaml.SafeLoader) # str to dict | |||||
metadata = self._translate_dict(content_dict) # convert to CodeMeta | |||||
vlorentz: You can remove these comments (they are only useful in the example) | |||||
for author in content_dict["authors"]: | |||||
metadata["schema:author"].append( | |||||
{ | |||||
"@id": author.get("orcid", None), | |||||
"@type": "Person", | |||||
"affiliation": { | |||||
"@type": "Organization", | |||||
"legalName": author.get("affiliation", None), | |||||
}, | |||||
"familyName": author.get("family-names", None), | |||||
"givenName": author.get("given-names", None), | |||||
} | |||||
vlorentzUnsubmitted Not Done Inline ActionsThis is technically correct IIRC, but I would rather not have a field than have it with a None value vlorentz: This is technically correct IIRC, but I would rather not have a field than have it with a… | |||||
) | |||||
return metadata | |||||
def normalize_license(self, s): | |||||
if isinstance(s, str): | |||||
return {"@id": "https://spdx.org/licenses/" + s} | |||||
def normalize_doi(self, s): | |||||
if isinstance(s, str): | |||||
return {"@id": "https://doi.org/" + s} |
You can remove these comments (they are only useful in the example)