diff --git a/swh/indexer/metadata_dictionary/cff.py b/swh/indexer/metadata_dictionary/cff.py index 48be831..731cab1 100644 --- a/swh/indexer/metadata_dictionary/cff.py +++ b/swh/indexer/metadata_dictionary/cff.py @@ -20,6 +20,24 @@ class CffMapping(DictMapping, SingleFileIntrinsicMapping): name = "cff" filename = b"CITATION.cff" mapping = CROSSWALK_TABLE["Citation File Format Core (CFF-Core) 1.0.2"] + extra_context = { + "schema": SCHEMA_URI, + "authors": { + "@id": "schema:author", + "@type": "schema:Person", + "@container": "@list", + "@context": { + "orcid": "@id", + "family-names": "schema:familyName", + "given-names": "schema:givenName", + "affiliation": { + "@type": "schema:Organization", + "@id": "schema:affiliation", + } + } + } + } + string_fields = ["keywords", "license", "abstract", "version", "doi"] def translate(self, raw_content: bytes) -> Optional[Dict[str, str]]: @@ -34,29 +52,6 @@ def translate(self, raw_content: bytes) -> Optional[Dict[str, str]]: return None - def normalize_authors(self, d: List[dict]) -> Dict[str, list]: - result = [] - for author in d: - author_data: Dict[str, Optional[Union[str, Dict]]] = { - "@type": SCHEMA_URI + "Person" - } - if "orcid" in author and isinstance(author["orcid"], str): - author_data["@id"] = author["orcid"] - if "affiliation" in author and isinstance(author["affiliation"], str): - author_data[SCHEMA_URI + "affiliation"] = { - "@type": SCHEMA_URI + "Organization", - SCHEMA_URI + "name": author["affiliation"], - } - if "family-names" in author and isinstance(author["family-names"], str): - author_data[SCHEMA_URI + "familyName"] = author["family-names"] - if "given-names" in author and isinstance(author["given-names"], str): - author_data[SCHEMA_URI + "givenName"] = author["given-names"] - - result.append(author_data) - - result_final = {"@list": result} - return result_final -