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 French/German/Italian/Dutch chapter words (#49)
Shubham Srivastavaa4f13eea5d82
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9067182..7f37b3d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -18,6 +18,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0blocks are ignored.- Table-of-contents detection extended to Chinese, Japanese, French, German,Italian, and Dutch.+- Chapter detection now recognizes French, German, Italian, and Dutch chapter+ words (`Chapitre`, `Kapitel`, `Capitolo`, `Hoofdstuk`), matching the+ table-of-contents languages added previously.+- Heading-title detection now accepts titles starting with `Ü`/`Û`/`Ý`/`Þ`+ (e.g. German "Überblick"), which the previous `À–Ú` range excluded.### Security- **CI security scanning** — added CodeQL (Python, security-and-quality + weeklydiff --git a/scripts/extractor/utils.py b/scripts/extractor/utils.pyindex 3c08a6e..df31886 100644--- a/scripts/extractor/utils.py+++ b/scripts/extractor/utils.py@@ -51,20 +51,24 @@ def estimate_tokens(text: str) -> int:# Explicit chapter heading: "Chapter 5", "Capítulo 5: ...", "Chapter 1. Intro".-# Captures the number (bounded to 1..99 — drops years like "2025.") and whatever-# follows it on the line, so we can reject prose.+# Also French/German/Italian/Dutch chapter words (chapitre/kapitel/capitolo/+# hoofdstuk), matching the ToC languages added alongside. "ch.?" stays last so+# the longer words match in full. Captures the number (bounded to 1..99 — drops+# years like "2025.") and whatever follows it on the line, so we can reject prose._EXPLICIT_CHAPTER = re.compile(- r"^\s*(?:chapter|cap[ií]tulo|ch\.?)\s*(\d{1,2})\b(?P<rest>.*)$", re.IGNORECASE+ r"^\s*(?:chapter|chapitre|kapitel|cap[ií]tulo|capitolo|hoofdstuk|ch\.?)\s*(\d{1,2})\b(?P<rest>.*)$",+ re.IGNORECASE,)-# A heading's number is followed by end-of-line, punctuation (". : - —"), or a-# Capitalized title word. A lowercase continuation ("Chapter 6 explores...",-# "Chapter 8 are relevant...") is prose / a cross-reference, not a heading.-_HEADING_TAIL = re.compile(r"^\s*$|^\s*[.:\-—–]|^\s+[A-ZÀ-Ú0-9\"“(]")+# A heading's number is followed by end-of-line, punctuation (“. : - —“), or a+# Capitalized title word. A lowercase continuation (“Chapter 6 explores...”,+# “Chapter 8 are relevant...”) is prose / a cross-reference, not a heading.+# The uppercase class is À-Þ so titles starting with Ü/Û (common in German, e.g. “Überblick”) are recognized.+_HEADING_TAIL = re.compile(r"^\s*$|^\s*[.:\-—–]|^\s+[A-ZÀ-Þ0-9\"“(]")# Roman-numeral chapter heading: "I: Loomings", "II. The Carpet-Bag".# Requires a separator (":" or ".") and a Capitalized title after it, so a bare# "I" or "V." (a page divider / list marker) is not mistaken for a chapter.-_ROMAN_HEAD = re.compile(r"^\s*([IVXLCDM]+)\s*[:.]\s+[A-ZÀ-Ú\"“(]")+_ROMAN_HEAD = re.compile(r"^\s*([IVXLCDM]+)\s*[:.]\s+[A-ZÀ-Þ\"“(]")_ROMAN_VALUES = {"I": 1, "V": 5, "X": 10, "L": 50, "C": 100, "D": 500, "M": 1000}# Chinese chapter headings. Two common styles:diff --git a/tests/test_extractor.py b/tests/test_extractor.pyindex bf5dca0..ee0a379 100644--- a/tests/test_extractor.py+++ b/tests/test_extractor.py@@ -725,6 +725,38 @@ class TestDetectStructure:assert _cn_numeral_to_int("不是数字") is Noneassert _cn_numeral_to_int("9999") is None # out of 1..999 chapter range+ def test_french_chapitre(self):+ assert detect_structure("Chapitre 1\nx\nChapitre 2\nx")["chapters_detected"] == 2++ def test_german_kapitel(self):+ assert detect_structure("Kapitel 1\nx\nKapitel 2\nx")["chapters_detected"] == 2++ def test_italian_capitolo(self):+ assert detect_structure("Capitolo 1\nx\nCapitolo 2\nx")["chapters_detected"] == 2++ def test_dutch_hoofdstuk(self):+ assert detect_structure("Hoofdstuk 1\nx\nHoofdstuk 2\nx")["chapters_detected"] == 2++ def test_german_kapitel_with_title(self):+ text = "Kapitel 1: Einführung\nx\nKapitel 2: Methoden\nx"+ assert detect_structure(text)["chapters_detected"] == 2++ def test_european_lowercase_cross_reference_not_chapter(self):+ # A lowercase continuation is prose / a cross-reference, not a heading —+ # the existing _HEADING_TAIL guard must reject it for the new words too.+ text = "Kapitel 3 behandelt das Thema ausführlich.\nChapitre 6 explique le contexte ici.\n"+ assert detect_structure(text)["chapters_detected"] == 0++ def test_german_kapitel_umlaut_title(self):+ # "Überblick" starts with Ü (U+00DC) — the widened À-Þ range accepts it.+ text = "Kapitel 1 Anfang\nx\nKapitel 2 Überblick\nx"+ assert detect_structure(text)["chapters_detected"] == 2++ def test_roman_heading_umlaut_title(self):+ # _ROMAN_HEAD range widened too: a Roman heading with an Ü-title counts.+ text = "I: Überblick\nbody\nII: Anfang\nbody\n"+ assert detect_structure(text)["chapters_detected"] == 2+class TestTextExtraction:"""Tests for plain-text file extraction."""