Skip to content

Commit e7f1d22

Browse files
authored
Merge pull request #24 from vogelbam/add-tag-filter
Sound event tag filter for annotation mode
2 parents 515ba06 + 9d66631 commit e7f1d22

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

back/src/whombat/filters/annotation_tasks.py

+50
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,55 @@ def filter(self, query: Select) -> Select:
206206
)
207207

208208

209+
class SoundEventAnnotationTagFilter(base.Filter):
210+
"""Filter for tasks by sound event annotation tag."""
211+
212+
key: str | None = None
213+
value: str | None = None
214+
215+
def filter(self, query: Select) -> Select:
216+
"""Filter the query."""
217+
if self.key is None and self.value is None:
218+
return query
219+
220+
query = (
221+
query.join(
222+
models.Clip,
223+
models.Clip.id == models.AnnotationTask.clip_id,
224+
)
225+
.join(
226+
models.ClipAnnotation,
227+
models.ClipAnnotation.clip_id == models.Clip.id,
228+
)
229+
.join(
230+
models.SoundEventAnnotation,
231+
models.SoundEventAnnotation.clip_annotation_id == models.ClipAnnotation.id,
232+
)
233+
.join(
234+
models.SoundEventAnnotationTag,
235+
models.SoundEventAnnotationTag.sound_event_annotation_id == models.SoundEventAnnotation.id,
236+
)
237+
.join(
238+
models.Tag,
239+
models.Tag.id == models.SoundEventAnnotationTag.tag_id,
240+
)
241+
)
242+
if self.key is None:
243+
return query.where(
244+
models.Tag.value == self.value,
245+
)
246+
247+
if self.value is None:
248+
return query.where(
249+
models.Tag.key == self.key,
250+
)
251+
252+
return query.where(
253+
models.Tag.key == self.key,
254+
models.Tag.value == self.value,
255+
)
256+
257+
209258
AnnotationTaskFilter = base.combine(
210259
assigned_to=AssignedToFilter,
211260
pending=PendingFilter,
@@ -215,4 +264,5 @@ def filter(self, query: Select) -> Select:
215264
annotation_project=AnnotationProjectFilter,
216265
dataset=DatasetFilter,
217266
recording_tag=RecordingTagFilter,
267+
sound_event_annotation_tag=SoundEventAnnotationTagFilter,
218268
)

front/src/api/annotation_tasks.ts

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const AnnotationTaskFilterSchema = z.object({
2727
dataset: DatasetSchema.optional(),
2828
annotation_project: AnnotationProjectSchema.optional(),
2929
recording_tag: TagSchema.optional(),
30+
sound_event_annotation_tag: TagSchema.optional(),
3031
pending: z.boolean().optional(),
3132
assigned: z.boolean().optional(),
3233
verified: z.boolean().optional(),
@@ -88,6 +89,8 @@ export function registerAnnotationTasksAPI(
8889
annotation_project__eq: params.annotation_project?.uuid,
8990
recording_tag__key: params.recording_tag?.key,
9091
recording_tag__value: params.recording_tag?.value,
92+
sound_event_annotation_tag__key: params.sound_event_annotation_tag?.key,
93+
sound_event_annotation_tag__value: params.sound_event_annotation_tag?.value,
9194
pending__eq: params.pending,
9295
assigned__eq: params.assigned,
9396
verified__eq: params.verified,

front/src/components/filters/tasks.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ const tasksFilterDefs: FilterDef<AnnotationTaskFilter>[] = [
7070
<NeedsReviewIcon className="h-5 w-5 inline-block text-stone-500 mr-1 align-middle" />
7171
),
7272
},
73+
74+
{
75+
field: "sound_event_annotation_tag",
76+
name: "Sound Event Tag",
77+
render: ({ value, clear }) => (
78+
<FilterBadge
79+
field="Sound Event Tag"
80+
value={`${value.key}: ${value.value}`}
81+
onRemove={clear}
82+
/>
83+
),
84+
selector: ({ setFilter }) => (
85+
<TagFilter onChange={(val) => setFilter("sound_event_annotation_tag", val)} />
86+
),
87+
description: "Select task that contain a sound event with a specific tag",
88+
icon: (
89+
<TagIcon className="h-5 w-5 inline-block text-stone-500 mr-1 align-middle" />
90+
),
91+
},
92+
7393
{
7494
field: "dataset",
7595
name: "Dataset",

0 commit comments

Comments
 (0)