Skip to content

Commit

Permalink
Merge pull request #24 from vogelbam/add-tag-filter
Browse files Browse the repository at this point in the history
Sound event tag filter for annotation mode
  • Loading branch information
mbsantiago committed Jun 11, 2024
2 parents 515ba06 + 9d66631 commit e7f1d22
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
50 changes: 50 additions & 0 deletions back/src/whombat/filters/annotation_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,55 @@ def filter(self, query: Select) -> Select:
)


class SoundEventAnnotationTagFilter(base.Filter):
"""Filter for tasks by sound event annotation tag."""

key: str | None = None
value: str | None = None

def filter(self, query: Select) -> Select:
"""Filter the query."""
if self.key is None and self.value is None:
return query

query = (
query.join(
models.Clip,
models.Clip.id == models.AnnotationTask.clip_id,
)
.join(
models.ClipAnnotation,
models.ClipAnnotation.clip_id == models.Clip.id,
)
.join(
models.SoundEventAnnotation,
models.SoundEventAnnotation.clip_annotation_id == models.ClipAnnotation.id,
)
.join(
models.SoundEventAnnotationTag,
models.SoundEventAnnotationTag.sound_event_annotation_id == models.SoundEventAnnotation.id,
)
.join(
models.Tag,
models.Tag.id == models.SoundEventAnnotationTag.tag_id,
)
)
if self.key is None:
return query.where(
models.Tag.value == self.value,
)

if self.value is None:
return query.where(
models.Tag.key == self.key,
)

return query.where(
models.Tag.key == self.key,
models.Tag.value == self.value,
)


AnnotationTaskFilter = base.combine(
assigned_to=AssignedToFilter,
pending=PendingFilter,
Expand All @@ -215,4 +264,5 @@ def filter(self, query: Select) -> Select:
annotation_project=AnnotationProjectFilter,
dataset=DatasetFilter,
recording_tag=RecordingTagFilter,
sound_event_annotation_tag=SoundEventAnnotationTagFilter,
)
3 changes: 3 additions & 0 deletions front/src/api/annotation_tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const AnnotationTaskFilterSchema = z.object({
dataset: DatasetSchema.optional(),
annotation_project: AnnotationProjectSchema.optional(),
recording_tag: TagSchema.optional(),
sound_event_annotation_tag: TagSchema.optional(),
pending: z.boolean().optional(),
assigned: z.boolean().optional(),
verified: z.boolean().optional(),
Expand Down Expand Up @@ -88,6 +89,8 @@ export function registerAnnotationTasksAPI(
annotation_project__eq: params.annotation_project?.uuid,
recording_tag__key: params.recording_tag?.key,
recording_tag__value: params.recording_tag?.value,
sound_event_annotation_tag__key: params.sound_event_annotation_tag?.key,
sound_event_annotation_tag__value: params.sound_event_annotation_tag?.value,
pending__eq: params.pending,
assigned__eq: params.assigned,
verified__eq: params.verified,
Expand Down
20 changes: 20 additions & 0 deletions front/src/components/filters/tasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,26 @@ const tasksFilterDefs: FilterDef<AnnotationTaskFilter>[] = [
<NeedsReviewIcon className="h-5 w-5 inline-block text-stone-500 mr-1 align-middle" />
),
},

{
field: "sound_event_annotation_tag",
name: "Sound Event Tag",
render: ({ value, clear }) => (
<FilterBadge
field="Sound Event Tag"
value={`${value.key}: ${value.value}`}
onRemove={clear}
/>
),
selector: ({ setFilter }) => (
<TagFilter onChange={(val) => setFilter("sound_event_annotation_tag", val)} />
),
description: "Select task that contain a sound event with a specific tag",
icon: (
<TagIcon className="h-5 w-5 inline-block text-stone-500 mr-1 align-middle" />
),
},

{
field: "dataset",
name: "Dataset",
Expand Down

0 comments on commit e7f1d22

Please sign in to comment.