HedTag

class HedTag(hed_string, hed_schema, span=None, def_dict=None)[source]

A single HED tag.

Notes

  • HedTag is a smart class in that it keeps track of its original value and positioning as well as pointers to the relevant HED schema information, if relevant.

Methods

HedTag.__init__(hed_string, hed_schema[, ...])

Creates a HedTag.

HedTag.base_tag_has_attribute(tag_attribute)

Check to see if the tag has a specific attribute.

HedTag.casefold()

Convenience function, equivalent to str(self).casefold().

HedTag.copy()

Return a deep copy of this tag.

HedTag.get_stripped_unit_value(extension_text)

Return the extension divided into value and units, if the units are valid.

HedTag.get_tag_unit_class_units()

Get the unit class units associated with a particular tag.

HedTag.has_attribute(attribute)

Return True if this is an attribute this tag has.

HedTag.is_basic_tag()

Return True if a known tag with no extension or value.

HedTag.is_column_ref()

Return if this tag is a column reference from a sidecar.

HedTag.is_placeholder()

Returns if this tag has a placeholder in it.

HedTag.is_takes_value_tag()

Return True if this is a takes value tag.

HedTag.is_unit_class_tag()

Return True if this is a unit class tag.

HedTag.is_value_class_tag()

Return True if this is a value class tag.

HedTag.lower()

Convenience function, equivalent to str(self).lower().

HedTag.replace_placeholder(placeholder_value)

If tag has a placeholder character(#), replace with value.

HedTag.tag_exists_in_schema()

Return whether the schema entry for this tag exists.

HedTag.tag_modified()

Return True if tag has been modified from original.

HedTag.value_as_default_unit()

Return the value converted to default units if possible.

Attributes

HedTag.attributes

Return a dict of all the attributes this tag has.

HedTag.base_tag

Long form without value or extension.

HedTag.default_unit

Get the default unit class unit for this tag.

HedTag.expandable

Return what this expands to.

HedTag.expanded

Return if this is currently expanded or not.

HedTag.extension

Get the extension or value of tag.

HedTag.long_tag

Long form including value or extension.

HedTag.org_base_tag

Original form without value or extension.

HedTag.org_tag

Return the original unmodified tag.

HedTag.schema_namespace

Library namespace for this tag if one exists.

HedTag.short_base_tag

Short form without value or extension.

HedTag.short_tag

Short form including value or extension.

HedTag.tag

Returns the tag.

HedTag.unit_classes

Return a dict of all the unit classes this tag accepts.

HedTag.value_classes

Return a dict of all the value classes this tag accepts.

HedTag.__init__(hed_string, hed_schema, span=None, def_dict=None)[source]

Creates a HedTag.

Parameters:
  • hed_string (str) – Source HED string for this tag.

  • hed_schema (HedSchema) – A parameter for calculating canonical forms on creation.

  • span (int, int) – The start and end indexes of the tag in the hed_string.

  • def_dict (DefinitionDict or None) – The def dict to use to identify def/def expand tags.

HedTag.base_tag_has_attribute(tag_attribute)[source]

Check to see if the tag has a specific attribute.

This is primarily used to check for things like TopLevelTag on Definitions and similar.

Parameters:

tag_attribute (str) – A tag attribute.

Returns:

True if the tag has the specified attribute. False, if otherwise.

Return type:

bool

HedTag.casefold()[source]

Convenience function, equivalent to str(self).casefold().

HedTag.copy()[source]

Return a deep copy of this tag.

Returns:

The copied group.

Return type:

HedTag

HedTag.get_stripped_unit_value(extension_text)[source]

Return the extension divided into value and units, if the units are valid.

Parameters:

extension_text (str) – The text to split, in case it’s a portion of a tag.

Returns:

The extension portion with the units removed. unit (str or None): None if no valid unit found.

Return type:

stripped_unit_value (str)

Examples

‘Duration/3 ms’ will return ‘3’

HedTag.get_tag_unit_class_units()[source]

Get the unit class units associated with a particular tag.

Returns:

A list containing the unit class units associated with a particular tag or an empty list.

Return type:

list

HedTag.has_attribute(attribute)[source]

Return True if this is an attribute this tag has.

Parameters:

attribute (str) – Name of the attribute.

Returns:

True if this tag has the attribute.

Return type:

bool

HedTag.is_basic_tag()[source]

Return True if a known tag with no extension or value.

Returns:

True if this is a known tag without extension or value.

Return type:

bool

HedTag.is_column_ref()[source]

Return if this tag is a column reference from a sidecar.

You should only see these if you are directly accessing sidecar strings, tools should remove them otherwise.

Returns:

Returns True if this is a column ref.

Return type:

bool

HedTag.is_placeholder()[source]

Returns if this tag has a placeholder in it.

Returns:

True if it has a placeholder

Return type:

has_placeholder(bool)

HedTag.is_takes_value_tag()[source]

Return True if this is a takes value tag.

Returns:

True if this is a takes value tag.

Return type:

bool

HedTag.is_unit_class_tag()[source]

Return True if this is a unit class tag.

Returns:

True if this is a unit class tag.

Return type:

bool

HedTag.is_value_class_tag()[source]

Return True if this is a value class tag.

Returns:

True if this is a tag with a value class.

Return type:

bool

HedTag.lower()[source]

Convenience function, equivalent to str(self).lower().

HedTag.replace_placeholder(placeholder_value)[source]

If tag has a placeholder character(#), replace with value.

Parameters:

placeholder_value (str) – Value to replace placeholder with.

HedTag.tag_exists_in_schema()[source]

Return whether the schema entry for this tag exists.

Returns:

True if this tag exists.

Return type:

bool

Notes

  • This does NOT assure this is a valid tag.

HedTag.tag_modified()[source]

Return True if tag has been modified from original.

Returns:

Return True if the tag is modified.

Return type:

bool

Notes

  • Modifications can include adding a column name_prefix.

HedTag.value_as_default_unit()[source]

Return the value converted to default units if possible.

Returns None if the units are invalid.(No default unit or invalid).

Returns:

The extension value as default units.

If there are no default units, returns None.

Return type:

value (float or None)

Examples

‘Duration/300 ms’ will return .3

HedTag.attributes

Return a dict of all the attributes this tag has.

Returns empty dict if this is not a value tag.

Returns:

A dict of attributes this tag has.

Return type:

dict

Notes

  • Returns empty dict if this is not a unit class tag.

  • The dictionary has unit name as the key and HedSchemaEntry as value.

HedTag.base_tag

Long form without value or extension.

Returns:

The long form of the tag, without value or extension.

Return type:

base_tag (str)

HedTag.default_unit

Get the default unit class unit for this tag.

Only a tag with a single unit class can have default units.

Returns:

the default unit entry for this tag, or None

Return type:

unit(UnitEntry or None)

HedTag.expandable

Return what this expands to.

This is primarily used for Def/Def-expand tags at present.

Lazily set the first time it’s called.

Returns:

Returns the expanded form of this tag.

Return type:

HedGroup or HedTag or None

HedTag.expanded

Return if this is currently expanded or not.

Will always be False unless expandable is set. This is primarily used for Def/Def-expand tags at present.

Returns:

Returns True if this is currently expanded.

Return type:

bool

HedTag.extension

Get the extension or value of tag.

Generally this is just the portion after the last slash. Returns an empty string if no extension or value.

Returns:

The tag name.

Return type:

str

Notes

  • This tag must have been computed first.

HedTag.long_tag

Long form including value or extension.

Returns:

The long form of this tag.

Return type:

str

HedTag.org_base_tag

Original form without value or extension.

Returns:

The original form of the tag, without value or extension.

Return type:

base_tag (str)

Notes

  • Warning: This could be empty if the original tag had a name_prefix prepended. e.g. a column where “Label/” is prepended, thus the column value has zero base portion.

HedTag.org_tag

Return the original unmodified tag.

Returns:

The original unmodified tag.

Return type:

str

HedTag.schema_namespace

Library namespace for this tag if one exists.

Returns:

The library namespace, including the colon.

Return type:

namespace (str)

HedTag.short_base_tag

Short form without value or extension.

Returns:

The short non-extension port of a tag.

Return type:

base_tag (str)

Notes

  • ParentNodes/Def/DefName would return just “Def”.

HedTag.short_tag

Short form including value or extension.

Returns:

The short form of the tag, including value or extension.

Return type:

short_tag (str)

HedTag.tag

Returns the tag.

Returns the original tag if no user form set.

Returns:

The custom set user form of the tag.

Return type:

tag (str)

HedTag.unit_classes

Return a dict of all the unit classes this tag accepts.

Returns:

A dict of unit classes this tag accepts.

Return type:

unit_classes (dict)

Notes

  • Returns empty dict if this is not a unit class tag.

  • The dictionary has unit name as the key and HedSchemaEntry as value.

HedTag.value_classes

Return a dict of all the value classes this tag accepts.

Returns:

A dictionary of HedSchemaEntry value classes this tag accepts.

Return type:

dict

Notes

  • Returns empty dict if this is not a value class.

  • The dictionary has unit name as the key and HedSchemaEntry as value.