Adapter

Base class for adapters

class BuildResult(schemas: ~typing.List[~linkml_runtime.linkml_model.meta.SchemaDefinition] = <factory>, classes: ~typing.List[~linkml_runtime.linkml_model.meta.ClassDefinition] = <factory>, slots: ~typing.List[~linkml_runtime.linkml_model.meta.SlotDefinition] = <factory>, types: ~typing.List[~linkml_runtime.linkml_model.meta.TypeDefinition] = <factory>, **_kwargs)

Container class for propagating nested build results back up to caller

schemas: List[SchemaDefinition]
classes: List[ClassDefinition]
slots: List[SlotDefinition]
types: List[TypeDefinition]
as_linkml() str

Print build results as linkml-style YAML.

Note that only non-schema results will be included, as a schema usually contains all the other types.

class Adapter

Abstract base class for adapters

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

property debug: bool

Whether we are in debug mode, which adds extra metadata in generated elements.

Set explicitly via _debug , or else checks for the truthiness of the environment variable NWB_LINKML_DEBUG

property logger: Logger

A logger with the name of the adapter class! See config

abstract build() BuildResult

Generate the corresponding linkML element for this adapter

get(name: str) Group | Dataset

Get the first item whose neurodata_type_def matches name

Convenience wrapper around walk_field_values()

get_model_with_field(field: str) Generator[Group | Dataset, None, None]

Yield models that have a non-None value in the given field.

Useful during development to find all the ways that a given field is used.

Parameters:

field (str) – Field to search for

walk(input: BaseModel | dict | list) Generator[BaseModel | Any | None, None, None]

Iterate through all items in the given model.

Could be a staticmethod or a function, but bound to adapters to make it available to them :)

walk_fields(input: BaseModel | dict | list, field: str | Tuple[str, ...]) Generator[Any, None, None]

Recursively walk input for fields that match field

Parameters:

Returns:

walk_field_values(input: BaseModel | dict | list, field: Literal['neurodata_type_def'], value: Any | None = None) Generator[Group | Dataset, None, None]

Recursively walk input for models that contain a field as a direct child with a value matching value

Parameters:
  • input (pydantic.BaseModel) – Model to walk

  • field (str) – Name of field - unlike walk_fields(), only one field can be given

  • value (Any) – Value to match for given field. If None , return models that have the field

Returns:

pydantic.BaseModel the matching model

walk_types(input: BaseModel | dict | list, get_type: Type[T] | Tuple[Type[T], Type[Unpack[Ts]]]) Generator[T | Ts, None, None]

Walk a model, yielding items that are the same type as the given type

Parameters:
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self – The BaseModel instance.

  • context – The context.

class Map

The generic top-level mapping class is just a classmethod for checking if the map applies and a method for applying the check if it does

abstract classmethod check(*args: Sequence, **kwargs: Mapping) bool

Check if this map applies to the given item to read

abstract classmethod apply(*args: Sequence, **kwargs: Mapping) Any

Actually apply the map!

is_1d(cls: Dataset | Attribute) bool

Check if the values of a dataset are 1-dimensional.

Specifically: * a single-layer dim/shape list of length 1, or * a nested dim/shape list where every nested spec is of length 1

is_compound(cls: Dataset) bool

Check if dataset has a compound dtype

has_attrs(cls: Dataset) bool

Check if a dataset has any attributes at all without defaults

defaults(cls: Dataset | Attribute) dict

Handle default values -

  • If value is present, yield equals_string or equals_number depending on dtype as well as an ifabsent value - we both constrain the possible values to 1 and also supply it as the default

  • else, if default_value is present, yield an appropriate ifabsent value

  • If neither, yield an empty dict

Unlike nwb_schema_language, when value is set, we yield both a equals_* constraint and an ifabsent constraint, because an equals_* can be declared without a default in order to validate that a value is correctly set as the constrained value, and fail if a value isn’t provided.

is_container(group: Group) bool

Check if a group is a container group.

i.e. a group that… * has no name * multivalued quantity * has a neurodata_type_inc * has no neurodata_type_def * has no sub-groups * has no datasets * has no attributes

Examples

- name: templates
  groups:
  - neurodata_type_inc: TimeSeries
    doc: TimeSeries objects containing template data of presented stimuli.
    quantity: '*'
  - neurodata_type_inc: Images
    doc: Images objects containing images of presented stimuli.
    quantity: '*'