Schema¶
HED schema management, loading, and validation functionality.
HedSchema¶
HedSchema ¶
Bases: HedSchemaBase
A HED schema suitable for processing.
Source code in hed/schema/hed_schema.py
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 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 |
|
attributes
property
¶
Return the attributes schema section.
Returns:
Name | Type | Description |
---|---|---|
HedSchemaSection |
'HedSchemaSection'
|
The attributes section. |
library
property
¶
The name of this library schema if one exists.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Library name if any. |
merged
property
¶
Returns if this schema was loaded from a merged file.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if file was loaded from a merged file. |
properties
property
¶
Return the properties schema section.
Returns:
Name | Type | Description |
---|---|---|
HedSchemaSection |
'HedSchemaSection'
|
The properties section. |
schema_namespace
property
¶
Returns the schema namespace prefix.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The schema namespace prefix. |
tags
property
¶
Return the tag schema section.
Returns:
Name | Type | Description |
---|---|---|
HedSchemaTagSection |
'HedSchemaTagSection'
|
The tag section. |
unit_classes
property
¶
Return the unit classes schema section.
Returns:
Name | Type | Description |
---|---|---|
HedSchemaUnitClassSection |
'HedSchemaUnitClassSection'
|
The unit classes section. |
unit_modifiers
property
¶
Return the modifiers classes schema section.
Returns:
Name | Type | Description |
---|---|---|
HedSchemaSection |
'HedSchemaSection'
|
The unit modifiers section. |
units
property
¶
Return the unit schema section.
Returns:
Name | Type | Description |
---|---|---|
HedSchemaUnitSection |
'HedSchemaUnitSection'
|
The unit section. |
valid_prefixes
property
¶
Return a list of all prefixes this schema will accept
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: A list of valid tag prefixes for this schema. |
Notes
- The return value is always length 1 if using a HedSchema.
value_classes
property
¶
Return the value classes schema section.
Returns:
Name | Type | Description |
---|---|---|
HedSchemaSection |
'HedSchemaSection'
|
The value classes section. |
version
property
¶
The complete schema version, including prefix and library name(if applicable).
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The complete schema version including library name and namespace. |
version_number
property
¶
The HED version of this schema.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The version of this schema. |
with_standard
property
¶
The version of the base schema this is extended from, if it exists.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
HED version or empty string. |
can_save ¶
Returns if it's legal to save this schema.
You cannot save schemas loaded as merged from multiple library schemas.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if this can be saved. |
Source code in hed/schema/hed_schema.py
check_compliance ¶
Check for HED3 compliance of this schema.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
check_for_warnings
|
bool
|
If True, checks for formatting issues like invalid characters, capitalization. |
True
|
name
|
str
|
If present, use as the filename for context, rather than using the actual filename. Useful for temp filenames when supporting web services. |
None
|
error_handler
|
ErrorHandler or None
|
Used to report errors. Uses a default one if none passed in. |
None
|
Returns:
Type | Description |
---|---|
list[dict]
|
list[dict]: A list of all warnings and errors found in the file. Each issue is a dictionary. |
Source code in hed/schema/hed_schema.py
finalize_dictionaries ¶
find_tag_entry ¶
find_tag_entry(
tag, schema_namespace=""
) -> tuple[
Union["HedTagEntry", None], Union[str, None], list[dict]
]
Find the schema entry for a given source tag.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tag
|
(str, HedTag)
|
Any form of tag to look up. Can have an extension, value, etc. |
required |
schema_namespace
|
str
|
The schema namespace of the tag, if any. |
''
|
Returns:
Type | Description |
---|---|
Union['HedTagEntry', None]
|
tuple[Union["HedTagEntry", None], Union[str, None], list[dict]]: |
Union[str, None]
|
|
list[dict]
|
|
tuple[Union['HedTagEntry', None], Union[str, None], list[dict]]
|
|
Notes
Works left to right (which is mostly relevant for errors).
Source code in hed/schema/hed_schema.py
get_as_dataframes ¶
Get a dict of dataframes representing this file
Parameters:
Name | Type | Description | Default |
---|---|---|---|
save_merged
|
bool
|
If True, returns DFs as if merged with standard. |
False
|
Returns:
Type | Description |
---|---|
dict[DataFrame]
|
dict[DataFrame]: A dict of dataframes you can load as a schema. |
Source code in hed/schema/hed_schema.py
get_as_mediawiki_string ¶
Return the schema to a mediawiki string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
save_merged
|
bool
|
If True, this will save the schema as a merged schema if it is a "withStandard" schema. If it is not a "withStandard" schema, this setting has no effect. |
False
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The schema as a string in mediawiki format. |
Source code in hed/schema/hed_schema.py
get_as_xml_string ¶
Return the schema to an XML string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
save_merged
|
bool
|
If True, this will save the schema as a merged schema if it is a "withStandard" schema. If it is not a "withStandard" schema, this setting has no effect. |
True
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The schema as an XML string. |
Source code in hed/schema/hed_schema.py
get_extras ¶
Get the extras corresponding to the given key
Parameters:
Name | Type | Description | Default |
---|---|---|---|
extras_key
|
str
|
The key to check for in the extras dictionary. |
required |
Returns:
Type | Description |
---|---|
Union[DataFrame, None]
|
Union[DataFrame, None]: The DataFrame for this extras key, or None if it doesn't exist or is empty. |
Source code in hed/schema/hed_schema.py
get_formatted_version ¶
The HED version string including namespace and library name if any of this schema.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A json formatted string of the complete version of this schema including library name and namespace. |
Source code in hed/schema/hed_schema.py
get_save_header_attributes ¶
Returns the attributes that should be saved.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
save_merged
|
bool
|
Whether to save as merged schema. |
False
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
The header attributes dictionary. |
Source code in hed/schema/hed_schema.py
get_schema_versions ¶
A list of HED version strings including namespace and library name if any of this schema.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: The complete version of this schema including library name and namespace. |
Source code in hed/schema/hed_schema.py
get_tag_attribute_names_old ¶
Return a dict of all allowed tag attributes.
Returns:
Type | Description |
---|---|
dict[str, HedSchemaEntry]
|
dict[str, HedSchemaEntry]: A dictionary whose keys are attribute names and values are HedSchemaEntry object. |
Source code in hed/schema/hed_schema.py
get_tag_entry ¶
get_tag_entry(
name: str,
key_class=HedSectionKey.Tags,
schema_namespace: str = "",
) -> Union["HedSchemaEntry", None]
Return the schema entry for this tag, if one exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Any form of basic tag(or other section entry) to look up. This will not handle extensions or similar. If this is a tag, it can have a schema namespace, but it's not required |
required |
key_class
|
HedSectionKey or str
|
The type of entry to return. |
Tags
|
schema_namespace
|
str
|
Only used on Tags. If incorrect, will return None. |
''
|
Returns:
Type | Description |
---|---|
Union['HedSchemaEntry', None]
|
HedSchemaEntry or None: The schema entry for the given tag, or None if not found. |
Source code in hed/schema/hed_schema.py
get_tags_with_attribute ¶
Return tag entries with the given attribute.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attribute
|
str
|
A tag attribute. Eg HedKey.ExtensionAllowed |
required |
key_class
|
HedSectionKey
|
The HedSectionKey for the section to retrieve from. |
Tags
|
Returns:
Type | Description |
---|---|
list['HedSchemaEntry']
|
list[HedSchemaEntry]: A list of all tags with this attribute. |
Notes
- The result is cached so will be fast after first call.
Source code in hed/schema/hed_schema.py
has_duplicates ¶
Returns the first duplicate tag/unit/etc. if any section has a duplicate name
Source code in hed/schema/hed_schema.py
save_as_dataframes ¶
Save as dataframes to a folder of files.
If base_filename has a .tsv suffix, save directly to the indicated location.
If base_filename is a directory(does NOT have a .tsv suffix), save the contents into a directory named that.
The subfiles are named the same. e.g. HED8.3.0/HED8.3.0_Tag.tsv
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_filename
|
str
|
Save filename. A suffix will be added to most, e.g. _Tag |
required |
save_merged
|
bool
|
If True, this will save the schema as a merged schema if it is a "withStandard" schema. If it is not a "withStandard" schema, this setting has no effect. |
False
|
Raises:
Type | Description |
---|---|
OSError
|
File cannot be saved for some reason. |
Source code in hed/schema/hed_schema.py
save_as_mediawiki ¶
Save as mediawiki to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
Save location. |
required |
save_merged
|
bool
|
If True, this will save the schema as a merged schema if it is a "withStandard" schema. If it is not a "withStandard" schema, this setting has no effect. |
False
|
Raises:
Type | Description |
---|---|
OSError
|
File cannot be saved for some reason. |
Source code in hed/schema/hed_schema.py
save_as_xml ¶
Save as XML to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
Save location. |
required |
save_merged
|
bool
|
If true, this will save the schema as a merged schema if it is a "withStandard" schema. If it is not a "withStandard" schema, this setting has no effect. |
True
|
Raises:
Type | Description |
---|---|
OSError
|
File cannot be saved for some reason. |
Source code in hed/schema/hed_schema.py
schema_for_namespace ¶
Return HedSchema object for this namespace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
namespace
|
str
|
The schema library name namespace. |
required |
Returns:
Type | Description |
---|---|
Union['HedSchema', None]
|
HedSchema or None: The HED schema object for this schema, or None if namespace doesn't match. |
Source code in hed/schema/hed_schema.py
set_schema_prefix ¶
Set library namespace associated for this schema.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema_namespace
|
str
|
Should be empty, or end with a colon.(Colon will be automated added if missing). |
required |
:raises HedFileError: - The prefix is invalid
Source code in hed/schema/hed_schema.py
Schema I/O¶
hed_schema_io ¶
Utilities for loading and outputting HED schema.
from_dataframes ¶
Create a schema from the given string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema_data
|
dict
|
A dict of DF_SUFFIXES:file_as_string_or_df Should have an entry for all values of DF_SUFFIXES. |
required |
schema_namespace
|
(str, None)
|
The name_prefix all tags in this schema will accept. |
None
|
name
|
str or None
|
User supplied identifier for this schema |
None
|
Returns:
Name | Type | Description |
---|---|---|
HedSchema |
'HedSchema'
|
The loaded schema. |
:raises HedFileError: - Empty/invalid parameters
Notes
- The loading is determined by file type.
Source code in hed/schema/hed_schema_io.py
from_string ¶
Create a schema from the given string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema_string
|
str
|
An XML or mediawiki file as a single long string |
required |
schema_format
|
str
|
The schema format of the source schema string. Allowed normal values: .mediawiki, .xml |
'.xml'
|
schema_namespace
|
(str, None)
|
The name_prefix all tags in this schema will accept. |
None
|
schema
|
HedSchema or None
|
A HED schema to merge this new file into It must be a with-standard schema with the same value. |
None
|
name
|
str or None
|
User supplied identifier for this schema |
None
|
Returns:
Type | Description |
---|---|
HedSchema
|
The loaded schema. |
:raises HedFileError: - If empty string or invalid extension is passed. - Other fatal formatting issues with file
Notes
- The loading is determined by file type.
Source code in hed/schema/hed_schema_io.py
get_hed_xml_version ¶
Get the version number from a HED XML file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xml_file_path
|
str
|
The path to a HED XML file. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The version number of the HED XML file. |
:raises HedFileError: - There is an issue loading the schema
Source code in hed/schema/hed_schema_io.py
load_schema ¶
Load a schema from the given file or URL path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hed_path
|
str
|
A filepath or url to open a schema from. If loading a TSV file, this should be a single filename where: Template: basename.tsv, where files are named basename_Struct.tsv, basename_Tag.tsv, etc. Alternatively, you can point to a directory containing the .tsv files. |
required |
schema_namespace
|
str or None
|
The name_prefix all tags in this schema will accept. |
None
|
schema
|
HedSchema or None
|
A HED schema to merge this new file into It must be a with-standard schema with the same value. |
None
|
name
|
str or None
|
User supplied identifier for this schema |
None
|
Returns:
Name | Type | Description |
---|---|---|
HedSchema |
'HedSchema'
|
The loaded schema. |
:raises HedFileError: - Empty path passed - Unknown extension - Any fatal issues when loading the schema.
Source code in hed/schema/hed_schema_io.py
load_schema_version ¶
Return a HedSchema or HedSchemaGroup extracted from xml_version
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xml_version
|
str or list
|
List or str specifying which official HED schemas to use.
A json str format is also supported,
based on the output of HedSchema.get_formatted_version
Basic format: |
None
|
xml_folder
|
str
|
Path to a folder containing schema. |
None
|
Returns:
Type | Description |
---|---|
Union['HedSchema', 'HedSchemaGroup']
|
HedSchema or HedSchemaGroup: The schema or schema group extracted. |
:raises HedFileError: - The xml_version is not valid. - The specified version cannot be found or loaded - Other fatal errors loading the schema (These are unlikely if you are not editing them locally) - The prefix is invalid
Source code in hed/schema/hed_schema_io.py
parse_version_list ¶
Takes a list of xml versions and returns a dictionary split by prefix
e.g. ["score", "testlib"] will return {"": "score, testlib"}
e.g. ["score", "testlib", "ol:otherlib"] will return {"": "score, testlib", "ol:": "otherlib"}
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xml_version_list
|
list
|
List of str specifying which HED schemas to use |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary of version strings split by prefix. |
Source code in hed/schema/hed_schema_io.py
HedSchemaEntry¶
HedSchemaEntry ¶
A single node in a HedSchema.
The structure contains all the node information including attributes and properties.
Source code in hed/schema/hed_schema_entry.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 |
|
attribute_has_property ¶
Return True if attribute has property.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attribute
|
str
|
Attribute name to check for property_name. |
required |
property_name
|
str
|
The property value to return. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
Returns True if this entry has the property. |
Source code in hed/schema/hed_schema_entry.py
finalize_entry ¶
Called once after loading to set internal state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema
|
HedSchema
|
The schema that holds the rules. |
required |
Source code in hed/schema/hed_schema_entry.py
has_attribute ¶
Checks for the existence of an attribute in this entry.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attribute
|
str
|
The attribute to check for. |
required |
return_value
|
bool
|
If True, returns the actual value of the attribute. If False, returns a boolean indicating the presence of the attribute. |
False
|
Returns:
Type | Description |
---|---|
Union[bool, Any]
|
bool or any: If return_value is False, returns True if the attribute exists and False otherwise. |
Union[bool, Any]
|
If return_value is True, returns the value of the attribute if it exists, else returns None. |
Notes
- The existence of an attribute does not guarantee its validity.
Source code in hed/schema/hed_schema_entry.py
HedSchemaGroup¶
HedSchemaGroup ¶
Bases: HedSchemaBase
Container for multiple HedSchema objects.
Notes
- The container class is useful when library schema are included.
- You cannot save/load/etc. the combined schema object directly.
Source code in hed/schema/hed_schema_group.py
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 |
|
valid_prefixes
property
¶
Return a list of all prefixes this group will accept.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: A list of strings representing valid prefixes for this group. |
check_compliance ¶
Check for HED3 compliance of this schema.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
check_for_warnings
|
bool
|
If True, checks for formatting issues like invalid characters, capitalization. |
True
|
name
|
str
|
If present, use as the filename for context, rather than using the actual filename. Useful for temp filenames when supporting web services. |
None
|
error_handler
|
ErrorHandler or None
|
Used to report errors. Uses a default one if none passed in. |
None
|
Returns:
Type | Description |
---|---|
list[dict]
|
list[dict]: A list of all warnings and errors found in the file. Each issue is a dictionary. |
Source code in hed/schema/hed_schema_group.py
find_tag_entry ¶
find_tag_entry(
tag, schema_namespace=""
) -> tuple[
Union["HedTagEntry", None], Union[str, None], list
]
Find the schema entry for a given source tag.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tag
|
(str, HedTag)
|
Any form of tag to look up. Can have an extension, value, etc. |
required |
schema_namespace
|
str
|
The schema namespace of the tag, if any. |
''
|
Returns:
Name | Type | Description |
---|---|---|
HedTagEntry |
Union['HedTagEntry', None]
|
The located tag entry for this tag. |
str |
Union[str, None]
|
The remainder of the tag that isn't part of the base tag. |
list |
list
|
A list of errors while converting. |
Notes
Works left to right (which is mostly relevant for errors).
Source code in hed/schema/hed_schema_group.py
get_formatted_version ¶
The HED version string including namespace and library name if any of this schema.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The complete version of this schema including library name and namespace. |
Source code in hed/schema/hed_schema_group.py
get_schema_versions ¶
A list of HED version strings including namespace and library name if any for these schemas.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: The complete version of this schema including library name and namespace. |
Source code in hed/schema/hed_schema_group.py
get_tag_entry ¶
get_tag_entry(
name, key_class=HedSectionKey.Tags, schema_namespace=""
) -> Union["HedSchemaEntry", None]
Return the schema entry for this tag, if one exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Any form of basic tag(or other section entry) to look up. This will not handle extensions or similar. If this is a tag, it can have a schema namespace, but it's not required |
required |
key_class
|
HedSectionKey or str
|
The type of entry to return. |
Tags
|
schema_namespace
|
str
|
Only used on Tags. If incorrect, will return None. |
''
|
Returns:
Name | Type | Description |
---|---|---|
HedSchemaEntry |
Union['HedSchemaEntry', None]
|
The schema entry for the given tag. |
Source code in hed/schema/hed_schema_group.py
get_tags_with_attribute ¶
Return tag entries with the given attribute.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
attribute
|
str
|
A tag attribute. Eg HedKey.ExtensionAllowed |
required |
key_class
|
HedSectionKey
|
The HedSectionKey for the section to retrieve from. |
Tags
|
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
A list of all tags with this attribute. |
Notes
- The result is cached so will be fast after first call.
Source code in hed/schema/hed_schema_group.py
schema_for_namespace ¶
Return the HedSchema for the library namespace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
namespace
|
str
|
A schema library name namespace. |
required |
Returns:
Type | Description |
---|---|
Union[HedSchema, None]
|
Union[HedSchema,None]: The specific schema for this library name namespace if exists. |
Source code in hed/schema/hed_schema_group.py
Schema Comparison¶
schema_comparer ¶
Functions supporting comparison of schemas.
SchemaComparer ¶
Class for comparing HED schemas and generating change logs.
Source code in hed/schema/schema_comparer.py
8 9 10 11 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 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 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
|
compare_differences ¶
Compare the tags and extras in the two schemas, reporting all differences.
Source code in hed/schema/schema_comparer.py
compare_schemas ¶
Compare the two schemas section by section.
Source code in hed/schema/schema_comparer.py
find_matching_tags ¶
Compare the tags in the two schemas.
Source code in hed/schema/schema_comparer.py
gather_schema_changes ¶
Generate a changelog by comparing the two schemas.
Source code in hed/schema/schema_comparer.py
pretty_print_change_dict ¶
Format the change dictionary into a string.
Source code in hed/schema/schema_comparer.py
HED Cache Functions¶
hed_cache ¶
Infrastructure for caching HED schema from remote repositories.
cache_local_versions ¶
Cache all schemas included with the HED installation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cache_folder
|
str
|
The folder holding the cache. |
required |
Returns:
Type | Description |
---|---|
int
|
int or None: Returns -1 on cache access failure. None otherwise |
Source code in hed/schema/hed_cache.py
cache_xml_versions ¶
cache_xml_versions(
hed_base_urls=DEFAULT_URL_LIST,
hed_library_urls=DEFAULT_LIBRARY_URL_LIST,
skip_folders=DEFAULT_SKIP_FOLDERS,
cache_folder=None,
) -> float
Cache all schemas at the given URLs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hed_base_urls
|
str or list
|
Path or list of paths. These should point to a single folder. |
DEFAULT_URL_LIST
|
hed_library_urls
|
str or list
|
Path or list of paths. These should point to folder containing library folders. |
DEFAULT_LIBRARY_URL_LIST
|
skip_folders
|
list
|
A list of subfolders to skip over when downloading. |
DEFAULT_SKIP_FOLDERS
|
cache_folder
|
str
|
The folder holding the cache. |
None
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
Returns -1 if cache failed for any reason, including having been cached too recently. Returns 0 if it successfully cached this time. |
Notes
- The Default skip_folders is 'deprecated'.
- The HED cache folder defaults to HED_CACHE_DIRECTORY.
- The directories on GitHub are of the form: https://api.github.com/repos/hed-standard/hed-schemas/contents/standard_schema
Source code in hed/schema/hed_cache.py
get_cache_directory ¶
Return the current value of HED_CACHE_DIRECTORY.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cache_folder
|
str
|
Optional cache folder override. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The cache directory path. |
Source code in hed/schema/hed_cache.py
get_hed_version_path ¶
get_hed_version_path(
xml_version,
library_name=None,
local_hed_directory=None,
check_prerelease=False,
)
Get HED XML file path in a directory. Only returns filenames that exist.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
library_name
|
str or None
|
Optional the schema library name. |
None
|
xml_version
|
str
|
Returns this version if it exists |
required |
local_hed_directory
|
str
|
Path to local HED directory. Defaults to HED_CACHE_DIRECTORY |
None
|
check_prerelease
|
bool
|
Also check for prerelease schemas |
False
|
Returns: str: The path to the latest HED version the HED directory.
Source code in hed/schema/hed_cache.py
get_hed_versions ¶
get_hed_versions(
local_hed_directory=None,
library_name=None,
check_prerelease=False,
) -> Union[list, dict]
Get the HED versions in the HED directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
local_hed_directory
|
str
|
Directory to check for versions which defaults to hed_cache. |
None
|
library_name
|
str or None
|
An optional schema library name. None retrieves the standard schema only. Pass "all" to retrieve all standard and library schemas as a dict. |
None
|
check_prerelease
|
bool
|
If True, results can include prerelease schemas |
False
|
Returns:
Type | Description |
---|---|
Union[list, dict]
|
Union[list, dict]: List of version numbers or dictionary {library_name: [versions]}. |
Source code in hed/schema/hed_cache.py
get_library_data
cached
¶
Retrieve the library data for the given library.
Currently, this is just the valid ID range.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
library_name
|
str
|
The schema name. "" for standard schema. |
required |
cache_folder
|
str
|
The cache folder to use if not using the default. |
None
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
The data for a specific library. |
Source code in hed/schema/hed_cache.py
set_cache_directory ¶
Set default global HED cache directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_cache_dir
|
str
|
Directory to check for versions. |
required |
Source code in hed/schema/hed_cache.py
Schema Validation Utilities¶
schema_validation_util ¶
Utilities used in HED validation/loading using a HED schema.
get_allowed_characters ¶
Returns the allowed characters in a given container of value classes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value_classes
|
list of HedSchemaEntry
|
A list of schema entries that should have the allowedCharacter attribute |
required |
Returns:
Type | Description |
---|---|
set[str]
|
set[str]: The set of all characters from the given classes |
Source code in hed/schema/schema_validation_util.py
get_allowed_characters_by_name ¶
Returns the allowed characters from a list of character set names
Note: "nonascii" is a special case "character" that can be included as well
Parameters:
Name | Type | Description | Default |
---|---|---|---|
character_set_names
|
list of str
|
A list of character sets to allow. See hed_schema_constants.character_types |
required |
Returns:
Type | Description |
---|---|
set[str]
|
set[str]: The set of all characters from the names |
Source code in hed/schema/schema_validation_util.py
get_problem_indexes ¶
Finds indexes with values not in character set
Parameters:
Name | Type | Description | Default |
---|---|---|---|
validation_string
|
str
|
The string to check characters in. |
required |
character_set
|
set
|
The list of valid characters (or the value "nonascii" as a set entry). |
required |
index_adj
|
int
|
The value to adjust the reported indices by, if this isn't the start of a string. |
0
|
Returns:
Type | Description |
---|---|
list[tuple[str, int]]
|
list[tuple[str, int]]: The list of problematic characters and their indices. |
Source code in hed/schema/schema_validation_util.py
schema_version_for_library ¶
Given the library name and HED schema object, return the version
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hed_schema
|
HedSchema
|
the schema object |
required |
library_name
|
str or None
|
The library name you're interested in. "" for the standard schema. |
required |
Returns:
Type | Description |
---|---|
Union[str, None]
|
Union[str, None]: The version number of the given library name. Returns None if unknown library_name. |
Source code in hed/schema/schema_validation_util.py
validate_schema_description_new ¶
Check the description of the entry for invalid character issues
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hed_entry
|
HedSchemaEntry
|
A single schema entry |
required |
Returns:
Type | Description |
---|---|
list[dict]
|
list[dict]: A list issues pertaining to all invalid characters found in description. Each issue is a dictionary. |
Source code in hed/schema/schema_validation_util.py
validate_schema_tag_new ¶
Check tag entry for capitalization and illegal characters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hed_entry
|
HedTagEntry
|
A single tag entry |
required |
Returns:
Type | Description |
---|---|
list[dict]
|
list[dict]: A list of all formatting issues found in the term. Each issue is a dictionary. |
Source code in hed/schema/schema_validation_util.py
validate_schema_term_new ¶
Check the term for invalid character issues
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hed_entry
|
HedSchemaEntry
|
A single schema entry |
required |
hed_term
|
str or None
|
Use instead of hed_entry.name if present. |
None
|
Returns:
Type | Description |
---|---|
list[dict]
|
list[dict]: A list of all formatting issues found in the term. Each issue is a dictionary. |