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_all_schema_tags([return_last_term])

Get a list of all hed terms from the schema.

HedSchema.get_all_tag_attributes(tag_name[, ...])

Gather all attributes for a given tag name.

HedSchema.get_as_mediawiki_string([save_merged])

Return the schema to a mediawiki string.

HedSchema.get_as_owl_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_desc_iter()

Return an iterator over all the descriptions.

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()

Return a dict of all allowed tag attributes.

HedSchema.get_tag_description(tag_name[, ...])

Return the description associated with the tag.

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

Retrieve the current list of unknown attributes.

HedSchema.has_duplicates()

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

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

Save as mediawiki to a file.

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

Save as json 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_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_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_owl_string(save_merged=False, file_format='owl')[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.

  • file_format (str or None) – Override format from filename extension. Accepts any value rdflib accepts(We fully support “turtle”, “xml”(“owl” also accepted) and “json-ld”). Other values should work, but aren’t as fully supported.

Returns:

The schema as a string in mediawiki format.

Return type:

str

Raises:

rdflib.plugin.PluginException

  • Invalid format of file_format. Make sure you use a supported RDF format.

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

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

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_owl(filename, save_merged=False, file_format=None)[source]

Save as json to a file.

filename: str

Save the file here

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.

file_format(str or None): Required for owl formatted files other than the following:

.ttl: turtle .owl: xml .json-ld: json-ld

Raises:
  • OSError

    • File cannot be saved for some reason

  • rdflib.plugin.PluginException

    • Invalid format of file_format. Make sure you use a supported RDF format.

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