Skip to content

Turn any technical book PDF into a Claude Code skill — ready to study, reference, and use while you work.

feat(extractor): detect Tamil (அத்தியாயம்) chapter headings (#212)

Shubham Srivastava0ad050ec2b4f
diff --git a/book_to_skill/utils.py b/book_to_skill/utils.py
index 0338292..6e53257 100644
--- a/book_to_skill/utils.py
+++ b/book_to_skill/utils.py
@@ -198,6 +198,18 @@ _BN_CHAPTER = re.compile(
rf"^\s*(?:#{{1,6}}\s+)?অধ্যায়\s*([0-9{_BN_DIGITS}]+)\b"
)
+# Tamil chapter headings: "அத்தியாயம் 1", "அத்தியாயம் ௧", "## அத்தியாயம் 2".
+# அத்தியாயம் ("chapter") + a number. Tamil digits (U+0BE6-U+0BEF) are positional
+# like the Devanagari/Bengali blocks above, so only a digit remap is needed.
+# Optional Markdown "#" prefix. Requiring a number keeps prose that merely uses
+# the word (or an inflected form like "அத்தியாயத்தில்", which is a different stem)
+# from matching.
+_TA_DIGITS = "௦-௯"
+_TA_DIGIT_MAP = str.maketrans("௦௧௨௩௪௫௬௭௮௯", "0123456789")
+_TA_CHAPTER = re.compile(
+ rf"^\s*(?:#{{1,6}}\s+)?அத்தியாயம்\s*([0-9{_TA_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
@@ -581,6 +593,9 @@ def _match_chapter_number(line: str) -> int | None:
bm = _BN_CHAPTER.match(s)
if bm:
return int(bm.group(1).translate(_BN_DIGIT_MAP))
+ tam = _TA_CHAPTER.match(s)
+ if tam:
+ return int(tam.group(1).translate(_TA_DIGIT_MAP))
rum = _RU_CHAPTER.match(s)
if rum:
return int(rum.group(1))
@@ -607,6 +622,7 @@ def _chapter_number(line: str) -> int | None:
Chinese ("第三章 …", "## 一 · …", "## 第一讲"), Thai ("บทที่ 3",
"## บทที่ ๑"), Hindi ("अध्याय 1", "अध्याय १", "## अध्याय 2"),
Bengali ("অধ্যায় 1", "অধ্যায় ১", "## অধ্যায় 2"),
+ Tamil ("அத்தியாயம் 1", "அத்தியாயம் ௧", "## அத்தியாயம் 2"),
Russian ("Глава 1", "ГЛАВА 12", "## Глава 2"),
Greek ("Κεφάλαιο 1", "ΚΕΦΑΛΑΙΟ 12", "## Κεφάλαιο 2"),
Korean ("제1장 총칙", "## 제4장 근로시간과 휴식"), and
diff --git a/tests/test_book_to_skill.py b/tests/test_book_to_skill.py
index 42a3a0b..98faa75 100644
--- a/tests/test_book_to_skill.py
+++ b/tests/test_book_to_skill.py
@@ -668,6 +668,26 @@ class TestDetectStructure:
assert _chapter_number("এই অধ্যায়ে আমরা আলোচনা করব") is None
assert _chapter_number("অধ্যায়") is None
+ def test_detects_tamil_chapters(self):
+ """Tamil headings: `அத்தியாயம் N`, with Tamil or Arabic digits."""
+ text = (
+ "அத்தியாயம் ௧ முன்னுரை\nஉள்ளடக்கம்\n"
+ "அத்தியாயம் ௨ முறைகள்\nஉள்ளடக்கம்\n"
+ "அத்தியாயம் 3 முடிவுகள்\nஉள்ளடக்கம்"
+ )
+ assert detect_structure(text)["chapters_detected"] == 3
+
+ def test_tamil_markdown_prefix(self):
+ text = "## அத்தியாயம் ௧ முதல்\nஉள்ளடக்கம்\n## அத்தியாயம் ௨ இரண்டாம்\nஉள்ளடக்கம்"
+ assert detect_structure(text)["chapters_detected"] == 2
+
+ def test_tamil_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 = (