File size: 2,652 Bytes
060a244 be65a65 060a244 be65a65 060a244 be65a65 060a244 be65a65 060a244 be65a65 060a244 be65a65 060a244 be65a65 060a244 be65a65 060a244 be65a65 060a244 be65a65 060a244 be65a65 060a244 be65a65 060a244 be65a65 060a244 be65a65 060a244 | 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | """
Keyword-based fallback detector.
Used automatically when no API key is configured.
With an API key, the LLM in app.py takes over and this is bypassed.
"""
import re
discrimination_rules = {
"Gender": [
"male only", "female only",
"waitress", "waiter", "cameriera", "cameriere",
"salesman", "saleswoman", "salesgirl",
"young lady", "hostess", "stewardess",
"seamstress", "fairy hands",
"he will", "she will", "his duties", "her duties",
],
"Age": [
"under 30", "under 35", "under 25",
"age not exceeding", "max age",
"recent graduate only", "junior only",
"young professional", "young candidate",
],
"Origin": [
"italian only", "eu nationals only",
"must be italian", "native english speaker only",
"south american nationality",
"residence near", "residence in",
"must reside in", "local candidates only",
],
"Mobility": [
"own means of transportation",
"own vehicle required",
"own car required",
"own transport",
"driving licence required",
"driver's license required",
"patente di guida",
],
"Salary": [
"to be defined", "to be agreed",
"commensurate with experience",
"salary not specified",
"compensation tbd",
"retribuzione da definire",
],
"Standing": [
"professional appearance",
"smart appearance",
"good appearance",
"presentable",
"bella presenza",
],
"PPE": [
"own safety equipment",
"provide own ppe",
"own protective equipment",
"own hard hat",
"own boots",
],
"Religion": [
"christian only", "muslim only",
"catholic preferred", "must be christian",
],
"Disability": [
"physically fit only", "able bodied",
"no disabilities", "full physical fitness required",
],
}
def clean_text(text: str) -> str:
text = str(text).lower()
text = re.sub(r"[^\w\s]", " ", text)
return text
def detect_discrimination(text: str) -> tuple[str, str]:
cleaned = clean_text(text)
found_cats, found_kws = [], []
for category, keywords in discrimination_rules.items():
for kw in keywords:
if kw in cleaned:
if category not in found_cats:
found_cats.append(category)
found_kws.append(kw)
if not found_cats:
return "None", "No discriminatory keywords detected"
return ", ".join(found_cats), "Keywords found: " + ", ".join(found_kws) |