7. Library schemas¶
A HED library schema contains the vocabulary terms needed for annotation in a specialized area. An example of such a library is the HED SCORE schema for annotation of EEG by clinical neurologists. All officially released HED schemas, whether standard or library, are hosted on the hed-standard/hed-schemas GitHub repository and can be viewed using the hed-schema-browser.
7.1. Why library schemas?¶
The variety and complexity of events in electrophysiological experiments make full documentation challenging. As more experiments move out of controlled laboratory environments and into less controlled virtual and real-world settings, the terminology required to adequately describe events and other experimental metadata has the potential to grow exponentially.
In addition, experiments in any given subfield can create pressures to add overly-specific terms and jargon to the schema hierarchy - for example, adding musical terms to tag events in music-based experiments, video markup terms for experiments involving movie viewing, traffic terms for experiments involving virtual driving, and so forth.
Clinical fields using neuroimaging also have their own specific vocabularies for describing data features of clinical interest (e.g., seizure, sleep stage IV). Including these discipline-specific terms quickly makes the standard HED schema unwieldy and less usable by the broader user community.
Third generation HED addressed the problem of vocabulary bloat by introducing HED library schemas to organize discipline-specific terminology. To use a programming analogy, when programmers write a Python module, the resulting code does not become part of the Python language or core libraries. Instead, the module becomes part of a library used in conjunction with core modules of the programming language.
7.2. Unpartnered library schemas¶
HED library schemas were originally designed as standalone vocabularies. These unpartnered library schemas were self-contained schemas with all the needed schema attributes and properties. In practice however, these “standalone” schemas almost always required tags from the standard schema, and library schemas either had to duplicate items from the standard schema or use namespaces so that each schema could be used independently in an annotation without conflicts. See 3.1.1. Schema versions and 3.1.2 Version combinations for more detailed explanations of namespaces and merge groups.
Using tags from schemas in different namespaces for annotation proved to be inconvenient, because the tags of each namespace carry its prefix. In the following example score_1.0.0 is in the default namespace and 8.4.0 is in the ts: namespace:
A version specification of the score library version 1.0.0 with standard schema version 8.4.0.
["score_1.0.0", "ts:8.4.0"]
Annotations using this version specification prefix every tag from the standard schema with ts: (e.g., ts:Sensory-event). Partnered library schemas were introduced to avoid the namespace complication for annotators in most practical use cases.
7.3. Partnered library schemas¶
A partnered library schema is tied to a specific version of the HED standard schema and designed to be used with its partner as a unified vocabulary in a single namespace. A given library schema version is either partnered or unpartnered depending on whether its header has the withStandard="x.y.z" attribute, where x.y.z is the version of its standard schema partner. A new version of a partnered library schema MUST be partnered with the latest released standard schema at the time the library version is released. While it is in development it may be partnered with a prerelease of the standard schema. The versions a partner may have are stated in 3.1.2.1. Partnered vs unpartnered. Unpartnered library schemas do not have a withStandard attribute. The filenames for library schemas are the same regardless of partnership.
7.3.1. Partnered file formats¶
HED schema files (including library schema files) can be represented in one of 4 equivalent formats: MediaWiki, TSV, XML, and JSON. The hed-python tools read each of these formats into a common object format and can then convert to any other equivalent formats.
MediaWiki format has one line per tag, is relatively easy to read, and clearly displays the hierarchy structure for human readers. Many developers work in this format after the tag vocabulary has been established.
TSV is a multi-file format (13 TSV files) that stores the sections of a schema in separate spreadsheets. Developers often use TSV format in the initial development of a library vocabulary, because they only need to focus on the _Tag.tsv spreadsheet which contains the library tags. Most of the other TSV files will be empty or fixed after the initial setup.
XML is hard to read, so humans almost never use this format directly, but instead, convert XML to MediaWiki or TSV. XML is easily parsed by tools and is the standard format for tools in the HED ecosystem.
JSON is a flattened format that is useful for AI agents, as its tags are in a top-level dictionary.
7.3.2. Schema filenames¶
The canonical filenames for the standard schemas are HEDx.y.z.mediawiki, HEDx.y.z.xml, and HEDx.y.z.json for the MediaWiki, XML, and JSON formats, respectively. The x.y.z represents the semantic version (e.g., 8.4.0). The filenames for TSV format are of the form HEDx.y.z_www.tsv, where www designates the spreadsheet type (e.g., HED8.4.0_Tag.tsv).
Library schemas have the form HED_libname_x.y.z.mediawiki, HED_libname_x.y.z.xml, and HED_libname_x.y.z.json for the MediaWiki, XML, and JSON formats, respectively. The x.y.z represents the semantic version (e.g., 1.1.0) and libname is the name of the library in lower case (e.g., HED_lang_1.1.0.mediawiki is version 1.1.0 of the language library schema lang). The TSV format for library schemas follows the HED_libname_x.y.z_www.tsv pattern.
Library schema filenames don’t show partnership.
Whether a schema file represents a partnered or unpartnered schema can ONLY be determined by the schema header not by the filename. If the withStandard attribute is present in the schema header, it is partnered. If the withStandard is absent it is unpartnered.
Library schema filenames don’t show merge status.
Whether a schema library file has been stored in merged or unmerged form can ONLY be determined by the schema header:
If the unmerged="true" attribute is present in the schema header, it is unmerged. If the attribute is absent or false, it is merged.
7.3.3. Merged vs unmerged¶
There are several significant differences between merged and unmerged partnered library schema formats:
An unmerged schema has the
unmerged="true"attribute in its header line. The merged version does not have anunmergedattribute in its header.An unmerged schema SHOULD have a non-empty prologue and epilogue that explain the purpose of the library schema (the sections themselves are always present, see 3.1.4. Schema layout overview). The contents of these prologue and epilogue sections become the prologue and epilogue, respectively, in the merged schema. The prologue and epilogue of the standard schema are omitted in the merged schema.
With the exception of the prologue and epilogue sections, the merged form of library schema
xxxhas theinLibrary=xxxattribute on every schema element and schema attribute that is in the library and on every row that the library contributes to the extra sections (see 3.1.2.2. Merged vs unmerged). Herexxxis the name of the library. The unmerged form has none (see 3.1.2.2. Merged vs unmerged).The schema properties section of an unmerged library schema MUST always be empty except for its section header. The schema properties section of a merged schema will have only the standard schema properties.
An unmerged schema MUST only include content in the auxiliary sections other than the schema properties section, and in the extra sections (Sources, Prefixes, and External annotations), that it explicitly extends. An auxiliary or extra section that it does not extend is written empty (see 3.1.4. Schema layout overview). The merged version will have all of the section values from both the library schema and its partner.
In an unmerged schema, nodes with the
rooted=XXXschema attribute MUST be top-level tags, andXXXMUST correspond to a node in the standard schema. In the merged schema, nodes with therooted=XXXschema attribute are placed directly under the standard schema nodeXXX.
A.2.4. MediaWiki schema section shows a rooted node of the MOUSE library schema in unmerged and in merged form.
7.3.4. Partnered attributes¶
To support partnered library schema the following items were introduced:
Name |
Type |
Role |
|---|---|---|
|
Header attribute |
|
|
Header attribute |
|
|
Element attribute |
|
|
Node attribute |
|
|
Node attribute |
|
7.3.5. Motivation for partners¶
Partnered library schemas are the strongly preferred format for HED libraries for consistency and elimination of redundancy. This section explains why partnered library schemas are preferred.
7.3.5.1. Auxiliary consistency¶
An unpartnered library schema MUST duplicate the auxiliary schema sections appearing in standard schemas, introducing the possibility of inconsistency in usage or definition between the library schema and standard schemas. A partnered library schema automatically inherits its standard partner’s auxiliary sections, assuring consistent handling by tools and preventing the introduction of inconsistently handled attributes.
Although unpartnered library schemas may add additional items to the auxiliary sections, HED tools only guarantee support of standard schema auxiliary items requiring special handling. Thus, addition of items in the auxiliary sections of a library schema is discouraged.
7.3.5.3. Annotation conciseness¶
The most common use case for library schemas in annotation requires tags from both a standard schema and a library schema, thus requiring a namespace prefix (e.g., xx:) on the tags from one of the schemas when unpartnered library schemas are used.
Because a partnered library schema is merged with a standard schema to form a single, unified schema, users can annotate data without the xx: namespace prefix. The xx: is still needed when multiple incompatible library schemas are used together. See 7.3.6 Lazy partnering for more information on compatibility.
7.3.5.4. Library searches¶
The subtrees appearing in the library schemas are often elaborations of a particular term in the standard schema. However, if the library schema terms are not in the appropriate standard schema hierarchy, HED search cannot be leveraged to find these elaborations by searching for a more general standard schema term.
7.3.6. Lazy partnering¶
HED allows the partnered schemas of a merge group to be combined into one unified vocabulary tree, provided that the schemas are compatible. We refer to this process as lazy partnering.
In the following example, all the library schemas are partnered with standard schema 8.4.0. Library schemas liba_1.0.0 and libc_4.3.2 are merged in the default namespace, and library schemas ac:libb_2.8.1 and ac:exam_2.3.2 are merged in the ac namespace. The schema sc:test_1.3.2 stays the same, and listing 8.4.0 adds nothing, since it is already the partner of liba_1.0.0 and libc_4.3.2. If there are any conflicts during the merging process, an error is raised.
Example: Merging of multiple schemas.
['liba_1.0.0', 'ac:libb_2.8.1', 'libc_4.3.2', '8.4.0', 'sc:test_1.3.2', 'ac:exam_2.3.2']
The full set of rules governing merge groups and partnered combination is given in the rule table of 3.1.2.4. Partnered combinations. The subsections below give worked examples of version specifications that load and version specifications that fail, organized by the row groups of that table. An incompatible list of schemas cannot be loaded.
Avoid new auxiliary section entries in library schemas.
Auxiliary sections have information for HED tools, and new entries may require modification to schema validation and analysis tools.
With the possible (and rare) exception of new unitClasses and units, partnered library schemas
usually have empty auxiliary sections. The empty sections
are still written (see 3.1.4. Schema layout overview).
While new value class and schema attribute definitions are allowed in library schemas, this is strongly discouraged. If a new entry is needed, contact the HED Working Group (hed.maintainers@gmail.com) to see if the entry might be added to the standard schema instead.
7.3.6.1. Test schema examples¶
The worked examples in the following subsections use four test-only library schemas: testconflict, testclash, testminimal, and testaux. These schemas are maintained in the hed-tests repository (under json_test_data/test_schemas/) and are not released HED schemas. Their contents are fully controlled, so each example exercises exactly one rule of the rule table in 3.1.2.4. Partnered combinations. Each example mirrors a test case in that repository’s json_test_data/validation_test_data/SCHEMA_LOAD_FAILED.json, keeping the specification and the validator test suites in sync.
Schema versions |
Standard schema partner ( |
|---|---|
|
None (unpartnered) |
|
|
|
|
|
None (unpartnered) |
|
|
|
|
|
|
The examples rely on the following facts about these libraries:
testconflict_2.1.0istestconflict_2.0.0plus one added tag.testconflict_2.1.1differs fromtestconflict_2.1.0only in one revised tag description (a patch-level change).testconflict_2.0.0declares the top-level tagsShared-item,Attribute-item(withsuggestedTag=Object-one),Description-item,Anchor-item(with childNested-item),Placeholder-item(with a#child), andRooted-tag(withrooted=Event), whose children areRooted-one(with childDeep-one) andRooted-two.Each
testclashversion declares its ownClash-tagsubtree plus at most one probe element also declared by another test library, identical except for at most one controlled difference. Versions1.0.0through12.0.0probe tag elements declared bytestconflict_2.0.0; the differences are tabulated in 7.3.6.5. Element compatibility examples. Versions13.0.0through19.0.0probe auxiliary elements and a schema attribute declared bytestaux_1.0.0; the differences are tabulated in 7.3.6.6. Auxiliary element examples.testminimaldeclares only its ownMini-tagsubtree, which is disjoint from the vocabularies of the other libraries.testaux_1.0.0declares one auxiliary element of each kind - the unit classauxUnits(with unitsauxunitandbigauxunit), the unit modifierauxMod, and the value classauxClass- and the schema attributeauxAttribute, plus the tagsAux-measure(which takes a value withauxUnitsunits) andAux-value(which takes a value of theauxClassvalue class). Its vocabulary is disjoint from the other libraries and from the standard schema.
7.3.6.2. Merge group examples¶
Version specification |
Loads |
Explanation |
|---|---|---|
|
Yes |
All three libraries are partnered with |
|
Yes |
Three merge groups (unprefixed, |
|
Yes |
A standard schema in its own namespace forms its own merge group, so the two standard versions do not conflict. |
|
No |
Duplicate schemas (the same name, whatever the version) cannot appear in the same merge group; an exact duplicate fails like two different versions. |
|
No |
Different versions of the same schema cannot appear in the same merge group, even though these two share the |
|
No |
The rules apply inside each namespace: the |
7.3.6.3. Standard partner examples¶
Version specification |
Loads |
Explanation |
|---|---|---|
|
Yes |
A partnered library schema automatically includes its standard schema partner ( |
|
Yes |
A standard schema matching the group partner is allowed and adds nothing to the merged result. |
|
No |
A standard schema in a merge group must match the group partner; |
|
No |
Partnered library schemas in a merge group must have the same partner; here the partners are |
|
No |
Two standard schemas cannot be listed in the same merge group, whatever their versions; |
7.3.6.4. Unpartnered examples¶
Version specification |
Loads |
Explanation |
|---|---|---|
|
Yes |
The unpartnered |
|
No |
The unpartnered |
|
No |
Two unpartnered library schemas cannot share a namespace; each needs its own. |
7.3.6.5. Element compatibility examples¶
Each example in this subsection loads testconflict_2.0.0 together with one of the testclash versions 1.0.0 through 12.0.0, each of which carries at most one probe element shared with testconflict_2.0.0, so each pair isolates a single element compatibility rule:
Version specification |
Probe element |
Difference from |
Loads |
|---|---|---|---|
|
|
None: an identical copy. Identical shared elements are compatible, and the merged vocabulary keeps a single copy. |
Yes |
|
|
The |
No |
|
|
The description text differs. |
No |
|
|
Declared at the top level instead of as a child of |
No |
|
|
Has no |
No |
|
|
Declared as an ordinary top-level tag instead of with |
No |
|
|
Declared with |
No |
|
|
|
Yes |
|
|
The shared child |
No |
|
|
Identical, but its only child is |
Yes |
|
|
The chain |
Yes |
|
|
The shared grandchild |
No |
Two versions of one library are never compared element by element, because different versions of the same schema cannot appear in the same merge group: ['testconflict_2.1.0', 'testconflict_2.1.1'] fails to load on that rule alone. To use two versions together, give one its own namespace, for example ['testconflict_2.1.0', 'alt:testconflict_2.1.1'] (a name such as v2 is not a namespace name; see 3.1.1. Schema versions).
Any failing pair in this subsection can still be used together by giving one schema its own namespace. For example, ['testconflict_2.0.0', 'cl:testclash_2.0.0'] loads because the two Attribute-item declarations are in different merge groups and are never compared.
7.3.6.6. Auxiliary element examples¶
The element compatibility rules apply to the auxiliary elements (unit classes, units, unit modifiers, and value classes) and to schema attributes exactly as they do to tags. The first example pairs testconflict_2.0.0, which declares neither, with testaux_1.0.0 to show direct merging; each remaining example loads testaux_1.0.0 together with one of the testclash versions 13.0.0 through 19.0.0, so each pair isolates a single rule:
Version specification |
Probe element |
Difference from |
Loads |
|---|---|---|---|
|
all auxiliary elements |
None shared: every |
Yes |
|
all auxiliary elements |
None: identical copies. Identical shared auxiliary elements and schema attributes are compatible, and the merged vocabulary keeps a single copy of each. |
Yes |
|
unit |
The |
No |
|
unit class |
The shared units are identical; |
Yes |
|
value class |
The |
No |
|
schema attribute |
Declared without |
No |
|
schema attribute |
The description text differs. |
No |
|
unit modifier |
The |
No |
7.4. Library schema design¶
Most library schema developers work with unmerged MediaWiki or unmerged TSV format. Developers SHOULD always validate the schema before converting to XML. Only validated versions of the schema SHOULD be uploaded to the GitHub hed-schemas repository. The online HEDtools provide easy access to tools for schema validation, conversion, and comparison. More information about the development process is contained in the HED Schema developers guide.
Because of the partnering rule of 7.3. Partnered library schemas, developers release new versions whenever HED updates its standard schema. This ensures that the partnered library schema benefits from the latest updates to HED features and tools.
If the update can be done without conflict, this update may be initiated as part of the release mechanism by the maintainers of the HED repositories.
7.4.1. General design rules¶
This section summarizes the general design rules for all library schema.
General design rules for HED library schema.
Follow naming conventions:
A library schema MUST be given a name containing only lowercase alphabetic characters. This name MUST appear in the schema header line in the required format.
Use semantic versioning:
A library schema MUST use semantic versioning and follow the versioning update rules used by the HED standard schema as specified in 3.1.3. Version updates.
Tag uniqueness:
The terms of a library schema follow the rules for nodes in 3.1.4.3. The schema section, uniqueness included.
Have a meaningful prologue:
The schema SHOULD include a prologue section giving an overview, purpose and scope of the library schema.
Have a meaningful epilogue:
The schema SHOULD include an epilogue section containing reference, citation, and license information.
Be understandable:
Schema terms SHOULD be readily understood by most users. The terms SHOULD NOT be ambiguous and SHOULD be meaningful in themselves without reference to their position in the schema hierarchy.
Be well-organized:
If possible, no schema sub-tree SHOULD have more than 7 direct subordinate sub-trees.
Maintain subtree orthogonality:
Terms that are used independently of one another SHOULD be in different sub-trees (orthogonality).
Enforce is-a relationship between child nodes and their parents:
Every node in a HED hierarchy is a subclass of its parent node, as 3.1. Schema rules requires. This is what makes HED search generalizable.
Validators enforce rules 1 and 3 and the version format of rule 2. The version update rules of rule 2, the content of the prologue and epilogue (rules 4 and 5), and rules 6 through 9 are the responsibility of the schema designers and review committees.
In general, library schema developers SHOULD avoid adding schema terms that duplicate those found in the latest HED standard schema at the time of release. For partnered library schemas this is a strict requirement: an unmerged partnered library schema MUST NOT have a schema element or schema attribute with the same name as one of its standard schema partner, except a unit class that it names only to add new units under it; the merged form necessarily contains all of its partner’s tags. Library schema developers SHOULD also try to avoid overlap of terms found in other schema libraries.
If your application requires schema classes that are not available in the standard HED schema and you would like these classes to be supported, please make a request using the issues forum of the hed-schemas GitHub repository.
7.4.2. Unpartnered design rules¶
A new library schema is partnered with the latest released standard schema (7.3. Partnered library schemas). A new unpartnered library schema is not supported until rules for one are specified: B.3. Differences for earlier schema versions states how the released unpartnered library, SCORE 1.0.0, is validated. The rules of 3.2.8. Reserved tags for library schemas apply to it; definitions and temporal scope come from a standard schema, either partnered with the library or listed separately in the version specification (see 7.5. Library schemas in BIDS).
7.4.3. Partnered design rules¶
Partnered library schemas are now the recommended format for the reasons listed in Motivation for partners. The following design rules are specifically meant for partnered library schemas. Developers usually work on their library schemas in either unmerged MediaWiki or unmerged TSV format because these formats are concise and easy to edit. The HED online tools provide online tools for converting from one schema format to all formats in merged or unmerged forms.
Design rules specific to partnered HED library schemas.
Check for overlap:
The terms of a partnered library schema follow 7.4.1. General design rules on duplicates, and no term may be rooted under a reserved tag (see 3.2.8. Reserved tags).
Use the latest released version of the standard schema:
A partnered library schema follows the partnering rule of 7.3. Partnered library schemas.
The auxiliary sections of the unmerged partnered library schema are usually empty:
The auxiliary sections of an unmerged partnered library schema hold only the items it adds (see 7.3.3. Merged vs unmerged).
Seek reviews early in the process:
Any additions to the auxiliary sections MUST be reviewed by the HED Working Group to determine what requirements the additions would impose on downstream tools.
It is recognized that HED standard and library schemas will both evolve and that additions or tag reorganizations may cause conflicts. These conflicts are resolved as they occur. In general the standard schema takes precedence over any library schema in resolving these conflicts.
7.5. Library schemas in BIDS¶
By far the most common use case is to tag events using a standard HED schema (preferably the latest one) available in the standard_schema/hedxml directory of the hed-schemas repository of the hed-standard organization on GitHub. The standard schemas are available at: https://github.com/hed-standard/hed-schemas/tree/main/standard_schema.
The official library schemas are available at https://github.com/hed-standard/hed-schemas/tree/main/library_schemas.
Standard schemas are referenced by their version number (e.g., 8.1.0), while library schema are referenced by a combination of library name and version number (e.g., score_1.0.0).
For BIDS datasets, the versions of the HED schema are specified by the HEDVersion field of the BIDS dataset_description.json file. The schema versions in this section’s examples are historical: SCORE 1.0.0 (unpartnered) and SCORE 1.1.0 (partnered) are used to illustrate the difference partnering makes for annotators. The following example specifies that version 8.1.0 of the standard HED schema is to be used in addition to score library schema version 1.0.0.
Illustration of using the namespace prefix for tagging.
The dataset_description.json file contains:
{
"Name": "A great experiment",
"BIDSVersion": "1.8.0",
"HEDVersion": ["8.1.0", "sc:score_1.0.0"]
}
A typical annotation is:
"Data-feature, sc:Photomyogenic-response, sc:Wicket-spikes"
Based on the above description tools will download:
The standard HED schema:
https://raw.githubusercontent.com/hed-standard/hed-schemas/main/standard_schema/hedxml/HED8.1.0.xml.The HED
scorelibrary schema version1.0.0:
https://raw.githubusercontent.com/hed-standard/hed-schemas/main/library_schemas/score/hedxml/HED_score_1.0.0.xml.
In the dataset annotations for the above example, tags drawn from the score schema would be prefixed with sc:, where sc is the namespace name chosen to distinguish tags from the additional schema.
SCORE version 1.0.0 is not partnered, so the HED version specification had to include both the library and standard schema versions. In contrast, SCORE version 1.1.0 is partnered with HED standard schema 8.2.0, so no namespace prefixes are needed as shown in the following example:
Example: An example specification of HED version for a partnered schema.
The dataset_description.json file contains:
{
"Name": "A great experiment",
"BIDSVersion": "1.8.0",
"HEDVersion": "score_1.1.0"
}
A typical annotation is:
"Data-feature, Photomyogenic-response, Wicket-spikes"