forge
Explore
Log in

Don't you dare go Hollow

hezarfen_rag

Clone
★ 0

0 watching0 forksPython2.4 MiB184b84dAhmet Kaan Gümüş2 months ago189 commits

test_query_understanding.py47 lines, 1.8 KiBHistoryRawDownload
1"""#14 Sorgu anlama — intent + NER (deterministik, model gerektirmez)."""
2import unittest
3
4from src.understand import Intent, analyze, classify_intent, extract_entities
5
6
7class IntentTests(unittest.TestCase):
8 def test_intents(self):
9 cases = {
10 "DNA nedir?": Intent.TANIM,
11 "Fotosentez nasıl gerçekleşir?": Intent.ACIKLAMA,
12 "DNA ile RNA arasındaki fark nedir?": Intent.KARSILASTIRMA, # tanım'dan önce
13 "Mitokondri neden enerji üretir?": Intent.NEDEN_SONUC,
14 "Kaç gram tuz gerekir?": Intent.HESAPLAMA,
15 "Canlıların ortak özellikleri nelerdir?": Intent.LISTE,
16 "Bu konuyu özetle": Intent.OZET,
17 "Merhaba, nasılsın?": Intent.SOHBET,
18 "": Intent.DIGER,
19 }
20 for q, exp in cases.items():
21 self.assertEqual(classify_intent(q), exp, q)
22
23 def test_out_of_scope_and_summary_flags(self):
24 self.assertTrue(analyze("Selam!").is_out_of_scope)
25 self.assertTrue(analyze("Bunu özetler misin").wants_summary)
26 self.assertFalse(analyze("DNA nedir").is_out_of_scope)
27
28
29class NerTests(unittest.TestCase):
30 def test_acronyms_and_proper_and_formula(self):
31 self.assertIn("DNA", extract_entities("DNA'nın yapısı nedir?"))
32 self.assertIn("Watson-Crick", extract_entities("Watson-Crick modelini açıkla"))
33 self.assertIn("H2O", extract_entities("H2O molekülü polar mıdır?"))
34
35 def test_quoted_term(self):
36 self.assertIn("hücre zarı", extract_entities('"hücre zarı" nedir?'))
37
38 def test_no_entities_empty(self):
39 self.assertEqual(extract_entities(""), [])
40
41 def test_dedup_and_order(self):
42 ents = extract_entities("DNA ve DNA tekrar; ATP")
43 self.assertEqual(ents, ["DNA", "ATP"]) # tekrarsız, sıra korunur
44
45
46if __name__ == "__main__":
47 unittest.main()