Validator¶
Validation tools for HED data structures and annotations.
Core validator classes¶
HedValidator¶
- class hed.validator.hed_validator.HedValidator(hed_schema, def_dicts=None, definitions_allowed=False)[source]¶
Bases:
objectTop level validation of HED strings.
This module contains the HedValidator class which is used to validate the tags in a HED string or a file. The file types include .tsv, .txt, and .xlsx. To get the validation issues after creating a HedValidator class call the get_validation_issues() function.
- __init__(hed_schema, def_dicts=None, definitions_allowed=False)[source]¶
Constructor for the HedValidator class.
- Parameters:
hed_schema (HedSchema or HedSchemaGroup) – HedSchema object to use for validation.
def_dicts (DefinitionDict or list or dict) – the def dicts to use for validation
definitions_allowed (bool) – If False, flag definitions found as errors
- validate(hed_string, allow_placeholders, error_handler=None) list[dict][source]¶
Validate the HED string object using the schema.
- Parameters:
hed_string (HedString) – the string to validate.
allow_placeholders (bool) – allow placeholders in the string.
error_handler (ErrorHandler or None) – the error handler to use, creates a default one if none passed.
- Returns:
A list of issues for HED string.
- Return type:
- run_basic_checks(hed_string, allow_placeholders) list[dict][source]¶
Run basic validation checks on a HED string.
- Parameters:
- Returns:
A list of issues found during validation. Each issue is represented as a dictionary.
- Return type:
Notes
This method performs initial validation checks on the HED string, including character validation and tag validation.
It checks for invalid characters, calculates canonical forms, and validates individual tags.
If any issues are found during these checks, the method stops and returns the issues immediately.
The method also validates definition tags if applicable.
- run_full_string_checks(hed_string, *, required_tags=True, unique_tags=True) list[dict][source]¶
Run all full-string validation checks on a HED string.
- Parameters:
hed_string (HedString) – The HED string to validate.
required_tags (bool) – Run the required-tag check. Pass False for a fragment of a row (a HED cell, a sidecar string): the tag it lacks may come from another column, so the check needs the assembled row.
unique_tags (bool) – Run the unique-tag check. A unique tag repeated inside a fragment is repeated in the row too, so this check is safe on a fragment; pass False to leave it to assembly.
- Returns:
A list of issues found during validation. Each issue is represented as a dictionary.
- Return type:
Notes
This method iterates through a series of validation checks defined in the checks list.
Each check is a callable function that takes hed_string as input and returns a list of issues.
If any check returns issues, the method stops and returns those issues immediately.
If no issues are found, an empty list is returned.
The group-level checks (tag placement, reserved groups, duplicates, Onset and Offset) always run: a group in a fragment is a group of the row.
- pattern_doubleslash = re.compile('([ \\t/]{2,}|^/|/$)')¶
- validate_units(original_tag, validate_text=None, report_as=None, error_code=None, index_offset=0, allow_placeholders=True) list[dict][source]¶
Validate units and value classes
- Parameters:
original_tag (HedTag) – The source tag
validate_text (str) – the text we want to validate, if not the full extension.
report_as (HedTag) – Report the error tag as coming from a different one. Mostly for definitions that expand.
error_code (str) – The code to override the error as. Again mostly for def/def-expand tags.
index_offset (int) – Offset into the extension validate_text starts at
allow_placeholders (bool) – Whether placeholders are allowed (affects value class validation for “#”)
- Returns:
Issues found from units
- Return type:
Specialized validators¶
SidecarValidator¶
- class hed.validator.sidecar_validator.SidecarValidator(hed_schema)[source]¶
Bases:
objectValidates HED annotations in a BIDS JSON sidecar against a HED schema.
- reserved_column_names = ['HED']¶
- reserved_category_values = ['n/a']¶
- __init__(hed_schema)[source]¶
Constructor for the SidecarValidator class.
- Parameters:
hed_schema (HedSchema) – HED schema object to use for validation.
- validate(sidecar, extra_def_dicts=None, name=None, error_handler=None) list[dict][source]¶
Validate the input data using the schema
- Parameters:
sidecar (Sidecar) – Input data to be validated.
extra_def_dicts (list or DefinitionDict) – extra def dicts in addition to sidecar
name (str) – The name to report this sidecar as. If empty, no FILE_NAME context is added, so a caller that manages its own location context (for example a table inside a larger file) sees only the context it pushed.
error_handler (ErrorHandler) – Error context to use. Creates a new one if None.
- Returns:
A list of issues associated with each level in the HED string.
- Return type:
- validate_structure(sidecar, error_handler) list[dict][source]¶
Validate the raw structure of this sidecar.
- Parameters:
sidecar (Sidecar) – the sidecar to validate
error_handler (ErrorHandler) – The error handler to use for error context.
- Returns:
A list of issues found with the structure.
- Return type:
Notes
A top-level key that begins or ends with whitespace is SIDECAR_INVALID, whether or not its entry has a
"HED"key, and is reported before the entries’ own structure.
SpreadsheetValidator¶
- class hed.validator.spreadsheet_validator.SpreadsheetValidator(hed_schema, def_dicts=None)[source]¶
Bases:
objectValidates HED annotations in tabular data against a HED schema, in four stages after a header check.
The stages run in order and each stops the run when it finds an error (never on a warning alone):
Column names: a table with a padded, blank or repeated column name gets one TABULAR_INVALID per such name and nothing else: neither the sidecar nor any row is checked or assembled (specification 3.2.10). Names are compared exactly. A
BaseInputsupplies the names it recorded from its header (padded_columns,blank_columns,duplicate_columns); for any other column source they are found incolumn_names().Sidecar: every template and categorical string of the sidecar (
SidecarValidator). A sidecar string is a fragment of a row, so the required-tag check waits for assembly.Column values: the column structure (mapper issues, sidecar references to columns the table lacks), then, for each value and categorical column, its distinct values: one TABULAR_INVALID per value that begins or ends with whitespace (
validate_padded_values), then the other values, each value column’s against the units or value class of its#tag and each categorical column’s against its sidecar keys.HED column: each distinct string of every HED-tags column, the basic (single-string) checks. For a source that offers no assembly, the group-level checks follow on the same strings, since no stage 4 will run them on the whole row. The required-tag check belongs to the assembled row and never runs on a cell; the unique-tag check does, since a repeat inside a cell is a repeat of the row.
Assembly: the rows assembled from all columns, the group-level checks, and the onset and temporal checks of a timeline file.
Stages 2 and 3 work from a
ColumnSource, which answers with column names and distinct values and never has to involve pandas; a source that returns None fromas_base_inputnever reaches stage 4.BaseInputis the source for BIDS files. Each stage is also a public method, so a caller can run one column at a time.Rows are reported as the 0-based row index plus
row_offset. For aBaseInputthe default offset counts the header line and reports 1-based file lines, as before. An issue found for a value or HED-column string is reported once, at the first row holding the value, with the number of rows holding it inrow_count. The categorical check keeps its column-level form: one SIDECAR_KEY_MISSING warning per column naming every unknown value, with no row, as before.- ONSET_TOLERANCE = 1e-07¶
- TIMELINE_TAGS = frozenset({'Delay', 'Inset', 'Offset', 'Onset'})¶
- TEMPORAL_ANCHORS = re.compile('delay|inset|offset|onset')¶
- __init__(hed_schema, def_dicts=None)[source]¶
Constructor for the SpreadsheetValidator class.
- Parameters:
hed_schema (HedSchema) – HED schema object to use for validation.
def_dicts (DefinitionDict, list, str, or None) – Definitions for the stage methods when they are called on their own.
validatereplaces them with the sidecar’s definitions plus itsextra_def_dictsfor the duration of the run.
- validate(source, sidecar=None, extra_def_dicts=None, name=None, error_handler=None, row_offset=None, validate_sidecar=True, def_dicts=None) list[dict][source]¶
Run the stages on a column source, stopping at the first stage that finds an error.
A table with a padded, blank or repeated column name is reported by stage 0 alone: one TABULAR_INVALID per padded name, then per blank name, then per repeated name, with the FILE_NAME context when
nameis given (seevalidate_column_names).- Parameters:
source (ColumnSource) – The table to validate. A BaseInput (TabularInput, SpreadsheetInput) or any object with the ColumnSource methods.
sidecar (Sidecar or None) – The sidecar describing the columns. For a BaseInput this must be the sidecar it was constructed with (None takes it), since the input’s mapper and assembly come from that sidecar; anything else raises ValueError.
extra_def_dicts (list of DefinitionDict or DefinitionDict or None) – Definitions in addition to the sidecar’s.
name (str or None) – The name to report errors from this table as. If empty, no FILE_NAME context is added, so a caller that manages its own location context (for example a table inside a larger file) sees only the context it pushed.
error_handler (ErrorHandler) – Error context to use. Creates a new one if None.
row_offset (int or None) – Added to the 0-based row index in every reported row. None means 1 plus 1 for the header line for a BaseInput (1-based file lines), and 0 otherwise.
validate_sidecar (bool) – If False, skip stage 1 because the caller has validated the sidecar already. The sidecar is still used for its definitions and column descriptions. A sidecar error that the caller did not catch is not found by the later stages: a template or categorical string with an invalid tag simply contributes nothing to check.
def_dicts – Deprecated name for
extra_def_dicts(removed in hedtools 2.0.0). Before the stages, this was the second positional parameter; a positional definition dictionary is now caught and reported as a TypeError rather than validated as a sidecar.
- Returns:
The issues found, sorted by location.
- Return type:
- static validate_column_names(padded, blank, repeated, error_handler) list[dict][source]¶
Stage 0: report the column names that break the column-name rules, as TABULAR_INVALID.
The issues are kept in the order given (not sorted): (b) each padded name, then (c) each blank name, then (a) each repeated name. A padded or repeated name carries the COLUMN context; a blank name has no name to give, so its message names its 1-based position instead.
- Parameters:
padded (list) – The padded names, as
check_column_names()returns them.blank (list[int]) – The 0-based positions of the blank names.
repeated (list) – The repeated names.
error_handler (ErrorHandler) – Holds context.
- Returns:
The issues found.
- Return type:
- validate_column_structure(column_names, mapper, sidecar, error_handler) list[dict][source]¶
Report the column-level issues that need no data: mapper issues and sidecar references to columns the table does not have.
- Parameters:
column_names (list) – The table’s column names.
mapper (ColumnMapper) – The mapper for these columns.
sidecar (Sidecar or None) – The sidecar whose column references are checked.
error_handler (ErrorHandler) – Holds context.
- Returns:
The issues found.
- Return type:
- static validate_padded_values(column_name, distinct, error_handler, row_offset=0) list[dict][source]¶
Report each distinct value of a value or categorical column that begins or ends with whitespace.
Values are used exactly as written (specification 3.2.9.1), so a padded value would match no annotation key or be substituted with its whitespace; it is TABULAR_INVALID (specification 3.2.10.2). Whitespace is blank, tab, line feed and carriage return; a value made only of whitespace and
n/a `` count, while the missing values ``""andn/aare not indistinctat all.- Parameters:
- Returns:
One issue per distinct padded value, at its first row, each with
row_count.- Return type:
- validate_value_column(column_name, template, distinct, error_handler, row_offset=0, check_template=False, from_prefix=False) list[dict][source]¶
Check each distinct value of a value column as the template’s
#tag with the value in place.Only that one tag is checked, with
HedValidator.validate_units: a unit class tag needs valid units and a numeric value, a value class tag needs a value of that class, and any other tag needs an extension made of allowed characters. A value that passes is then spliced into the tag and the result parsed with the basic single-string checks, so a value that would break the HED string it lands in (an unbalanced parenthesis, a tilde, a pound sign) is rejected too. The other tags of the template and its{column}references play no part; they are the sidecar validator’s business. For aDef/Name/#template the placeholder tag inside the definition is the one checked.- Parameters:
column_name (str or int) – The column, for the error context.
template (str) – The column’s HED string with its
#.distinct (dict[str, list[int]]) – Distinct cell text -> 0-based rows holding it.
error_handler (ErrorHandler) – Holds context.
row_offset (int) – Added to the first row of each reported value.
check_template (bool) – If True, run the basic checks on the template itself first (with placeholders allowed) and skip the values if it has an error. For a template that no sidecar validation has covered.
from_prefix (bool) – True if the template was built from a
column_prefix_dictionaryprefix ending in/. Its#was not written by the user but stands for the cell, so under an extension-allowed tag it is the TAG_EXTENDED warning it always was, not the PLACEHOLDER_INVALID that a#written as an extension is (specification 3.2.5 rule 5).
- Returns:
The issues found, one per distinct bad value, each with
row_count.- Return type:
- static validate_categorical_column(column_name, keys, distinct, error_handler) list[dict][source]¶
Report the distinct values of a categorical column that its sidecar does not annotate.
- Parameters:
- Returns:
One SIDECAR_KEY_MISSING issue (a warning) naming every unknown value, or nothing.
- Return type:
- validate_hed_column(column_name, distinct, error_handler, row_offset=0, full_string=False) list[dict][source]¶
Run the single-string checks on each distinct string of a HED-tags column, once per string.
- Parameters:
column_name (str or int) – The column, for the error context.
distinct (dict[str, list[int]]) – Distinct cell text -> 0-based rows holding it.
error_handler (ErrorHandler) – Holds context.
row_offset (int) – Added to the first row of each reported string.
full_string (bool) – If True, also run the group-level checks on each string that passes the basic checks. For a caller that will never assemble rows; otherwise those checks belong to the assembly stage, where the row is whole. The required-tag check needs the assembled row and never runs here; the unique-tag check does, since a repeat inside a cell is a repeat of the row.
- Returns:
The issues found, each with
row_count.- Return type:
- validate_assembled(data, error_handler, row_offset=None) list[dict][source]¶
Validate the assembled rows of a BaseInput: the group-level checks on each whole row, and for a timeline file the onset ordering, time conversions, and temporal relations.
The single-string checks are not repeated here; stages 2 and 3 have covered every column’s values.
- Parameters:
data (BaseInput) – The table, with its sidecar attached.
error_handler (ErrorHandler) – Holds context.
row_offset (int or None) – Added to the 0-based row index. None means 1 plus 1 for the header.
- Returns:
The issues found.
- Return type:
DefValidator¶
- class hed.validator.def_validator.DefValidator(def_dicts=None, hed_schema=None)[source]¶
Bases:
DefinitionDictValidates Def/ and Def-expand/, as well as Temporal groups: Onset, Inset, and Offset
- __init__(def_dicts=None, hed_schema=None)[source]¶
Initialize for definitions in HED strings.
- Parameters:
def_dicts (list or DefinitionDict or str) – DefinitionDicts containing the definitions to pass to baseclass
hed_schema (HedSchema or None) – Required if passing strings or lists of strings, unused otherwise.
- validate_def_tags(hed_string_obj) list[dict][source]¶
Validate Def/Def-Expand tags.
- Parameters:
hed_string_obj (HedString) – The HED string to process.
hed_validator (HedValidator) – Used to validate the placeholder replacement.
- Returns:
Issues found related to validating defs. Each issue is a dictionary.
- Return type:
OnsetValidator¶
- class hed.validator.onset_validator.OnsetValidator[source]¶
Bases:
objectValidates onset/offset pairs.
- validate_temporal_relations(hed_string_obj) list[dict][source]¶
Validate onset/offset/inset tag relations
- static check_for_banned_tags(hed_string) list[dict][source]¶
Returns an issue for every tag found from the banned list (for files without onset column).
- Parameters:
hed_string (HedString) – The string to check.
- Returns:
The validation issues associated with the characters. Each issue is dictionary.
- Return type:
Notes
The banned tags are the rows of reserved_tags.json with requiresTimeline (specification 3.2.8 rule 4).
ReservedChecker¶
- class hed.validator.reserved_checker.ReservedChecker[source]¶
Bases:
objectThread-safe singleton that loads reserved tag rules and checks groups for compliance.
- reserved_reqs_path = '/home/runner/work/hed-python/hed-python/hed/validator/data/reserved_tags.json'¶
- ORGANIZATIONAL_TAGS = frozenset({'Collection', 'Condition-variable', 'Control-variable', 'Event-stream', 'Experimental-intertrial', 'Experimental-trial', 'Indicator-variable', 'Recording', 'Task', 'Time-block'})¶
- static get_instance()[source]¶
Return the singleton ReservedChecker instance, creating it on first call.
- Returns:
The shared singleton instance.
- Return type:
- get_error_code(tag_name) str | None[source]¶
Return the ERROR_CODE of the row for a tag name, or None if the name is not a row.
- get_reserved(group)[source]¶
Return the list of reserved tags found directly within the given HED group.
- get_governing_tag(reserved_tags)[source]¶
Return the tag whose row gives the group rules, or None if the reserved tags cannot share a group.
- check_reserved_compatibility(group, reserved_tags)[source]¶
Check to make sure that the reserved tags can be used together and no duplicates.
- Parameters:
- Returns:
Validation issues. Each issue is a dictionary.
- Return type:
Notes
These are placement errors, reported as TAG_GROUP_ERROR (specification 3.2.8 rule 6).
- check_tag_requirements(group, reserved_tags)[source]¶
Check the group against the row of its governing tag.
- Parameters:
- Returns:
Validation issues. Each issue is a dictionary.
- Return type:
Notes
Call this only after check_reserved_compatibility found no issue, so a governing tag exists.
A missing or extra anchor and a wrong number of inner groups are content errors, reported with the row’s ERROR_CODE; a top-level tag the row does not allow is a placement error, reported as TAG_GROUP_ERROR (specification 3.2.8 rule 6).
An anchor is a Def tag or a Def-expand group; neither counts as an other tag or an inner group.
Validator utilities¶
CharValidator¶
- class hed.validator.util.char_util.CharValidator(modern_allowed_char_rules=False)[source]¶
Bases:
objectClass responsible for basic character level validation of a string or tag.
- __init__(modern_allowed_char_rules=False)[source]¶
Does basic character validation for HED strings/tags
- Parameters:
modern_allowed_char_rules (bool) – If True, use 8.3 style rules for unicode characters.
- check_invalid_character_issues(hed_string, allow_placeholders) list[dict][source]¶
Report characters no HED string may contain.
- Parameters:
- Returns:
Validation issues. Each issue is a dictionary.
- Return type:
Notes
The forbidden characters come from
character_sets.jsonhed_string.forbidden(specification Appendix B CHARACTER_INVALID a):[ ] ~ "and the control code ranges (0-31 and 127-159), whatever the schema version. Curly braces are forbidden where placeholders are not allowed (CHARACTER_INVALID b). Schemas before 8.3.0 also reject every non-ASCII character.
- check_tag_invalid_chars(original_tag, allow_placeholders) list[dict][source]¶
Report invalid characters in the given tag.
- check_for_invalid_extension_chars(original_tag, validate_text, error_code=None, index_offset=0) list[dict][source]¶
Report invalid characters in a tag extension.
- Parameters:
original_tag (HedTag) – The original tag that is used to report the error.
validate_text (str) – the text we want to validate, if not the full extension.
error_code (str) – The code to override the error as. Again mostly for def/def-expand tags.
index_offset (int) – Offset into the extension validate_text starts at.
- Returns:
Validation issues. Each issue is a dictionary.
- Return type:
CharRexValidator¶
- class hed.validator.util.char_util.CharRexValidator(modern_allowed_char_rules=False, hed_schema=None)[source]¶
Bases:
CharValidatorCharacter validation of values against the value classes of the loaded schema.
- __init__(modern_allowed_char_rules=False, hed_schema=None)[source]¶
Does basic character validation for HED strings/tags
- Parameters:
modern_allowed_char_rules (bool) – If True, use 8.3 style rules for Unicode characters.
hed_schema (HedSchema, HedSchemaGroup or None) – The schema being validated against. It decides whether a value class’s own
allowedCharacterdeclaration or the specification’s per-class defaults define its characters (seeallowed_names). None trusts the declaration.
- schema_for_tag(tag)[source]¶
Return the schema of the group that owns tag, or None when it is unknown.
- property character_sets: CharacterSets¶
The shared character-set table.
- allowed_names(cname, declared_names=None, hed_schema=None) list[str][source]¶
Return the character-set names that define the characters of value class cname.
From standard schema 8.5.0, and in libraries partnered with 8.5.0 or later, the schema’s own
allowedCharacterdeclaration defines the class (decision D2, 2026-09-30), provided every name is a known set, an alias, or a single literal character; an unknown name is a schema compliance error and the defaults apply instead. On earlier standard versions the specification’svalue_class_defaultsdefine the five standard classes (D5), because their released declarations are incomplete (nameClass omitsnonascii; the 8.0.0 to 8.2.0 textClass enumerates characters without the underscore, and the file recordstextthere, as validators have always applied). A class the file has no defaults for (a library’s own value class) always follows its declaration.- Parameters:
cname (str) – The value class name.
declared_names (list of str or None) – The
allowedCharacternames the schema declares for it.hed_schema (HedSchema or None) – The schema that owns the tag being checked. Its standard version decides the policy; None uses the schema or group this validator was built with.
- Returns:
The names; empty when nothing constrains the characters.
- Return type:
- get_problem_chars(in_str, cname, declared_names=None, hed_schema=None)[source]¶
Return a list of (index, char) pairs for characters in in_str not allowed by the value class cname.
- Parameters:
in_str (str) – The string to check.
cname (str) – The value class name used to look up allowed character classes.
declared_names (list of str or None) – The
allowedCharacternames the schema declares for the class, if any. Seeallowed_namesfor when they are used.hed_schema (HedSchema or None) – The schema that owns the value’s tag; see
allowed_names.
- Returns:
Each tuple contains the character index and the offending character.
- Return type:
- is_valid_value(in_string, cname)[source]¶
Check whether in_string is a valid whole-word value for class cname.
- Parameters:
- Returns:
Trueif no word-level regex is defined for cname (class imposes no constraint).A
re.Matchobject if in_string matches the word-level regex (valid value).Falseif in_string does not match the word-level regex, or is a dateTimeClass value whose date does not exist (invalid value).
- Return type:
True | re.Match | False
UnitValueValidator¶
- class hed.validator.util.class_util.UnitValueValidator(modern_allowed_char_rules=False, value_validators=None, hed_schema=None)[source]¶
Bases:
objectValidates units.
- __init__(modern_allowed_char_rules=False, value_validators=None, hed_schema=None)[source]¶
Validates the unit and value classes on a given tag.
- Parameters:
modern_allowed_char_rules (bool) – If True, use the 8.3.0 and later character rules.
value_validators (dict or None) – Deprecated, removed in hedtools 2.0.0. Accepted so that existing callers keep working; it has no effect. The per-class validator functions it used to override were never reached by validation.
hed_schema (HedSchema, HedSchemaGroup or None) – The schema being validated against; it decides whether a value class’s own declaration or the specification’s defaults define its characters (
CharRexValidator.allowed_names).
Notes
The per-character sets and the whole-value rules of each value class come from the specification’s
character_sets.json(hed/validator/data/) throughCharRexValidator; there is no per-class validator function.
- check_tag_unit_class_units_are_valid(original_tag, validate_text, report_as=None, error_code=None, allow_placeholders=True, index_offset=0) list[dict][source]¶
Report incorrect unit class or units.
- Parameters:
original_tag (HedTag) – The original tag that is used to report the error.
validate_text (str) – The text to validate.
report_as (HedTag) – Report errors as coming from this tag, rather than original_tag.
error_code (str) – Override error codes.
allow_placeholders (bool) – Whether placeholders are allowed (affects value class validation for “#”)
index_offset (int) – Where validate_text starts within the extension of report_as, for the character index of an issue (a Def tag’s placeholder value follows its label).
- Returns:
Validation issues. Each issue is a dictionary.
- Return type:
- check_tag_value_class_valid(original_tag, validate_text, report_as=None, index_offset=0) list[dict][source]¶
Report an invalid value portion.
- Parameters:
original_tag (HedTag) – The original tag that is used to report the error.
validate_text (str) – The text to validate.
report_as (HedTag) – Report errors as coming from this tag, rather than original_tag.
index_offset (int) – Where validate_text starts within the extension of report_as, for the character index of an issue.
- Returns:
Validation issues.
- Return type:
- report_value_errors(error_dict, class_valid, report_as, allowed_names=None, rule_failures=None)[source]¶
Build validation issues from per-class character error and validity dicts.
- Parameters:
error_dict (dict) – Mapping of class name to list of (char, index) problem tuples.
class_valid (dict) – Mapping of class name to a validity result (
True,re.Match, orFalse) indicating whether the full value passed word-level format validation for that class.report_as (HedTag) – The tag object used as context in error reporting.
allowed_names (dict or None) – Mapping of class name to the character-set names in force for it, for the messages and the
char_setissue key.rule_failures (dict or None) – Mapping of class name to the whole-value rule the value broke (
CharRexValidator.value_failure); the class’s rule description when absent.
- Returns:
Validation issue dictionaries.
- Return type:
- static report_value_char_errors(class_name, errors, report_as, char_set=None, allows=None)[source]¶
Build validation issues for specific invalid characters within a value class string.
- Parameters:
class_name (str) – The value class name that detected the errors (”” for a value with no class).
errors (list[tuple[str, int]]) – Character/index pairs of invalid characters.
report_as (HedTag) – The tag object used as context in error reporting.
char_set (str or None) – The
char_setissue key: the character-set names the value failed.allows (str or None) – What the class allows, for the message.
- Returns:
Validation issue dictionaries.
- Return type:
DuplicateChecker¶
- class hed.validator.util.dup_util.DuplicateChecker[source]¶
Bases:
objectDetects duplicate tags and groups within a HED annotation.
- __init__()[source]¶
Checker for duplications in HED groups.
Notes
This checker has an early out strategy – it returns when it finds an error.
- check_for_duplicates(group) list[dict][source]¶
Find duplicates in a HED group and return the errors found.
- get_hash(group) int | None[source]¶
Return the unique hash for the group as long as no duplicates.
- Parameters:
group (HedGroup) – The HED group to be checked.
- Returns:
Unique hash or None if duplicates were detected within the group.
- Return type:
Union[int, None]
Note: As a side effect, this method will clear the issues list if no duplicates are found.
GroupValidator¶
- class hed.validator.util.group_util.GroupValidator(hed_schema)[source]¶
Bases:
objectValidation for attributes across groups HED tags.
This is things like Required, Unique, top level tags, etc.
- __init__(hed_schema)[source]¶
Constructor for GroupValidator
- Parameters:
hed_schema (HedSchema) – A HedSchema object.
- run_tag_level_validators(hed_string_obj) list[dict][source]¶
Report invalid groups at each level.
- Parameters:
hed_string_obj (HedString) – A HedString object.
- Returns:
Issues associated with each level in the HED string. Each issue is a dictionary.
- Return type:
Notes
This pertains to the top-level, all groups, and nested groups.
- run_all_tags_validators(hed_string_obj) list[dict][source]¶
Report invalid the multi-tag properties in a HED string, e.g. required tags.
- static check_tag_level_issue(original_tag_list, is_top_level, is_group) list[source]¶
Report tags incorrectly positioned in hierarchy.
- Parameters:
- Returns:
Validation issues. Each issue is a dictionary.
- Return type:
Notes
A tag is a tagGroup or topLevelTagGroup tag when its schema says so or its row in reserved_tags.json does: schemas 8.0.0 and 8.1.0 carry neither attribute on Delay and Duration, and the file supplies them (specification 3.2.8 rule 1).
StringValidator¶
- class hed.validator.util.string_util.StringValidator[source]¶
Bases:
objectRuns checks on the raw string that depend on multiple characters, e.g. mismatched parentheses
- OPENING_GROUP_CHARACTER = '('¶
- CLOSING_GROUP_CHARACTER = ')'¶
- COMMA = ','¶
- run_string_validator(hed_string_obj)[source]¶
Run all string-level structural checks on a HED string object.
TagValidator¶
- class hed.validator.util.tag_util.TagValidator[source]¶
Bases:
objectValidation for individual HED tags.
- CAMEL_CASE_EXPRESSION = '([A-Z]+\\s*[a-z-]*)+'¶
- run_individual_tag_validators(original_tag, allow_placeholders=False, is_definition=False) list[dict][source]¶
Runs the validators on the individual tags.
This ignores most illegal characters except in extensions.
- Parameters:
- Returns:
The validation issues associated with the tags. Each issue is dictionary.
- Return type:
- static check_tag_exists_in_schema(original_tag, allow_placeholders=True) list[dict][source]¶
Report invalid tag or doesn’t take a value.
- Parameters:
- Returns:
Validation issues. Each issue is a dictionary.
- Return type:
Notes
A reserved tag whose row in reserved_tags.json has noExtension may not be extended, although it inherits extensionAllowed (specification 3.2.5): TAG_EXTENSION_INVALID, also for
Onset/#.#used as an extension of any other tag is PLACEHOLDER_INVALID, whether or not the parent allows extension (specification 3.2.5 rule 5).An extension term must contain at least one letter (specification 3.2.5 rule 6), for every schema version:
Item/Blech/3andItem/1-2are TAG_EXTENSION_INVALID. A letter is any character for whichstr.isalphais true. The specification limits letters to A-Z and a-z before 8.3.0, and that needs no separate test: before 8.3.0 every non-ASCII character is already CHARACTER_INVALID.
- static check_tag_requires_child(original_tag) list[dict][source]¶
Report if tag is a leaf with ‘requiredTag’ attribute.
- Parameters:
original_tag (HedTag) – The original tag that is used to report the error.
- Returns:
Validation issues. Each issue is a dictionary.
- Return type:
Notes
A reserved tag whose row in reserved_tags.json has requireValue also needs a value: Delay and Duration carry requireChild only from schema 8.3.0 (TAG_REQUIRES_CHILD b).
- check_capitalization(original_tag) list[dict][source]¶
Report warning if incorrect tag capitalization.
- check_tag_is_deprecated(original_tag) list[dict][source]¶
Return a validation issue if the tag carries the DeprecatedFrom attribute.