diff --git a/hed/models/string_util.py b/hed/models/string_util.py index 9f6023223..1f678b758 100644 --- a/hed/models/string_util.py +++ b/hed/models/string_util.py @@ -1,6 +1,27 @@ from hed.models.hed_string import HedString +def gather_descriptions(hed_string): + """Removes any description tags from the string and concatenates them + + Parameters: + hed_string(HedString): To be modified + + Returns: tuple + description(str): The concatenated values of all description tags. + + Side-effect: + The input HedString has its Definition tags removed. + + """ + desc_tags = hed_string.find_tags("description", recursive=True, include_groups=0) + desc_string = " ".join([tag.extension if tag.extension.endswith(".") else tag.extension + "." for tag in desc_tags]) + + hed_string.remove(desc_tags) + + return desc_string + + def split_base_tags(hed_string, base_tags, remove_group=False): """ Splits a HedString object into two separate HedString objects based on the presence of base tags. diff --git a/hed/tools/analysis/annotation_util.py b/hed/tools/analysis/annotation_util.py index a0942068e..8de527f5a 100644 --- a/hed/tools/analysis/annotation_util.py +++ b/hed/tools/analysis/annotation_util.py @@ -165,6 +165,7 @@ def merge_hed_dict(sidecar_dict, hed_dict): hed_dict(dict): Dictionary derived from a dataframe representation of HED in sidecar. """ + for key, value_dict in hed_dict.items(): if key not in sidecar_dict: sidecar_dict[key] = value_dict diff --git a/tests/data/bids_tests/eeg_ds003645s_hed/task-FacePerception_events.json b/tests/data/bids_tests/eeg_ds003645s_hed/task-FacePerception_events.json index fa018c473..f24a3f1f0 100644 --- a/tests/data/bids_tests/eeg_ds003645s_hed/task-FacePerception_events.json +++ b/tests/data/bids_tests/eeg_ds003645s_hed/task-FacePerception_events.json @@ -60,8 +60,7 @@ } }, "trial": { - "Description": "Indicates which trial this event belongs to.", - "HED": "Experimental-trial/#" + "Description": "Indicates which trial this event belongs to." }, "rep_lag": { "Description": "How face images before this one was the image was previously presented.", diff --git a/tests/data/bids_tests/eeg_ds003645s_hed_inheritance/task-FacePerception_events.json b/tests/data/bids_tests/eeg_ds003645s_hed_inheritance/task-FacePerception_events.json index b98b57b9c..420f75b97 100644 --- a/tests/data/bids_tests/eeg_ds003645s_hed_inheritance/task-FacePerception_events.json +++ b/tests/data/bids_tests/eeg_ds003645s_hed_inheritance/task-FacePerception_events.json @@ -43,8 +43,7 @@ } }, "trial": { - "Description": "Indicates which trial this event belongs to.", - "HED": "Experimental-trial/#" + "Description": "Indicates which trial this event belongs to." }, "stim_file": { "Description": "Path of the stimulus file in the stimuli directory.", diff --git a/tests/data/bids_tests/eeg_ds003645s_hed_library/task-FacePerception_events.json b/tests/data/bids_tests/eeg_ds003645s_hed_library/task-FacePerception_events.json index f542dc10d..ab39a1085 100644 --- a/tests/data/bids_tests/eeg_ds003645s_hed_library/task-FacePerception_events.json +++ b/tests/data/bids_tests/eeg_ds003645s_hed_library/task-FacePerception_events.json @@ -60,8 +60,7 @@ } }, "trial": { - "Description": "Indicates which trial this event belongs to.", - "HED": "Experimental-trial/#, test:Informational-property, sc:Discontinuous-background-activity" + "Description": "Indicates which trial this event belongs to." }, "rep_lag": { "Description": "How face images before this one was the image was previously presented.", diff --git a/tests/data/bids_tests/eeg_ds003645s_hed_remodel.zip b/tests/data/bids_tests/eeg_ds003645s_hed_remodel.zip index 520877e3b..64cbd3de7 100644 Binary files a/tests/data/bids_tests/eeg_ds003645s_hed_remodel.zip and b/tests/data/bids_tests/eeg_ds003645s_hed_remodel.zip differ diff --git a/tests/tools/analysis/test_event_manager.py b/tests/tools/analysis/test_event_manager.py index 3094c8cec..d221f2c47 100644 --- a/tests/tools/analysis/test_event_manager.py +++ b/tests/tools/analysis/test_event_manager.py @@ -65,12 +65,11 @@ def test_str_list_to_hed(self): hed_obj2 = manager.str_list_to_hed([hed[1], base[1], '(Event-context, (' + context[1] + '))']) self.assertIsInstance(hed_obj2, HedString) - self.assertEqual(10, len(hed_obj2.children)) + self.assertEqual(9, len(hed_obj2.children)) hed3, base3, context3 = manager.unfold_context(remove_types=['Condition-variable', 'Task']) - hed_obj3 = manager.str_list_to_hed([hed3[1], base3[1], '(Event-context, (' + context3[1] + '))']) self.assertIsInstance(hed_obj3, HedString) - self.assertEqual(6, len(hed_obj3.children)) + self.assertEqual(5, len(hed_obj3.children)) def test_get_type_defs(self): manager1 = EventManager(self.input_data, self.schema) diff --git a/tests/tools/analysis/test_hed_tag_counts.py b/tests/tools/analysis/test_hed_tag_counts.py index 2821abd55..8f492466b 100644 --- a/tests/tools/analysis/test_hed_tag_counts.py +++ b/tests/tools/analysis/test_hed_tag_counts.py @@ -48,7 +48,7 @@ def test_constructor(self): counts.update_event_counts(HedString(self.input_df.iloc[k]['HED_assembled'], self.hed_schema), file_name='Base_name') self.assertIsInstance(counts.tag_dict, dict) - self.assertEqual(len(counts.tag_dict), 15) + self.assertEqual(14, len(counts.tag_dict)) def test_merge_tag_dicts(self): counts1 = HedTagCounts('Base_name1', 50) @@ -61,10 +61,10 @@ def test_merge_tag_dicts(self): counts3 = HedTagCounts("All", 0) counts3.merge_tag_dicts(counts1.tag_dict) counts3.merge_tag_dicts(counts2.tag_dict) - self.assertEqual(len(counts1.tag_dict), 15) - self.assertEqual(len(counts2.tag_dict), 15) - self.assertEqual(len(counts3.tag_dict), 15) - self.assertEqual(counts3.tag_dict['experiment-structure'].events, 2) + self.assertEqual(14, len(counts1.tag_dict)) + self.assertEqual(14, len(counts2.tag_dict)) + self.assertEqual(14, len(counts3.tag_dict)) + self.assertEqual(2, counts3.tag_dict['experiment-structure'].events) def test_hed_tag_count(self): name = 'Base_name1' @@ -82,10 +82,10 @@ def test_organize_tags(self): for hed in hed_strings: counts.update_event_counts(hed, 'run-1') self.assertIsInstance(counts.tag_dict, dict) - self.assertEqual(len(counts.tag_dict), 47) + self.assertEqual(46, len(counts.tag_dict)) org_tags, leftovers = counts.organize_tags(self.tag_template) - self.assertEqual(len(org_tags), 19) - self.assertEqual(len(leftovers), 22) + self.assertEqual(19, len(org_tags)) + self.assertEqual(21, len(leftovers)) if __name__ == '__main__':