| 1 | |
| 2 | import unittest |
| 3 | |
| 4 | from src.ingest.distill import distill_units, _signature |
| 5 | |
| 6 | |
| 7 | class _U: |
| 8 | def __init__(self, text): self.text = text |
| 9 | |
| 10 | |
| 11 | class DistillTests(unittest.TestCase): |
| 12 | def test_exact_duplicate_dropped_first_kept(self): |
| 13 | a = _U("Mitokondri hücrenin enerji santralidir ve ATP üretir.") |
| 14 | b = _U("Mitokondri hücrenin enerji santralidir ve ATP üretir.") |
| 15 | c = _U("Ribozomlar protein sentezinin yapıldığı organellerdir.") |
| 16 | kept, rep = distill_units([a, b, c]) |
| 17 | self.assertEqual(kept, [a, c]) |
| 18 | self.assertEqual(rep.dropped_exact, 1) |
| 19 | self.assertEqual(rep.kept, 2) |
| 20 | |
| 21 | def test_boilerplate_repeated_collapses_to_one(self): |
| 22 | boiler = "Bu etkinliği yaparken laboratuvar güvenlik kurallarına mutlaka uyunuz." |
| 23 | units = [_U(boiler), _U("Özgün içerik biri."), _U(boiler), _U(boiler), |
| 24 | _U("Özgün içerik iki.")] |
| 25 | kept, rep = distill_units(units) |
| 26 | texts = [u.text for u in kept] |
| 27 | self.assertEqual(texts.count(boiler), 1) |
| 28 | self.assertEqual(rep.dropped_exact, 2) |
| 29 | |
| 30 | def test_near_duplicate_dropped(self): |
| 31 | a = _U("Hücre zarı seçici geçirgen bir yapıdır ve madde giriş çıkışını düzenler burada.") |
| 32 | b = _U("Hücre zarı seçici geçirgen bir yapıdır ve madde giriş çıkışını düzenler orada.") |
| 33 | kept, rep = distill_units([a, b], near_threshold=0.9) |
| 34 | self.assertEqual(kept, [a]) |
| 35 | self.assertEqual(rep.dropped_near, 1) |
| 36 | |
| 37 | def test_unique_kept(self): |
| 38 | units = [_U("Konu A hakkında uzun ve özgün bir açıklama metni burada yer alır."), |
| 39 | _U("Tamamen farklı konu B için bambaşka özgün bir paragraf yazılmıştır.")] |
| 40 | kept, rep = distill_units(units) |
| 41 | self.assertEqual(len(kept), 2) |
| 42 | self.assertEqual(rep.dropped_exact + rep.dropped_near, 0) |
| 43 | |
| 44 | def test_short_text_never_dropped(self): |
| 45 | units = [_U("H2O"), _U("H2O"), _U("ATP")] |
| 46 | kept, _ = distill_units(units) |
| 47 | self.assertEqual(len(kept), 3) |
| 48 | |
| 49 | def test_order_preserved(self): |
| 50 | u = [_U(f"Özgün paragraf numara {i} burada uzunca yer almaktadır.") for i in range(5)] |
| 51 | kept, _ = distill_units(u) |
| 52 | self.assertEqual(kept, u) |
| 53 | |
| 54 | def test_signature_prefix(self): |
| 55 | self.assertEqual(_signature("bir iki üç dört beş altı yedi sekiz dokuz on"), |
| 56 | ("bir", "iki", "üç", "dört", "beş", "altı", "yedi", "sekiz")) |
| 57 | |
| 58 | |
| 59 | if __name__ == "__main__": |
| 60 | unittest.main() |