From 4277ac8c8dce1805e6cf041b1fe34dd71cb3c3df Mon Sep 17 00:00:00 2001 From: IanCa Date: Fri, 27 Oct 2023 15:10:30 -0500 Subject: [PATCH] Update check for prefix/minor unit typos --- hed/errors/error_messages.py | 3 ++- hed/models/hed_tag.py | 1 + hed/validator/hed_validator.py | 2 ++ hed/validator/tag_validator.py | 17 +++++++++++++++-- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/hed/errors/error_messages.py b/hed/errors/error_messages.py index 67389df8..77c00d05 100644 --- a/hed/errors/error_messages.py +++ b/hed/errors/error_messages.py @@ -227,8 +227,9 @@ def val_warning_capitalization(tag): @hed_tag_error(ValidationErrors.UNITS_MISSING, default_severity=ErrorSeverity.WARNING) def val_warning_default_units_used(tag, default_unit): + # todo: add a test case for no default unit. if default_unit is None: - return f"No unit specified on - '{tag}'. Multiple default values exist and cannot be inferred" + return f"No unit specified on - '{tag}'. No default unit is specified for type." return f"No unit specified. Using '{default_unit}' as the default - '{tag}'" diff --git a/hed/models/hed_tag.py b/hed/models/hed_tag.py index bf1f2f3b..7f4b5321 100644 --- a/hed/models/hed_tag.py +++ b/hed/models/hed_tag.py @@ -499,6 +499,7 @@ def default_unit(self): Returns: unit(UnitEntry or None): the default unit entry for this tag, or None """ + # todo: Make this cached unit_classes = self.unit_classes.values() if len(unit_classes) == 1: first_unit_class_entry = list(unit_classes)[0] diff --git a/hed/validator/hed_validator.py b/hed/validator/hed_validator.py index b955d5e4..41ebb16d 100644 --- a/hed/validator/hed_validator.py +++ b/hed/validator/hed_validator.py @@ -62,6 +62,8 @@ def run_basic_checks(self, hed_string, allow_placeholders): return issues if hed_string == "n/a" or not self._hed_schema: return issues + for tag in hed_string.get_all_tags(): + self._tag_validator.run_validate_tag_characters(tag, allow_placeholders=allow_placeholders) issues += hed_string._calculate_to_canonical_forms(self._hed_schema) if check_for_any_errors(issues): return issues diff --git a/hed/validator/tag_validator.py b/hed/validator/tag_validator.py index f0d585a7..be2c9840 100644 --- a/hed/validator/tag_validator.py +++ b/hed/validator/tag_validator.py @@ -67,6 +67,19 @@ def run_hed_string_validators(self, hed_string_obj, allow_placeholders=False): validation_issues += self.check_tag_formatting(tag) return validation_issues + def run_validate_tag_characters(self, original_tag, allow_placeholders): + """ Basic character validation of tags + + Parameters: + original_tag (HedTag): A original tag. + allow_placeholders (bool): Allow value class or extensions to be placeholders rather than a specific value. + + Returns: + list: The validation issues associated with the characters. Each issue is dictionary. + + """ + return self.check_tag_invalid_chars(original_tag, allow_placeholders) + def run_individual_tag_validators(self, original_tag, allow_placeholders=False, is_definition=False): """ Runs the hed_ops on the individual tags. @@ -77,11 +90,11 @@ def run_individual_tag_validators(self, original_tag, allow_placeholders=False, is_definition (bool): This tag is part of a Definition, not a normal line. Returns: - list: The validation issues associated with the top-level tags. Each issue is dictionary. + list: The validation issues associated with the tags. Each issue is dictionary. """ validation_issues = [] - validation_issues += self.check_tag_invalid_chars(original_tag, allow_placeholders) + # validation_issues += self.check_tag_invalid_chars(original_tag, allow_placeholders) if self._hed_schema: validation_issues += self.check_tag_exists_in_schema(original_tag) if original_tag.is_unit_class_tag():