HedSchema

class HedSchema[source]

A HED schema suitable for processing.

Methods

HedSchema.__init__()

Constructor for the HedSchema class.

HedSchema.can_save()

Returns if it's legal to save this schema.

HedSchema.check_compliance([...])

Check for HED3 compliance of this schema.

HedSchema.finalize_dictionaries()

Call to finish loading.

HedSchema.find_tag_entry(tag[, schema_namespace])

Find the schema entry for a given source tag.

HedSchema.get_as_mediawiki_string([save_merged])

Return the schema to a mediawiki string.

HedSchema.get_as_xml_string([save_merged])

Return the schema to an XML string.

HedSchema.get_formatted_version()

The HED version string including namespace and library name if any of this schema.

HedSchema.get_save_header_attributes([...])

returns the attributes that should be saved.

HedSchema.get_schema_versions()

A list of HED version strings including namespace and library name if any of this schema.

HedSchema.get_tag_attribute_names_old()

Return a dict of all allowed tag attributes.

HedSchema.get_tag_entry(name[, key_class, ...])

Return the schema entry for this tag, if one exists.

HedSchema.get_tags_with_attribute(attribute)

Return tag entries with the given attribute.

HedSchema.has_duplicates()

Returns the first duplicate tag/unit/etc if any section has a duplicate name

HedSchema.save_as_dataframes(base_filename)

Save as mediawiki to a file.

HedSchema.save_as_mediawiki(filename[, ...])

Save as mediawiki to a file.

HedSchema.save_as_xml(filename[, save_merged])

Save as XML to a file.

HedSchema.schema_for_namespace(namespace)

Return HedSchema object for this namespace.

HedSchema.set_schema_prefix(schema_namespace)

Set library namespace associated for this schema.

Attributes

HedSchema.attributes

Return the attributes schema section.

HedSchema.library

The name of this library schema if one exists.

HedSchema.merged

Returns if this schema was loaded from a merged file

HedSchema.name

User provided name for this schema, defaults to filename or version if no name provided.

HedSchema.properties

Return the properties schema section.

HedSchema.schema_83_props

Returns if this is an 8.3.0 or greater schema.

HedSchema.schema_namespace

Returns the schema namespace prefix

HedSchema.tags

Return the tag schema section.

HedSchema.unit_classes

Return the unit classes schema section.

HedSchema.unit_modifiers

Return the modifiers classes schema section

HedSchema.units

Return the unit schema section.

HedSchema.valid_prefixes

Return a list of all prefixes this schema will accept

HedSchema.value_classes

Return the value classes schema section.

HedSchema.version

The complete schema version, including prefix and library name(if applicable)

HedSchema.version_number

The HED version of this schema.

HedSchema.with_standard

The version of the base schema this is extended from, if it exists.

HedSchema.__init__()[source]

Constructor for the HedSchema class.

A HedSchema can be used for validation, checking tag attributes, parsing tags, etc.

HedSchema.can_save()[source]

Returns if it’s legal to save this schema.

You cannot save schemas loaded as merged from multiple library schemas.

Returns:

True if this can be saved

Return type:

bool

HedSchema.check_compliance(check_for_warnings=True, name=None, error_handler=None)[source]

Check for HED3 compliance of this schema.

Parameters:
  • check_for_warnings (bool) – If True, checks for formatting issues like invalid characters, capitalization.

  • name (str) – If present, use as the filename for context, rather than using the actual filename. Useful for temp filenames when supporting web services.

  • error_handler (ErrorHandler or None) – Used to report errors. Uses a default one if none passed in.

Returns:

A list of all warnings and errors found in the file. Each issue is a dictionary.

Return type:

list

HedSchema.finalize_dictionaries()[source]

Call to finish loading.

HedSchema.find_tag_entry(tag, schema_namespace='')[source]

Find the schema entry for a given source tag.

Parameters:
  • tag (str, HedTag) – Any form of tag to look up. Can have an extension, value, etc.

  • schema_namespace (str) – The schema namespace of the tag, if any.

Returns:

The located tag entry for this tag. str: The remainder of the tag that isn’t part of the base tag. list: A list of errors while converting.

Return type:

HedTagEntry

Notes

Works left to right (which is mostly relevant for errors).

HedSchema.get_as_mediawiki_string(save_merged=False)[source]

Return the schema to a mediawiki string.

Parameters:

save_merged (bool) – If True, this will save the schema as a merged schema if it is a “withStandard” schema. If it is not a “withStandard” schema, this setting has no effect.

Returns:

The schema as a string in mediawiki format.

Return type:

str

HedSchema.get_as_xml_string(save_merged=True)[source]

Return the schema to an XML string.

Parameters:
  • save_merged (bool) –

  • True (If) –

  • schema. (this will save the schema as a merged schema if it is a "withStandard") –

  • schema (If it is not a "withStandard") –

  • effect. (this setting has no) –

Returns:

Return the schema as an XML string.

Return type:

str

HedSchema.get_formatted_version()[source]

The HED version string including namespace and library name if any of this schema.

Returns:

A json formatted string of the complete version of this schema including library name and namespace.

Return type:

str

HedSchema.get_save_header_attributes(save_merged=False)[source]

returns the attributes that should be saved.

HedSchema.get_schema_versions()[source]

A list of HED version strings including namespace and library name if any of this schema.

Returns:

The complete version of this schema including library name and namespace.

Return type:

list

HedSchema.get_tag_attribute_names_old()[source]

Return a dict of all allowed tag attributes.

Returns:

A dictionary whose keys are attribute names and values are HedSchemaEntry object.

Return type:

dict

HedSchema.get_tag_entry(name, key_class=HedSectionKey.Tags, schema_namespace='')[source]

Return the schema entry for this tag, if one exists.

Parameters:
  • name (str) – Any form of basic tag(or other section entry) to look up. This will not handle extensions or similar. If this is a tag, it can have a schema namespace, but it’s not required

  • key_class (HedSectionKey or str) – The type of entry to return.

  • schema_namespace (str) – Only used on Tags. If incorrect, will return None.

Returns:

The schema entry for the given tag.

Return type:

HedSchemaEntry

HedSchema.get_tags_with_attribute(attribute, key_class=HedSectionKey.Tags)[source]

Return tag entries with the given attribute.

Parameters:
  • attribute (str) – A tag attribute. Eg HedKey.ExtensionAllowed

  • key_class (HedSectionKey) – The HedSectionKey for the section to retrieve from.

Returns:

A list of all tags with this attribute.

Return type:

list

Notes

  • The result is cached so will be fast after first call.

HedSchema.has_duplicates()[source]

Returns the first duplicate tag/unit/etc if any section has a duplicate name

HedSchema.save_as_dataframes(base_filename, save_merged=False)[source]

Save as mediawiki to a file.

base_filename: str

save filename. A suffix will be added to most, e.g. _Tag

save_merged: bool

If True, this will save the schema as a merged schema if it is a “withStandard” schema. If it is not a “withStandard” schema, this setting has no effect.

Raises:

OSError

  • File cannot be saved for some reason.

HedSchema.save_as_mediawiki(filename, save_merged=False)[source]

Save as mediawiki to a file.

filename: str

save location

save_merged: bool

If True, this will save the schema as a merged schema if it is a “withStandard” schema. If it is not a “withStandard” schema, this setting has no effect.

Raises:

OSError

  • File cannot be saved for some reason.

HedSchema.save_as_xml(filename, save_merged=True)[source]

Save as XML to a file.

filename: str

save location

save_merged: bool

If true, this will save the schema as a merged schema if it is a “withStandard” schema. If it is not a “withStandard” schema, this setting has no effect.

Raises:

OSError

  • File cannot be saved for some reason

HedSchema.schema_for_namespace(namespace)[source]

Return HedSchema object for this namespace.

Parameters:

namespace (str) – The schema library name namespace.

Returns:

The HED schema object for this schema.

Return type:

HedSchema

HedSchema.set_schema_prefix(schema_namespace)[source]

Set library namespace associated for this schema.

Parameters:

schema_namespace (str) – Should be empty, or end with a colon.(Colon will be automated added if missing).

Raises:

HedFileError

  • The prefix is invalid

HedSchema.attributes

Return the attributes schema section.

Returns:

The attributes section.

Return type:

HedSchemaSection

HedSchema.library

The name of this library schema if one exists.

Returns:

Library name if any.

Return type:

str

HedSchema.merged

Returns if this schema was loaded from a merged file

Returns:

True if file was loaded from a merged file

Return type:

bool

HedSchema.name

User provided name for this schema, defaults to filename or version if no name provided.

HedSchema.properties

Return the properties schema section.

Returns:

The properties section.

Return type:

HedSchemaSection

HedSchema.schema_83_props

Returns if this is an 8.3.0 or greater schema.

Returns:

True if standard or partnered schema is 8.3.0 or greater.

Return type:

is_83_schema(bool)

HedSchema.schema_namespace

Returns the schema namespace prefix

HedSchema.tags

Return the tag schema section.

Returns:

The tag section.

Return type:

HedSchemaTagSection

HedSchema.unit_classes

Return the unit classes schema section.

Returns:

The unit classes section.

Return type:

HedSchemaUnitClassSection

HedSchema.unit_modifiers

Return the modifiers classes schema section

Returns:

The unit modifiers section.

Return type:

HedSchemaSection

HedSchema.units

Return the unit schema section.

Returns:

The unit section.

Return type:

HedSchemaSection

HedSchema.valid_prefixes

Return a list of all prefixes this schema will accept

Returns:

A list of valid tag prefixes for this schema.

Return type:

list

Notes

  • The return value is always length 1 if using a HedSchema.

HedSchema.value_classes

Return the value classes schema section.

Returns:

The value classes section.

Return type:

HedSchemaSection

HedSchema.version

The complete schema version, including prefix and library name(if applicable)

HedSchema.version_number

The HED version of this schema.

Returns:

The version of this schema.

Return type:

str

HedSchema.with_standard

The version of the base schema this is extended from, if it exists.

Returns:

HED version or “”

Return type:

str