From 1674862f6ef0a78be4972b8baff639558fe86f40 Mon Sep 17 00:00:00 2001 From: Brian McFee Date: Mon, 4 Jun 2018 15:40:58 -0400 Subject: [PATCH] added namespace conversion from scaper to tag_open --- jams/nsconvert.py | 14 ++++++++++++++ tests/test_convert.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/jams/nsconvert.py b/jams/nsconvert.py index 136fb24..5a55b30 100644 --- a/jams/nsconvert.py +++ b/jams/nsconvert.py @@ -238,6 +238,20 @@ def tag_to_open(annotation): return annotation +@_conversion('tag_open', 'scaper') +def scaper_to_tag(annotation): + '''Convert scaper annotations to tag_open''' + + annotation.namespace = 'tag_open' + + data = annotation.pop_data() + for obs in data: + annotation.append(time=obs.time, duration=obs.duration, + confidence=obs.confidence, value=obs.value['label']) + + return annotation + + @_conversion('beat', 'beat_position') def beat_position(annotation): '''Convert beat_position to beat''' diff --git a/tests/test_convert.py b/tests/test_convert.py index 37b6e26..adf0e13 100644 --- a/tests/test_convert.py +++ b/tests/test_convert.py @@ -253,6 +253,37 @@ def test_beat_position(): assert obs1.confidence == obs2.confidence +def test_scaper_tag_open(): + ann = jams.Annotation(namespace='scaper') + + value = { + "source_time": 5, + "event_duration": 0.5310546236891855, + "event_time": 5.6543442662431795, + "time_stretch": 0.8455598669219283, + "pitch_shift": -1.2204911976305648, + "snr": 7.790682558359417, + "label": 'gun_shot', + "role": "foreground", + "source_file": "/audio/foreground/gun_shot/135544-6-17-0.wav" + } + + ann.append(time=0, duration=1, value=value) + + ann2 = jams.convert(ann, 'tag_open') + + ann.validate() + ann2.validate() + assert ann2.namespace == 'tag_open' + + assert len(ann) == len(ann2) + for obs1, obs2 in zip(ann.data, ann2.data): + assert obs1.time == obs2.time + assert obs1.duration == obs2.duration + assert obs1.confidence == obs2.confidence + assert obs1.value['label'] == obs2.value + + def test_can_convert_equal(): ann = jams.Annotation(namespace='chord')