Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/metadata_dictionary/composer.py
# Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import os.path | import os.path | ||||
from swh.indexer.codemeta import _DATA_DIR, SCHEMA_URI, _read_crosstable | from swh.indexer.codemeta import _DATA_DIR, _read_crosstable | ||||
from swh.indexer.namespaces import SCHEMA | |||||
from .base import JsonMapping, SingleFileIntrinsicMapping | from .base import JsonMapping, SingleFileIntrinsicMapping | ||||
COMPOSER_TABLE_PATH = os.path.join(_DATA_DIR, "composer.csv") | COMPOSER_TABLE_PATH = os.path.join(_DATA_DIR, "composer.csv") | ||||
with open(COMPOSER_TABLE_PATH) as fd: | with open(COMPOSER_TABLE_PATH) as fd: | ||||
(CODEMETA_TERMS, COMPOSER_TABLE) = _read_crosstable(fd) | (CODEMETA_TERMS, COMPOSER_TABLE) = _read_crosstable(fd) | ||||
Show All 21 Lines | class ComposerMapping(JsonMapping, SingleFileIntrinsicMapping): | ||||
def normalize_license(self, s): | def normalize_license(self, s): | ||||
if isinstance(s, str): | if isinstance(s, str): | ||||
return {"@id": "https://spdx.org/licenses/" + s} | return {"@id": "https://spdx.org/licenses/" + s} | ||||
def normalize_authors(self, author_list): | def normalize_authors(self, author_list): | ||||
authors = [] | authors = [] | ||||
for author in author_list: | for author in author_list: | ||||
author_obj = {"@type": SCHEMA_URI + "Person"} | author_obj = {"@type": SCHEMA.Person} | ||||
if isinstance(author, dict): | if isinstance(author, dict): | ||||
if isinstance(author.get("name", None), str): | if isinstance(author.get("name", None), str): | ||||
author_obj[SCHEMA_URI + "name"] = author.get("name", None) | author_obj[SCHEMA.name] = author.get("name", None) | ||||
if isinstance(author.get("email", None), str): | if isinstance(author.get("email", None), str): | ||||
author_obj[SCHEMA_URI + "email"] = author.get("email", None) | author_obj[SCHEMA.email] = author.get("email", None) | ||||
authors.append(author_obj) | authors.append(author_obj) | ||||
return {"@list": authors} | return {"@list": authors} |