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
21 changes: 21 additions & 0 deletions hed/models/string_util.py
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
1 change: 1 addition & 0 deletions hed/tools/analysis/annotation_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
Binary file modified tests/data/bids_tests/eeg_ds003645s_hed_remodel.zip
Binary file not shown.
5 changes: 2 additions & 3 deletions tests/tools/analysis/test_event_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions tests/tools/analysis/test_hed_tag_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'
Expand All @@ -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__':
Expand Down