Download tests/test_segmentation.py from tadad/midf-sanskrit-ocr: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/tadad/midf-sanskrit-ocr/resolve/main/tests/test_segmentation.py
- Command line
-
hf download hf://tadad/midf-sanskrit-ocr/tests/test_segmentation.py
-
curl -L -o test_segmentation.py https://huggingface.co/tadad/midf-sanskrit-ocr/resolve/main/tests/test_segmentation.py
1.19 kB
| import unittest | |
| from dataclasses import dataclass, field | |
| from ocr import drop_short_lines | |
| class Line: | |
| baseline: list | |
| class Bounds: | |
| lines: list = field(default_factory=list) | |
| def row(x0, x1, y=100): | |
| return Line(baseline=[[x0, y], [x1, y]]) | |
| class DropShortLinesTests(unittest.TestCase): | |
| def test_drops_marginal_fragments(self): | |
| bounds = Bounds([row(100, 1100, y) for y in range(100, 1300, 100)] + [row(20, 60), row(1150, 1190)]) | |
| kept, dropped = drop_short_lines(bounds, 0.2) | |
| self.assertEqual(dropped, 2) | |
| self.assertEqual(len(kept.lines), 12) | |
| def test_keeps_short_final_line_above_threshold(self): | |
| bounds = Bounds([row(100, 1100, y) for y in range(100, 900, 100)] + [row(100, 400, 1000)]) | |
| kept, dropped = drop_short_lines(bounds, 0.2) | |
| self.assertEqual(dropped, 0) | |
| self.assertEqual(len(kept.lines), 9) | |
| def test_disabled_or_empty_is_unchanged(self): | |
| bounds = Bounds([row(0, 10), row(0, 1000)]) | |
| self.assertEqual(drop_short_lines(bounds, 0)[1], 0) | |
| self.assertEqual(drop_short_lines(Bounds([]), 0.2)[1], 0) | |
| if __name__ == "__main__": | |
| unittest.main() | |