Validator¶
Validation tools and error handling for HED strings and schemas.
HedValidator¶
HedValidator ¶
Top 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.
Source code in hed/validator/hed_validator.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
check_tag_formatting ¶
Report repeated or erroneous slashes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
original_tag
|
HedTag
|
The original tag that is used to report the error. |
required |
Returns:
Type | Description |
---|---|
list[dict]
|
list[dict]: Validation issues. Each issue is a dictionary. |
Source code in hed/validator/hed_validator.py
run_basic_checks ¶
Run basic validation checks on a HED string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hed_string
|
HedString
|
The HED string to validate. |
required |
allow_placeholders
|
bool
|
Whether placeholders are allowed in the HED string. |
required |
Returns:
Type | Description |
---|---|
list[dict]
|
list[dict]: A list of issues found during validation. Each issue is represented as a dictionary. |
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.
Source code in hed/validator/hed_validator.py
run_full_string_checks ¶
Run all full-string validation checks on a HED string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hed_string
|
HedString
|
The HED string to validate. |
required |
Returns:
Type | Description |
---|---|
list[dict]
|
list[dict]: A list of issues found during validation. Each issue is represented as a dictionary. |
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.
Source code in hed/validator/hed_validator.py
validate ¶
Validate the HED string object using the schema.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hed_string
|
HedString
|
the string to validate. |
required |
allow_placeholders
|
bool
|
allow placeholders in the string. |
required |
error_handler
|
ErrorHandler or None
|
the error handler to use, creates a default one if none passed. |
None
|
Returns:
Type | Description |
---|---|
list[dict]
|
list[dict]: A list of issues for HED string. |
Source code in hed/validator/hed_validator.py
validate_units ¶
validate_units(
original_tag,
validate_text=None,
report_as=None,
error_code=None,
index_offset=0,
) -> list[dict]
Validate units and value classes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
original_tag
|
HedTag
|
The source tag |
required |
validate_text
|
str
|
the text we want to validate, if not the full extension. |
None
|
report_as
|
HedTag
|
Report the error tag as coming from a different one. Mostly for definitions that expand. |
None
|
error_code
|
str
|
The code to override the error as. Again mostly for def/def-expand tags. |
None
|
index_offset
|
int
|
Offset into the extension validate_text starts at |
0
|
Returns:
Type | Description |
---|---|
list[dict]
|
list[dict]: Issues found from units |
Source code in hed/validator/hed_validator.py
Definition Validator¶
def_validator ¶
Validates of Def, Def-expand and Temporal groups.
DefValidator ¶
Bases: DefinitionDict
Validates Def/ and Def-expand/, as well as Temporal groups: Onset, Inset, and Offset
Source code in hed/validator/def_validator.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
validate_def_tags ¶
Validate Def/Def-Expand tags.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hed_string_obj
|
HedString
|
The HED string to process. |
required |
hed_validator
|
HedValidator
|
Used to validate the placeholder replacement. |
None
|
Returns: list: Issues found related to validating defs. Each issue is a dictionary.
Source code in hed/validator/def_validator.py
validate_def_value_units ¶
Equivalent to HedValidator.validate_units for the special case of a Def or Def-expand tag
Source code in hed/validator/def_validator.py
validate_onset_offset ¶
Validate onset/offset
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hed_string_obj
|
HedString
|
The HED string to check. |
required |
Returns:
Type | Description |
---|---|
list[dict]
|
list[dict]: A list of issues found in validating onsets (i.e., out of order onsets, unknown def names). |
Source code in hed/validator/def_validator.py
Onset Validator¶
onset_validator ¶
Validates the onset/offset conditions.
OnsetValidator ¶
Validates onset/offset pairs.
Source code in hed/validator/onset_validator.py
check_for_banned_tags
staticmethod
¶
Returns an issue for every tag found from the banned list (for files without onset column).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hed_string
|
HedString
|
The string to check. |
required |
Returns:
Type | Description |
---|---|
list[dict]
|
list[dict]: The validation issues associated with the characters. Each issue is dictionary. |
Source code in hed/validator/onset_validator.py
validate_temporal_relations ¶
Validate onset/offset/inset tag relations
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hed_string_obj
|
HedString
|
The HED string to check. |
required |
Returns:
Type | Description |
---|---|
list[dict]
|
list[dict]: A list of issues found in validating onsets (i.e., out of order onsets, repeated def names). |
Source code in hed/validator/onset_validator.py
Sidecar Validator¶
SidecarValidator ¶
Source code in hed/validator/sidecar_validator.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
|
validate ¶
Validate the input data using the schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sidecar
|
Sidecar
|
Input data to be validated. |
required |
extra_def_dicts
|
list or DefinitionDict
|
extra def dicts in addition to sidecar |
None
|
name
|
str
|
The name to report this sidecar as |
None
|
error_handler
|
ErrorHandler
|
Error context to use. Creates a new one if None |
None
|
Returns: list[dict]: A list of issues associated with each level in the HED string.
Source code in hed/validator/sidecar_validator.py
validate_structure ¶
Validate the raw structure of this sidecar.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sidecar
|
Sidecar
|
the sidecar to validate |
required |
error_handler
|
ErrorHandler
|
The error handler to use for error context |
required |
Returns:
Name | Type | Description |
---|---|---|
issues |
list
|
A list of issues found with the structure |
Source code in hed/validator/sidecar_validator.py
Spreadsheet Validator¶
spreadsheet_validator ¶
Validates spreadsheet tabular data.
SpreadsheetValidator ¶
Source code in hed/validator/spreadsheet_validator.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
|
validate ¶
Validate the input data using the schema
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
BaseInput
|
Input data to be validated. |
required |
def_dicts
|
list of DefDict or DefDict
|
all definitions to use for validation |
None
|
name
|
str
|
The name to report errors from this file as |
None
|
error_handler
|
ErrorHandler
|
Error context to use. Creates a new one if None |
None
|
Returns: list[dict]: A list of issues for HED string
Source code in hed/validator/spreadsheet_validator.py
Validation Utilities¶
util ¶
Validation of HED tags.