2023-08-22 04:43:02 +00:00
|
|
|
"""
|
|
|
|
Language elements in nwb schema language that have a fixed, alternative representation
|
|
|
|
in LinkML. These are exported as an nwb.language.yml file along with every generated namespace
|
|
|
|
"""
|
|
|
|
|
|
|
|
from nwb_schema_language.datamodel.nwb_schema_pydantic import FlatDtype as FlatDtype_source
|
|
|
|
from linkml_runtime.linkml_model import \
|
|
|
|
ClassDefinition, \
|
|
|
|
EnumDefinition, \
|
|
|
|
SchemaDefinition, \
|
|
|
|
SlotDefinition, \
|
|
|
|
TypeDefinition,\
|
|
|
|
Prefix,\
|
|
|
|
PermissibleValue
|
2023-09-04 20:49:07 +00:00
|
|
|
from nwb_linkml.maps.dtype import flat_to_linkml, flat_to_python
|
2023-08-22 04:43:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
FlatDType = EnumDefinition(
|
|
|
|
name="FlatDType",
|
|
|
|
permissible_values=[PermissibleValue(p) for p in FlatDtype_source.__members__.keys()],
|
|
|
|
)
|
|
|
|
|
2023-08-25 07:22:47 +00:00
|
|
|
# DimNameSlot = SlotDefinition(
|
|
|
|
# name="dim_name",
|
|
|
|
# range="string",
|
|
|
|
# description="The name of a dimension"
|
|
|
|
# )
|
|
|
|
# DimShapeSlot = SlotDefinition(
|
|
|
|
# name="dim_shape",
|
|
|
|
# range="integer",
|
|
|
|
# required=False
|
|
|
|
# )
|
|
|
|
# DimClass = ClassDefinition(
|
|
|
|
# name="Dimension",
|
|
|
|
# slots=[DimNameSlot.name, DimShapeSlot.name],
|
|
|
|
# description="A single dimension within a shape"
|
|
|
|
# )
|
|
|
|
# DimSlot = SlotDefinition(
|
|
|
|
# name="dim",
|
|
|
|
# range=DimClass.name,
|
|
|
|
# multivalued=True,
|
|
|
|
# description="Slot representing the dimensions that a Shape can have"
|
|
|
|
# )
|
2023-08-22 04:43:02 +00:00
|
|
|
|
|
|
|
# ShapeClass = ClassDefinition(
|
|
|
|
# name="Shape",
|
|
|
|
# description="A possible shape for an array-like dataset",
|
|
|
|
# slots=[DimSlot.name]
|
|
|
|
# )
|
|
|
|
|
|
|
|
DTypeTypes = []
|
|
|
|
for nwbtype, linkmltype in flat_to_linkml.items():
|
|
|
|
amin = None
|
|
|
|
if nwbtype.startswith('uint'):
|
|
|
|
amin = 0
|
|
|
|
|
|
|
|
atype = TypeDefinition(
|
|
|
|
name=nwbtype,
|
|
|
|
minimum_value=amin,
|
2023-09-04 20:49:07 +00:00
|
|
|
typeof=linkmltype,
|
|
|
|
base=flat_to_python[nwbtype]
|
2023-08-22 04:43:02 +00:00
|
|
|
)
|
|
|
|
DTypeTypes.append(atype)
|
|
|
|
|
2023-08-25 07:22:47 +00:00
|
|
|
Arraylike = ClassDefinition(
|
|
|
|
name="Arraylike",
|
|
|
|
description= ("Container for arraylike information held in the dims, shape, and dtype properties."
|
|
|
|
"this is a special case to be interpreted by downstream i/o. this class has no slots"
|
|
|
|
"and is abstract by default."
|
|
|
|
"- Each slot within a subclass indicates a possible dimension."
|
|
|
|
"- Only dimensions that are present in all the dimension specifiers in the"
|
|
|
|
" original schema are required."
|
|
|
|
"- Shape requirements are indicated using max/min cardinalities on the slot."
|
|
|
|
),
|
|
|
|
abstract=True
|
|
|
|
)
|
|
|
|
|
|
|
|
AnyType = ClassDefinition(
|
|
|
|
name="AnyType",
|
|
|
|
class_uri="linkml:Any",
|
|
|
|
description="""Needed because some classes in hdmf-common are datasets without dtype"""
|
|
|
|
)
|
2023-08-22 04:43:02 +00:00
|
|
|
|
|
|
|
NwbLangSchema = SchemaDefinition(
|
|
|
|
name="nwb.language",
|
|
|
|
id='nwb.language',
|
|
|
|
description="Adapter objects to mimic the behavior of elements in the nwb-schema-language",
|
|
|
|
enums=[FlatDType],
|
2023-08-25 07:22:47 +00:00
|
|
|
# slots=[DimNameSlot, DimShapeSlot, DimSlot],
|
|
|
|
classes=[Arraylike, AnyType],
|
2023-08-22 04:43:02 +00:00
|
|
|
types=DTypeTypes,
|
|
|
|
imports=['linkml:types'],
|
2023-09-04 20:49:07 +00:00
|
|
|
prefixes={
|
|
|
|
'linkml': Prefix('linkml','https://w3id.org/linkml'),
|
|
|
|
'nwb.language': f'https://example.com/nwb.language/'},
|
|
|
|
default_prefix='nwb.language',
|
|
|
|
|
2023-08-22 04:43:02 +00:00
|
|
|
)
|
|
|
|
|