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

hed.models.hed_tag.HedTag.__init__(...[, ...])

Creates a HedTag.

hed.models.hed_tag.HedTag.base_tag_has_attribute(...)

Check to see if the tag has a specific attribute.

hed.models.hed_tag.HedTag.copy()

Return a deep copy of this tag.

hed.models.hed_tag.HedTag.get_stripped_unit_value()

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

hed.models.hed_tag.HedTag.get_tag_unit_class_units()

Get the unit class units associated with a particular tag.

hed.models.hed_tag.HedTag.has_attribute(...)

Return true if this is an attribute this tag has.

hed.models.hed_tag.HedTag.is_basic_tag()

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

hed.models.hed_tag.HedTag.is_column_ref()

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

hed.models.hed_tag.HedTag.is_placeholder()

hed.models.hed_tag.HedTag.is_takes_value_tag()

Return true if this is a takes value tag.

hed.models.hed_tag.HedTag.is_unit_class_tag()

Return true if this is a unit class tag.

hed.models.hed_tag.HedTag.is_value_class_tag()

Return true if this is a value class tag.

hed.models.hed_tag.HedTag.lower()

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

hed.models.hed_tag.HedTag.replace_placeholder(...)

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

hed.models.hed_tag.HedTag.tag_exists_in_schema()

Get the schema entry for this tag.

hed.models.hed_tag.HedTag.tag_modified()

Return true if tag has been modified from original.

hed.models.hed_tag.HedTag.value_as_default_unit()

Returns the value converted to default units if possible.

Attributes

hed.models.hed_tag.HedTag.attributes

Return a dict of all the attributes this tag has.

hed.models.hed_tag.HedTag.base_tag

Long form without value or extension.

hed.models.hed_tag.HedTag.default_unit

Get the default unit class unit for this tag.

hed.models.hed_tag.HedTag.expandable

Returns what this expands to

hed.models.hed_tag.HedTag.expanded

Returns if this is currently expanded or not.

hed.models.hed_tag.HedTag.extension

Get the extension or value of tag

hed.models.hed_tag.HedTag.long_tag

Long form including value or extension.

hed.models.hed_tag.HedTag.org_base_tag

Original form without value or extension.

hed.models.hed_tag.HedTag.org_tag

Return the original unmodified tag.

hed.models.hed_tag.HedTag.schema_namespace

Library namespace for this tag if one exists.

hed.models.hed_tag.HedTag.short_base_tag

Short form without value or extension

hed.models.hed_tag.HedTag.short_tag

Short form including value or extension.

hed.models.hed_tag.HedTag.tag

Returns the tag.

hed.models.hed_tag.HedTag.unit_classes

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

hed.models.hed_tag.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.copy()[source]

Return a deep copy of this tag.

Returns:

The copied group.

Return type:

HedTag

HedTag.get_stripped_unit_value()[source]

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

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]

Returns 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]
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]

Get the schema entry for this tag.

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]

Returns 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 not 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

Returns what this expands to

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

Returns:

Returns the expanded form of this tag

Return type:

HedGroup or HedTag or None

HedTag.expanded

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