| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | from __future__ import annotations |
| 22 | |
| 23 | from dataclasses import dataclass |
| 24 | from typing import Any, Final |
| 25 | |
| 26 | from .normalize import fold_accents, folded_tokens, normalize |
| 27 | |
| 28 | |
| 29 | |
| 30 | _RAW_RULES: Final[list[dict[str, Any]]] = [ |
| 31 | {"intent": "greeting", "groups": [ |
| 32 | {"all": ["merhaba"]}, {"all": ["selam"]}, {"all": ["günaydın"]}, |
| 33 | {"all": ["hey"]}, {"all": ["iyi", "günler"]}, |
| 34 | ]}, |
| 35 | {"intent": "smalltalk", "groups": [ |
| 36 | {"all": ["naber"]}, {"all": ["nasılsın"]}, {"all": ["napıyorsun"]}, |
| 37 | {"all": ["ne", "haber"]}, {"all": ["keyifler"]}, |
| 38 | ]}, |
| 39 | {"intent": "thanks", "groups": [ |
| 40 | {"all": ["teşekkür"]}, {"all": ["sağol"]}, {"all": ["sağ", "ol"]}, |
| 41 | {"all": ["eyvallah"]}, |
| 42 | ]}, |
| 43 | {"intent": "farewell", "groups": [ |
| 44 | {"all": ["görüşürüz"]}, {"all": ["hoşça"]}, {"all": ["hoşçakal"]}, |
| 45 | {"all": ["iyi", "gece"]}, |
| 46 | |
| 47 | {"all": ["bye"]}, {"all": ["goodbye"]}, |
| 48 | ]}, |
| 49 | {"intent": "bot_identity", "groups": [ |
| 50 | {"all": ["kimsin"]}, {"all": ["robot"]}, {"all": ["yapay", "zeka"]}, |
| 51 | {"all": ["adın", "ne"]}, {"all": ["kim", "yaptı", "seni"]}, |
| 52 | ]}, |
| 53 | {"intent": "platform_info", "groups": [ |
| 54 | |
| 55 | |
| 56 | |
| 57 | {"all": ["hezarfen", "nedir"]}, {"all": ["hezarfen", "ne"]}, |
| 58 | {"all": ["hezarfen", "tanıt"]}, {"all": ["hazerfen"]}, |
| 59 | {"all": ["bu", "site", "nedir"]}, {"all": ["bu", "uygulama", "nedir"]}, |
| 60 | {"all": ["bu", "platform"]}, {"all": ["hezafen"]}, |
| 61 | ]}, |
| 62 | {"intent": "help_capabilities", "groups": [ |
| 63 | |
| 64 | |
| 65 | |
| 66 | {"all": ["neler", "yapabil"], "none": [ |
| 67 | "yönetici", "öğretmen", "rol", "yetki", "etkinlik", "ders", "sınav", |
| 68 | "ödev", "mesaj", "karne", "yoklama", "defter", "not", "takvim", "soru", |
| 69 | "pomodoro", "randevu", "yemek", "ödeme", "dönem", "sınıf", "profil", |
| 70 | "şifre", "devamsız", "rehber", "ayar", "havuz", "tahta", "mesai", "çocuk"]}, |
| 71 | {"all": ["ne", "yapabil"], "none": [ |
| 72 | "yönetici", "öğretmen", "rol", "yetki", "etkinlik", "ders", "sınav", |
| 73 | "ödev", "mesaj", "karne", "yoklama", "defter", "not", "takvim", "soru", |
| 74 | "pomodoro", "randevu", "yemek", "ödeme", "dönem", "sınıf", "profil", |
| 75 | "şifre", "devamsız", "rehber", "ayar", "havuz", "tahta", "mesai", "çocuk"]}, |
| 76 | {"all": ["özellik"], "none": ["etkinlik", "ders", "sınav", "ödev", "soru"]}, |
| 77 | {"all": ["yardım", "edebil"]}, |
| 78 | ]}, |
| 79 | {"intent": "roles_permissions", "groups": [ |
| 80 | {"all": ["yönetici", "yapabil"]}, {"all": ["öğretmen", "yapabil"]}, |
| 81 | {"all": ["rol", "kademe"]}, {"all": ["yetki", "seviye"]}, |
| 82 | {"all": ["rol", "nedir"]}, {"all": ["kim", "yetki"]}, |
| 83 | |
| 84 | |
| 85 | {"all": ["rolüm"]}, {"all": ["rol", "fark"]}, |
| 86 | ]}, |
| 87 | {"intent": "privacy_security", "groups": [ |
| 88 | {"all": ["arkadaş"]}, {"all": ["başka", "öğrenci"]}, |
| 89 | {"all": ["başka", "öğretmen"]}, {"all": ["başka", "birinin"]}, |
| 90 | {"all": ["başka", "karne"]}, {"all": ["başka", "telefon"]}, |
| 91 | {"all": ["öğretmen", "telefon"]}, {"all": ["herkes", "not"]}, |
| 92 | {"all": ["birinin", "karne"]}, |
| 93 | |
| 94 | |
| 95 | {"all": ["arkadaş", "devamsız"]}, {"all": ["arkadaş", "yoklama"]}, |
| 96 | {"all": ["arkadaş", "not"]}, {"all": ["arkadaş", "karne"]}, |
| 97 | {"all": ["arkadaş", "ortalama"]}, {"all": ["arkadaş", "puan"]}, |
| 98 | {"all": ["başka", "devamsız"]}, {"all": ["başka", "yoklama"]}, |
| 99 | {"all": ["başka", "not"]}, {"all": ["başka", "ortalama"]}, |
| 100 | {"all": ["başka", "puan"]}, |
| 101 | {"all": ["birinin", "devamsız"]}, {"all": ["birinin", "yoklama"]}, |
| 102 | {"all": ["birinin", "not"]}, {"all": ["birinin", "ortalama"]}, |
| 103 | ]}, |
| 104 | {"intent": "account_access_problem", "groups": [ |
| 105 | {"all": ["şifre", "unut"]}, {"all": ["şifre", "yanlış"]}, |
| 106 | {"all": ["şifre", "sıfırla"]}, {"all": ["şifre", "değiştir"]}, |
| 107 | {"all": ["parola", "unut"]}, {"all": ["parola", "değiştir"]}, |
| 108 | {"all": ["parola", "hatırla"]}, {"all": ["giremiyor"]}, |
| 109 | {"all": ["yapamıyor"]}, {"all": ["erişemiyor"]}, |
| 110 | ]}, |
| 111 | {"intent": "login_how", "groups": [ |
| 112 | {"all": ["giriş", "yap"], "none": ["yapamıyor", "giremiyor", "mesai"]}, |
| 113 | {"all": ["log", "in"]}, {"all": ["giriş", "ekran"]}, |
| 114 | ]}, |
| 115 | {"intent": "logout_how", "groups": [ |
| 116 | {"all": ["oturum", "kapat"]}, {"all": ["sistemden", "çık"]}, |
| 117 | {"all": ["hesap", "çık"]}, |
| 118 | ]}, |
| 119 | {"intent": "session_info", "groups": [ |
| 120 | {"all": ["oturum", "süre"]}, {"all": ["kaç", "gün", "geçerli"]}, |
| 121 | {"all": ["oturum", "kaç", "gün"]}, {"all": ["oturum", "açık", "kal"]}, |
| 122 | ]}, |
| 123 | {"intent": "report_card_view", "groups": [ |
| 124 | {"all": ["karne"], "none": ["öğrenci", "başka", "birinin", "yükselt", "artır", "sil", "kaldır", "düzelt"]}, |
| 125 | {"all": ["harf", "not"]}, |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | {"all": ["karnem"], "none": ["başka", "birinin"]}, |
| 132 | |
| 133 | |
| 134 | {"all": ["notum", "kaç"]}, {"all": ["notum", "ne"], "none": ["nereden", "nasıl"]}, |
| 135 | ]}, |
| 136 | {"intent": "weighted_average_info", "groups": [ |
| 137 | {"all": ["ortalama", "hesap"]}, {"all": ["ağırlık", "ortalama"]}, |
| 138 | {"all": ["ağırlıklı", "ortalama"]}, |
| 139 | ]}, |
| 140 | {"intent": "student_marks_lookup", "groups": [ |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | {"all": ["öğrenci", "karne"], "none": ["başka", "birinin", "karnem"]}, |
| 147 | {"all": ["öğrenci", "not", "gör"], "none": ["başka", "birinin", "notum", "notlarım"]}, |
| 148 | {"all": ["öğrenci", "not", "sorgu"], "none": ["başka", "birinin", "notum", "notlarım"]}, |
| 149 | {"all": ["öğrenci", "not", "bak"], "none": ["başka", "birinin", "notum", "notlarım"]}, |
| 150 | |
| 151 | {"all": ["not", "nasıl", "bak"], "none": ["notum", "notlarım", "karnem", "kendi", "benim", "başka", "birinin", "arkadaş"]}, |
| 152 | {"all": ["dönem", "not", "bak"], "none": ["notum", "notlarım", "karnem", "benim", "başka", "birinin", "arkadaş"]}, |
| 153 | ]}, |
| 154 | {"intent": "note_create", "groups": [ |
| 155 | {"all": ["defter"]}, {"all": ["yeni", "not"]}, {"all": ["not", "oluştur"]}, |
| 156 | ]}, |
| 157 | {"intent": "course_create", "groups": [ |
| 158 | {"all": ["yeni", "ders"], "none": ["saat", "oturum", "sınav", "öğrenci"]}, |
| 159 | {"all": ["ders", "oluştur"], "none": ["saat", "oturum", "sınav", "öğrenci"]}, |
| 160 | {"all": ["ders", "aç"], "none": ["saat", "oturum", "sınav", "öğrenci", "liste"]}, |
| 161 | {"all": ["sınıf", "oluştur"]}, |
| 162 | ]}, |
| 163 | {"intent": "lesson_session_add", "groups": [ |
| 164 | {"all": ["oturum", "ekle"]}, {"all": ["oturum", "oluştur"]}, |
| 165 | {"all": ["ders", "oturum"]}, |
| 166 | {"all": ["ders", "saat"], "none": ["var", "yok", "yoklama", "işaretle"]}, |
| 167 | ]}, |
| 168 | {"intent": "roll_call", "groups": [ |
| 169 | {"all": ["yoklama", "al"]}, {"all": ["yoklama", "kaydet"]}, |
| 170 | {"all": ["devam", "kontrol"]}, |
| 171 | ]}, |
| 172 | {"intent": "exam_create", "groups": [ |
| 173 | {"all": ["sınav", "oluştur"], "none": ["mod", "anlat"]}, {"all": ["yeni", "sınav"]}, |
| 174 | {"all": ["sınav", "hazırla"]}, {"all": ["yazılı", "oluştur"]}, |
| 175 | ]}, |
| 176 | {"intent": "exam_add_question", "groups": [ |
| 177 | {"all": ["soru", "ekle"]}, {"all": ["soru", "oluştur"]}, |
| 178 | {"all": ["seçmeli", "soru"]}, |
| 179 | |
| 180 | {"all": ["doğru", "şık"]}, |
| 181 | ]}, |
| 182 | {"intent": "exam_save_answer", "groups": [ |
| 183 | {"all": ["cevab", "kaydet"]}, {"all": ["cevap", "kaydet"]}, |
| 184 | {"all": ["şık", "seç"]}, {"all": ["işaretle", "cevab"]}, |
| 185 | ]}, |
| 186 | {"intent": "exam_live_monitor", "groups": [ |
| 187 | {"all": ["sınav", "takip"]}, {"all": ["anlık", "takip"]}, |
| 188 | {"all": ["sınav", "izle"]}, {"all": ["canlı", "izle"]}, |
| 189 | ]}, |
| 190 | {"intent": "course_view", "groups": [ |
| 191 | {"all": ["ders", "liste"], "none": ["oluştur", "yeni", "öğrenci", "not"]}, |
| 192 | {"all": ["derslerim"], "none": ["oluştur", "not"]}, |
| 193 | ]}, |
| 194 | {"intent": "exam_enter_room", "groups": [ |
| 195 | {"all": ["sınav", "gir"], "none": ["oluştur", "sonuc", "aldı", "takvim", "tarih", "geri", "ikinci", "kez", "tekrar", "yeniden", "hak"]}, |
| 196 | {"all": ["exam", "gir"]}, {"all": ["exam", "nasıl"]}, |
| 197 | ]}, |
| 198 | {"intent": "exam_modes_info", "groups": [ |
| 199 | {"all": ["sınav", "mod"]}, {"all": ["senkron", "sınav"]}, {"all": ["asenkron", "sınav"]}, |
| 200 | ]}, |
| 201 | {"intent": "exam_rejoin_retake", "groups": [ |
| 202 | {"all": ["geri", "gir"], "none": ["mesai"]}, {"all": ["yeniden", "gir"]}, |
| 203 | {"all": ["bağlantı", "kop"]}, {"all": ["tekrar", "gir"], "none": ["mesai"]}, |
| 204 | ]}, |
| 205 | {"intent": "exam_grade_student", "groups": [ |
| 206 | {"all": ["öğrenci", "not", "gir"]}, {"all": ["notlandır"]}, |
| 207 | {"all": ["sınav", "puanla"]}, |
| 208 | ]}, |
| 209 | {"intent": "exam_finish_result", "groups": [ |
| 210 | |
| 211 | {"all": ["sınav", "sonuc"]}, {"all": ["sınav", "aldı"], "none": ["ödev"]}, |
| 212 | {"all": ["sınav", "bitir", "kaç"]}, |
| 213 | ]}, |
| 214 | {"intent": "event_create", "groups": [ |
| 215 | {"all": ["etkinlik", "oluştur"]}, {"all": ["etkinlik", "ekle"]}, |
| 216 | {"all": ["etkinlik", "planla"]}, |
| 217 | |
| 218 | |
| 219 | {"all": ["etkinliğ", "oluştur"]}, {"all": ["etkinliğ", "ekle"]}, |
| 220 | {"all": ["etkinliğ", "planla"]}, |
| 221 | {"all": ["etkinlik", "ekl"]}, {"all": ["etkinliğ", "ekl"]}, |
| 222 | ]}, |
| 223 | {"intent": "user_role_change", "groups": [ |
| 224 | {"all": ["rol", "değiştir"]}, {"all": ["rol", "ata"]}, |
| 225 | {"all": ["yetki", "yükselt"]}, {"all": ["kullanıcı", "rol"]}, |
| 226 | {"all": ["kullanıcı", "admin"]}, {"all": ["admin", "yap"], "none": ["beni"]}, |
| 227 | ]}, |
| 228 | {"intent": "term_manage", "groups": [ |
| 229 | {"all": ["dönem", "oluştur"]}, {"all": ["akademik", "dönem"]}, |
| 230 | {"all": ["yarıyıl"]}, |
| 231 | ]}, |
| 232 | {"intent": "school_settings", "groups": [ |
| 233 | {"all": ["okul", "ayar"]}, {"all": ["not", "bant"]}, |
| 234 | {"all": ["sınav", "tür", "ağırlık"]}, |
| 235 | ]}, |
| 236 | {"intent": "language_theme", "groups": [ |
| 237 | |
| 238 | {"all": ["dil", "ayar"]}, {"all": ["dil", "değiştir"], "none": ["okul"]}, |
| 239 | {"all": ["dil", "seç"]}, {"all": ["tema"]}, {"all": ["ingilizce", "çevir"]}, |
| 240 | ]}, |
| 241 | {"intent": "work_checkin_out", "groups": [ |
| 242 | {"all": ["mesai", "giriş"]}, {"all": ["mesai", "çık"]}, |
| 243 | {"all": ["işe", "gel"]}, |
| 244 | |
| 245 | {"all": ["mesai", "başlat"]}, {"all": ["mesai", "başla"]}, |
| 246 | {"all": ["mesai", "gir"]}, {"all": ["mesai", "aç"], "none": ["personel", "yönet", "düzenle"]}, |
| 247 | {"all": ["mesai", "kayd"], "none": ["düzenle", "personel", "yönet"]}, |
| 248 | {"all": ["mesay"], "none": ["personel", "yönet", "düzenle"]}, |
| 249 | ]}, |
| 250 | {"intent": "course_enroll_student", "groups": [ |
| 251 | {"all": ["derse", "kaydet"]}, {"all": ["öğrenci", "kaydet"]}, |
| 252 | {"all": ["derse", "öğrenci"], "none": ["çıkar", "sil"]}, |
| 253 | {"all": ["sınıfa", "öğrenci"]}, |
| 254 | {"all": ["derse", "kaydol"]}, {"all": ["ders", "kaydol"]}, |
| 255 | {"all": ["öğrenci", "kayd"], "none": ["çıkar", "sil", "iptal", "kaldır", "başka", "birinin"]}, |
| 256 | {"all": ["derse", "ekle"], "none": ["oluştur", "çıkar", "sil"]}, |
| 257 | ]}, |
| 258 | |
| 259 | {"intent": "guide_info", "groups": [ |
| 260 | {"all": ["kılavuz"]}, {"all": ["guide"]}, {"all": ["adım", "tanıtım"]}, |
| 261 | ]}, |
| 262 | {"intent": "register_how", "groups": [ |
| 263 | {"all": ["üye", "ol"]}, {"all": ["kayıt", "ol"]}, |
| 264 | {"all": ["kayıt", "form"]}, {"all": ["hesap", "aç"]}, |
| 265 | ]}, |
| 266 | {"intent": "profile_edit", "groups": [ |
| 267 | {"all": ["iletişim", "bilgi", "değiştir"]}, |
| 268 | {"all": ["ad", "soyad", "güncelle"]}, |
| 269 | {"all": ["telefon", "değiştir"]}, |
| 270 | ]}, |
| 271 | {"intent": "attendance_view", "groups": [ |
| 272 | {"all": ["devamsızlık", "gör"]}, {"all": ["devamsızlık", "durum"]}, |
| 273 | {"all": ["yoklama", "geçmiş"]}, |
| 274 | {"all": ["devam", "yüzde"], "none": ["formül", "hesap", "nasıl"]}, |
| 275 | |
| 276 | {"all": ["devamsız"], "none": ["öğrenci", "başka", "birinin", "yazıl", "sayıl", "kural", "geç", "sil", "kaldır", "düzelt", "yükselt"]}, |
| 277 | ]}, |
| 278 | {"intent": "attendance_rate_info", "groups": [ |
| 279 | |
| 280 | {"all": ["devam", "hesap"]}, {"all": ["devam", "formül"]}, |
| 281 | {"all": ["devam", "oran", "nasıl"]}, |
| 282 | ]}, |
| 283 | {"intent": "student_attendance_lookup", "groups": [ |
| 284 | {"all": ["öğrenci", "yoklama"]}, {"all": ["öğrenci", "devamsızlık"]}, |
| 285 | {"all": ["öğrenci", "devam", "durum"]}, |
| 286 | |
| 287 | {"all": ["devamsız", "nasıl", "bak"], "none": ["devamsızlığım", "kendi", "benim", "başka", "birinin", "arkadaş"]}, |
| 288 | {"all": ["yoklama", "nasıl", "bak"], "none": ["yoklamam", "kendi", "benim", "başka", "birinin", "arkadaş"]}, |
| 289 | ]}, |
| 290 | {"intent": "event_attendance_mark", "groups": [ |
| 291 | {"all": ["etkinlik", "katıl"]}, {"all": ["etkinlik", "yoklama"]}, |
| 292 | ]}, |
| 293 | |
| 294 | |
| 295 | {"intent": "homework_view", "groups": [ |
| 296 | {"all": ["ödev", "nerede"], "none": [ |
| 297 | "oluştur", "ekle", "ata", "gönder", "yükle", "teslim", |
| 298 | "notland", "değerlendir", "puan", "gir"]}, |
| 299 | {"all": ["ödev", "hangi", "sayfa"]}, |
| 300 | {"all": ["ödev", "takip"]}, {"all": ["ödev", "listem"]}, |
| 301 | {"all": ["atanan", "ödev"]}, |
| 302 | {"all": ["verilen", "ödev"], "none": ["yükle", "gönder", "teslim"]}, |
| 303 | {"all": ["ödevlerim"], "none": [ |
| 304 | "teslim", "gönder", "yükle", "notland", "değerlendir", "puan"]}, |
| 305 | ]}, |
| 306 | {"intent": "homework_submit", "groups": [ |
| 307 | {"all": ["ödev", "gönder"]}, {"all": ["ödev", "yükle"]}, |
| 308 | {"all": ["ödev", "teslim"], "none": [ |
| 309 | "takip", "notland", "değerlendir", "puan", "not"]}, |
| 310 | {"all": ["ödev", "yol"], "none": ["notland", "değerlendir", "puan"]}, |
| 311 | ]}, |
| 312 | {"intent": "homework_assign", "groups": [ |
| 313 | {"all": ["ödev", "oluştur"]}, {"all": ["ödev", "ekle"]}, |
| 314 | {"all": ["yeni", "ödev"]}, |
| 315 | {"all": ["ödev", "ata"], "none": ["atanan"]}, |
| 316 | {"all": ["ödev", "ver"], "none": [ |
| 317 | "not", "puan", "verilen", "notland", "değerlendir", "gir"]}, |
| 318 | ]}, |
| 319 | {"intent": "homework_grade", "groups": [ |
| 320 | {"all": ["ödev", "notland"]}, {"all": ["ödev", "değerlendir"]}, |
| 321 | {"all": ["ödev", "puan"]}, |
| 322 | {"all": ["ödev", "not", "ver"], "none": ["bak", "aldı", "nereden"]}, |
| 323 | {"all": ["ödev", "not", "gir"], "none": ["bak", "aldı"]}, |
| 324 | ]}, |
| 325 | |
| 326 | {"intent": "pomodoro_use", "groups": [ |
| 327 | |
| 328 | {"all": ["pomodoro"], "none": ["öğrenci"]}, |
| 329 | {"all": ["odak", "başlat"]}, {"all": ["odağ", "başlat"]}, |
| 330 | {"all": ["odak", "bitir"]}, {"all": ["odağ", "bitir"]}, |
| 331 | {"all": ["odak", "oturum"], "none": ["öğrenci"]}, |
| 332 | |
| 333 | {"all": ["odak", "say"], "none": ["öğrenci"]}, |
| 334 | {"all": ["odağ", "say"], "none": ["öğrenci"]}, |
| 335 | ]}, |
| 336 | {"intent": "student_pomodoro_lookup", "groups": [ |
| 337 | {"all": ["öğrenci", "pomodoro"]}, {"all": ["öğrenci", "odak"]}, |
| 338 | {"all": ["öğrenci", "odağ"]}, |
| 339 | ]}, |
| 340 | {"intent": "messages_use", "groups": [ |
| 341 | {"all": ["mesaj"]}, {"all": ["gelen", "kutusu"]}, |
| 342 | {"all": ["öğretmen", "soru", "sor"]}, {"all": ["öğretmene", "sor"]}, |
| 343 | {"all": ["msj"]}, {"all": ["mesj"]}, |
| 344 | ]}, |
| 345 | {"intent": "study_club_info", "groups": [ |
| 346 | |
| 347 | {"all": ["etüt"]}, {"all": ["etüd"]}, |
| 348 | {"all": ["kulüp"]}, {"all": ["kulüb"]}, |
| 349 | ]}, |
| 350 | {"intent": "parent_info", "groups": [ |
| 351 | {"all": ["veli"]}, {"all": ["ebeveyn"]}, |
| 352 | ]}, |
| 353 | |
| 354 | {"intent": "fees_info", "groups": [ |
| 355 | {"all": ["ücret"]}, {"all": ["ödeme"], "none": ["sınav", "ödev"]}, |
| 356 | ]}, |
| 357 | {"intent": "branches_info", "groups": [ |
| 358 | {"all": ["şube"]}, |
| 359 | ]}, |
| 360 | {"intent": "calendar_info", "groups": [ |
| 361 | {"all": ["takvim"], "none": ["sınav"]}, |
| 362 | {"all": ["haftalık", "program"]}, |
| 363 | {"all": ["ders", "program"], "none": ["sen", "ayarla", "kur"]}, |
| 364 | ]}, |
| 365 | {"intent": "today_info", "groups": [ |
| 366 | {"all": ["bugün", "panel"]}, {"all": ["ana", "panel"]}, |
| 367 | ]}, |
| 368 | {"intent": "question_bank_info", "groups": [ |
| 369 | {"all": ["soru", "banka"]}, |
| 370 | |
| 371 | |
| 372 | {"all": ["soru", "havuz"]}, {"all": ["havuz"]}, |
| 373 | ]}, |
| 374 | {"intent": "notification_settings_info", "groups": [ |
| 375 | {"all": ["bildirim"]}, |
| 376 | ]}, |
| 377 | {"intent": "nav_overview", "groups": [ |
| 378 | {"all": ["akademik"], "none": ["dönem"]}, |
| 379 | {"all": ["öğrenci", "yönetim", "bölüm"]}, |
| 380 | {"all": ["yönetim", "menü"]}, {"all": ["admin", "bölüm"]}, |
| 381 | {"all": ["admin", "sayfa"]}, {"all": ["bölüm", "neler"]}, |
| 382 | {"all": ["menü", "bölüm", "var"]}, {"all": ["menü", "anlat"]}, |
| 383 | {"all": ["hangi", "bölüm", "var"]}, |
| 384 | ]}, |
| 385 | {"intent": "event_view", "groups": [ |
| 386 | {"all": ["etkinlik", "nerede"], "none": ["oluştur", "ekle", "planla", "katıl", "yoklama", "işaretle"]}, |
| 387 | {"all": ["etkinlik", "gör"], "none": ["oluştur", "ekle", "planla", "katıl", "yoklama"]}, |
| 388 | {"all": ["etkinlik", "liste"], "none": ["oluştur", "ekle"]}, |
| 389 | ]}, |
| 390 | {"intent": "exam_schedule_info", "groups": [ |
| 391 | {"all": ["sınav", "takvim"]}, {"all": ["sınav", "tarih"]}, |
| 392 | ]}, |
| 393 | {"intent": "course_materials_info", "groups": [ |
| 394 | {"all": ["ders", "not", "pdf"]}, {"all": ["ders", "not", "dosya"]}, |
| 395 | {"all": ["öğretmen", "pdf"]}, {"all": ["ders", "dosya"], "none": ["defter"]}, |
| 396 | ]}, |
| 397 | ] |
| 398 | |
| 399 | |
| 400 | def _kw_of(word: str) -> str: |
| 401 | |
| 402 | |
| 403 | return fold_accents(normalize(word)).replace(" ", "") |
| 404 | |
| 405 | |
| 406 | @dataclass(frozen=True) |
| 407 | class _Group: |
| 408 | all_kw: tuple[str, ...] |
| 409 | none_kw: tuple[str, ...] = () |
| 410 | |
| 411 | |
| 412 | @dataclass(frozen=True) |
| 413 | class _Rule: |
| 414 | intent: str |
| 415 | groups: tuple[_Group, ...] |
| 416 | |
| 417 | |
| 418 | def _compile_rules(raw_rules: list[dict[str, Any]]) -> list[_Rule]: |
| 419 | compiled: list[_Rule] = [] |
| 420 | for raw in raw_rules: |
| 421 | groups = tuple( |
| 422 | _Group( |
| 423 | all_kw=tuple(_kw_of(w) for w in group["all"]), |
| 424 | none_kw=tuple(_kw_of(w) for w in group.get("none", ())), |
| 425 | ) |
| 426 | for group in raw["groups"] |
| 427 | ) |
| 428 | compiled.append(_Rule(intent=raw["intent"], groups=groups)) |
| 429 | return compiled |
| 430 | |
| 431 | |
| 432 | _RULES: Final[list[_Rule]] = _compile_rules(_RAW_RULES) |
| 433 | |
| 434 | |
| 435 | @dataclass(frozen=True) |
| 436 | class RuleMatch: |
| 437 | |
| 438 | |
| 439 | intent: str |
| 440 | score: int |
| 441 | matched: tuple[str, ...] |
| 442 | reason: str |
| 443 | space_id: str | None = None |
| 444 | |
| 445 | |
| 446 | def _present(keyword: str, tokens: list[str]) -> bool: |
| 447 | |
| 448 | |
| 449 | if len(keyword) >= 2: |
| 450 | return any(token.startswith(keyword) for token in tokens) |
| 451 | return any(token == keyword for token in tokens) |
| 452 | |
| 453 | |
| 454 | def _group_matches(group: _Group, tokens: list[str]) -> bool: |
| 455 | if any(not _present(k, tokens) for k in group.all_kw): |
| 456 | return False |
| 457 | if any(_present(k, tokens) for k in group.none_kw): |
| 458 | return False |
| 459 | return True |
| 460 | |
| 461 | |
| 462 | class RuleMatcher: |
| 463 | |
| 464 | |
| 465 | def __init__( |
| 466 | self, |
| 467 | intent_names: set[str] | frozenset[str] | None = None, |
| 468 | *, |
| 469 | space_id: str | None = None, |
| 470 | ) -> None: |
| 471 | allowed = None if intent_names is None else frozenset(intent_names) |
| 472 | self._rules = tuple( |
| 473 | rule for rule in _RULES if allowed is None or rule.intent in allowed |
| 474 | ) |
| 475 | self.space_id = space_id |
| 476 | |
| 477 | def match(self, query: str) -> RuleMatch | None: |
| 478 | |
| 479 | |
| 480 | |
| 481 | |
| 482 | |
| 483 | |
| 484 | tokens = folded_tokens(query) |
| 485 | if not tokens: |
| 486 | return None |
| 487 | |
| 488 | best_by_intent: dict[str, tuple[int, tuple[str, ...]]] = {} |
| 489 | for rule in self._rules: |
| 490 | for group in rule.groups: |
| 491 | if _group_matches(group, tokens): |
| 492 | score = len(group.all_kw) |
| 493 | prev = best_by_intent.get(rule.intent) |
| 494 | if prev is None or score > prev[0]: |
| 495 | best_by_intent[rule.intent] = (score, group.all_kw) |
| 496 | |
| 497 | if not best_by_intent: |
| 498 | return None |
| 499 | |
| 500 | ranked = sorted(best_by_intent.items(), key=lambda kv: kv[1][0], reverse=True) |
| 501 | top_intent, (top_score, matched) = ranked[0] |
| 502 | |
| 503 | if len(ranked) > 1 and ranked[1][1][0] == top_score: |
| 504 | return None |
| 505 | |
| 506 | return RuleMatch( |
| 507 | intent=top_intent, |
| 508 | score=top_score, |
| 509 | matched=matched, |
| 510 | reason=f"kural: {top_intent} <- {list(matched)}", |
| 511 | space_id=self.space_id, |
| 512 | ) |
| 513 | |
| 514 | |
| 515 | _DEFAULT_RULE_MATCHER: Final[RuleMatcher] = RuleMatcher() |
| 516 | |
| 517 | |
| 518 | def match(query: str) -> RuleMatch | None: |
| 519 | |
| 520 | |
| 521 | return _DEFAULT_RULE_MATCHER.match(query) |