Turn any technical book PDF into a Claude Code skill — ready to study, reference, and use while you work.
Python agent-skillsai-agentsbook-to-skillcontext-engineeringdocument-processingedtechknowledge-baseknowledge-managementllmpdf-to-markdownragself-studystudy-tools
feat(extractor): detect Telugu (అధ్యాయము) chapter headings (#223)
Shubham Srivastava2057f07cecd5
diff --git a/book_to_skill/utils.py b/book_to_skill/utils.pyindex 6e53257..5d40424 100644--- a/book_to_skill/utils.py+++ b/book_to_skill/utils.py@@ -210,6 +210,18 @@ _TA_CHAPTER = re.compile(rf"^\s*(?:#{{1,6}}\s+)?அத்தியாயம்\s*([0-9{_TA_DIGITS}]+)\b")+# Telugu chapter headings: "అధ్యాయము 1", "అధ్యాయం ౧", "## అధ్యాయం 2".+# The chapter word has two common spellings — అధ్యాయము (formal) and అధ్యాయం+# (modern), sharing the stem అధ్యాయ — so both endings are matched. Telugu digits+# (U+0C66-U+0C6F) are positional like the other Indic blocks above, so only a+# digit remap is needed. Requiring the full word then a number keeps prose (or an+# inflected form like "అధ్యాయంలో", a different suffix) from matching.+_TE_DIGITS = "౦-౯"+_TE_DIGIT_MAP = str.maketrans("౦౧౨౩౪౫౬౭౮౯", "0123456789")+_TE_CHAPTER = re.compile(+ rf"^\s*(?:#{{1,6}}\s+)?అధ్యాయ(?:ము|ం)\s*([0-9{_TE_DIGITS}]+)\b"+)+# Russian (Cyrillic) chapter headings: "Глава 1", "ГЛАВА 12", "## Глава 2".# "Глава" ("chapter") + a number. Cyrillic uses ordinary Arabic digits, so —# unlike the Devanagari/Bengali blocks above — no digit remap is needed. A@@ -596,6 +608,9 @@ def _match_chapter_number(line: str) -> int | None:tam = _TA_CHAPTER.match(s)if tam:return int(tam.group(1).translate(_TA_DIGIT_MAP))+ tem = _TE_CHAPTER.match(s)+ if tem:+ return int(tem.group(1).translate(_TE_DIGIT_MAP))rum = _RU_CHAPTER.match(s)if rum:return int(rum.group(1))@@ -623,6 +638,7 @@ def _chapter_number(line: str) -> int | None:"## บทที่ ๑"), Hindi ("अध्याय 1", "अध्याय १", "## अध्याय 2"),Bengali ("অধ্যায় 1", "অধ্যায় ১", "## অধ্যায় 2"),Tamil ("அத்தியாயம் 1", "அத்தியாயம் ௧", "## அத்தியாயம் 2"),+ Telugu ("అధ్యాయము 1", "అధ్యాయం ౧", "## అధ్యాయం 2"),Russian ("Глава 1", "ГЛАВА 12", "## Глава 2"),Greek ("Κεφάλαιο 1", "ΚΕΦΑΛΑΙΟ 12", "## Κεφάλαιο 2"),Korean ("제1장 총칙", "## 제4장 근로시간과 휴식"), anddiff --git a/tests/test_book_to_skill.py b/tests/test_book_to_skill.pyindex 98faa75..e125296 100644--- a/tests/test_book_to_skill.py+++ b/tests/test_book_to_skill.py@@ -688,6 +688,26 @@ class TestDetectStructure:assert _chapter_number("இந்த அத்தியாயத்தில் நாம் பார்ப்போம்") is Noneassert _chapter_number("அத்தியாயம்") is None+ def test_detects_telugu_chapters(self):+ """Telugu headings: both spellings (అధ్యాయము/అధ్యాయం), Telugu or Arabic digits."""+ text = (+ "అధ్యాయము ౧ పరిచయం\nసారాంశం\n"+ "అధ్యాయం ౨ పద్ధతులు\nసారాంశం\n"+ "అధ్యాయం 3 ఫలితాలు\nసారాంశం"+ )+ assert detect_structure(text)["chapters_detected"] == 3++ def test_telugu_markdown_prefix(self):+ text = "## అధ్యాయం ౧ మొదటి\nసారాంశం\n## అధ్యాయం ౨ రెండవ\nసారాంశం"+ assert detect_structure(text)["chapters_detected"] == 2++ def test_telugu_prose_is_not_a_chapter_heading(self):+ """An inflected form (అధ్యాయంలో) or a bare word is not a heading."""+ from book_to_skill.utils import _chapter_number++ assert _chapter_number("ఈ అధ్యాయంలో మనం చర్చిస్తాము") is None+ assert _chapter_number("అధ్యాయం") is None+def test_detects_russian_chapters(self):"""Russian headings: `Глава N`, case-insensitive, with Arabic digits."""text = (