HedSchema

class HedSchema[source]

A HED schema suitable for processing.

Methods

hed.schema.hed_schema.HedSchema.__init__()

Constructor for the HedSchema class.

hed.schema.hed_schema.HedSchema.check_compliance([...])

Check for HED3 compliance of this schema.

hed.schema.hed_schema.HedSchema.finalize_dictionaries()

Call to finish loading.

hed.schema.hed_schema.HedSchema.find_tag_entry(tag)

Find the schema entry for a given source tag.

hed.schema.hed_schema.HedSchema.get_all_schema_tags([...])

Get a list of all hed terms from the schema.

hed.schema.hed_schema.HedSchema.get_all_tag_attributes(...)

Gather all attributes for a given tag name.

hed.schema.hed_schema.HedSchema.get_as_mediawiki_string([...])

Return the schema to a mediawiki string.

hed.schema.hed_schema.HedSchema.get_as_xml_string([...])

Return the schema to an XML string.

hed.schema.hed_schema.HedSchema.get_desc_iter()

Return an iterator over all the descriptions.

hed.schema.hed_schema.HedSchema.get_formatted_version()

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

hed.schema.hed_schema.HedSchema.get_save_header_attributes([...])

returns the attributes that should be saved.

hed.schema.hed_schema.HedSchema.get_schema_versions()

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

hed.schema.hed_schema.HedSchema.get_tag_attribute_names()

Return a dict of all allowed tag attributes.

hed.schema.hed_schema.HedSchema.get_tag_description(...)

Return the description associated with the tag.

hed.schema.hed_schema.HedSchema.get_tag_entry(name)

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

hed.schema.hed_schema.HedSchema.get_tags_with_attribute(...)

Return tag entries with the given attribute.

hed.schema.hed_schema.HedSchema.get_unknown_attributes()

Retrieve the current list of unknown attributes.

hed.schema.hed_schema.HedSchema.save_as_mediawiki([...])

Save as mediawiki to a file.

hed.schema.hed_schema.HedSchema.save_as_xml([...])

Save as XML to a file.

hed.schema.hed_schema.HedSchema.schema_for_namespace(...)

Return HedSchema object for this namespace.

hed.schema.hed_schema.HedSchema.set_schema_prefix(...)

Set library namespace associated for this schema.

Attributes

hed.schema.hed_schema.HedSchema.attributes

Return the attributes schema section.

hed.schema.hed_schema.HedSchema.library

The name of this library schema if one exists.

hed.schema.hed_schema.HedSchema.merged

Returns if this schema was loaded from a merged file

hed.schema.hed_schema.HedSchema.properties

Return the properties schema section.

hed.schema.hed_schema.HedSchema.tags

Return the tag schema section.

hed.schema.hed_schema.HedSchema.unit_classes

Return the unit classes schema section.

hed.schema.hed_schema.HedSchema.unit_modifiers

Return the modifiers classes schema section

hed.schema.hed_schema.HedSchema.valid_prefixes

Return a list of all prefixes this schema will accept

hed.schema.hed_schema.HedSchema.value_classes

Return the value classes schema section.

hed.schema.hed_schema.HedSchema.version

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

hed.schema.hed_schema.HedSchema.version_number

The HED version of this schema.

hed.schema.hed_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.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_all_schema_tags(return_last_term=False)[source]

Get a list of all hed terms from the schema.

Returns:

A list of all terms(short tags) from the schema.

Return type:

list

Notes

Compatible with Hed2 or Hed3.

HedSchema.get_all_tag_attributes(tag_name, key_class=HedSectionKey.Tags)[source]

Gather all attributes for a given tag name.

Parameters:
  • tag_name (str) – The name of the tag to check.

  • key_class (str) – The type of attributes requested. e.g. Tag, Units, Unit modifiers, or attributes.

Returns:

A dictionary of attribute name and attribute value.

Return type:

dict

Notes

If keys is None, gets all normal hed tag attributes.

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_desc_iter()[source]

Return an iterator over all the descriptions.

Yields:

tuple – - str: The tag node name. - str: The description associated with the node.

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()[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_description(tag_name, key_class=HedSectionKey.Tags)[source]

Return the description associated with the tag.

Parameters:
  • tag_name (str) – A hed tag name(or unit/unit modifier etc) with proper capitalization.

  • key_class (str) – A string indicating type of description (e.g. All tags, Units, Unit modifier). The default is HedSectionKey.Tags.

Returns:

A description of the specified tag.

Return type:

str

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.get_unknown_attributes()[source]

Retrieve the current list of unknown attributes.

Returns:

The keys are attribute names and the values are lists of tags with this attribute.

Return type:

dict

Notes

  • This includes attributes found in the wrong section for example unitClass attribute found on a Tag.

  • The return tag list is in long form.

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

Save as mediawiki to a file.

filename: str

If present, move the resulting file to this 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.

Returns:

The newly created schema filename.

Return type:

str

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

Save as XML to a file.

filename: str

If present, move the resulting file to this 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.

Returns:

The name of the newly created schema file.

Return type:

str

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.properties

Return the properties schema section.

Returns:

The properties section.

Return type:

HedSchemaSection

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.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