Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/metadata_dictionary/cff.py
# Copyright (C) 2021-2022 The Software Heritage developers | # Copyright (C) 2021-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 | ||||
from typing import List | from typing import List | ||||
import urllib.parse | |||||
from rdflib import BNode, Graph, Literal, URIRef | from rdflib import BNode, Graph, Literal, URIRef | ||||
import rdflib.term | import rdflib.term | ||||
from swh.indexer.codemeta import CROSSWALK_TABLE | from swh.indexer.codemeta import CROSSWALK_TABLE | ||||
from swh.indexer.namespaces import RDF, SCHEMA | from swh.indexer.namespaces import RDF, SCHEMA | ||||
from .base import YamlMapping | from .base import YamlMapping | ||||
Show All 10 Lines | class CffMapping(YamlMapping): | ||||
filename = b"CITATION.cff" | filename = b"CITATION.cff" | ||||
mapping = CROSSWALK_TABLE["Citation File Format Core (CFF-Core) 1.0.2"] | mapping = CROSSWALK_TABLE["Citation File Format Core (CFF-Core) 1.0.2"] | ||||
string_fields = ["keywords", "license", "abstract", "version", "doi"] | string_fields = ["keywords", "license", "abstract", "version", "doi"] | ||||
date_fields = ["date-released"] | date_fields = ["date-released"] | ||||
uri_fields = ["repository-code"] | uri_fields = ["repository-code"] | ||||
def _translate_author(self, graph: Graph, author: dict) -> rdflib.term.Node: | def _translate_author(self, graph: Graph, author: dict) -> rdflib.term.Node: | ||||
node: rdflib.term.Node | node: rdflib.term.Node | ||||
if "orcid" in author and isinstance(author["orcid"], str): | if ( | ||||
"orcid" in author | |||||
and isinstance(author["orcid"], str) | |||||
and urllib.parse.urlparse(author["orcid"]).netloc | |||||
): | |||||
node = URIRef(author["orcid"]) | node = URIRef(author["orcid"]) | ||||
else: | else: | ||||
node = BNode() | node = BNode() | ||||
graph.add((node, RDF.type, SCHEMA.Person)) | graph.add((node, RDF.type, SCHEMA.Person)) | ||||
if "affiliation" in author and isinstance(author["affiliation"], str): | if "affiliation" in author and isinstance(author["affiliation"], str): | ||||
affiliation = BNode() | affiliation = BNode() | ||||
graph.add((node, SCHEMA.affiliation, affiliation)) | graph.add((node, SCHEMA.affiliation, affiliation)) | ||||
graph.add((affiliation, RDF.type, SCHEMA.Organization)) | graph.add((affiliation, RDF.type, SCHEMA.Organization)) | ||||
Show All 19 Lines |