h5rdmtoolbox 2.6.1__tar.gz → 2.7.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/LICENSE +1 -1
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/PKG-INFO +1 -1
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/__init__.py +4 -1
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/catalog/__init__.py +3 -1
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/catalog/_initialization.py +2 -1
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/catalog/utils.py +12 -34
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/convention/references.py +7 -1
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/ld/__init__.py +7 -3
- h5rdmtoolbox-2.7.0/h5rdmtoolbox/ld/_types.py +11 -0
- h5rdmtoolbox-2.7.0/h5rdmtoolbox/ld/hdf/attributes.py +57 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/ld/user/attributes.py +6 -4
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/ld/user/datasets.py +3 -1
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/ld/user/file.py +11 -4
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/ld/user/groups.py +9 -4
- h5rdmtoolbox-2.7.0/h5rdmtoolbox/ld/user/utils.py +33 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/ld/utils.py +21 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/protocols.py +2 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/repository/zenodo/core.py +1 -1
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/utils.py +4 -5
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/wrapper/core.py +5 -2
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox.egg-info/PKG-INFO +1 -1
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox.egg-info/SOURCES.txt +1 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/pyproject.toml +1 -1
- h5rdmtoolbox-2.6.1/h5rdmtoolbox/ld/hdf/attributes.py +0 -33
- h5rdmtoolbox-2.6.1/h5rdmtoolbox/ld/user/utils.py +0 -8
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/README.md +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/_cfg.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/_repr.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/_version.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/catalog/abstracts.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/catalog/core.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/catalog/profiles.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/catalog/query_templates.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/catalog/stores/__init__.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/catalog/stores/hdf5.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/cli.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/consts.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/convention/__init__.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/convention/cfg.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/convention/consts.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/convention/core.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/convention/errors.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/convention/generate.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/convention/ontology/__init__.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/convention/ontology/h5ontocls.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/convention/ontology/hdf_datatypes.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/convention/standard_attributes.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/convention/toolbox_validators.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/convention/utils.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/data/def_icon.png +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/data/fluid-v1.yml +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/data/h5tbx.yaml +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/data/id_icon.png +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/data/iri_icon.png +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/data/ld_icon.png +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/data/piv-v1.yml +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/data/style.css +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/data/tutorial_convention.yaml +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/data/tutorial_convention_vfuncs.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/data/tutorial_standard_name_table.yaml +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/data/type_icon.png +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/database/__init__.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/database/hdfdb/__init__.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/database/hdfdb/filedb.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/database/hdfdb/objdb.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/database/hdfdb/query.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/database/hdfdb/utils.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/database/interface.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/database/lazy.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/database/mongo.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/errors.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/extensions/__init__.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/extensions/magnitude.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/extensions/normalize.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/extensions/onto.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/extensions/units.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/extensions/vector.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/gui/__init__.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/gui/fairify.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/gui/src/__init__.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/gui/src/main.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/identifiers.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/layout/__init__.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/layout/core.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/ld/globals.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/ld/hdf/__init__.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/ld/hdf/datasets.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/ld/hdf/file.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/ld/hdf/groups.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/ld/rdf.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/ld/shacl.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/ld/user/__init__.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/plotting.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/protected_attributes.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/repository/__init__.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/repository/default_metamapper.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/repository/interface.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/repository/utils.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/repository/zenodo/__init__.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/repository/zenodo/metadata.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/repository/zenodo/tokens.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/repository/zenodo/utils.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/tutorial.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/user.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/wrapper/__init__.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/wrapper/accessor.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/wrapper/accessors/__init__.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/wrapper/accessors/provenance.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/wrapper/ds_decoder.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/wrapper/h5attr.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/wrapper/h5ext.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/wrapper/h5utils.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/wrapper/h5yaml.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/wrapper/jsonld.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/wrapper/xr2hdf.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox.egg-info/dependency_links.txt +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox.egg-info/entry_points.txt +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox.egg-info/requires.txt +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox.egg-info/top_level.txt +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/setup.cfg +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/tests/test_cli.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/tests/test_config.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/tests/test_extensions.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/tests/test_identifiers.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/tests/test_plotting.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/tests/test_readme.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/tests/test_repr.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/tests/test_user.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/tests/test_utils.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/tests/test_version.py +0 -0
- {h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/tests/test_xarray_export.py +0 -0
|
@@ -55,6 +55,7 @@ import json
|
|
|
55
55
|
from .wrapper.accessor import register_accessor
|
|
56
56
|
|
|
57
57
|
from .ld.shacl import validate_hdf, ValidationResult
|
|
58
|
+
from .ld._types import RDFMappingEntry
|
|
58
59
|
# noinspection PyUnresolvedReferences
|
|
59
60
|
from .utils import DownloadFileManager
|
|
60
61
|
|
|
@@ -282,6 +283,7 @@ def serialize(hdf_filename,
|
|
|
282
283
|
structural: bool = True,
|
|
283
284
|
contextual: bool = True,
|
|
284
285
|
file_uri: Optional[str] = None,
|
|
286
|
+
rdf_mappings: Dict[str, RDFMappingEntry] = None,
|
|
285
287
|
**kwargs):
|
|
286
288
|
"""Alternative to json-ld but allows multiple serialization options"""
|
|
287
289
|
fmt = kwargs.pop("format", fmt)
|
|
@@ -290,7 +292,8 @@ def serialize(hdf_filename,
|
|
|
290
292
|
skipND=skipND,
|
|
291
293
|
structural=structural,
|
|
292
294
|
contextual=contextual,
|
|
293
|
-
file_uri=file_uri
|
|
295
|
+
file_uri=file_uri,
|
|
296
|
+
rdf_mappings=rdf_mappings)
|
|
294
297
|
|
|
295
298
|
|
|
296
299
|
def build_pyvis_graph(hdf_filename, output_filename="kg-graph.html", notebook=False,
|
|
@@ -117,7 +117,9 @@ def _download_catalog_datasets(
|
|
|
117
117
|
f"Found {n_ttl_resources} TTL web resources to download. Downloading to {download_directory}..."
|
|
118
118
|
)
|
|
119
119
|
return download(
|
|
120
|
-
download_directory=download_directory,
|
|
120
|
+
download_directory=download_directory,
|
|
121
|
+
web_resources=list_of_ttl_web_resources,
|
|
122
|
+
use_agent_header=True
|
|
121
123
|
)
|
|
122
124
|
|
|
123
125
|
|
|
@@ -84,5 +84,6 @@ def database_initialization(
|
|
|
84
84
|
f"Found {len(list_of_ttl_web_resources)} TTL web resources to download. Downloading to {download_directory}...")
|
|
85
85
|
return download(
|
|
86
86
|
download_directory=download_directory,
|
|
87
|
-
web_resources=list_of_ttl_web_resources
|
|
87
|
+
web_resources=list_of_ttl_web_resources,
|
|
88
|
+
use_agent_header=True
|
|
88
89
|
)
|
|
@@ -17,6 +17,7 @@ from pydantic.v1 import HttpUrl
|
|
|
17
17
|
from rdflib import Graph
|
|
18
18
|
|
|
19
19
|
from .. import logger
|
|
20
|
+
from .._version import __version__
|
|
20
21
|
|
|
21
22
|
# --- minimal caster for common XSD datatypes ---
|
|
22
23
|
_XSD = "http://www.w3.org/2001/XMLSchema#"
|
|
@@ -28,6 +29,10 @@ _NUM_DT = {
|
|
|
28
29
|
_FLOAT_DT = {_XSD + "float", _XSD + "double"}
|
|
29
30
|
_DEC_DT = {_XSD + "decimal"}
|
|
30
31
|
|
|
32
|
+
USER_AGENT_HEADER = {
|
|
33
|
+
"User-Agent": f"h5rdmtoolbox/{__version__} (https://github.com/matthiasprobst/h5rdmtoolbox)",
|
|
34
|
+
}
|
|
35
|
+
|
|
31
36
|
|
|
32
37
|
def file_uri_or_path_to_path(value) -> pathlib.Path:
|
|
33
38
|
# Keep behavior close to your code
|
|
@@ -190,40 +195,8 @@ def extract_record_id(value: str) -> str:
|
|
|
190
195
|
raise ValueError(f"Could not extract a numeric record ID from '{value}'")
|
|
191
196
|
|
|
192
197
|
|
|
193
|
-
def get_file_metadata(record: str, sandbox: bool = False) -> Iterator[Tuple[str, Dict]]:
|
|
194
|
-
"""
|
|
195
|
-
Fetch the Zenodo record JSON and yield (filename, file-metadata-dict) tuples.
|
|
196
|
-
"""
|
|
197
|
-
record_id = extract_record_id(record)
|
|
198
|
-
base_url = "https://sandbox.zenodo.org/api/records" if sandbox else "https://zenodo.org/api/records"
|
|
199
|
-
url = f"{base_url}/{record_id}"
|
|
200
|
-
|
|
201
|
-
resp = requests.get(url)
|
|
202
|
-
if resp.status_code != 200:
|
|
203
|
-
raise RuntimeError(
|
|
204
|
-
f"Failed to fetch record {record_id}: HTTP {resp.status_code} - {resp.text}"
|
|
205
|
-
)
|
|
206
198
|
|
|
207
|
-
data = resp.json()
|
|
208
199
|
|
|
209
|
-
# Zenodo records normally have 'files' at the top level
|
|
210
|
-
files = data.get("files", [])
|
|
211
|
-
|
|
212
|
-
if not files:
|
|
213
|
-
# Some records may store file info differently; handle gracefully
|
|
214
|
-
raise RuntimeError(f"No files found in record {record_id} (or unexpected schema).")
|
|
215
|
-
|
|
216
|
-
for f in files:
|
|
217
|
-
# Common fields in Zenodo API
|
|
218
|
-
name = f.get("key") or f.get("filename") or "<unknown>"
|
|
219
|
-
yield name, f
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
def _is_sandbox_doi(doi: str) -> bool:
|
|
223
|
-
"""Return True if the provided doi string looks like a sandbox URL/DOI."""
|
|
224
|
-
if "10.5281/zenodo" in doi:
|
|
225
|
-
return True
|
|
226
|
-
return False
|
|
227
200
|
|
|
228
201
|
|
|
229
202
|
def download_and_verify_file(file_meta: Dict, dest_dir: pathlib.Path) -> Tuple[pathlib.Path, bool, str, str]:
|
|
@@ -312,7 +285,8 @@ def parse_checksum(raw: str) -> Tuple[str, str]:
|
|
|
312
285
|
return algo.lower(), val.lower()
|
|
313
286
|
|
|
314
287
|
|
|
315
|
-
def download(download_directory: pathlib.Path, web_resources: List[WebResource]) -> List[
|
|
288
|
+
def download(download_directory: pathlib.Path, web_resources: List[WebResource], use_agent_header=True) -> List[
|
|
289
|
+
DownloadStatus]:
|
|
316
290
|
"""Download and verify a list of WebResource items.
|
|
317
291
|
|
|
318
292
|
For each resource:
|
|
@@ -403,7 +377,11 @@ def download(download_directory: pathlib.Path, web_resources: List[WebResource])
|
|
|
403
377
|
# stream download to tmp file while computing md5
|
|
404
378
|
tmp_path = record_dir / (filename + ".tmp")
|
|
405
379
|
try:
|
|
406
|
-
|
|
380
|
+
if use_agent_header:
|
|
381
|
+
kwargs_request = {"headers": USER_AGENT_HEADER}
|
|
382
|
+
else:
|
|
383
|
+
kwargs_request = {}
|
|
384
|
+
resp = requests.get(url, stream=True, timeout=60, **kwargs_request)
|
|
407
385
|
resp.raise_for_status()
|
|
408
386
|
|
|
409
387
|
md5 = hashlib.md5()
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import requests
|
|
2
2
|
|
|
3
|
+
from h5rdmtoolbox import __version__
|
|
4
|
+
|
|
5
|
+
USER_AGENT_HEADER = {
|
|
6
|
+
"User-Agent": f"h5rdmtoolbox/{__version__} (https://github.com/matthiasprobst/h5rdmtoolbox)",
|
|
7
|
+
}
|
|
8
|
+
|
|
3
9
|
|
|
4
10
|
def validate_url(url: str) -> bool:
|
|
5
11
|
"""Validate URL
|
|
@@ -15,7 +21,7 @@ def validate_url(url: str) -> bool:
|
|
|
15
21
|
True if URL
|
|
16
22
|
"""
|
|
17
23
|
try:
|
|
18
|
-
response = requests.get(url)
|
|
24
|
+
response = requests.get(url, headers=USER_AGENT_HEADER)
|
|
19
25
|
except requests.exceptions.MissingSchema:
|
|
20
26
|
return False
|
|
21
27
|
if response.status_code == 200:
|
|
@@ -4,18 +4,21 @@ from typing import Union, Optional, Dict
|
|
|
4
4
|
import h5py
|
|
5
5
|
import rdflib
|
|
6
6
|
|
|
7
|
+
from ._types import RDFMappingEntry
|
|
7
8
|
from .hdf.file import get_ld as get_hdf_ld
|
|
8
9
|
from .user.file import get_ld as get_contextual_ld
|
|
9
10
|
from .utils import optimize_context
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
BINARY_AS_STRING=True
|
|
12
13
|
def get_ld(
|
|
13
14
|
hdf_filename: Union[str, pathlib.Path],
|
|
14
15
|
structural: bool = True,
|
|
15
16
|
contextual: bool = True,
|
|
16
17
|
file_uri: Optional[str] = None,
|
|
17
18
|
skipND: Optional[int] = 1,
|
|
18
|
-
context: Optional[Dict] = None
|
|
19
|
+
context: Optional[Dict] = None,
|
|
20
|
+
rdf_mappings: Dict[str, RDFMappingEntry] = None
|
|
21
|
+
) -> rdflib.Graph:
|
|
19
22
|
"""Return the HDF file content as a rdflib.Graph object."""
|
|
20
23
|
if file_uri and not (str(file_uri).endswith("#") or str(file_uri).endswith("/")):
|
|
21
24
|
raise ValueError("file_uri must end with '#' or '/'")
|
|
@@ -23,7 +26,8 @@ def get_ld(
|
|
|
23
26
|
with h5py.File(hdf_filename) as h5:
|
|
24
27
|
if contextual and structural:
|
|
25
28
|
graph1 = get_hdf_ld(h5, file_uri=file_uri, skipND=skipND)
|
|
26
|
-
graph2 = get_contextual_ld(h5, file_uri=file_uri
|
|
29
|
+
graph2 = get_contextual_ld(h5, file_uri=file_uri,
|
|
30
|
+
rdf_mappings=rdf_mappings)
|
|
27
31
|
graph = graph1 + graph2
|
|
28
32
|
else:
|
|
29
33
|
if structural:
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from typing import Callable, Optional, Any
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, Field
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class RDFMappingEntry(BaseModel):
|
|
7
|
+
predicate: Optional[Any] = Field(None, description="Predicate IRI or rdflib term")
|
|
8
|
+
object: Optional[Callable[[Any], Any]] = Field(None, description="Function to generate object value")
|
|
9
|
+
|
|
10
|
+
class Config:
|
|
11
|
+
arbitrary_types_allowed = True
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import warnings
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
from ontolutils.namespacelib.hdf5 import HDF5
|
|
5
|
+
from rdflib import Namespace, Literal, XSD, RDF
|
|
6
|
+
|
|
7
|
+
from ..utils import get_attr_node, to_literal
|
|
8
|
+
|
|
9
|
+
HDF = Namespace(str(HDF5))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def process_attribute(*, name, value, graph, parent, parent_uri, blank_node_iri_base):
|
|
13
|
+
"""Process an HDF5 attribute, adding it to the RDF graph."""
|
|
14
|
+
if name.isupper() or name.startswith('@'):
|
|
15
|
+
return
|
|
16
|
+
attr_uri = get_attr_node(
|
|
17
|
+
parent,
|
|
18
|
+
name,
|
|
19
|
+
blank_node_iri_base
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
if isinstance(value, str):
|
|
23
|
+
graph.add((attr_uri, RDF.type, HDF5.StringAttribute))
|
|
24
|
+
if isinstance(value, bytes):
|
|
25
|
+
value = value.decode('utf-8', errors='ignore')
|
|
26
|
+
graph.add((attr_uri, HDF.data, to_literal(value)))
|
|
27
|
+
elif isinstance(value, int):
|
|
28
|
+
graph.add((attr_uri, RDF.type, HDF5.IntegerAttribute))
|
|
29
|
+
graph.add((attr_uri, HDF.data, Literal(value, datatype=XSD.integer)))
|
|
30
|
+
elif isinstance(value, float):
|
|
31
|
+
graph.add((attr_uri, RDF.type, HDF5.FloatAttribute))
|
|
32
|
+
graph.add((attr_uri, HDF.data, Literal(value, datatype=XSD.float)))
|
|
33
|
+
elif isinstance(value, np.ndarray):
|
|
34
|
+
if value.ndim == 1:
|
|
35
|
+
for v in value:
|
|
36
|
+
graph.add((attr_uri, HDF.data, to_literal(v)))
|
|
37
|
+
if value.dtype.kind in {'i', 'u'}:
|
|
38
|
+
graph.add((attr_uri, RDF.type, HDF5.IntegerAttribute))
|
|
39
|
+
elif value.dtype.kind == 'f':
|
|
40
|
+
graph.add((attr_uri, RDF.type, HDF5.FloatAttribute))
|
|
41
|
+
else:
|
|
42
|
+
graph.add((attr_uri, RDF.type, HDF5.Attribute))
|
|
43
|
+
else:
|
|
44
|
+
warnings.warn(f"Attribute data containing more than one dimension is not fully supported.")
|
|
45
|
+
graph.add((attr_uri, RDF.type, HDF5.Attribute))
|
|
46
|
+
graph.add((attr_uri, HDF.data, to_literal(value)))
|
|
47
|
+
else:
|
|
48
|
+
# attributes that are string bytes should be HDF5.StringAttribute
|
|
49
|
+
if isinstance(value, bytes):
|
|
50
|
+
value = value.decode('utf-8', errors='ignore')
|
|
51
|
+
graph.add((attr_uri, RDF.type, HDF5.StringAttribute))
|
|
52
|
+
else:
|
|
53
|
+
graph.add((attr_uri, RDF.type, HDF5.Attribute))
|
|
54
|
+
graph.add((attr_uri, HDF.data, to_literal(value)))
|
|
55
|
+
|
|
56
|
+
graph.add((attr_uri, HDF.name, Literal(name)))
|
|
57
|
+
graph.add((parent_uri, HDF.attribute, attr_uri))
|
|
@@ -9,7 +9,7 @@ from ontolutils import SCHEMA
|
|
|
9
9
|
from ontolutils.classes.thing import is_url
|
|
10
10
|
from rdflib import RDF, DCTERMS, XSD, URIRef, Literal, Graph, BNode
|
|
11
11
|
|
|
12
|
-
from h5rdmtoolbox.ld.utils import get_attr_dtype_as_xsd, get_obj_bnode
|
|
12
|
+
from h5rdmtoolbox.ld.utils import get_attr_dtype_as_xsd, get_obj_bnode, to_literal
|
|
13
13
|
from .utils import to_uriref
|
|
14
14
|
from ..rdf import FileRDFManager, RDFManager
|
|
15
15
|
|
|
@@ -230,9 +230,11 @@ def process_attribute(parent_obj, name, data, graph, blank_node_iri_base):
|
|
|
230
230
|
)
|
|
231
231
|
else:
|
|
232
232
|
graph.add(
|
|
233
|
-
(
|
|
234
|
-
|
|
235
|
-
|
|
233
|
+
(
|
|
234
|
+
parent_uri,
|
|
235
|
+
to_uriref(rdf_user_predicate, blank_node_iri_base),
|
|
236
|
+
to_literal(data)
|
|
237
|
+
) # Literal(data, datatype=get_attr_dtype_as_xsd(data)))
|
|
236
238
|
)
|
|
237
239
|
return _graph
|
|
238
240
|
|
|
@@ -4,14 +4,16 @@ from ontolutils.namespacelib import SCHEMA
|
|
|
4
4
|
from h5rdmtoolbox.ld.rdf import PROTECTED_ATTRIBUTE_NAMES
|
|
5
5
|
from h5rdmtoolbox.ld.user.attributes import process_attribute
|
|
6
6
|
from h5rdmtoolbox.ld.utils import get_obj_bnode
|
|
7
|
+
from .utils import apply_rdf_mappings
|
|
7
8
|
from ..rdf import RDFManager
|
|
8
9
|
|
|
9
10
|
|
|
10
|
-
def process_dataset(dataset, graph, blank_node_iri_base=None):
|
|
11
|
+
def process_dataset(*, dataset, graph, rdf_mappings, blank_node_iri_base=None):
|
|
11
12
|
dataset_uri = get_obj_bnode(dataset, blank_node_iri_base=blank_node_iri_base)
|
|
12
13
|
for ak, av in dataset.attrs.items():
|
|
13
14
|
if ak not in PROTECTED_ATTRIBUTE_NAMES:
|
|
14
15
|
process_attribute(dataset, ak, av, graph, blank_node_iri_base=blank_node_iri_base)
|
|
16
|
+
apply_rdf_mappings(dataset, dataset_uri, graph, rdf_mappings)
|
|
15
17
|
|
|
16
18
|
rdf_type = RDFManager(dataset.attrs).type
|
|
17
19
|
if rdf_type is not None:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from typing import Optional
|
|
1
|
+
from typing import Optional, Dict
|
|
2
2
|
from typing import Union
|
|
3
3
|
|
|
4
4
|
import h5py
|
|
@@ -12,16 +12,21 @@ from h5rdmtoolbox.ld.user.attributes import process_file_attribute
|
|
|
12
12
|
from h5rdmtoolbox.ld.user.groups import process_group
|
|
13
13
|
from h5rdmtoolbox.ld.utils import get_file_bnode
|
|
14
14
|
from .utils import to_uriref
|
|
15
|
+
from .._types import RDFMappingEntry
|
|
15
16
|
from ..rdf import FileRDFManager
|
|
17
|
+
from .utils import apply_rdf_mappings
|
|
16
18
|
|
|
17
19
|
HDF = Namespace(str(HDF5))
|
|
18
20
|
|
|
19
21
|
|
|
20
22
|
def get_ld(
|
|
21
23
|
source: Union[str, h5py.File],
|
|
22
|
-
file_uri: Optional[str] = None
|
|
24
|
+
file_uri: Optional[str] = None,
|
|
25
|
+
rdf_mappings: Dict[str, RDFMappingEntry] = None
|
|
26
|
+
) -> rdflib.Graph:
|
|
23
27
|
"""Convert an HDF5 file into an RDF graph."""
|
|
24
|
-
|
|
28
|
+
if rdf_mappings is None:
|
|
29
|
+
rdf_mappings = {}
|
|
25
30
|
if not isinstance(source, h5py.File):
|
|
26
31
|
with h5py.File(source) as h5f:
|
|
27
32
|
return get_ld(h5f, file_uri=file_uri)
|
|
@@ -53,6 +58,8 @@ def get_ld(
|
|
|
53
58
|
for ak, av in source.attrs.items():
|
|
54
59
|
process_file_attribute(source, ak, av, graph, file_node, blank_node_iri_base=file_uri)
|
|
55
60
|
|
|
56
|
-
|
|
61
|
+
apply_rdf_mappings(source, file_node, graph, rdf_mappings)
|
|
62
|
+
|
|
63
|
+
process_group(group=source, graph=graph, blank_node_iri_base=file_uri, rdf_mappings=rdf_mappings)
|
|
57
64
|
|
|
58
65
|
return graph
|
|
@@ -8,15 +8,18 @@ from ontolutils.namespacelib import SCHEMA
|
|
|
8
8
|
from h5rdmtoolbox.ld.user.attributes import process_attribute
|
|
9
9
|
from h5rdmtoolbox.ld.user.datasets import process_dataset
|
|
10
10
|
from h5rdmtoolbox.ld.utils import get_obj_bnode, get_file_bnode
|
|
11
|
+
from .utils import apply_rdf_mappings
|
|
11
12
|
from .utils import to_uriref
|
|
12
13
|
from ..rdf import RDFManager
|
|
13
14
|
|
|
14
15
|
|
|
15
|
-
def process_group(group, graph, blank_node_iri_base: Optional[str] = None):
|
|
16
|
+
def process_group(*, group, graph, rdf_mappings, blank_node_iri_base: Optional[str] = None):
|
|
17
|
+
group_uri = get_obj_bnode(group, blank_node_iri_base)
|
|
18
|
+
|
|
16
19
|
for ak, av in group.attrs.items():
|
|
17
20
|
process_attribute(group, ak, av, graph, blank_node_iri_base)
|
|
21
|
+
apply_rdf_mappings(group, group_uri, graph, rdf_mappings)
|
|
18
22
|
|
|
19
|
-
group_uri = get_obj_bnode(group, blank_node_iri_base)
|
|
20
23
|
rdf_manager = RDFManager(group.attrs)
|
|
21
24
|
parent_rdf_manager = RDFManager(group.parent.attrs) if group.parent is not None else None
|
|
22
25
|
rdf_type = rdf_manager.type
|
|
@@ -57,7 +60,9 @@ def process_group(group, graph, blank_node_iri_base: Optional[str] = None):
|
|
|
57
60
|
# graph.add((group_uri, HDF.member, sub_group_or_dataset_uri))
|
|
58
61
|
|
|
59
62
|
if isinstance(sub_group_or_dataset, h5py.Group):
|
|
60
|
-
process_group(sub_group_or_dataset, graph,
|
|
63
|
+
process_group(group=sub_group_or_dataset, graph=graph, rdf_mappings=rdf_mappings,
|
|
64
|
+
blank_node_iri_base=blank_node_iri_base)
|
|
61
65
|
|
|
62
66
|
elif isinstance(sub_group_or_dataset, h5py.Dataset):
|
|
63
|
-
process_dataset(sub_group_or_dataset, graph,
|
|
67
|
+
process_dataset(dataset=sub_group_or_dataset, graph=graph, rdf_mappings=rdf_mappings,
|
|
68
|
+
blank_node_iri_base=blank_node_iri_base)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import rdflib
|
|
2
|
+
from rdflib import URIRef
|
|
3
|
+
|
|
4
|
+
from h5rdmtoolbox.ld.rdf import PROTECTED_ATTRIBUTE_NAMES
|
|
5
|
+
from ..utils import to_literal
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def to_uriref(value: str, blank_node_iri_base: str = None) -> URIRef:
|
|
9
|
+
"""Convert a value to a URIRef, handling blank nodes if necessary."""
|
|
10
|
+
if value.startswith("_:") and blank_node_iri_base:
|
|
11
|
+
value = blank_node_iri_base + value[2:]
|
|
12
|
+
return URIRef(value)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def apply_rdf_mappings(obj, obj_uri, graph, rdf_mappings):
|
|
16
|
+
for ak, av in obj.attrs.items():
|
|
17
|
+
if ak not in PROTECTED_ATTRIBUTE_NAMES:
|
|
18
|
+
if ak in rdf_mappings:
|
|
19
|
+
mapping = rdf_mappings[ak]
|
|
20
|
+
predicate_uri = rdflib.URIRef(mapping['predicate'])
|
|
21
|
+
if predicate_uri:
|
|
22
|
+
object_uri = mapping.get('object')
|
|
23
|
+
if object_uri:
|
|
24
|
+
if callable(object_uri):
|
|
25
|
+
object_uri = str(object_uri(av, obj.attrs))
|
|
26
|
+
if object_uri is None:
|
|
27
|
+
return
|
|
28
|
+
graph.add((obj_uri, predicate_uri, rdflib.URIRef(object_uri)))
|
|
29
|
+
else:
|
|
30
|
+
graph.add((obj_uri, predicate_uri, to_literal(av)))
|
|
31
|
+
type_uri = mapping.get('type')
|
|
32
|
+
if type_uri:
|
|
33
|
+
graph.add((obj_uri, rdflib.RDF.type, rdflib.URIRef(type_uri)))
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import base64
|
|
1
2
|
import pathlib
|
|
2
3
|
import urllib.parse
|
|
3
4
|
from typing import Optional
|
|
@@ -5,8 +6,28 @@ from typing import Union
|
|
|
5
6
|
|
|
6
7
|
import h5py
|
|
7
8
|
import rdflib
|
|
9
|
+
from rdflib import Literal
|
|
8
10
|
from rdflib.namespace import XSD
|
|
9
11
|
|
|
12
|
+
def to_literal(value, *, binary_as_string=None, encoding="utf-8") -> Literal:
|
|
13
|
+
"""
|
|
14
|
+
Convert a Python value to an rdflib Literal.
|
|
15
|
+
|
|
16
|
+
- str -> xsd:string
|
|
17
|
+
- bytes -> xsd:base64Binary (default)
|
|
18
|
+
- bytes -> xsd:string if binary_as_string=True
|
|
19
|
+
"""
|
|
20
|
+
if binary_as_string is None:
|
|
21
|
+
from . import BINARY_AS_STRING
|
|
22
|
+
binary_as_string = BINARY_AS_STRING
|
|
23
|
+
if isinstance(value, bytes):
|
|
24
|
+
if binary_as_string:
|
|
25
|
+
return Literal(value.decode(encoding))
|
|
26
|
+
encoded = base64.b64encode(value).decode("ascii")
|
|
27
|
+
return Literal(encoded, datatype=XSD.base64Binary)
|
|
28
|
+
|
|
29
|
+
return Literal(value, datatype=get_attr_dtype_as_xsd(value))
|
|
30
|
+
|
|
10
31
|
|
|
11
32
|
def _parse_obj_name(obj_name: str):
|
|
12
33
|
return urllib.parse.quote(obj_name, safe='/')
|
|
@@ -221,7 +221,7 @@ class ZenodoRecord(RepositoryInterface):
|
|
|
221
221
|
return r.json()
|
|
222
222
|
|
|
223
223
|
record_url = url.replace("deposit/depositions/", "records/")
|
|
224
|
-
r = requests.get(record_url)
|
|
224
|
+
r = requests.get(record_url, headers=USER_AGENT_HEADER)
|
|
225
225
|
if r.status_code == 404:
|
|
226
226
|
access_token = self.access_token
|
|
227
227
|
r = requests.get(url, params={"access_token": access_token})
|
|
@@ -32,7 +32,6 @@ logger = logging.getLogger('h5rdmtoolbox')
|
|
|
32
32
|
DEFAULT_LOGGING_LEVEL = logging.INFO
|
|
33
33
|
RETRY_STATUS = {429, 500, 502, 503, 504}
|
|
34
34
|
|
|
35
|
-
|
|
36
35
|
def get_filesize(filename: Union[str, pathlib.Path]) -> int:
|
|
37
36
|
"""Get the size of a file in bytes"""
|
|
38
37
|
return os.path.getsize(filename) * get_ureg().byte
|
|
@@ -199,9 +198,9 @@ def generate_temporary_filename(prefix='tmp', suffix: str = '', touch: bool = Fa
|
|
|
199
198
|
tmp_filename: pathlib.Path
|
|
200
199
|
The generated temporary filename
|
|
201
200
|
"""
|
|
202
|
-
_filename =
|
|
201
|
+
_filename = user.UserDir['tmp'] / f"{prefix}{next(user._filecounter)}{suffix}"
|
|
203
202
|
while _filename.exists():
|
|
204
|
-
_filename =
|
|
203
|
+
_filename = user.UserDir['tmp'] / f"{prefix}{next(user._filecounter)}{suffix}"
|
|
205
204
|
if touch:
|
|
206
205
|
if _filename.suffix in ('.h5', '.hdf', '.hdf5'):
|
|
207
206
|
with h5py.File(_filename, 'w'):
|
|
@@ -225,9 +224,9 @@ def generate_temporary_directory(prefix='tmp') -> pathlib.Path:
|
|
|
225
224
|
tmp_filename: pathlib.Path
|
|
226
225
|
The generated temporary filename
|
|
227
226
|
"""
|
|
228
|
-
_dir =
|
|
227
|
+
_dir = user.UserDir['tmp'] / f"{prefix}{next(user._dircounter)}"
|
|
229
228
|
while _dir.exists():
|
|
230
|
-
_dir =
|
|
229
|
+
_dir = user.UserDir['tmp'] / f"{prefix}{next(user._dircounter)}"
|
|
231
230
|
_dir.mkdir(parents=True)
|
|
232
231
|
return _dir
|
|
233
232
|
|
|
@@ -32,6 +32,7 @@ from .. import protocols
|
|
|
32
32
|
from .._repr import H5Repr, H5PY_SPECIAL_ATTRIBUTES
|
|
33
33
|
from ..convention.consts import DefaultValue
|
|
34
34
|
from ..ld import rdf
|
|
35
|
+
from ..ld._types import RDFMappingEntry
|
|
35
36
|
|
|
36
37
|
logger = logging.getLogger('h5rdmtoolbox')
|
|
37
38
|
|
|
@@ -2486,7 +2487,8 @@ class File(h5py.File, Group):
|
|
|
2486
2487
|
contextual: bool = True,
|
|
2487
2488
|
file_uri: Optional[Union[str, Dict]] = None,
|
|
2488
2489
|
context: Optional[Dict] = None,
|
|
2489
|
-
indent: int = 2
|
|
2490
|
+
indent: int = 2,
|
|
2491
|
+
rdf_mappings: Dict[str, RDFMappingEntry] = None
|
|
2490
2492
|
):
|
|
2491
2493
|
"""Serialize the file content to a specific format"""
|
|
2492
2494
|
from h5rdmtoolbox.ld.utils import optimize_context
|
|
@@ -2510,7 +2512,8 @@ class File(h5py.File, Group):
|
|
|
2510
2512
|
structural=structural,
|
|
2511
2513
|
contextual=contextual,
|
|
2512
2514
|
file_uri=file_uri,
|
|
2513
|
-
skipND=skipND
|
|
2515
|
+
skipND=skipND,
|
|
2516
|
+
rdf_mappings=rdf_mappings)
|
|
2514
2517
|
if prefix:
|
|
2515
2518
|
graph.bind(prefix, file_uri)
|
|
2516
2519
|
context = context or {}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
from ontolutils.namespacelib.hdf5 import HDF5
|
|
2
|
-
from rdflib import Namespace, Literal, XSD, RDF
|
|
3
|
-
|
|
4
|
-
from ..utils import get_attr_node
|
|
5
|
-
|
|
6
|
-
HDF = Namespace(str(HDF5))
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def process_attribute(*, name, value, graph, parent, parent_uri, blank_node_iri_base):
|
|
10
|
-
"""Process an HDF5 attribute, adding it to the RDF graph."""
|
|
11
|
-
if name.isupper() or name.startswith('@'):
|
|
12
|
-
return
|
|
13
|
-
attr_uri = get_attr_node(
|
|
14
|
-
parent,
|
|
15
|
-
name,
|
|
16
|
-
blank_node_iri_base
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
if isinstance(value, str):
|
|
20
|
-
graph.add((attr_uri, RDF.type, HDF5.StringAttribute))
|
|
21
|
-
graph.add((attr_uri, HDF.data, Literal(value)))
|
|
22
|
-
elif isinstance(value, int):
|
|
23
|
-
graph.add((attr_uri, RDF.type, HDF5.IntegerAttribute))
|
|
24
|
-
graph.add((attr_uri, HDF.data, Literal(value, datatype=XSD.integer)))
|
|
25
|
-
elif isinstance(value, float):
|
|
26
|
-
graph.add((attr_uri, RDF.type, HDF5.FloatAttribute))
|
|
27
|
-
graph.add((attr_uri, HDF.data, Literal(value, datatype=XSD.float)))
|
|
28
|
-
else:
|
|
29
|
-
graph.add((attr_uri, RDF.type, HDF5.Attribute))
|
|
30
|
-
graph.add((attr_uri, HDF.data, Literal(value)))
|
|
31
|
-
|
|
32
|
-
graph.add((attr_uri, HDF.name, Literal(name)))
|
|
33
|
-
graph.add((parent_uri, HDF.attribute, attr_uri))
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
from rdflib import URIRef
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def to_uriref(value: str, blank_node_iri_base: str = None) -> URIRef:
|
|
5
|
-
"""Convert a value to a URIRef, handling blank nodes if necessary."""
|
|
6
|
-
if value.startswith("_:") and blank_node_iri_base:
|
|
7
|
-
value = blank_node_iri_base + value[2:]
|
|
8
|
-
return URIRef(value)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{h5rdmtoolbox-2.6.1 → h5rdmtoolbox-2.7.0}/h5rdmtoolbox/data/tutorial_standard_name_table.yaml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|