hed_schema_io¶
Utilities for loading and outputting HED schema.
Functions
|
Create a schema from the given string. |
|
Get the version number from a HED XML file. |
|
Load a schema from the given file or URL path. |
|
Return a HedSchema or HedSchemaGroup extracted from xml_version |
|
Takes a list of xml versions and returns a dictionary split by prefix |
- from_string(schema_string, schema_format='.xml', schema_namespace=None, schema=None, name=None)[source]¶
Create a schema from the given string.
- Parameters:
schema_string (str or dict) – An XML, mediawiki or OWL, file as a single long string If tsv, Must be a dict of spreadsheets as strings.
schema_format (str) – The schema format of the source schema string. Allowed normal values: .mediawiki, .xml, .tsv Note: tsv is in progress and has limited features
schema_namespace (str, None) – The name_prefix all tags in this schema will accept.
schema (HedSchema or None) – A hed schema to merge this new file into It must be a with-standard schema with the same value.
name (str or None) – User supplied identifier for this schema
- Returns:
The loaded schema.
- Return type:
(HedSchema)
- Raises:
If empty string or invalid extension is passed.
Other fatal formatting issues with file
Notes
The loading is determined by file type.
- get_hed_xml_version(xml_file_path)[source]¶
Get the version number from a HED XML file.
- Parameters:
xml_file_path (str) – The path to a HED XML file.
- Returns:
The version number of the HED XML file.
- Return type:
str
- Raises:
There is an issue loading the schema
- load_schema(hed_path, schema_namespace=None, schema=None, name=None)[source]¶
Load a schema from the given file or URL path.
- Parameters:
hed_path (str or dict) – A filepath or url to open a schema from. If loading a TSV file, this can be a single filename template, or a dict of filenames. Template: basename.tsv, where files are named basename_Struct.tsv and basename_Tag.tsv
schema_namespace (str or None) – The name_prefix all tags in this schema will accept.
schema (HedSchema or None) – A hed schema to merge this new file into It must be a with-standard schema with the same value.
name (str or None) – User supplied identifier for this schema
- Returns:
The loaded schema.
- Return type:
HedSchema
- Raises:
Empty path passed
Unknown extension
Any fatal issues when loading the schema.
- load_schema_version(xml_version=None, xml_folder=None)[source]¶
Return a HedSchema or HedSchemaGroup extracted from xml_version
- Parameters:
xml_version (str or list) – List or str specifying which official HED schemas to use. A json str format is also supported, based on the output of HedSchema.get_formatted_version Basic format: [schema_namespace:][library_name_]X.Y.Z.
xml_folder (str) – Path to a folder containing schema.
- Returns:
The schema or schema group extracted.
- Return type:
HedSchema or HedSchemaGroup
- Raises:
The xml_version is not valid.
The specified version cannot be found or loaded
Other fatal errors loading the schema (These are unlikely if you are not editing them locally)
The prefix is invalid
- parse_version_list(xml_version_list)[source]¶
Takes a list of xml versions and returns a dictionary split by prefix
e.g. [“score”, “testlib”] will return {“”: “score, testlib”} e.g. [“score”, “testlib”, “ol:otherlib”] will return {“”: “score, testlib”, “ol:”: “otherlib”}
- Parameters:
xml_version_list (list) – List of str specifying which hed schemas to use
- Returns:
The schema or schema group extracted.
- Return type:
HedSchema or HedSchemaGroup