-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed the duplicate tag tests by adding a DuplicateChecker class with…
… hashes
- Loading branch information
Showing
11 changed files
with
178 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
""" Defined constants for definitions, def labels, and expanded labels. """ | ||
|
||
|
||
class DefTagNames: | ||
""" Source names for definitions, def labels, and expanded labels. """ | ||
|
||
DEF_KEY = 'Def' | ||
DEF_EXPAND_KEY = 'Def-expand' | ||
DEFINITION_KEY = "Definition" | ||
|
||
ONSET_KEY = "Onset" | ||
OFFSET_KEY = "Offset" | ||
INSET_KEY = "Inset" | ||
DURATION_KEY = "Duration" | ||
DELAY_KEY = "Delay" | ||
|
||
TEMPORAL_KEYS = {ONSET_KEY, OFFSET_KEY, INSET_KEY} | ||
DURATION_KEYS = {DURATION_KEY, DELAY_KEY} | ||
|
||
ALL_TIME_KEYS = TEMPORAL_KEYS.union(DURATION_KEYS) | ||
""" Defined constants for definitions, def labels, and expanded labels. """ | ||
|
||
|
||
class DefTagNames: | ||
""" Source names for definitions, def labels, and expanded labels. """ | ||
|
||
DEF_KEY = 'Def' | ||
DEF_EXPAND_KEY = 'Def-expand' | ||
DEFINITION_KEY = "Definition" | ||
|
||
ONSET_KEY = "Onset" | ||
OFFSET_KEY = "Offset" | ||
INSET_KEY = "Inset" | ||
DURATION_KEY = "Duration" | ||
DELAY_KEY = "Delay" | ||
|
||
TEMPORAL_KEYS = {ONSET_KEY, OFFSET_KEY, INSET_KEY} | ||
DURATION_KEYS = {DURATION_KEY, DELAY_KEY} | ||
|
||
ALL_TIME_KEYS = TEMPORAL_KEYS.union(DURATION_KEYS) | ||
TIMELINE_KEYS = {ONSET_KEY, OFFSET_KEY, INSET_KEY, DELAY_KEY} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from hed.errors.error_reporter import ErrorHandler | ||
from hed.models.hed_tag import HedTag | ||
from hed.errors.error_types import ValidationErrors | ||
|
||
|
||
class DuplicateChecker: | ||
|
||
def __init__(self, hed_schema): | ||
""" Constructor for GroupValidator | ||
Parameters: | ||
hed_schema (HedSchema): A HedSchema object. | ||
""" | ||
if hed_schema is None: | ||
raise ValueError("HedSchema required for validation") | ||
self._hed_schema = hed_schema | ||
self.issues = [] | ||
|
||
def check_for_duplicates(self, original_group): | ||
self.issues = [] | ||
self._get_recursive_hash(original_group) | ||
return self.issues | ||
|
||
def get_hash(self, original_group): | ||
self.issues = [] | ||
duplication_hash = self._get_recursive_hash(original_group) | ||
return duplication_hash | ||
|
||
def _get_recursive_hash(self, group): | ||
if len(self.issues) > 0: | ||
return None | ||
group_hashes = set() | ||
for child in group.children: | ||
if isinstance(child, HedTag): | ||
this_hash = hash(child) | ||
else: | ||
this_hash = self._get_recursive_hash(child) | ||
if len(self.issues) > 0 or this_hash is None: | ||
return None | ||
if this_hash in group_hashes: | ||
self.issues += self._get_duplication_error(child) | ||
return None | ||
group_hashes.add(this_hash) | ||
return hash(frozenset(group_hashes)) | ||
|
||
@staticmethod | ||
def _get_duplication_error(child): | ||
if isinstance(child, HedTag): | ||
return ErrorHandler.format_error(ValidationErrors.HED_TAG_REPEATED, child) | ||
else: | ||
found_group = child | ||
base_steps_up = 0 | ||
while isinstance(found_group, list): | ||
found_group = found_group[0] | ||
base_steps_up += 1 | ||
for _ in range(base_steps_up): | ||
found_group = found_group._parent | ||
return ErrorHandler.format_error(ValidationErrors.HED_TAG_REPEATED_GROUP, found_group) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters