hed_schema_io¶
Utilities for loading and outputting HED schema.
Functions
|
Create a schema from the given string. |
|
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_dataframes(schema_data, schema_namespace=None, name=None)[source]¶
Create a schema from the given string.
- Parameters:
schema_string (dict) – A dict of DF_SUFFIXES:file_as_string_or_df Should have an entry for all values of DF_SUFFIXES.
schema_namespace (str, None) – The name_prefix all tags in this schema will accept.
name (str or None) – User supplied identifier for this schema
- Returns:
The loaded schema.
- Return type:
(HedSchema)
- Raises:
Empty/invalid parameters
Notes
The loading is determined by file type.
- 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) – An XML or mediawiki file as a single long string
schema_format (str) – The schema format of the source schema string. Allowed normal values: .mediawiki, .xml
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) – A filepath or url to open a schema from. If loading a TSV file, this should be a single filename where: Template: basename.tsv, where files are named basename_Struct.tsv, basename_Tag.tsv, etc. Alternatively, you can point to a directory containing the .tsv files.
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