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_tr_normalize.py71 lines, 2.7 KiBHistoryRawDownload
1"""Faz 0.6 birim testleri — TR normalizasyon (edge case, gerçek PDF quirk'leri)."""
2import unittest
3
4from src.text import (tr_lower, tr_upper, strip_invisibles,
5 join_hyphenation, normalize, fold_for_match)
6
7
8class TrCaseTests(unittest.TestCase):
9 def test_lower_dotted_I(self):
10 self.assertEqual(tr_lower("KİTAP"), "kitap") # combining-dot tuzağı
11 self.assertEqual(tr_lower("İSTANBUL"), "istanbul")
12
13 def test_lower_dotless_I(self):
14 self.assertEqual(tr_lower("IŞIK"), "ışık")
15 self.assertEqual(tr_lower("ISI"), "ısı")
16
17 def test_upper(self):
18 self.assertEqual(tr_upper("iğne"), "İĞNE")
19 self.assertEqual(tr_upper("ışık"), "IŞIK")
20
21
22class InvisibleTests(unittest.TestCase):
23 def test_strip_bom_zero_width(self):
24 self.assertEqual(strip_invisibles("gen aktarımı"), "gen aktarımı")
25 self.assertEqual(strip_invisibles("a​b"), "ab")
26
27
28class HyphenationTests(unittest.TestCase):
29 def test_soft_hyphen_join(self):
30 # gerçek quirk: "mü\xadhendisliği"
31 self.assertEqual(join_hyphenation("mü\xadhendisliği"), "mühendisliği")
32
33 def test_soft_hyphen_with_newline(self):
34 self.assertEqual(join_hyphenation("çalış\xad\nmaları"), "çalışmaları")
35
36 def test_linebreak_hyphen_join(self):
37 self.assertEqual(join_hyphenation("düzen-\nleme"), "düzenleme")
38
39 def test_midline_hyphen_preserved(self):
40 # satır ORTASINDAKİ tire (bileşik) korunur
41 self.assertEqual(join_hyphenation("neden-sonuç ilişkisi"), "neden-sonuç ilişkisi")
42
43
44class NormalizeTests(unittest.TestCase):
45 def test_full_pipeline(self):
46 raw = "Genetik mü\xadhendisliği DNA'yı\n\n\n\ndeğiştirir."
47 out = normalize(raw)
48 self.assertIn("mühendisliği", out)
49 self.assertNotIn("", out)
50 self.assertNotIn("\xad", out)
51 self.assertNotIn(" ", out) # boşluk sıkışmış
52 self.assertNotIn("\n\n\n", out) # fazla yeni-satır sıkışmış
53
54 def test_preserves_scientific_symbols(self):
55 # alt-indis / özel simge KORUNMALI
56 for token in ("CO₂", "H₂O", "3ʹ", "5ʹ", "β-galaktozidaz"):
57 self.assertIn(token, normalize(f"metin {token} devam"))
58
59 def test_empty(self):
60 self.assertEqual(normalize(""), "")
61
62
63class FoldTests(unittest.TestCase):
64 def test_fold_lowercases_keeps_accents(self):
65 # aksan korunur (biyolojik terim), harf-durumu eşitlenir
66 self.assertEqual(fold_for_match("DNA Polimeraz"), "dna polimeraz")
67 self.assertEqual(fold_for_match("Çekirdek"), "çekirdek")
68
69
70if __name__ == "__main__":
71 unittest.main()