Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new add_hed_ids script. Minor documentation corrections #986

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hed/errors/error_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'"

Expand Down
3 changes: 1 addition & 2 deletions hed/errors/error_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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"

Expand All @@ -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'

Expand Down
27 changes: 27 additions & 0 deletions hed/scripts/add_hed_ids.py
Original file line number Diff line number Diff line change
@@ -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())
2 changes: 1 addition & 1 deletion hed/scripts/create_ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading