diff --git a/hed/errors/error_messages.py b/hed/errors/error_messages.py index 8c74db94..06e64008 100644 --- a/hed/errors/error_messages.py +++ b/hed/errors/error_messages.py @@ -173,7 +173,7 @@ def val_error_unknown_namespace(tag, unknown_prefix, known_prefixes): return f"Tag '{tag} has unknown namespace '{unknown_prefix}'. Valid prefixes: {known_prefixes}" -@hed_tag_error(ValidationErrors.NODE_NAME_EMPTY, has_sub_tag=True) +@hed_tag_error(ValidationErrors.NODE_NAME_EMPTY, has_sub_tag=True, actual_code=ValidationErrors.TAG_INVALID) def val_error_extra_slashes_spaces(tag, problem_tag): return f"Extra slashes or spaces '{problem_tag}' in tag '{tag}'" diff --git a/hed/errors/error_types.py b/hed/errors/error_types.py index 4a95f79d..4fe568d7 100644 --- a/hed/errors/error_types.py +++ b/hed/errors/error_types.py @@ -31,7 +31,6 @@ class ValidationErrors: DEF_INVALID = "DEF_INVALID" DEFINITION_INVALID = "DEFINITION_INVALID" ELEMENT_DEPRECATED = "ELEMENT_DEPRECATED" - NODE_NAME_EMPTY = 'NODE_NAME_EMPTY' TEMPORAL_TAG_ERROR = 'TEMPORAL_TAG_ERROR' PARENTHESES_MISMATCH = 'PARENTHESES_MISMATCH' PLACEHOLDER_INVALID = 'PLACEHOLDER_INVALID' @@ -69,6 +68,7 @@ class ValidationErrors: INVALID_PARENT_NODE = "invalidParent" NO_VALID_TAG_FOUND = "invalidTag" + NODE_NAME_EMPTY = 'NODE_NAME_EMPTY' HED_LIBRARY_UNMATCHED = "HED_LIBRARY_UNMATCHED" @@ -88,7 +88,6 @@ class ValidationErrors: DUPLICATE_COLUMN_BETWEEN_SOURCES = "DUPLICATE_COLUMN_BETWEEN_SOURCES" HED_BLANK_COLUMN = "HED_BLANK_COLUMN" - # Below here shows what the given error maps to INVALID_TAG_CHARACTER = 'invalidTagCharacter' diff --git a/hed/scripts/add_hed_ids.py b/hed/scripts/add_hed_ids.py new file mode 100644 index 00000000..8963cbad --- /dev/null +++ b/hed/scripts/add_hed_ids.py @@ -0,0 +1,27 @@ +from hed.schema import load_schema_version +from hed.scripts.script_util import get_prerelease_path +from hed.scripts.convert_and_update_schema import convert_and_update +import argparse +from hed.schema.schema_io.df2schema import SchemaLoaderDF + +# Slightly tweaked version of convert_and_update_schema.py with a new main function to allow different parameters. +def main(): + parser = argparse.ArgumentParser(description='Add hed ids to a specific schema.') + parser.add_argument('repo_path', help='The location of the hed-schemas directory') + parser.add_argument('schema_name', help='The name of the schema("standard" for standard schema) to modify') + parser.add_argument('schema_version', help='The schema version to modify') + + args = parser.parse_args() + + basepath = get_prerelease_path(args.repo_path, schema_name=args.schema_name, schema_version=args.schema_version) + filenames = list(SchemaLoaderDF.convert_filenames_to_dict(basepath).values()) + set_ids = True + + # Trigger a local cache hit (this ensures trying to load withStandard schemas will work properly) + _ = load_schema_version("8.2.0") + + return convert_and_update(filenames, set_ids) + + +if __name__ == "__main__": + exit(main()) diff --git a/hed/scripts/create_ontology.py b/hed/scripts/create_ontology.py index 601bd0db..04ea2712 100644 --- a/hed/scripts/create_ontology.py +++ b/hed/scripts/create_ontology.py @@ -45,7 +45,7 @@ def main(): parser = argparse.ArgumentParser(description='Convert a specified schema in the prerelease folder to an ontology.') parser.add_argument('repo_path', help='The location of the hed-schemas directory') parser.add_argument('schema_name', help='The name of the schema to convert("standard" for standard schema)') - parser.add_argument('schema_version', help='The location of the hed-schemas directory') + parser.add_argument('schema_version', help='The schema version to modify') parser.add_argument('--dest', default=os.path.join("src", "ontology"), help='The base location to save to') args = parser.parse_args() diff --git a/pyproject.toml b/pyproject.toml index 67f8bc46..3b732340 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,6 +57,7 @@ run_remodel_backup = "hed.tools.remodeling.cli.run_remodel_backup:main" run_remodel_restore = "hed.tools.remodeling.cli.run_remodel_restore:main" hed_validate_schemas = "hed.scripts.validate_schemas:main" hed_update_schemas = "hed.scripts.convert_and_update_schema:main" +hed_add_ids = "hed.scripts.add_hed_ids:main" hed_create_ontology = "hed.scripts.create_ontology:main" [tool.versioneer]