Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion tests/datadoc/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_told():
# pylint: disable=too-many-statements
from pathlib import Path

from tripper import DCAT, DCTERMS, RDF, Triplestore
from tripper import DCAT, DCTERMS, OWL, RDF, RDFS, Triplestore
from tripper.datadoc.dataset import store, told
from tripper.datadoc.errors import InvalidDatadocError
from tripper.utils import en
Expand Down Expand Up @@ -229,6 +229,27 @@ def test_told():
d8 = told(descrH)
assert d8["@type"] == "owl:Class"

# A dataset type should remain a class and use datamodel as subclass.
descrI = {
"@id": "ex:TechnicalDataset",
"@type": "owl:Class",
"title": "Technical dataset type",
"datamodel": "ex:BaseDataModel",
}
d9 = told(descrI)
assert d9["@id"] == "ex:TechnicalDataset"
assert d9["@type"] == "owl:Class"
assert d9["datamodel"] == "ex:BaseDataModel"
assert d9["subClassOf"] == "ex:BaseDataModel"

# Test store() on descrI
ts.remove()
store(ts, descrI, prefixes=prefixes)
EX = ts.namespaces["ex"]
assert ts.has(EX.TechnicalDataset, RDF.type, OWL.Class)
assert ts.has(EX.TechnicalDataset, RDFS.subClassOf, EX.BaseDataModel)
assert not ts.has(EX.TechnicalDataset, RDF.type, EX.BaseDataModel)

# Multi-rep with invalid root keyword
descrG = {
"prefixes": {"laz": "http://lazarus.org/reincarnated/data"},
Expand Down
13 changes: 12 additions & 1 deletion tripper/datadoc/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,19 @@ def _deduplicate_types(d):
]
add(d, k, [tuple(t) for t in lst])
elif k == "datamodel":
add(d, "@type", v)
# Check if d is is of type @type owl:Class, if not, add the
# datamodel as a @type. Otherwise, the datamodel will be
# added as a subclass of the class.
is_class = OWL.Class in {
expand(t) if isinstance(t, str) else t
for t in asseq(get(d, "@type", ()))
}
if is_class:
add(d, "subClassOf", v)
else:
add(d, "@type", v)
d[k] = v

#
# The below works fine. It is commented out since it is doubtable
# whether it is a good idea to invent new shortcuts for json-ld.
Expand Down
Loading