Skip to content

Commit

Permalink
Updated test_dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
jesper-friis committed Oct 14, 2024
1 parent b233c7e commit 8853893
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 31 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ mappings = [
"pint>=0.16.1,<0.24",
]
dataset = [
"pint>=0.16.1,<0.24",
"pint>=0.16.1,<0.24", # not used yet...
"PyYaml>=3.0.0,<6.0.3", # todo: check lower version
"requests>=2.0.0,<3.4.1", # todo: check lower version
]
Expand Down
67 changes: 39 additions & 28 deletions tests/dataset/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,32 @@ def test_save_and_load_dataset():
"""Test save_dataset() and load_dataset()."""
# pylint: disable=too-many-locals,invalid-name

import os

# from paths import inputdir, outputdir
from tripper import Triplestore
from tripper.dataset import load_datadoc
from tripper.dataset import load_datadoc, load_dataset, save_dataset

backend = "rdflib"
TRIPLESTORE_HOST = os.getenv("TRIPLESTORE_HOST", "localhost")
TRIPLESTORE_PORT = os.getenv("TRIPLESTORE_PORT", "3030")
fuseki_args = {
"backend": "fuseki",
"base_iri": "http://example.com/ontology#",
"triplestore_url": f"http://{TRIPLESTORE_HOST}:{TRIPLESTORE_PORT}",
"database": "openmodel",
}

# Connect to triplestore
if backend == "fuseki":
ts = Triplestore(**fuseki_args)
ts.remove_database(**fuseki_args)
else:
ts = Triplestore("rdflib")
ts = Triplestore("rdflib")

# Load data documentation
datadoc = load_datadoc(inputdir / "datasets.yaml")
assert isinstance(datadoc, dict)
assert "@context" in datadoc

# # Store dict representation of the dataset to triplestore
# ds = save_dataset(ts, dataset, prefixes=prefixes)
# repr1 = set(ts.triples())
#
# # Load back dict representation from the triplestore
# EX = ts.namespaces["ex"]
# d = load_dataset(ts, iri=EX.mydata)
#
prefixes = datadoc["prefixes"]
for dataset in datadoc["datasets"]:
ds = save_dataset(ts, dataset, prefixes=prefixes)
repr1 = set(ts.triples())

# Load back dict representation from the triplestore
SEMDATA = ts.namespaces["semdata"]
d = load_dataset(ts, iri=SEMDATA["sample3/pos1_01_grid_200x"])

# Should the prefix be expanded?
assert ds["@id"] == "semdata:sample3/pos1_01_grid_200x"

assert "semdata:sample3/pos1_01_grid_200x" in repr1
assert d["@id"] == (
"http://sintef.no/data/matchmaker/SEM/sample3/pos1_01_grid_200x"
)
# # Store the new dict representation to another triplestore
# ts2 = Triplestore("rdflib")
# ds2 = save_dataset(ts2, d)
Expand Down Expand Up @@ -89,3 +79,24 @@ def test_datadoc():
# ts2.close() # explicit close ts2

print(ts.serialize())


def test_fuseki():
"""Test save and load dataset with Fuseki."""
import os

from tripper import Triplestore

host = os.getenv("TRIPLESTORE_HOST", "localhost")
port = os.getenv("TRIPLESTORE_PORT", "3030")
fuseki_args = {
"backend": "fusekix",
"base_iri": "http://example.com/ontology#",
"triplestore_url": f"http://{host}:{port}",
"database": "openmodel",
}
try:
ts = Triplestore(**fuseki_args)
except ModuleNotFoundError:
pytest.skip("Cannot connect to Fuseki server")
ts.remove_database(**fuseki_args)
2 changes: 1 addition & 1 deletion tests/input/datasets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ datasets:
# Dataset type as defined in the SEM domain ontology
"@type": "https://w3id.com/emmo/domain/sem/0.1#"
title: SEM image of cement
description: Back-scattered SEM image of cement sample 3, polished with 1 µm diamond compound.
description: Back-scattered SEM image of cement sample 3, polished with 1 µm diamond compound.
creator: Sigurd Wenner
contactPoint: "Sigurd Wenner <[email protected]>"

Expand Down
2 changes: 1 addition & 1 deletion tripper/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# )

CONTEXT_PATH = (
Path(__file__).parent.parent / "context" / "0.1" / "context.json"
Path(__file__).parent.parent / "context" / "0.2" / "context.json"
).as_uri()

# __TODO__: Update URI when merged to master
Expand Down

0 comments on commit 8853893

Please sign in to comment.