Skip to content
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
1 change: 0 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ updates:
interval: "daily"
target-branch: "develop"
directory: /
automerge: true
19 changes: 12 additions & 7 deletions hed/errors/error_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,41 +360,46 @@ def def_error_bad_location(tag):
return f"Tag '{str(tag)}' is found in a location it is not allowed to be."


@hed_tag_error(OnsetErrors.ONSET_DEF_UNMATCHED, actual_code=ValidationErrors.ONSET_OFFSET_ERROR)
@hed_tag_error(OnsetErrors.ONSET_DEF_UNMATCHED, actual_code=ValidationErrors.ONSET_OFFSET_INSET_ERROR)
def onset_error_def_unmatched(tag):
return f"The def tag in an onset/offset tag is unmatched. Def tag: '{tag}'"


@hed_tag_error(OnsetErrors.OFFSET_BEFORE_ONSET, actual_code=ValidationErrors.ONSET_OFFSET_ERROR)
@hed_tag_error(OnsetErrors.OFFSET_BEFORE_ONSET, actual_code=ValidationErrors.ONSET_OFFSET_INSET_ERROR)
def onset_error_offset_before_onset(tag):
return f"Offset tag '{tag}' does not have a matching onset."


@hed_tag_error(OnsetErrors.ONSET_NO_DEF_TAG_FOUND, actual_code=ValidationErrors.ONSET_OFFSET_ERROR)
@hed_tag_error(OnsetErrors.INSET_BEFORE_ONSET, actual_code=ValidationErrors.ONSET_OFFSET_INSET_ERROR)
def onset_error_inset_before_onset(tag):
return f"Inset tag '{tag}' does not have a matching onset."


@hed_tag_error(OnsetErrors.ONSET_NO_DEF_TAG_FOUND, actual_code=ValidationErrors.ONSET_OFFSET_INSET_ERROR)
def onset_no_def_found(tag):
return f"'{tag}' tag has no def or def-expand tag in string."


@hed_tag_error(OnsetErrors.ONSET_TOO_MANY_DEFS, actual_code=ValidationErrors.ONSET_OFFSET_ERROR)
@hed_tag_error(OnsetErrors.ONSET_TOO_MANY_DEFS, actual_code=ValidationErrors.ONSET_OFFSET_INSET_ERROR)
def onset_too_many_defs(tag, tag_list):
tag_list_strings = [str(tag) for tag in tag_list]
return f"Too many def tags found in onset for {tag}. Expected 1, also found: {tag_list_strings}"


@hed_tag_error(OnsetErrors.ONSET_WRONG_NUMBER_GROUPS, actual_code=ValidationErrors.ONSET_OFFSET_ERROR)
@hed_tag_error(OnsetErrors.ONSET_WRONG_NUMBER_GROUPS, actual_code=ValidationErrors.ONSET_OFFSET_INSET_ERROR)
def onset_too_many_groups(tag, tag_list):
tag_list_strings = [str(a_tag) for a_tag in tag_list]
return f"An onset tag should have at most 2 sibling nodes, an offset tag should have 1. " +\
f"Found {len(tag_list_strings)}: {tag_list_strings}"


@hed_tag_error(OnsetErrors.ONSET_TAG_OUTSIDE_OF_GROUP, actual_code=ValidationErrors.ONSET_OFFSET_ERROR)
@hed_tag_error(OnsetErrors.ONSET_TAG_OUTSIDE_OF_GROUP, actual_code=ValidationErrors.ONSET_OFFSET_INSET_ERROR)
def onset_wrong_type_tag(tag, def_tag):
return f"Onset def tag '{def_tag}' has an improper sibling tag '{tag}'. All onset context tags must be " + \
f"in a single group together."


@hed_tag_error(OnsetErrors.ONSET_PLACEHOLDER_WRONG, actual_code=ValidationErrors.ONSET_OFFSET_ERROR)
@hed_tag_error(OnsetErrors.ONSET_PLACEHOLDER_WRONG, actual_code=ValidationErrors.ONSET_OFFSET_INSET_ERROR)
def onset_wrong_placeholder(tag, has_placeholder):
if has_placeholder:
return f"Onset/offset def tag {tag} expects a placeholder value, but does not have one."
Expand Down
6 changes: 3 additions & 3 deletions hed/errors/error_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ValidationErrors:
DEF_INVALID = "DEF_INVALID"
DEFINITION_INVALID = "DEFINITION_INVALID"
NODE_NAME_EMPTY = 'NODE_NAME_EMPTY'
ONSET_OFFSET_ERROR = 'ONSET_OFFSET_ERROR'
ONSET_OFFSET_INSET_ERROR = 'ONSET_OFFSET_INSET_ERROR'
PARENTHESES_MISMATCH = 'PARENTHESES_MISMATCH'
PLACEHOLDER_INVALID = 'PLACEHOLDER_INVALID'
REQUIRED_TAG_MISSING = 'REQUIRED_TAG_MISSING'
Expand Down Expand Up @@ -135,15 +135,15 @@ class DefinitionErrors:


class OnsetErrors:
# These are all ONSET_OFFSET_ERROR
# These are all ONSET_OFFSET_INSET_ERROR
OFFSET_BEFORE_ONSET = "OFFSET_BEFORE_ONSET"
ONSET_DEF_UNMATCHED = "ONSET_DEF_UNMATCHED"
ONSET_WRONG_NUMBER_GROUPS = "ONSET_WRONG_NUMBER_GROUPS"
ONSET_NO_DEF_TAG_FOUND = "ONSET_NO_DEF_TAG_FOUND"
ONSET_PLACEHOLDER_WRONG = "ONSET_PLACEHOLDER_WRONG"
ONSET_TOO_MANY_DEFS = "ONSET_TOO_MANY_DEFS"
ONSET_TAG_OUTSIDE_OF_GROUP = "ONSET_TAG_OUTSIDE_OF_GROUP"

INSET_BEFORE_ONSET = "INSET_BEFORE_ONSET"

class ColumnErrors:
INVALID_COLUMN_REF = "INVALID_COLUMN_REF"
Expand Down
5 changes: 4 additions & 1 deletion hed/models/model_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ class DefTagNames:
DEF_KEY = DEF_ORG_KEY.lower()
DEF_EXPAND_KEY = DEF_EXPAND_ORG_KEY.lower()
DEFINITION_KEY = DEFINITION_ORG_KEY.lower()
DEF_KEYS = (DEF_KEY, DEF_EXPAND_KEY)

ONSET_ORG_KEY = "Onset"
OFFSET_ORG_KEY = "Offset"
INSET_ORG_KEY = "Inset"

ONSET_KEY = ONSET_ORG_KEY.lower()
OFFSET_KEY = OFFSET_ORG_KEY.lower()
INSET_KEY = INSET_ORG_KEY.lower()

DEF_KEYS = (DEF_KEY, DEF_EXPAND_KEY)
TEMPORAL_KEYS = {ONSET_KEY, OFFSET_KEY, INSET_KEY}
10 changes: 7 additions & 3 deletions hed/validator/onset_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def validate_onset_offset(self, hed_string_obj):
return onset_issues

def _find_onset_tags(self, hed_string_obj):
return hed_string_obj.find_top_level_tags(anchor_tags={DefTagNames.ONSET_KEY, DefTagNames.OFFSET_KEY})
return hed_string_obj.find_top_level_tags(anchor_tags=DefTagNames.TEMPORAL_KEYS)

def _handle_onset_or_offset(self, def_tag, onset_offset_tag):
is_onset = onset_offset_tag.short_base_tag == DefTagNames.ONSET_ORG_KEY
Expand All @@ -89,9 +89,13 @@ def _handle_onset_or_offset(self, def_tag, onset_offset_tag):
# onset can never fail as it implies an offset
self._onsets[full_def_name.lower()] = full_def_name
else:
is_offset = onset_offset_tag.short_base_tag == DefTagNames.OFFSET_ORG_KEY
if full_def_name.lower() not in self._onsets:
return ErrorHandler.format_error(OnsetErrors.OFFSET_BEFORE_ONSET, tag=def_tag)
else:
if is_offset:
return ErrorHandler.format_error(OnsetErrors.OFFSET_BEFORE_ONSET, tag=def_tag)
else:
return ErrorHandler.format_error(OnsetErrors.INSET_BEFORE_ONSET, tag=def_tag)
elif is_offset:
del self._onsets[full_def_name.lower()]

return []
2 changes: 1 addition & 1 deletion hed/validator/tag_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def check_tag_level_issue(self, original_tag_list, is_top_level, is_group):
if top_level_tag.short_base_tag == DefTagNames.DEFINITION_ORG_KEY:
actual_code = ValidationErrors.DEFINITION_INVALID
elif top_level_tag.short_base_tag in {DefTagNames.ONSET_ORG_KEY, DefTagNames.OFFSET_ORG_KEY}:
actual_code = ValidationErrors.ONSET_OFFSET_ERROR
actual_code = ValidationErrors.ONSET_OFFSET_INSET_ERROR

if actual_code:
validation_issues += ErrorHandler.format_error(ValidationErrors.HED_TOP_LEVEL_TAG,
Expand Down
4 changes: 1 addition & 3 deletions spec_tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"DEF_INVALID",
"DEFINITION_INVALID",
"NODE_NAME_EMPTY",
"ONSET_OFFSET_ERROR",
"ONSET_OFFSET_INSET_ERROR",
"PARENTHESES_MISMATCH",
"PLACEHOLDER_INVALID",
"REQUIRED_TAG_MISSING",
Expand Down Expand Up @@ -53,8 +53,6 @@
"VERSION_DEPRECATED": "Not applicable",
"onset-offset-error-duplicated-onset-or-offset": "TBD how we implement this",
"tag-extension-invalid-bad-node-name": "Part of character invalid checking/didn't get to it yet",
"inset-group-has-extras": "Inset tags not in yet",
"inset-outside-its-event": "Inset tags not in yet"
}


Expand Down
2 changes: 1 addition & 1 deletion tests/validator/test_onset_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def test_onset_multiple_or_misplaced_errors(self):
f"({self.placeholder_label_def_string},Onset, Offset)",
]
test_issues = [
self.format_error(ValidationErrors.HED_TOP_LEVEL_TAG, tag=1, actual_error=ValidationErrors.ONSET_OFFSET_ERROR)
self.format_error(ValidationErrors.HED_TOP_LEVEL_TAG, tag=1, actual_error=ValidationErrors.ONSET_OFFSET_INSET_ERROR)
+ self.format_error(ValidationErrors.HED_TOP_LEVEL_TAG, tag=1),
self.format_error(ValidationErrors.HED_MULTIPLE_TOP_TAGS, tag=1, multiple_tags=["Onset"])
+ self.format_error(ValidationErrors.HED_TAG_REPEATED, tag=2)
Expand Down