3. HED formats¶
A HED schema is a formal specification of a standardized HED vocabulary including its properties and constraints.
Each HED schema vocabulary is organized hierarchically so that similar concepts and terms appear close to one another in the hierarchy.
The individual vocabulary terms (the HED schema nodes) MUST satisfy an “is-a” relationship with their parent nodes in the schema. That is, if node A is an ancestor of node B in the schema, then B is a type of A. This relationship is fundamental to HED and permits search generality. Searches for A are able to also return instances of B.
A HED annotation is a string consisting of comma-separated (and possibly parenthesized) terms from a HED schema. HED annotations provide a standardized language for describing virtually anything. HED’s primary application is to describe what happens during an experiment (the experimental events). HED annotations MUST be associated with one or more specific HED schema versions.
This chapter describes the requirements and formats for HED schemas and HED annotations. The error code that a tool reports for each violation of these requirements is given in Appendix B: HED errors.
Additional details about HED schema formats can be found in appendix A. Schema format details. 7. Library schemas discusses the additional requirements and restrictions on library schemas. B.2. Schema validation errors describes the schema errors.
The HED ecosystem supports a standard schema and additional discipline-specific library schemas. (See the expandable schema viewer to explore existing schemas.) Releases of the HED standard schema are stored in the standard_schema/hedxml directory of the hed-standard/hed-schemas GitHub repository. Releases of HED library schemas are stored in a subdirectory of library_schemas in the hed-standard/hed-schemas GitHub repository.
Additional rules for HED annotations can be found in 4. Basic annotation and 5. Advanced annotation. The Making HED meaningful tutorial explains the semantics of HED and rules for making meaningful, standardized, and complete annotations. B.1. HED validation errors gives a complete list of HED annotation validation errors.
3.1. Schema rules¶
3.1.1. Schema versions¶
A HED standard schema version is a string representing a valid semantic version (e.g., 8.4.0 specifies standard schema version 8.4.0). HED library schemas have their semantic version appended to "XXX_". Here "XXX" is the name of the library (e.g., lang_1.2.0 represents version 1.2.0 of the lang HED library schema). A standard schema version earlier than 8.0.0 is not supported: a version specification that names one fails to load.
A schema version specification may be preceded by a namespace prefix: a namespace name followed by a colon (:). An example of a schema version specification using a namespace prefix is "ts:8.4.0" or "mystuff:lang_1.2.0". A namespace name consists of one or more ASCII letters (A-Z, a-z) and nothing else, so v2 and my_lib are not namespace names; a version specification with any other namespace name fails to load. Namespace names are case-insensitive: ts, TS, and Ts are the same namespace, both among the entries of a version specification and between a version specification and the tags of an annotation, so ['ts:8.5.0', 'TS:lang_1.2.0'] lists two schemas in one namespace and ts:Red and TS:Red are the same tag. If the schema version specification has a namespace prefix, then all tags drawn from that schema MUST appear in any corresponding annotation with that namespace prefix prepended (e.g., "ts:Sensory-event" for the "Sensory-event" tag in schema "ts:8.4.0"). Namespaces allow annotators to use tags from incompatible HED schemas to annotate a dataset.
3.1.2. Version combinations¶
3.1.2.1. Partnered vs unpartnered¶
HED library schemas are of two types: partnered and unpartnered. A partnered library schema, which has a withStandard attribute in its header, is designed to be used with a specific version of the HED standard schema to form a single unified vocabulary. The value of withStandard MUST be a released standard schema version >= 8.2.0, the first version with the attributes that partnering uses. A library schema whose partner is earlier loads and merges, but it is not a compliant schema. For example, the score library schema version 2.1.0 is partnered with standard schema version 8.4.0 and has the header (in XML format):
<HED version="2.1.0" library="score" withStandard="8.4.0">
Without the withStandard attribute in the header, a schema is considered unpartnered and MUST be completely self-contained. All current versions of the supported HED library schemas are partnered. A new unpartnered schema is not supported until rules for one are specified (see 7.4.2. Unpartnered design rules).
3.1.2.2. Merged vs unmerged¶
A partnered library schema can be saved in two equivalent forms: merged or unmerged. The example in 3.1.2.1. Partnered vs unpartnered shows a schema that has been stored in merged form as a single vocabulary with all of its standard schema partner elements included in the schema file. Because these merged schema files are very large, an alternative, equivalent unmerged file format is also allowed. When stored in unmerged form the schema header includes the unmerged attribute as shown here for the XML format:
<HED version="2.1.0" library="score" withStandard="8.4.0" unmerged="True">
The value of the unmerged attribute is case-insensitive (true and True are equivalent). HED schema loaders MUST automatically load the HED standard schema partner when loading an unmerged partnered library schema. In a merged library schema the schema elements and schema attributes of the library always have the inLibrary schema attribute, which distinguishes them from those of the standard schema. These inLibrary attributes are removed when a library schema is saved in unmerged form.
A partnered library schema may also contribute rows of its own to the three extra sections (Sources, Prefixes, and External annotations; see 3.1.4.10. Sources, prefixes, and external annotations). In unmerged form these sections hold only the rows of the library, and the rows do not carry inLibrary. In merged form they hold the rows of the standard schema partner together with the rows of the library, and each row of the library carries inLibrary with the library name, as the schema elements and schema attributes of the library do; the rows of the partner are unmarked. A tool that loads an unmerged partnered library schema combines the rows of the library with those of its partner in the same way. A row of an extra section is identified by its key: source in Sources, prefix in Prefixes, and prefix together with id in External annotations. An unmerged partnered library schema MUST NOT have a row with the same key as a row of its standard schema partner, whether or not the other columns of the two rows agree. The rows of the libraries in a merge group are combined as described in 3.1.2.4. Partnered combinations. The form of the inLibrary mark on a row in each file format is given in A.2.5.7. Schema sources (MediaWiki), A.3.5.7. Schema sources (XML), A.4.5.6. Schema sources (JSON), and A.5.11.1. Sources file (TSV).
3.1.2.3. Merge groups¶
HED has adopted a strategy that allows multiple compatible library schemas to be combined into a single build-your-own unified vocabulary. If the library schemas are incompatible, they can still be used together by placing them in different namespaces. We refer to the schemas that a version specification lists in the same namespace as a merge group.
Merge groups are defined in the schema version specification, not in the schema itself: each namespace has one merge group. The schemas listed in the default namespace (no prefix) form one merge group, and each unique prefix in the version specification designates a distinct merge group. For example the following BIDS version specification:
"HEDVersion": ["lang_1.1.0", "score_2.1.0", "bc:mouse_1.0.0"]
indicates for this particular BIDS dataset HED tags from the lang and score HED library schemas can be used without prefix, but tags from mouse must have the bc: prefix prepended. The user-selected prefix bc: is a namespace prefix. This dataset uses two namespaces (default and bc:).
3.1.2.4. Partnered combinations¶
Combination of different schemas into a single vocabulary can proceed provided there are no conflicts as governed by the following rules. A specification that violates any of these rules cannot be loaded.
Loading assumes that each schema in a version specification is itself compliant. An error that concerns a single schema, such as a duplicate node or a schema attribute that is used but not defined, does not prevent the schema from loading; it is reported only when that schema is validated. A version specification fails to load (SCHEMA_LOAD_FAILED) only when a schema cannot be found or parsed, when the specification breaks the version and namespace rules of 3.1.1. Schema versions, or when its schemas break a rule of the following table.
Topic |
Rule |
|---|---|
Merge groups |
Schemas listed in the same namespace form a single merge group. |
Merge groups |
Each merge group is resolved independently; the standard schema partners of different merge groups do not have to agree. |
Merge groups |
Schemas in a merge group can be combined in any order. Whether or not the load fails is independent of order, but what element first generates a conflict depends on the order. |
Merge groups |
A schema cannot be listed twice in the same merge group, in the same or in different versions: two library schemas with the same library name, or two standard schemas, are an error. |
Standard partner |
All partnered library schemas in a merge group MUST have the same standard schema partner (the same |
Standard partner |
A standard schema in a merge group is allowed if its version is the same as the group partner; it adds nothing to the merged result. |
Standard partner |
A standard schema in a merge group raises an error if its version differs from the group partner. |
Standard partner |
An unmerged partnered library schema that has a schema element or schema attribute with the same name as one of its standard schema partner, other than a unit class it names only to add new units under it, cannot be loaded (see 7.4.1. General design rules). |
Unpartnered schemas |
An unpartnered library schema MUST be alone in its own namespace. |
Element compatibility |
A schema element (tag, unit class, unit, unit modifier, or value class) or a schema attribute appearing in more than one schema of a merge group MUST have the same attribute values, the same description, and the same ancestor path in each schema. The ancestor path of a unit is its unit class: a unit shared by two schemas MUST be in a unit class of the same name in each. |
Element compatibility |
For a schema attribute, the schema properties are the attribute values that are compared: two schema attributes with the same name MUST have the same properties. |
Element compatibility |
An element appearing in more than one schema of a merge group MUST either have a |
Element compatibility |
A shared element can have different non- |
Element compatibility |
The |
Element compatibility |
A schema element or schema attribute contributed by more than one library schema of a merge group carries one |
Auxiliary sections |
New library schema unit classes with their units, unit modifiers, value classes, and schema attributes are merged directly. |
Auxiliary sections |
New library schema units under an existing unit class are merged if there are no conflicts. |
Extra sections |
A row of the Sources, Prefixes, or External annotations section that appears with the same key (see 3.1.2.2. Merged vs unmerged) and the same contents in more than one library schema of a merge group is kept once, with one |
Extra sections |
The |
Extra sections |
Rows with the same key and different contents in two library schemas of a merge group are a conflict. |
Prologue and epilogue |
Differences in the prologues and epilogues of the schemas in a merge group are not conflicts, since merge groups are never saved. |
See 7.3.6. Lazy partnering for a description of the merging process and examples.
3.1.3. Version updates¶
HED schemas are versioned using the semantic versioning system and use these rules for changing the major.minor.patch semantic version. These rules are based on the assumption that annotators using the HED tag short form will not have to retag their data for patch-level or minor-version changes of the schema. That is, a dataset tagged with short-form tags using schema version X.Y.Z has no invalid tags under a later version with the same major version X; values and units MAY become invalid in a minor or patch change.
Here is a summary of the types of changes that correspond to different levels of changes in the semantic version:
Change |
Semantic-level |
|---|---|
Major addition to HED functionality |
Major |
Tag deleted from schema |
Major |
Tag renamed |
Major |
Unit or unit class removed from node |
Major |
|
Major |
Schema attribute, value class, or unit modifier removed from schema |
Major |
Schema property removed from schema |
Major |
|
Major |
Node attribute value changed |
Minor |
Inherited attribute change |
Minor |
New property added to schema |
Minor |
New value class added to schema |
Minor |
New unit modifier added to schema |
Minor |
New tag added to the schema |
Minor |
New attribute added to schema |
Minor |
New unit class or unit added to schema |
Minor |
New unit class added to node |
Minor |
New value class added to node |
Minor |
|
Minor |
Node moved in schema without change in meaning |
Minor |
Schema element or schema attribute deprecated |
Minor |
|
Minor |
|
Minor |
Standard schema partner version changed |
Minor |
Listed unit removed but still derivable (uV) |
Patch |
Revision of description field in schema |
Patch |
Correction of suggestedTag or relatedTag |
Patch |
Correction of wiki syntax such as closing tags |
Patch |
Narrowing allowedCharacter is a major change, with one exception: narrowing it for a value class that no # child uses is a minor change, because it makes no annotation invalid. A # child uses a value class when its valueClass attribute names that value class.
Note: It is an official policy that once in a schema, a schema element will not be removed without a major schema version change. The one exception is a listed unit that stays valid because it is derived from another unit of its class by an SI unit modifier (uV is u + V, so HED 8.5.0 no longer lists it): removing such a listing changes the validity of no annotation and is a patch-level change; the unit’s hedId is retired, not reused (see 8.3.1. Schema namespaces versus the ontology namespace). If a node becomes out-of-date, the deprecatedFrom attribute is added to the node in the schema (see A.1.4.5. deprecatedFrom). A suggested replacement SHOULD be included in the node description.
A schema element or schema attribute that has the deprecatedFrom attribute is deprecated (see A.1.4.5. deprecatedFrom). A deprecated element stays in the schema, and a schema with deprecated elements MUST satisfy these rules; a violation is SCHEMA_DEPRECATION_ERROR:
The value of
deprecatedFromMUST be a released schema version earlier than the version of the schema.A child tag of a deprecated tag MUST be deprecated, unless it is moved to a non-deprecated parent.
Every unit of a deprecated unit class MUST be deprecated. A deprecated unit MAY stay in a unit class that is not deprecated (
$incurrencyUnits,degree CelsiusintemperatureUnitsin HED8.5.0).A non-deprecated tag MUST NOT name a deprecated tag in its
suggestedTagorrelatedTagattribute.A deprecated schema attribute MUST NOT be used on a non-deprecated schema element.
A non-deprecated tag MUST NOT name a deprecated unit class or value class in its
unitClassorvalueClassattribute.A deprecated unit MUST NOT be the
defaultUnitsof a non-deprecated unit class.
3.1.4. Schema layout overview¶
Schemas can be specified in any of four equivalent formats: MediaWiki, TSV, XML, or JSON. This section gives the rules that hold in every format; appendix A. Schema format details describes each of the four formats. The HED schema online tools provide an easy way for users to validate schema and convert between formats.
HED schema developers usually use .mediawiki format for more convenient editing, display, and viewing on GitHub. However, the stable links provided for tools to access and download the HED schema are to the XML versions. TSV format is sometimes used early in schema development and JSON format is used primarily by AIs. All formats MUST be available and synchronized in the hed-standard/hed-schemas GitHub repository.
The sections of a HED schema are listed below in the order in which they MUST appear in the MediaWiki and XML formats. The JSON format stores the sections under keys and the TSV format in separate files, so order has no meaning there. Every section is required, although a section may be empty, and a tool that writes a schema file writes every section.
Order |
Section |
Rules |
|---|---|---|
1 |
Header |
|
2 |
Prologue |
|
3 |
Schema |
|
4 |
Unit classes |
|
5 |
Unit modifiers |
|
6 |
Value classes |
|
7 |
Schema attributes |
|
8 |
Schema properties |
|
9 |
Epilogue |
|
10 |
Sources |
|
11 |
Prefixes |
|
12 |
External annotations |
The names and markers that delimit the sections in each format are given in A.2.1. Overall file layout (MediaWiki), A.3.1. XML file layout, A.4.1. JSON file layout, and A.5.1. TSV file organization.
The HED tags are defined in the schema section, where the entry for a tag is called a node; the remaining sections specify additional information and behavior.
The name of every schema element other than the # placeholder, of every schema attribute, and of every schema property MUST consist of name characters (see 2.2 Character sets and restrictions). The name of a unit or unit modifier MAY also contain the characters that the unit or unit modifier itself declares with the allowedCharacter attribute: the unit m^2 declares allowedCharacter=caret. Any other character in such a name is an error. The one exception is the deprecated unit degree Celsius, whose name contains a blank (see 3.1.4.4. Unit classes and units).
If a section of the schema is missing or, in the MediaWiki or XML format, out of order, an error occurs. This error is reported by schema validation. Whether a schema without the extra sections loads is stated in 3.1.4.10. Sources, prefixes, and external annotations.
Each of the schema sections has “schema attributes”, which are the attributes that may be assigned to elements in a given section. If a schema attribute is applied improperly to an element in a given section, an error occurs.
See Appendix A for additional details on format.
3.1.4.1. The header¶
The schema header line MUST specify the version attribute whose value MUST be a valid semantic version.
A schema may optionally contain library, withStandard, and unmerged attributes for library schemas. A schema’s library name or lack thereof is used to locate the schema in the hed-schemas GitHub repository.
The header may optionally contain an XSD namespace specification. An unrecognized header attribute does not prevent the schema from loading and does not affect the validation of annotations with that schema. It is an error in schema validation, and a tool that writes the schema writes the attribute and its value unchanged.
See A.2.2. MediaWiki header and A.3.2. XML header for more detailed information on the MediaWiki and XML header formats, respectively.
3.1.4.2. The prologue¶
The prologue SHOULD contain a concise introduction to the schema and its purpose. Together with the epilogue section, the contents are used by tools to provide information about the schema to the users.
The prologue may contain text characters, the comma, or newline. Any other character is invalid.
3.1.4.3. The schema section¶
The schema section contains the actual vocabulary contents of the schema. Each entry in this section is a node: it defines one tag or is the # placeholder of a tag that takes a value. The location of a node within the section specifies its relationship to the other nodes of the schema.
The node of a tag specifies a name, schema attributes, and an informative description of the tag’s meaning. A node name may only contain valid name characters (alphanumeric, hyphen, underscore, and nonascii; see 2.2 Character sets and restrictions).
This also applies to tag extensions. Substitutions for the # placeholder that have value classes are governed by the rules of that value class.
The name of each node MUST be unique in the schema, without regard to case: two names that differ only in capitalization are the same name (see 3.2.3. Tag case-sensitivity).
3.1.4.4. Unit classes and units¶
A unit class is an attribute of a # schema placeholder node. A placeholder MUST NOT have more than one unit class; a unitClass attribute listing several unit classes is an error. A placeholder with a unit class MUST have valueClass=numericClass as its only value class, because a value with units is a number to be converted; a unit class on a placeholder with any other value class, with several value classes, or with none, is likewise an error. A schema MAY define the pseudo unit class anyUnits, which lists no units and has no defaultUnits; a placeholder with unitClass=anyUnits accepts a unit from any unit class of the schema, listed or derived, and, when that unit has a conversionFactor, its value converts to the default units of the class that unit belongs to; otherwise conversion is undefined, as for any unit without a factor. A value on such a placeholder MAY be written without a unit: it is then valid as a plain number with no default unit and no conversion; unlike Delay and Duration, whose bare numbers are in the default unit s, it has no default unit. When a unit string resolves in more than one unit class, the class that lists it outright wins over a class that only derives it (dB is the decibel of intensityUnits, not d + B of memorySizeUnits); a string that two classes derive and none lists is a schema error (SCHEMA_DUPLICATE_NODE c), and anyUnits with units or defaultUnits is a schema error (SCHEMA_ATTRIBUTE_INVALID d). The unit class definition section specifies the allowed unit classes for the schema as well as the associated units that can be used with tags that take values.
Only the singular version of each unit name is explicitly specified, but the corresponding plurals are also allowed. No plural is derived by a rule: the plural of a unit name is the one that the unit plurals file unit_plurals.json lists for it (seconds for second, feet for foot, inches for inch, degrees-Celsius for degree-Celsius; hertz is its own plural). The plurals are shown as a table in A.1.1. Unit classes and units, and the file is described in A.8. Unit plurals file. A unit name that the file does not list has no plural, and no other plural is valid (foots and inchs are invalid). Only unit names may be pluralized; unit symbols never are (mss and Hzs are invalid). A unit name that takes an SI unit modifier takes it in the plural too, as the modifier followed by the listed plural (milliseconds, kilohertz).
Units may be in one of four forms as designated by their unit type attributes:
Unit type |
Unit type attributes |
|---|---|
SI unit |
only |
SI unit symbol |
both |
unit that is not an SI unit |
no unit type attribute |
unit symbol is not an SI unit |
only |
Units appear after the value in annotations. A unit with the unitPrefix attribute appears before its value instead; the only such unit, $, and the unitPrefix attribute itself are deprecated and will be removed in a future major version. Currency values are written with the unit name, as in 5 dollars.
If the SIUnit, unitSymbol, or unitPrefix attribute appears in a section other than the unit class definition section of the schema, an error occurs. See appendix A.1.1. Unit classes and units for additional details and a listing.
Unit names and unit symbols are case-sensitive and MUST NOT contain blanks. A unit in an annotation MUST be a unit listed in the schema, the plural of a listed unit name, or a form derived from a listed unit that has the SIUnit attribute by prepending an SI unit modifier (for a compound unit, one modifier per component; see 3.1.4.5. Unit modifiers), with the case of the unit and of the modifier exactly as listed. Feet, Milliseconds, and MS are invalid. The deprecated unit degree Celsius, listed since before this rule, is the one legacy exception: it cannot be written in an annotation, because a blank separates the value from its unit. Unit class names are case-insensitive, but MUST contain only valid name characters. Any other character is invalid.
A unit class MUST NOT list a unit that can be formed by applying an SI unit modifier to another unit of the same class that has the SIUnit attribute; such a unit is derived, not listed. For example, uV is u + V and is not listed once V has SIUnit. A violation is an error. A unit name MUST appear at most once in a schema, compared exactly as written, whether in one unit class or in two; a violation is an error. Units whose names differ only in case are different units, and a schema MAY list both (volt and Volt), in one unit class or in two. See appendix A.1.1. Unit classes and units for the units of HED 8.5.0.
3.1.4.5. Unit modifiers¶
The unit modifier definition section lists the SI unit multiples and submultiples that are allowed to be prepended to units that have the SIUnit schema attribute.
Unit modifiers can only be used with SI units and SI unit symbols. SI unit modifiers used with ordinary SI units have the SIUnitModifier attribute, while unit modifiers used with SI unit symbols have the SIUnitSymbolModifier attribute.
A compound unit is a unit whose name contains -per- or a ^ exponent, such as m-per-s, m-per-s^2, m^2, m^3, and mol-per-L. Its components are unit symbols, and a compound unit that has the SIUnit attribute takes one SI unit symbol modifier on each component independently, never on the string as a whole. The grammar is:
unit := component ("-per-" component)*
component := [modifier] base ["^" digits]
Here base is a component of the listed unit and modifier is an SIUnitSymbolModifier. Thus cm-per-us, mm-per-s^2, and mm^3 are valid forms of m-per-s, m-per-s^2, and m^3, while kmm-per-s (two modifiers on one component), m-per-sec (not a symbol), and m-per-S (wrong case) are not. An exponent applies to the prefixed component, so mm^3 is a cubic millimeter. The conversion factor of a compound form is the listed conversionFactor multiplied, for each component, by the modifier’s conversionFactor raised to that component’s exponent, negative for components after -per-: cm-per-us = 1.0 x 0.01 x (1e-6)^-1 = 10000 m-per-s, and mm^3 = (0.001)^3 = 1e-9 m^3. A compound form that breaks these rules is an error.
If a SIUnitModifier or SIUnitSymbolModifier attribute appears in a section other than unit modifier section of the schema, an error occurs.
Unit modifiers are case-sensitive.
See appendix A.1.2. Unit modifiers for additional details and a listing of values for the standard schema.
3.1.4.6. Value classes¶
The value class definition section specifies rules for the values that are substituted for placeholders (#). Examples are special characters that are allowed for numeric values or dates. Placeholders that have no valueClass attributes are assumed to take textClass values.
See appendix A.1.3. Value classes for additional details and a listing of values for the standard schema.
Value class names are case-insensitive, but MUST contain only valid name characters.
3.1.4.7. Schema attributes¶
The schema attributes section defines the schema attributes that may be assigned to the schema elements: nodes, unit classes, units, unit modifiers, and value classes.
The specification of which type of schema elements a particular schema attribute may apply to is specified by its schema properties. If a schema attribute appears in a section contradicted by its properties, an error occurs. A schema attribute that is used in the schema MUST be defined in the schema attribute definition section; otherwise an error occurs. An undefined attribute on a schema element does not prevent the schema from loading: it is an error in schema validation, and a tool that writes the schema writes the attribute and its value unchanged.
The value of a schema attribute MUST satisfy the rule for that attribute; a violation is SCHEMA_ATTRIBUTE_VALUE_INVALID unless another code is named:
allowedCharacter: a row of the table in 2.2 Character sets and restrictions, an alias listed there, or a single character.conversionFactor: a positive number.defaultUnits: a unit of the unit class or a form derived from one by an SI unit modifier (see 3.1.4.4. Unit classes and units).isPartOf,relatedTag, andsuggestedTag: an existing tag of the schema, or of the merged schema for a partnered library schema.deprecatedFrom: as stated in 3.1.3. Version updates (SCHEMA_DEPRECATION_ERROR).hedId: as stated in A.1.4.7. hedId (SCHEMA_HED_ID_INVALID).
See appendices A.1.4. Schema attributes and A.1.5. Schema properties for additional details and a listing for the standard schema.
3.1.4.8. Schema properties¶
The schema properties section lists the allowed properties of the schema attributes. These properties help tools validate certain requirements directly based on the HED schema rather than on a hard-coded implementation. A property that is used on a schema attribute MUST be defined in the schema properties section; otherwise an error occurs.
There are two main types of properties: domain properties and range properties. Property names ending in Domain indicate the types of schema element a schema attribute may apply to. The domain properties are elementDomain, tagDomain, unitClassDomain, unitModifierDomain, unitDomain, and valueClassDomain. Schema attributes without any domain property are assumed to apply to nodes. A node (a tag or a # placeholder) may have the schema attributes that have the tagDomain or the elementDomain property or no domain property. A schema attribute that has the elementDomain property may be assigned to a schema element of any kind and to a schema attribute. A schema property is assigned no schema attribute other than hedId, so a schema property cannot be deprecated.
Property names ending in Range indicate the type of value a schema attribute may have. The range properties are boolRange, numericRange, stringRange, tagRange, unitClassRange, unitRange, and valueClassRange. A schema attribute with the boolRange property does not take a value: its presence indicates true, and its absence indicates false. The remaining property, annotationProperty, marks a schema attribute whose value is not inherited by child nodes.
A schema attribute may have multiple domain properties, indicating that the attribute may appear in multiple sections of the schema, and multiple range properties, indicating that its values may be of several types.
See A.1.4 Schema attributes and A.1.5. Schema properties for information and a listing of schema attributes and their respective properties.
3.1.4.9. The epilogue¶
The epilogue SHOULD give license information, acknowledgments, and references.
The epilogue may contain text characters, the comma, or newline. Any other character is invalid.
3.1.4.10. Sources, prefixes, and external annotations¶
The rules in this section apply to every schema: standard schemas and partnered and unpartnered library schemas. Schemas that do not have one or more of these sections or have a different format than specified in this document do not pass schema compliance, but they can still be loaded (see 3.1.2.4. Partnered combinations).
The purpose of these sections is to provide a mechanism for HED to link to external sources including other ontologies. The sources section defines external sources with links, the prefixes section defines the prefixes of the external ontologies and vocabularies, and the external annotations provide the ID links to actual UUIDs within the resources specified in the sources.
These sections are written like every other section (see 3.1.4. Schema layout overview). See A.2.5. MediaWiki sections after the schema section, A.3.5. XML sections after the schema section, A.4.5. JSON sections after the schema section, and A.5.11. TSV sources, prefixes, and annotations for specific format details.
3.1.5. Naming conventions¶
The different parts of the HED schema have different rules for the characters and the names that are allowed.
3.1.5.1. Node elements¶
Schema designers and users that extend HED schema or develop library schema will be mainly concerned with nodes (tag terms) found in the schema section. The names of these elements MUST consist of name characters (see 3.1.4.3. The schema section).
Other conventions and requirements for the contents of schema node elements are as follows:
Naming conventions for nodes (tag terms) in HED schema.
By convention, the first letter of a schema node (tag term) SHOULD be capitalized with the remainder lower case.
Schema node names consisting of multiple words MUST NOT contain blanks and SHOULD be hyphenated.
Schema descriptions SHOULD be concise sentences, possibly with clarifying examples.
Schema descriptions may include only
textcharacters and the comma, and MUST NOT containnewline.
3.1.5.2. Epilogue and prologue¶
The characters allowed in the epilogue and prologue are given in 3.1.4.2. The prologue and 3.1.4.9. The epilogue; new lines are preserved.
3.1.5.3. Naming in other blocks¶
The names of schema attributes, schema properties, unit classes, and value classes SHOULD start with a lower case letter, with the remainder in camel case.
Units and unit modifiers follow the naming conventions of the units they represent.
The case of units and unit modifiers is stated in 3.1.4.4. Unit classes and units and 3.1.4.5. Unit modifiers.
3.2. Annotation rules¶
HED annotations are comma-separated strings of HED tags drawn from a HED schema vocabulary. HED validators and other tools use the information encoded in the relevant schema when performing validation and other processing of HED annotations.
Users MUST provide the version of the HED schema they are using when creating an annotation.
Deprecated schema elements are defined in 3.1.3. Version updates. An annotation that uses a deprecated tag, unit, or unit modifier remains valid, but a validator issues a warning for each such use.
3.2.1. Vocabulary organization¶
HED (Hierarchical Event Descriptors) are nodes (tag terms) organized hierarchically under their respective root or top nodes. In HED standard schemas these top nodes are: Event, Agent, Action, Item, Property, and Relation. Each top node and its subtrees represent distinct is-a relationships for the vocabulary schema.
The Event subtree tags indicate the general event category, such as whether it is a sensory event, an agent action, a data feature, or an event indicating experiment control or structure.
The HED annotations describing each event may be assembled from a number of sources during processing and the annotations associated with a single event marker may represent multiple events.
Many analysis tools use the Event tags as a primary means of segregating, epoching, and processing the data. The recommendation for Event tags in event annotations is stated in 3.3.2.2. Event structure.
The Agent subtree tags indicate the types of agents (e.g., persons, animals, avatars) that take an active role or produce a specified effect. An Agent tag SHOULD be grouped with property tags that provide information about the agent, such as whether the agent is an experiment participant.
The Action subtree tags indicate actions performed by agents. Generally these are grouped in a triple (A, (Action, B)) which is interpreted as A does Action on B. If the action does not have a target, it SHOULD be annotated (A, (Action)), meaning A does Action.
The Item subtree tags represent things with (actual or virtual) physical existence such as objects, sounds, or language.
Descriptive tags are organized in the Property subtree. These descriptive tags SHOULD always be grouped with the tags they describe using parentheses.
Binary relations are in the Relation subtree. Like items from the Action subtree, these SHOULD be annotated using (A, (Relation, B)).
3.2.2. Tag forms¶
A HED tag is a term in the HED vocabulary identified by a path consisting of the individual node names from some branch of the HED schema hierarchy separated by forward slashes (/).
Valid HED tags do not have leading or trailing forward slashes (/). A HED tag path MUST NOT have consecutive forward slashes. A blank MUST NOT appear directly before or after a forward slash of the tag path, including the slashes of a tag extension and the slash that begins a value (for Definition, Def and Def-expand, also the slash before the second part of the value): Event/ Sensory-event, Label/ abc and, in a sidecar, Label/ # are invalid. A slash inside a value is part of the value, and the blanks next to it are judged by the rules for the value’s class: Description/left / right is valid.
Because node names are unique in the schema (see 3.1.4.3. The schema section), the user may specify as much of the path to the root as desired when using the tag in annotation.
The full path version is referred to as long form, and the version with only the final tag element (excluding placeholder) is called short form.
Any intermediate form of the tag path is also allowed as illustrated by this example:
The long, intermediate, and short forms of a tag are the same tag; validators and other tools MUST treat them as equivalent.
HED tools are available to map between shortened and long forms as needed. The tag MUST be associated with a schema and MUST correspond to a path in the schema (excluding any extension or value).
See the invalid-tag errors in Appendix B for errors involving forward slashes (/), extra white-space, and other types of tag syntax errors.
3.2.3. Tag case-sensitivity¶
Although by convention tag terms start with a capital letter with the remainder being lower case, tag processing is case-insensitive. This convention makes annotation strings more readable and is recommended for tag extensions. Validators and other tools MUST treat schema node names that differ only in capitalization as equivalent, in every tag form. A tag extension and the name of a definition (the part that follows Definition, Def, or Def-expand) are treated like node names: Red/Blech and Red/blech are the same tag expression, and so are Def/MyDef and Def/mydef.
The value that replaces a # placeholder is not part of this rule: a value is compared exactly as written. Label/abc and label/abc are the same tag expression, whereas Label/abc and Label/ABC are different. The value that follows a definition name, as in Def/MyDef/abc, is such a value.
Units and unit modifiers are matched with their case preserved, as stated in 3.1.4.4. Unit classes and units and 3.1.4.5. Unit modifiers.
3.2.5. Tag extensions¶
A tag extension, in contrast to a value, is a tag that users add as a child of an existing schema node as a more specific term for an item already in the schema. For example, a user might want to use Helicopter instead of the more general term Aircraft. Since Aircraft inherits the extensionAllowed attribute, users may use extended tags such as Aircraft/Helicopter in their annotation. The requirements for such an extension are:
Warning
Requirements for tag extensions by users:
Unlike values, an extension term MUST NOT already be a node in the schema.
The extension term MUST contain only
namecharacters.The parent of the tag extension MUST always be included with the extended tag in annotation.
The extension term MUST satisfy the “is-a” relationship with its parent node.
The
#placeholder cannot be used as an extension - in particular it cannot be used as a placeholder in definitions or as value annotations in sidecars. A#after an extension term (Item/Blech/#) is an error in every context, in a table or a sidecar alike.An extension term MUST contain at least one letter. A term made only of digits, hyphens, and underscores (
3,42,1-2) reads as a value and is an error. A letter isA-Zora-z, or any Unicode letter in schema versions whosenameClassallows non-ASCII characters (see A.1.3. Value classes).
Note: The is-a relationship is not checked by validators. It is needed so that term search works correctly.
A reserved tag (see 3.2.8. Reserved tags) MUST NOT be extended, although it inherits extensionAllowed from Property: Onset/Blah and Event-context/Blah are errors. A # after a reserved tag that takes no value (Onset/#) is also an error in every context.
Examples: Item and Property have extensionAllowed; Age has a # child.
Item/BlechandItem/Blech/Blech1/Blech2are valid extensions, of one and of three levels.Item/3D-printoutandItem/Blech/1redare valid: a term may begin with a digit when it contains a letter.Item/Blech/Redis an error:Redis already a node in the schema (rule 1).Item/Blech/3andItem/1-2are errors: the term has no letter (rule 6).Item/Blech/#,Item/#, andItem/Blech/#/Fooare errors:#cannot be an extension (rule 5).Age/3is the tagAgewith the value3, not an extension:Agehas a#child, so any child ofAgeis a value (see 3.2.4. Tags that take values). For the same reasonAge/Blechis not an extension:Blechis a value ofAge, and is an error because the value ofAgemust be numeric.
Tag extensions SHOULD follow the same naming conventions as those for schema nodes. See 3.1.5. Naming conventions for more information about HED naming conventions. No warning is issued for an extension that does not follow the convention.
Users SHOULD NOT use tag extension unless necessary for their application, as this breaks the commonality among annotations across datasets. Please open an issue proposing that the new term be added to the schema in question, if you think the term would be useful to other users.
Note: User tag extensions are sometimes accidental and due to misspelling, particularly when a long or intermediate form of the tag is used. For this reason a warning is issued for extended tags during validation.
3.2.6. Tag namespace prefixes¶
Users may select tags from multiple schemas, but additional schemas MUST be included in the HED version specification.
Users are free to choose any namespace name made of ASCII letters (see 3.1.1. Schema versions) and associate it with a specific schema in the HED version specification. The namespace prefix is that name followed by a colon (e.g., sc:); the rules for writing it on the tags of the associated schema are stated in 3.1.1. Schema versions. The namespace name and its prefix are chosen per dataset and are not part of any schema; they are an import mechanism, like import pandas as pd in Python, and the same schema may be given a different prefix in another dataset.
Only the tags of one merge group, the schemas listed without a namespace prefix in the version specification, appear in an annotation without a prefix (see 3.1.2.3. Merge groups).
See 7.5. Library schemas in BIDS for an example of how the namespace prefix notation is used in BIDS.
3.2.7. Strings and groups¶
A HED string is an unordered, comma-separated list of HED tags and/or HED tag groups.
A HED tag group is an unordered, comma-separated list of HED tags and/or tag groups enclosed in parentheses. Tag groups may include other tag groups.
Blanks before and after a comma or a parenthesis are not significant: (Red,Blue) and ( Red , Blue ) are the same HED string.
The validation errors for HED tags and HED strings are summarized in Appendix B: HED errors.
3.2.7.1. Parentheses and order¶
Any ordering of HED tags and HED tag groups at the same level within a HED string is equivalent. Valid HED strings may have parentheses nested to arbitrary levels (nested groups). The parentheses MUST be properly nested and matched.
Parentheses are meaningful and convey association. If A and B represent HED expressions, (A, B) is not equivalent to the HED string A, B. The distinction SHOULD be preserved if possible. (A, B) means that HED tag A and HED tag B are associated with each other, whereas A, B means that A and B are each annotating some larger construct.
Specific rules of association will be encoded in a future version of the HED specification.
3.2.7.2. Tag group attributes¶
A HED tag corresponding to a schema node with the tagGroup attribute MUST appear inside parentheses (i.e., MUST be in a HED tag group).
The topLevelTagGroup attribute is inherited: a tag has it when its schema node or any ancestor of that node has it. A HED tag that has the topLevelTagGroup attribute MUST appear in an unnested HED group in an assembled HED annotation. A top-level group MUST NOT contain more than one tag that has the topLevelTagGroup attribute, counting a tag and its descendants as separate tags (if A has the attribute, (A, A/B) is an error), except that a Delay tag MAY share a group with Onset, Offset, Inset, or Duration (see 3.2.8. Reserved tags). The topLevelTagGroup attribute is usually associated with tags that have special meanings in HED such as Definition and Onset.
3.2.7.4. Repeated expressions¶
Duplicated tag expressions at the same level in a HED tag group or HED string are not allowed. Tags are compared under the case rule of 3.2.3. Tag case-sensitivity. For example, the expressions (Red, Blue, Red) and (Red, Blue), (Red, Blue) have duplicated tag expressions at the same level and are hence invalid. Identical Definition groups are not repeated expressions (see 3.2.8.1. The Definition tag).
3.2.9. Sidecars¶
JSON sidecars are an integral part of the BIDS (Brain Imaging Data Structure) neuroimaging standard and are used to associate metadata with data files.
The JSON sidecars that are relevant to HED are associated with tables. For example, the rows of a timeline table represent time markers on the experimental timeline, and the assembled HED annotations for each row describe what happened at that time marker. A sidecar containing annotations associated with the columns of such a table allows HED tools to assemble HED annotations for each row of the table.
In addition to sidecars, HED annotations can also be given in the HED column of a table. At validation or analysis time the HED information from both the HED column of a table and its associated sidecar are assembled to provide the annotation.
HED validators assume that the annotation dictionary is saved in JSON format and that it complies with the BIDS sidecar format. A sidecar that is stored in a file is encoded in UTF-8, as BIDS requires of a JSON file.
3.2.9.1. Sidecar entries¶
A BIDS sidecar is a JSON dictionary with several types of entries, three of which are relevant to HED:
The other types of sidecar entries include categorical and value entries with no "HED" key, as well as arbitrary entries whose keys do not correspond to column names in an associated table.
A top-level sidecar key corresponds to a column name only when the two strings are identical: no trimming, change of case, or other normalization is applied. A key or column name with leading or trailing whitespace is itself an error (3.2.9.2. Sidecar validation, 3.2.10. Tabular files and structures). In the same way, a categorical value matches a key of its entry’s annotation dictionary only when the two strings are identical, and a value is substituted for the # exactly as written.
When annotations are assembled, sidecar entries with no "HED" key are ignored as are entries in the corresponding table that have n/a or blank values.
See 3.2.9.4. A sidecar example for an elaborated example of these different types of entries and 3.2.10.3. Event-level processing for an example of how the resulting HED annotations are assembled.
3.2.9.2. Sidecar validation¶
All HED-related entries in a JSON sidecar MUST have "HED" as a key in a second-level dictionary. "HED" MUST NOT appear as a sidecar key at any other level. A categorical entry MUST NOT have n/a as a key.
A top-level sidecar key MUST NOT begin or end with whitespace, as defined for column names in 3.2.10. Tabular files and structures. The rule applies to every top-level key, whether or not its entry has a "HED" key.
In a categorical entry, a column value listed as a key under "HED" (such as go in {"trial": {"HED": {"go": "Sensory-event"}}}) MUST NOT begin or end with whitespace either. Only these keys are checked; the keys of other dictionaries in the entry, such as a BIDS Levels dictionary, are not. Since values are matched exactly, such a key could only match a column value that begins or ends with whitespace, which is itself an error (see 3.2.10.2. Table annotations), so it could never annotate a row.
An annotation in a categorical entry MUST NOT be empty or consist only of blanks. A column value that has no HED annotation is given the annotation n/a (as in {"trial": {"HED": {"go": "Sensory-event", "rest": "n/a"}}}), which contributes nothing when the annotation of a row is assembled; the column value then has an entry, so no warning is reported for it. The annotation of a value entry MUST contain a #, so it is never n/a: a value column that has no annotation has no "HED" key.
Where definitions may appear in a sidecar is stated in 3.2.8.1. The Definition tag.
The sidecar does not have to provide a HED-relevant entry for every table column. Columns with no corresponding sidecar entry are skipped during assembly of the HED annotation for a table row. Two conditions are reported as warnings, not errors: a value in a column that the sidecar annotates as a categorical column has no HED annotation in the sidecar, and a column referenced in curly braces in the sidecar is not a column of the associated table.
HED value sidecar entries MUST contain exactly one # placeholder in the HED string annotation associated with the entry. The # placeholder MUST correspond to a # in the HED schema, indicating that the parent tag (also included in the annotation) expects a value. These issues are errors.
If the placeholder is followed by a unit designator, the validator checks that these units are consistent with the unit class of the corresponding # in the schema. The units are not mandatory.
3.2.9.3. Sidecar curly braces¶
The notation was introduced to facilitate proper nesting of HED tags associated with different table columns when the complete HED annotation for an event marker is assembled.
When a column name appears in curly braces within a HED annotation in a JSON sidecar, the corresponding HED annotation for that row is substituted for the curly braces and their contents when the HED annotation is assembled.
The notation is defined here for BIDS sidecars, but it applies to any tabular container whose per-row annotation is assembled from named columns in the same way: a column-level annotation (a value template or a categorical mapping) may reference another HED-annotated column of the same table, or HED for the table’s per-row HED column. The same rules apply.
Rules for curly braces notation in sidecars.
The item within the curly braces MUST either be the word
HEDor the name of another HED-annotated column within the sidecar.The HED annotation for the column in curly braces directly replaces the curly braces and their contents in the target annotation.
During assembly of a HED annotation for an event, if an
n/aor blank value appears in a curly brace column, the curly brace expression including the curly braces as well as any extra parentheses or commas are removed. Values in a curly brace column are validated as stated in 3.2.10.2. Table annotations.A sidecar column name MUST NOT both appear in curly braces and have an annotation that uses curly braces (to prevent circular references).
Curly braces MUST NOT appear in a
Definitionor anEvent-contextgroup.Curly braces MUST NOT appear in the
HEDcolumn of a table.Curly braces MUST NOT be nested.
A pair of curly braces MUST appear syntactically as a tag. Curly braces MUST NOT appear as part of another tag, such as the value that replaces the placeholder of a tag (
Label/{b}).The group rules of a structural reserved tag (its anchor, the number of inner groups, and the tags allowed beside it, see 3.2.8) are checked on the assembled annotation. A sidecar entry such as
(Duration/#, {stim_desc})is valid when each annotation ofstim_descsupplies the required inner group.A sidecar annotation with curly braces is valid only if it is valid when the annotations of each referenced column are substituted, one referenced column at a time, whether or not a table uses the substituted values.
Rule 10 is checked on the sidecar alone. For each annotation with curly braces, a validator MUST check these substitutions:
One referenced column at a time. Each annotation of that column is substituted for its reference, and every other reference is removed as in rule 3.
No column. All references are removed.
A substitution with no reference removed gets every check; this happens only when the annotation references a single column. Every other substitution is checked only for repeated expressions, since the annotation may rely on the removed columns being filled. A value column’s template is substituted with its # unfilled, and a {HED} reference is always removed. Because the values are not known, the number of # placeholders is checked on each sidecar entry as written, not on a substitution, and a tag with an unfilled # is never counted as repeating another tag. A column referenced more than once counts as one column.
Examples:
(Red, {color})is invalid if any annotation ofcolorisRed, since it gives(Red, Red), even when no file uses that value.(Red, {color}), (Red)and(Red, {HED}), (Red)are invalid, since removing the reference leaves(Red), (Red).(Label/#, {b}), where the value columnbis annotatedLabel/#, is valid: the substitution(Label/#, Label/#)has two placeholders and two equal tags, but a row withleftandrightgives(Label/left, Label/right). A row whose two values are equal fails when it is assembled.(Duration/#, {stim_desc})is valid if every annotation ofstim_descsupplies the inner group. A row whosestim_descisn/afails when it is assembled becauseDurationrequires an inner group.
Errors that this check does not find are reported when a row is assembled: those that need two or more referenced columns filled (the repeat in ({color}, {shade}) when both give Red), those that depend on a row’s values, and those that need the whole row, such as required tags or reserved tags. A validator MAY also check combinations of referenced columns in the sidecar.
3.2.9.4. A sidecar example¶
The following example illustrates the different types of JSON sidecar entries.
Different types of annotation entries that might appear in a sidecar.
{
"event_type": {
"LongName": "Event category",
"Description": "Indicator of type of event.",
"Levels": {
"show": "Show a face to a participant.",
"press": "Participant presses key to indicate symmetry."
},
"HED": {
"show": "Sensory-event, Visual-presentation, {stim_file}",
"press": "Agent-action, (Experiment-participant, (Press, {key}))"
}
},
"stim_file": {
"LongName": "Stimulus image file",
"Description": "Name of the stimulus image file.",
"HED": "(Image, Face, Pathname/#)"
},
"key": {
"LongName": "Indicates which key is pressed.",
"Description": "Indicator of participant evaluation.",
"HED": {
"left-arrow": "((Leftward, Arrow), Keypad-key)",
"right-arrow": "((Rightward, Arrow), Keypad-key)"
}
},
"symmetry": {
"LongName": "Indicates symmetrical or asymmetrical.",
"Description": "Indicates the participant's judgement of symmetry.",
"HED": {
"symmetric": "(Judge, Symmetrical)",
"asymmetric": "(Judge, Asymmetrical)"
}
},
"dummy_defs": {
"HED": {
"MyDef1": "(Definition/Cue1, (Buzz))",
"MyDef2": "(Definition/Image/#, (Image, Face, Label/#))"
}
}
}
In the example, "event_type" is the name of a column that is annotated using the categorical strategy. Its top-level dictionary has "LongName", "Description", "Levels", and "HED" keys.
The value of "Levels" is a dictionary with the unique values in the "event_type" column keyed to full text descriptions of these unique values.
The value of "HED" is a dictionary with the unique values in "event_type" keyed to the corresponding HED annotations of these unique values. In the above example, the unique values are "show" and "press". The HED annotation for show is "Sensory-event, Visual-presentation, {stim_file}".
Notice use of curly braces in the notation. Here "stim_file" must correspond to another HED-annotated column in the sidecar. The "stim_file" column is an example of a value column. Its top level dictionary keys are "LongName", "Description", and "HED", and its annotation entry is "(Image, Face, Pathname/#)". This annotation has a single #. The filename in the stim_file column replaces this # when the HED annotation for a line in an associated events.tsv file is assembled.
Since "stim_file" and "key" appear within curly braces in annotations for "event_type", their HED annotations cannot use curly braces.
The "dummy_defs" is an example of a dummy annotation. The value of this entry is a dictionary with a "HED" key pointing to a dictionary. A dummy annotation is similar in form to a categorical annotation, but its keys do not correspond to any table column values. Rather it is used as a container to organize HED definitions.
In the example, Definition/Cue1 is a definition that does not use a placeholder (#) modifier in its name, while Definition/Image/# is a definition whose name Image is modified by a placeholder value. Notice that Image is both a definition name and an actual tag in the schema in this example. This is permitted.
3.2.10. Tabular files and structures¶
A tabular (.tsv) file is a text file in which each line represents a row in a table. A tabular file is encoded in UTF-8. A byte-order mark at the start of the file is not part of the first column name. The column entries in a given row are separated by tabs. The first line of the file MUST contain a tab-separated list of column names. A column name MUST NOT appear more than once in the first line. A column name MUST NOT begin or end with whitespace, where whitespace means the blank (ASCII code 32), tab (9), line feed (10), and carriage return (13) characters and no others; the line terminator of the first line (LF or CRLF) is not part of the last column name. A column name MUST NOT be blank, that is, the empty string, as BIDS also requires; a first line that ends with a tab, for example, has a blank last column name. A name made only of whitespace is not blank but begins with whitespace, and is reported under the whitespace rule. Column names are compared exactly as written when looking for a repeated name: two names that differ only in leading or trailing whitespace, such as trial and trial (with a trailing blank), are not a repeated name, and the name with the whitespace is reported under the whitespace rule. A line other than the first MUST NOT be empty, that is, have no characters before its line terminator, as BIDS also requires; a single line ending at the end of the file is allowed and does not make an empty last line, but two line endings at the end of the file do. An empty first line is a single blank column name and is reported under the blank-name rule, not as an empty line. Every line other than the first MUST have as many tab-separated cells as the first line, as BIDS also requires. A line made only of tabs that has as many cells as the first line is a row of missing values and is allowed. A line made only of blanks has one cell, so it breaks the cell-count rule unless the table has one column; in a table with one column it is a value made only of whitespace, which is an error if the column has categorical or value HED annotations (see 3.2.10.2. Table annotations). When a file breaks either rule, every offending line is reported and the rows of the file are not validated. This description of tabular files conforms to that used by BIDS.
A validator MUST apply the rules of this section to every table that carries HED annotations, whether the table is stored in a file or held in a data structure in memory: a table with a column named HED, or a table whose associated sidecar contains HED annotations. The sidecar, too, is a JSON structure that may be stored in a file or held in memory. So that a malformed first line does not hide such a table, a text tabular file also counts as having a HED column when a cell of its first non-empty line is HED after leading and trailing whitespace is removed; the file is then validated, and its empty first line or its name with whitespace is reported under the rules above. A validator is not required to check a table that carries no HED annotations, and MAY skip it whatever its structure.
These column-name rules apply to every HED-annotated table whose columns have names, however the table stores them, not only to .tsv files: the header row of a HED-annotated spreadsheet (such as an Excel worksheet) and the column names that a tabular container such as an NWB table stores with its columns are held to them too, whether a tool refers to the columns by name or by column number. A table without column names, such as a spreadsheet with no header row, is not subject to them. They apply to the names under which the columns are assembled.
An NWB DynamicTable requires its column names to be unique, but it accepts names that differ only in leading or trailing whitespace, such as onset and onset (with a leading blank); HED treats the name with the whitespace as an error. NWB also accepts an empty column name, which HED treats as a blank name. A column may also be assembled under a name other than its own: the TimestampVectorData column named timestamp is the equivalent of an onset column (see 3.3.4. Timeline versus descriptor tables). An NWB table that has that column and also a separate column named onset therefore has two columns assembled as onset, which HED treats as a repeated name. The rules on empty lines and on the number of cells in a line are rules about the lines of a text tabular file and apply only to such files: they do not apply to spreadsheets or to NWB tables.
3.2.10.1. Tabular types¶
Generally each row in a table represents an item and the column values provide properties of that item. The most common HED-annotated tables represent event markers in an experiment. For example, each BIDS events.tsv file contains a table whose rows represent markers on the experimental timeline. The columns contain additional information pertaining to that time marker.
Another common HED-annotated table contains metadata. For example, in the BIDS participants.tsv each row represents a participant, and the columns provide characteristics or other information about the participant identified in that row.
In any case, the general strategy for validation or other processing is:
Process the individual components of the HED annotation (tag-level and string-level processing).
Assemble the component annotations for a row (event-level or row-level processing).
Check consistency and relationships among the row annotations (table-level processing).
See BIDS tabular files for more examples.
3.2.10.2. Table annotations¶
BIDS HED annotations for a table can occur both in a column called HED within the table and in an associated JSON sidecar.
The values in a table column that a sidecar value entry annotates MUST also be valid: for every row whose value is not n/a or blank, the string obtained by substituting the value for the # in the column’s annotation MUST be a valid HED string. This check is made column by column before row assembly and does not depend on whether the row’s assembled annotation uses the column, in particular when the column appears in curly braces only in templates the row does not select.
A value in a column with categorical or value HED annotations (in BIDS, a column whose sidecar entry has a "HED" key) MUST NOT begin or end with whitespace, as defined for column names in 3.2.10. Tabular files and structures. Values are used exactly as written (see 3.2.9.1. Sidecar entries), so such a value would otherwise match no annotation key or be substituted with its whitespace. The rule covers a value made only of whitespace as well as an n/a with whitespace before or after it (such as n/a ); both are reported. An empty value and n/a itself are missing values and are not checked. Only the four characters listed in 3.2.10 count as whitespace; a no-break space or other Unicode space does not. The check is made column by column before the value checks of the preceding paragraph and before row assembly. The HED column, whose HED strings may have blanks around their tags, and columns without HED annotations are not subject to the rule.
The HED strings that appear in a HED column MUST be valid HED strings. The tags that a table without an onset column may not contain are given by the Timeline only column of 3.2.8. Reserved tags.
Where definitions may appear is stated in 3.2.8.1. The Definition tag.
3.2.10.3. Event-level processing¶
After individual HED tags and HED strings in the HED column of tables and in the associated sidecars are validated or otherwise processed, the HED strings associated with each row of the table MUST be assembled to provide an overall annotation for the row. We refer to this as event-level or row processing.
The definitions from every source allowed by 3.2.8.1. The Definition tag MUST be gathered before the rows of a table are assembled, so that every Def tag and Def-expand group is checked against all of them.
If the HED schema used for processing contains a schema node that has the unique attribute, then the assembled HED annotation of each row, or in a timeline table of each event marker (see 3.2.10.4. Table-level processing), MUST contain no more than one occurrence of that tag or any of its descendants, taken together: if A has the unique attribute, A, A and A, A/B are errors. The unique attribute is inherited, so a descendant of A is itself unique. Currently, only Event-context has the unique attribute.
General procedure for event-level (row) assembly.
Create an empty result list.
Create an assembly list of columns that contain HED annotations and whose names do not appear in the curly braces of other HED annotations.
For each column in the assembly list look up the annotation in the sidecar, replacing all curly braces and placeholder values appropriately. Append to the result list.
If a
HEDcolumn annotation exists for that row andHEDdid not appear in curly braces in the sidecar, concatenate the annotation to the result list.Finally, join all the entries of the result list using a comma (
,) separator.
In all cases n/a column values are skipped.
To illustrate the assembly process, consider the following excerpt from a timeline table:
Example: excerpt from a timeline table.
onset |
duration |
event_type |
stim_file |
key |
symmetry |
HED |
|---|---|---|---|---|---|---|
3.42 |
n/a |
show |
h234.bmp |
n/a |
n/a |
(Recording, Label/Setup) |
3.86 |
n/a |
press |
n/a |
left-arrow |
asymmetric |
n/a |
7.42 |
n/a |
show |
h734.bmp |
n/a |
n/a |
n/a |
Using the example sidecar results in the following assembled HED annotation for the first row of the table:
A result for event-level (row) assembly of the sample file.
Sensory-event, Visual-presentation, (Image, Face, Pathname/h234.bmp), (Recording, Label/Setup)
The specific annotation (Image, Face, Pathname/h234.bmp) has been substituted for {stim_file} and the annotation in the HED column of the events.tsv file has been included. The entries with n/a have been ignored.
For more examples of event assembly, see How HED works in BIDS tutorial.
3.2.10.4. Table-level processing¶
HED allows annotation of relationships among rows in a table. Hence, processing generally requires that annotations for all the rows be assembled so that consistency can be checked.
In a timeline table, a validator MUST check the rules of 3.2.8.3. Onset, Offset, and Inset over the whole table. The rules apply to one table at a time: an event process that starts in one table cannot end in another. They use time, not row position:
The time of a row is the value in its
onsetcolumn, or in the equivalent column (see 3.3.4. Timeline versus descriptor tables).The rows of a table need not be in time order.
Onset,Offset, andInsetgroups are matched by their times, whatever the order of the rows. A table in which the time of a row is earlier than the time of a row above it is valid, but a validator reports a warning for it, once for the table.Rows whose times are equal as numbers (
1.0and1.00are equal) form one event marker. Two times are equal when they differ by no more than1e-9seconds; with the times taken in increasing order, a row belongs to an event marker when its time equals the earliest time of that marker. Their assembled annotations are joined, in row order, with a comma, and the joined annotation is checked as one assembled annotation: the repeated-expression rule (3.2.7.4. Repeated expressions) and theuniquerule (3.2.10.3. Event-level processing) apply to it, soRedin two rows at time1.0is a repeated expression. A row whoseonsetvalue isn/ais never joined with another row.A row whose
onsetvalue isn/ahas no time and takes no part in the order of the rows. Its annotation MUST NOT containOnset,Offset,Inset, orDelay; it MAY containDuration. The rest of its annotation is validated as in any other row.
3.3. Annotation semantics¶
HED annotations describe events and entities using tags drawn from a HED schema vocabulary. The semantic interpretation of these annotations depends on their structure and context.
3.3.1. The reversibility principle¶
A well-formed HED annotation SHOULD be translatable back into a coherent English description.
This reversibility principle serves as the fundamental semantic validation test. If a HED string cannot be converted back into a meaningful English sentence, the annotation likely has structural problems, usually related to incorrect grouping.
For example, the HED string:
Experimental-stimulus, Sensory-event, (Visual-presentation, (Red, Circle))
translates to: “An experimental stimulus sensory event consisting of a visual presentation of a red circle.”
In contrast, the ungrouped version:
Experimental-stimulus, Sensory-event, Visual-presentation, Red, Circle
is ambiguous: “An experimental stimulus sensory event with visual presentation; something red; something circular.”
The grouping (Red, Circle) makes it clear that both properties describe the same object. The outer grouping indicates that the red circle is something to be seen.
3.3.2. Semantic grouping¶
Parentheses group tags that describe the same entity, relationship, or concept.
Tags within a group are semantically bound and work together to describe one thing. Tags outside the group describe different aspects or entities.
3.3.2.1. Basic grouping rules¶
The following rules govern how tags should be grouped:
Object properties - Tags describing properties of an object SHOULD be grouped together.
Example:
(Red, Circle)indicates a single red circular object.
Agent-action-object - Agent-action-object triples SHOULD be grouped as the action with its object, inside a group with the agent (see 3.2.1. Vocabulary organization).
Pattern:
(Agent-tags, (Action-tag, Object-tags))Example:
(Experiment-participant, (Press, Mouse-button))
Directional relationships - Tags from the
Relation/subtree SHOULD be nested as follows.Pattern:
(A, (Relation-tag, C))means “A has the relationship to C”Example:
((Red, Circle), (To-left-of, (Green, Square)))
Independent facts - Tags describing independent separate events SHOULD be grouped separately.
Pattern:
(Event-type1, Task-event-role1, Sensory-presentation1, (...)), (Event-type2, Task-event-role2, Sensory-presentation2, (...)).Example:
(Experimental-stimulus, Sensory-event, Visual-presentation, (Red, Circle)), (Sensory-event)not(Experimental-stimulus, Sensory-event, Red, Circle)
Structural reserved tags - Structural reserved tags have special rules for grouping and location in an annotation.
Tags:
Definition,Def,Def-expand,Onset,Inset,Offset,Delay,Duration,Event-contextSee: 3.2.8. Reserved tags for details of the specification.
See: 5. Advanced annotation for example usage.
3.3.2.2. Event structure¶
In a timeline table, each assembled annotation SHOULD include an Event tag and a Task-event-role tag, at the top level or in a top-level group, so that analysis tools can segregate and epoch the data by event type:
Event tags (from
Event/) classify the nature of what happened:Sensory-event,Agent-action,Data-feature,Experiment-control,Experiment-procedure,Experiment-structure, orMeasurement-event
Task-event-role tags (from
Task-event-role/) classify the event’s role in the task:Experimental-stimulus,Cue,Participant-response,Feedback,Instructional, etc.
For Sensory-event types, a Sensory-presentation tag (e.g., Visual-presentation, Auditory-presentation) SHOULD appear with the Sensory-event tag.
3.3.3. Assembly semantics¶
When annotations are assembled from multiple sources (sidecar columns, HED column), the semantic interpretation depends on the assembly method.
3.3.3.1. Concatenation assembly¶
When columns are NOT referenced in curly braces, their annotations are concatenated with commas at the top level. Tags at the same level are independent.
3.3.3.2. Curly brace assembly¶
When curly braces {column_name} appear in a sidecar annotation, the referenced column’s annotation REPLACES the curly braces, allowing explicit control over grouping structure.
The rules for curly braces are stated in 3.2.9.3. Sidecar curly braces.
3.3.4. Timeline versus descriptor tables¶
A table with an onset (or equivalent) column is a timeline table: each row describes what happened at the time in its onset column. Currently the only timeline tables in BIDS are in *_events.tsv files. In NWB the equivalent of the onset column is a TimestampVectorData column named timestamp, the column that an EventsTable requires, and a DynamicTable that has such a column is a timeline table. A table may hold other TimestampVectorData columns, such as the offset time of a stimulus; a TimestampVectorData column with any other name is an ordinary column, which does not make the table a timeline table and is not assembled as onset.
A table without an onset or equivalent column is a descriptor table: each row describes the properties of an entity, such as a participant, session, or sample. An example of a descriptor table in BIDS is the table contained in the participants.tsv file.
In a timeline table, each assembled annotation includes an
Eventtag, as 3.3.2.2. Event structure recommends. The temporal tagsOnset,Offset,Inset,Duration, andDelayMAY be used.In a descriptor table, annotations describe characteristics of the entity; the tags it MUST NOT use are given by the Timeline only column of 3.2.8, and the units of
Durationby 3.2.8.4.