Skip to content

context.entities should be keyed based on the entity long name #80

Description

@effigies

Noticed while reviewing #71: entities["sub"] is populated, rather than entities["subject"].

The schema consistently uses the long name, not the short name. This means we'll need to look up the mapping from schema.objects.entities, and we should probably do that once per schema.

I recently introduced childmindresearch/bids2table#74 as a method for mapping schema specifiers onto an adapter class that extracts the bits the library actually needs. The basic idea is:

SchemaSpec: ty.TypeAlias = Namespace | os.PathLike[str] | str | None

def load_bids_schema(spec: SchemaSpec = None) -> BIDSSchemaAdapter: ...

def public_function(*args, schema: SchemaSpec = None) -> ReturnType:
    return _private_function(*args, adapter=load_bids_schema(schema))

def _private_function(*args, adapter: BIDSSchemaAdapter) -> ReturnType: ...

BIDSSchemaAdapter is never exposed as a public API, but is able to be passed around cheaply throughout private functions.

We can start by replacing the datatype-to-modality map:

_DATATYPE_MAP: dict[str, str] = {}
def datatype_to_modality(datatype: str, schema: Namespace) -> str:
"""Generate a global map for datatype to modality."""
global _DATATYPE_MAP
if not _DATATYPE_MAP:
for mod_name, mod_dtypes in schema.rules.modalities.items():
_DATATYPE_MAP |= dict.fromkeys(mod_dtypes['datatypes'], mod_name)
return _DATATYPE_MAP[datatype]

And a short-to-long entity name map would be good to have.

Need to consider how to actually thread this through. I suspect we attach the adapter to the Dataset object, so it's always available to the individual context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions