Skip to content

Commit

Permalink
Make cs creator / publisher accept ROR ID
Browse files Browse the repository at this point in the history
creator can also be ORCID
  • Loading branch information
dalito committed Aug 16, 2023
1 parent 2f6cc7c commit c7a059b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 23 deletions.
51 changes: 30 additions & 21 deletions src/voc4cat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,17 @@
from rdflib.namespace import DCAT, DCTERMS, OWL, RDF, RDFS, SKOS, XSD, NamespaceManager

from voc4cat import config
from voc4cat.fields import Orcid, Ror

logger = logging.getLogger(__name__)

# It defined here the key string can be used in xlsx instead of an URI.
ORGANISATIONS = {
"NFDI4Cat": URIRef("http://example.org/nfdi4cat/"),
"LIKAT": URIRef("https://www.catalysis.de/"),
# from rdflib.vocexcel
"CGI": URIRef("https://linked.data.gov.au/org/cgi"),
"GA": URIRef("https://linked.data.gov.au/org/ga"),
"GGIC": URIRef("https://linked.data.gov.au/org/ggic"),
"LIKAT": URIRef("https://ror.org/029hg0311"),
# from rdflib.vocexcel (used in old tests)
"CGI": URIRef("https://linked.data.gov.au/org/cgi-gtwg"),
"GSQ": URIRef("https://linked.data.gov.au/org/gsq"),
"ICSM": URIRef("https://linked.data.gov.au/org/icsm"),
"DES": URIRef("https://linked.data.gov.au/org/des"),
"BITRE": URIRef("https://linked.data.gov.au/org/bitre"),
"CASA": URIRef("https://linked.data.gov.au/org/casa"),
"ATSB": URIRef("https://linked.data.gov.au/org/atsb"),
}

ORGANISATIONS_INVERSE = {uref: name for name, uref in ORGANISATIONS.items()}
Expand Down Expand Up @@ -155,8 +150,8 @@ class ConceptScheme(BaseModel):
description: str
created: datetime.date
modified: datetime.date = None
creator: str
publisher: str
creator: Ror | Orcid | str
publisher: Ror | str
provenance: str
version: str = None
custodian: str = None
Expand All @@ -165,9 +160,12 @@ class ConceptScheme(BaseModel):

@validator("creator")
def creator_must_be_from_list(cls, v):
if v not in ORGANISATIONS:
msg = f"Organisations must be selected from the Organisations list: {', '.join(ORGANISATIONS)}"
raise ValueError(msg)
if isinstance(v, str):
if v.startswith("http"):
return v
if v not in ORGANISATIONS:
msg = f"Creator must be an ORCID or ROR ID or a string from the organisations list: {', '.join(ORGANISATIONS)}"
raise ValueError(msg)
return v

@validator("modified")
Expand All @@ -178,9 +176,12 @@ def set_modified_date_if_missing(cls, v):

@validator("publisher")
def publisher_must_be_from_list(cls, v):
if v not in ORGANISATIONS:
msg = f"Organisations must be selected from the Organisations list: {', '.join(ORGANISATIONS)}"
raise ValueError(msg)
if isinstance(v, str):
if v.startswith("http"):
return v
if v not in ORGANISATIONS:
msg = f"Publisher must be an ROR ID or a string from the organisations list: {', '.join(ORGANISATIONS)}"
raise ValueError(msg)
return v

@validator("version")
Expand All @@ -206,9 +207,17 @@ def to_graph(self):
g.add((v, SKOS.prefLabel, Literal(self.title, lang="en")))
g.add((v, SKOS.definition, Literal(self.description, lang="en")))
g.add((v, DCTERMS.created, Literal(self.created, datatype=XSD.date)))
g.add((v, DCTERMS.modified, Literal(self.modified, datatype=XSD.date))),
g.add((v, DCTERMS.creator, ORGANISATIONS[self.creator]))
g.add((v, DCTERMS.publisher, ORGANISATIONS[self.publisher]))
g.add((v, DCTERMS.modified, Literal(self.modified, datatype=XSD.date)))
g.add(
(v, DCTERMS.creator, ORGANISATIONS.get(self.creator, URIRef(self.creator)))
)
g.add(
(
v,
DCTERMS.publisher,
ORGANISATIONS.get(self.publisher, URIRef(self.publisher)),
)
)
g.add((v, OWL.versionInfo, Literal(self.version)))
g.add((v, DCTERMS.provenance, Literal(self.provenance, lang="en")))
if self.custodian is not None:
Expand Down
Binary file modified tests/templ_versions/043_exhaustive_example.xlsx
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
cs: a skos:ConceptScheme ;
dcterms:identifier "exhaustive_concept_scheme_vocabulary_iri"^^xsd:token ;
dcterms:created "2022-03-07"^^xsd:date ;
dcterms:creator <https://linked.data.gov.au/org/cgi> ;
dcterms:creator <https://linked.data.gov.au/org/gsq> ;
dcterms:hasPart <http://example.org/example_collection_uri> ;
dcterms:modified "2022-03-10"^^xsd:date ;
dcterms:provenance "Example Provenance"@en ;
dcterms:publisher <https://linked.data.gov.au/org/cgi> ;
dcterms:publisher <https://linked.data.gov.au/org/cgi-gtwg> ;
rdfs:seeAlso "1.2.3.4" ;
owl:versionInfo "0.1" ;
skos:definition "Exhaustive Vocabulary Description"@en ;
Expand Down
39 changes: 39 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,45 @@ def test_vocabulary_valid_version_via_envvar():
assert cs.version == "v2023-08-15"


@mock.patch.dict(os.environ, {"CI": "", "VOC4CAT_VERSION": "v2023-08-15"})
def test_vocabulary_creator_orcid():
cs = ConceptScheme(
uri="https://linked.data.gov.au/def/borehole-start-point",
title="Borehole Start Point",
description="Indicates the nature of the borehole start point location",
created="2020-04-02",
modified="2020-04-04",
creator="0000-0001-2345-6789",
publisher="GSQ",
version="1.0",
provenance="Derived from the 2011-09 version of CGI Borehole start point list",
custodian="Vance Kelly",
pid="http://pid.geoscience.gov.au/dataset/ga/114541",
)
assert cs.creator == "https://orcid.org/0000-0001-2345-6789"


@mock.patch.dict(os.environ, {"CI": "", "VOC4CAT_VERSION": "v2023-08-15"})
def test_vocabulary_creator_invalid():
with pytest.raises(
ValidationError,
match="Creator must be an ORCID or ROR ID or a string from the organisations list",
):
ConceptScheme(
uri="https://linked.data.gov.au/def/borehole-start-point",
title="Borehole Start Point",
description="Indicates the nature of the borehole start point location",
created="2020-04-02",
modified="2020-04-04",
creator="abc",
publisher="https://ror.org/04fa4r544",
version="1.0",
provenance="Derived from the 2011-09 version of CGI Borehole start point list",
custodian="Vance Kelly",
pid="http://pid.geoscience.gov.au/dataset/ga/114541",
)


@mock.patch.dict(os.environ, {"CI": "", "VOC4CAT_VERSION": "2023-08-15"})
def test_vocabulary_invalid_version_via_envvar():
with pytest.raises(
Expand Down

0 comments on commit c7a059b

Please sign in to comment.