File size: 818 Bytes
299866a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from __future__ import annotations

DOG_HINTS = {
    "terrier",
    "retriever",
    "spaniel",
    "hound",
    "poodle",
    "collie",
    "shepherd",
    "pug",
    "bulldog",
    "beagle",
    "dalmatian",
    "chihuahua",
    "maltese",
    "samoyed",
    "husky",
    "boxer",
    "doberman",
    "shiba",
    "akita",
    "rottweiler",
    "dog",
    "canine",
}

CAT_HINTS = {
    "cat",
    "tabby",
    "tiger cat",
    "persian cat",
    "siamese",
    "lynx",
}


def coarse_label(raw_label: str) -> str:
    normalized = raw_label.lower()
    if any(keyword in normalized for keyword in DOG_HINTS):
        return "dog"
    if any(keyword in normalized for keyword in CAT_HINTS):
        return "cat"
    cleaned = raw_label.split(",", maxsplit=1)[0].strip().lower()
    return cleaned.replace(" ", "_")