Skip to content

Commit

Permalink
Bugfix dumping jsonld with file semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasprobst committed Nov 5, 2024
1 parent bf0dd51 commit 3dfb0a7
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "https://spdx.org/licenses/MIT",
"codeRepository": "git+https://github.com/matthiasprobst/h5RDMtoolbox.git",
"name": "h5RDMtoolbox",
"version": "1.5.2",
"version": "1.5.3",
"description": "Supporting a FAIR Research Data lifecycle using Python and HDF5.",
"applicationCategory": "Engineering",
"programmingLanguage": [
Expand Down
4 changes: 2 additions & 2 deletions docs/colab/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"outputs": [],
"source": [
"# !pip install h5rdmtoolbox==1.5.2"
"# !pip install h5rdmtoolbox==1.5.3"
]
},
{
Expand All @@ -19,7 +19,7 @@
{
"data": {
"text/plain": [
"'1.5.2'"
"'1.5.3'"
]
},
"execution_count": 2,
Expand Down
7 changes: 6 additions & 1 deletion h5rdmtoolbox/wrapper/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2285,7 +2285,12 @@ def rdf(self):

@property
def frdf(self):
"""Return File RDF Manager"""
"""Via the File RDF Manager, semantic properties can be associated with the file rather than the
root group. If you want to describe a root attribute semantically, use `.rdf` instead.
.. versionadded:: 1.5.3
Explanation of the new feature, or additional notes if necessary.
"""
return rdf.FileRDFManager(self.attrs)

@property
Expand Down
4 changes: 2 additions & 2 deletions h5rdmtoolbox/wrapper/jsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,9 @@ def _add_hdf_node(name, obj, ctx) -> Dict:
# node = rdflib.URIRef(f'_:{obj.name}')
if isinstance(obj, h5py.File):
file_node = rdflib.BNode(value=f'N{next(_bnode_counter)}') if use_simple_bnode_value else rdflib.BNode()
iri_dict['.'] = file_node
_add_node(g, (file_node, RDF.type, HDF5.File))
if structural:
iri_dict['.'] = file_node
_add_node(g, (file_node, RDF.type, HDF5.File))
root_group = rdflib.BNode(
value=f'N{next(_bnode_counter)}') if use_simple_bnode_value else rdflib.BNode()
iri_dict[name] = root_group
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = h5rdmtoolbox
version = 1.5.2
version = 1.5.3
author = Matthias Probst
author_email = matth.probst@gmail.com
description = Supporting a FAIR Research Data lifecycle using Python and HDF5.
Expand Down
9 changes: 5 additions & 4 deletions tests/wrapper/test_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ def test_dump_jsonld(self):
ret = h5tbx.dump_jsonld(h5.hdf_filename, structural=False, resolve_keys=True, compact=False,
context={'foaf': 'http://xmlns.com/foaf/0.1/'})
jsondict = json.loads(ret)
self.assertEqual(jsondict["@graph"][1]['foaf:firstName'], 'John')
self.assertEqual(jsondict["@graph"][1]['@type'], 'prov:Person')
print(jsondict)
self.assertEqual(jsondict['foaf:firstName'], 'John')
self.assertEqual(jsondict['@type'], 'prov:Person')

ret = h5tbx.dump_jsonld(h5.hdf_filename, structural=False, resolve_keys=False)
jsondict = json.loads(ret)
self.assertEqual(jsondict["@graph"][1]['fname'], 'John')
self.assertEqual(jsondict["@graph"][1]['@type'], 'prov:Person')
self.assertEqual(jsondict['fname'], 'John')
self.assertEqual(jsondict['@type'], 'prov:Person')

ret = h5tbx.dump_jsonld(h5.hdf_filename, structural=True, resolve_keys=False, compact=False)
jsondict = json.loads(ret)
Expand Down
11 changes: 7 additions & 4 deletions tests/wrapper/test_rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,10 @@ def test_using_plain_jsonld(self):
h5.dump(False)
h5jld = h5.dump_jsonld(indent=2, structural=False)
h5jld_dict = json.loads(h5jld)
self.assertDictEqual(h5jld_dict["@context"],
{"ssno": "https://matthiasprobst.github.io/ssno#",
"ex": "https://example.org/",
"standard_name": "https://matthiasprobst.github.io/ssno#hasStandardName"})
self.assertDictEqual(
h5jld_dict["@context"],
{"ssno": "https://matthiasprobst.github.io/ssno#",
"ex": "https://example.org/",
"hdf5": "http://purl.allotrope.org/ontologies/hdf5/1.8#",
"standard_name": "https://matthiasprobst.github.io/ssno#hasStandardName"}
)

0 comments on commit 3dfb0a7

Please sign in to comment.