-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New TableDoc class providing a table interface for data documentation (…
…#273) # Description Added the TableDoc class providing a table interface for data documentation. --------- Co-authored-by: Tor S. Haugland <torshaugland@gmail.com>
- Loading branch information
1 parent
f040624
commit c84bae1
Showing
11 changed files
with
296 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# tabledoc | ||
|
||
::: tripper.dataset.tabledoc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""Defines paths for tests. | ||
It defines some directories and some utility functions that can be used | ||
with or without conftest. | ||
""" | ||
|
||
from pathlib import Path | ||
|
||
testdir = Path(__file__).resolve().parent.parent | ||
ontodir = testdir / "ontologies" | ||
indir = testdir / "input" | ||
outdir = testdir / "output" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
"""Test the TableDoc class.""" | ||
|
||
import pytest | ||
|
||
|
||
# if True: | ||
def test_as_dicts(): | ||
"""Test the as_dicts() method.""" | ||
|
||
pytest.importorskip("rdflib") | ||
|
||
from tripper import DCAT, EMMO, Namespace, Triplestore | ||
from tripper.dataset import TableDoc | ||
|
||
ONTO = Namespace("http:/example.com/onto#") | ||
DS = Namespace("http:/example.com/datasets#") | ||
|
||
td = TableDoc( | ||
header=[ | ||
"@id", | ||
"@type", | ||
"@type", | ||
"inSeries", | ||
"distribution.downloadURL", | ||
], | ||
data=[ | ||
("ds:s1", "onto:T1", "onto:T2", None, "file:///data/"), | ||
("ds:d1", "onto:T1", None, "ds:s1", "file:///data/d1.txt"), | ||
("ds:d2", "onto:T2", None, "ds:s1", "file:///data/d2.txt"), | ||
], | ||
prefixes={ | ||
"onto": "http:/example.com/onto#", | ||
"ds": "http:/example.com/datasets#", | ||
}, | ||
# Replace the "ds" prefix above with this, once the "context" keyword | ||
# argument is fully implemented. | ||
# context={ | ||
# "ds": "http:/example.com/datasets#", | ||
# }, | ||
) | ||
|
||
s1, d1, d2 = td.asdicts() # pylint: disable=unbalanced-tuple-unpacking | ||
|
||
assert s1["@id"] == DS.s1 | ||
assert set(s1["@type"]) == { | ||
DCAT.Dataset, | ||
EMMO.DataSet, | ||
ONTO.T1, | ||
ONTO.T2, | ||
} | ||
assert "inSeries" not in s1 | ||
assert s1.distribution == { | ||
"@type": DCAT.Distribution, | ||
"downloadURL": "file:///data/", | ||
} | ||
|
||
assert d1["@id"] == DS.d1 | ||
assert set(d1["@type"]) == { | ||
DCAT.Dataset, | ||
EMMO.DataSet, | ||
ONTO.T1, | ||
} | ||
assert d1.inSeries == DS.s1 | ||
assert d1.distribution == { | ||
"@type": DCAT.Distribution, | ||
"downloadURL": "file:///data/d1.txt", | ||
} | ||
|
||
assert d2["@id"] == DS.d2 | ||
assert set(d2["@type"]) == { | ||
DCAT.Dataset, | ||
EMMO.DataSet, | ||
ONTO.T2, | ||
} | ||
assert d2.inSeries == DS.s1 | ||
assert d2.distribution == { | ||
"@type": DCAT.Distribution, | ||
"downloadURL": "file:///data/d2.txt", | ||
} | ||
|
||
ts = Triplestore(backend="rdflib") | ||
td.save(ts) | ||
print(ts.serialize()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@id;@type;title;description;creator;contactPoint;inSeries;datamodel;datamodelStorage;distribution.downloadURL;distribution.mediaType;distribution.parser;fromSample;isDescriptionOf | ||
semdata:SEM_cement_batch2/77600-23-001/77600-23-001_5kV_400x_m001;sem:SEMImage;SEM image of cement;Back-scattered SEM image of cement sample 77600 from Heidelberg, polished with 1 �m diamond compound.;Sigurd Wenner;Sigurd Wenner <Sigurd.Wenner@sintef.no>;semdata:SEM_cement_batch2/77600-23-001;http://onto-ns.com/meta/matchmaker/0.2/SEMImage;https://github.com/HEU-MatCHMaker/DataDocumentation/blob/master/SEM/datamodels/SEMImage.yaml;https://github.com/EMMC-ASBL/tripper/raw/refs/heads/dataset/tests/input/77600-23-001_5kV_400x_m001.tif;image/tiff;parser:sem_hitachi;sample:SEM_cement_batch2/77600-23-001;mat:concrete1 | ||
semdata:SEM_cement_batch2/77600-23-001;sem:SEMImageSeries;Series of SEM image of cement sample 77600;Back-scattered SEM image of cement sample 77600, polished with 1 �m diamond compound.;Sigurd Wenner;Sigurd Wenner <Sigurd.Wenner@sintef.no>;semdata:SEM_cement_batch2; ;;sftp://nas.aimen.es/P_MATCHMAKER_SHARE_SINTEF/SEM_cement_batch2/77600-23-001;inode/directory;;; | ||
semdata:SEM_cement_batch2;sem:SEMImageSeries;Nested series of SEM images of cement batch2;�;Sigurd Wenner;Sigurd Wenner <Sigurd.Wenner@sintef.no>; ;;;sftp://nas.aimen.es/P_MATCHMAKER_SHARE_SINTEF/SEM_cement_batch2;inode/directory;;; | ||
mple:SEM_cement_batch2/77600-23-001;chameo:Sample;Series for SEM images for sample 77600-23-001.; ;;;;;;;;;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ | |
save_dict, | ||
search_iris, | ||
) | ||
from .tabledoc import TableDoc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.