Creating a convention using metadata4ing#
import h5rdmtoolbox as h5tbx
from h5rdmtoolbox import convention
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 1
----> 1 import h5rdmtoolbox as h5tbx
2 from h5rdmtoolbox import convention
File ~/checkouts/readthedocs.org/user_builds/h5rdmtoolbox/checkouts/v1.7.0/h5rdmtoolbox/__init__.py:129
125 with File(src) as h5:
126 return h5.dumps()
--> 129 from h5rdmtoolbox.wrapper.ld.hdf.file import get_ld as hdf_get_ld
130 from h5rdmtoolbox.wrapper.ld.user.file import get_ld as user_get_ld
133 def get_ld(
134 hdf_filename: Union[str, pathlib.Path],
135 structural: bool = True,
136 semantic: bool = True,
137 blank_node_iri_base: Optional[str] = None,
138 **kwargs) -> rdflib.Graph:
File ~/checkouts/readthedocs.org/user_builds/h5rdmtoolbox/checkouts/v1.7.0/h5rdmtoolbox/wrapper/ld/__init__.py:1
----> 1 import ssnolib.ssno.standard_name
2 from ontolutils.namespacelib import M4I
3 from ontolutils.namespacelib import SCHEMA
ModuleNotFoundError: No module named 'ssnolib'
cv = convention.Convention(name='PersonConvention', contact='John Doe')
cv.register()
from pydantic import BaseModel
from typing_extensions import Literal
Role = Literal[
"Creator",
"ContactPerson",
]
class Person(BaseModel):
first_name: str
last_name: str
role: Role
class SpecialStandardAttribute(h5tbx.convention.standard_attributes.StandardAttribute):
def set(self, parent, value, attrs=None):
"""Is called when attribute of a standard attribute is set"""
print(value)
grp_name = f'{value["role"]}Person'
i = 0
while grp_name in parent:
i += 1
grp_name = f'{value["role"]}Person{i}'
person_grp = parent.create_group(grp_name)
person_grp.create_string_dataset('first_name',
data=value['first_name'],
attrs=dict(iri='http://xmlns.com/foaf/0.1/firstName',
description='The first name of a person'))
person_grp.create_string_dataset('last_name',
data=value['last_name'],
attrs=dict(iri='http://xmlns.com/foaf/0.1/lastName',
description='The last name of a person'))
personStdAttr = SpecialStandardAttribute(
name='person',
validator=Person,
target_method='__init__',
description='Person',
default_value='$empty'
)
cv.add_standard_attribute(personStdAttr)
cv.registered_standard_attributes
{'person': <SpecialStandardAttribute@__init__[positional/obligatory]("person"): "Person.">}
h5tbx.use(None)
h5tbx.use(cv.name)
using("PersonConvention")
Person(first_name='Matthias', last_name='Probst', role='Creator')
Person(first_name='Matthias', last_name='Probst', role='Creator')
with h5tbx.File(person=dict(first_name='Matthias', last_name='Probst', role='Creator')) as h5:
h5.dump()
{'first_name': 'Matthias', 'last_name': 'Probst', 'role': 'Creator'}
-
-
-
: [|S8] data=b'Matthias'
- description : The first name of a person
- iri : http://xmlns.com/foaf/0.1/firstName
-
: [|S6] data=b'Probst'
- description : The last name of a person
- iri : http://xmlns.com/foaf/0.1/lastName
-