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 Kannada (ಅಧ್ಯಾಯ) chapter headings (#232)
Shubham Srivastava487cda9a5064
diff --git a/book_to_skill/utils.py b/book_to_skill/utils.pyindex 313690c..758b10d 100644--- a/book_to_skill/utils.py+++ b/book_to_skill/utils.py@@ -223,6 +223,17 @@ _TE_CHAPTER = re.compile(rf"^\s*(?:#{{1,6}}\s+)?అధ్యాయ(?:ము|ం)\s*([0-9{_TE_DIGITS}]+)\b")+# Kannada chapter headings: "ಅಧ್ಯಾಯ 1", "ಅಧ್ಯಾಯ ೧", "## ಅಧ್ಯಾಯ 2".+# ಅಧ್ಯಾಯ ("chapter") + a number. Kannada digits (U+0CE6-U+0CEF) are positional+# like the other Indic blocks above, so only a digit remap is needed. Requiring+# the word then a number keeps prose that merely uses an inflected form+# ("ಅಧ್ಯಾಯದಲ್ಲಿ", a case suffix) from matching.+_KN_DIGITS = "೦-೯"+_KN_DIGIT_MAP = str.maketrans("೦೧೨೩೪೫೬೭೮೯", "0123456789")+_KN_CHAPTER = re.compile(+ rf"^\s*(?:#{{1,6}}\s+)?ಅಧ್ಯಾಯ\s*([0-9{_KN_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@@ -612,6 +623,9 @@ def _match_chapter_number(line: str) -> int | None:tem = _TE_CHAPTER.match(s)if tem:return int(tem.group(1).translate(_TE_DIGIT_MAP))+ knm = _KN_CHAPTER.match(s)+ if knm:+ return int(knm.group(1).translate(_KN_DIGIT_MAP))rum = _RU_CHAPTER.match(s)if rum:return int(rum.group(1))@@ -640,6 +654,7 @@ def _chapter_number(line: str) -> int | None:Bengali ("অধ্যায় 1", "অধ্যায় ১", "## অধ্যায় 2"),Tamil ("அத்தியாயம் 1", "அத்தியாயம் ௧", "## அத்தியாயம் 2"),Telugu ("అధ్యాయము 1", "అధ్యాయం ౧", "## అధ్యాయం 2"),+ Kannada ("ಅಧ್ಯಾಯ 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 e25ed42..610021c 100644--- a/tests/test_book_to_skill.py+++ b/tests/test_book_to_skill.py@@ -708,6 +708,26 @@ class TestDetectStructure:assert _chapter_number("ఈ అధ్యాయంలో మనం చర్చిస్తాము") is Noneassert _chapter_number("అధ్యాయం") is None+ def test_detects_kannada_chapters(self):+ """Kannada headings: `ಅಧ್ಯಾಯ N`, Kannada or Arabic digits."""+ text = (+ "ಅಧ್ಯಾಯ ೧ ಪರಿಚಯ\nಸಾರಾಂಶ\n"+ "ಅಧ್ಯಾಯ ೨ ವಿಧಾನಗಳು\nಸಾರಾಂಶ\n"+ "ಅಧ್ಯಾಯ 3 ಫಲಿತಾಂಶಗಳು\nಸಾರಾಂಶ"+ )+ assert detect_structure(text)["chapters_detected"] == 3++ def test_kannada_markdown_prefix(self):+ text = "## ಅಧ್ಯಾಯ ೧ ಮೊದಲನೆಯ\nಸಾರಾಂಶ\n## ಅಧ್ಯಾಯ ೨ ಎರಡನೆಯ\nಸಾರಾಂಶ"+ assert detect_structure(text)["chapters_detected"] == 2++ def test_kannada_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 = (