From 9aee8e9061f0eaa4a39848eaa00ac639266a6991 Mon Sep 17 00:00:00 2001 From: IgnacioLD <178957758+IgnacioLD@users.noreply.github.com> Date: Tue, 24 Nov 2026 02:44:41 +0100 Subject: [PATCH] =?UTF-8?q?fix(content):=20show=20the=20article=20"a"=20as?= =?UTF-8?q?=20/=C9=99/=20in=20the=20textbook=20IPA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The British reference is phonemized word by word, so espeak-ng read "a" alone as the letter name /eɪ/ and learners saw it in 295 drills, dialogue turns and stories. apply_to_banks now writes the article as /ə/; a capital "A" counts as the article only at the start of a sentence. The scoring IPA is unchanged. --- tools/content/textbook_ipa.py | 33 +++++++++++++++++++++++++++--- tools/content/textbook_ipa_test.py | 26 +++++++++++++++++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/tools/content/textbook_ipa.py b/tools/content/textbook_ipa.py index cc2b8ab..6c71954 100644 --- a/tools/content/textbook_ipa.py +++ b/tools/content/textbook_ipa.py @@ -84,6 +84,31 @@ def to_textbook(ipa): return out +def weak_article(text, display): + """Write the article "a" as /ə/, not the letter name /eɪ/. + + The reference is phonemized word by word, and espeak-ng reads "a" alone as + the letter. A capital "A" is the article only at the start of a sentence + ("A man..."), not inside one ("plan A"). The display is left as it is when + its chunks do not line up one to one with the words. + """ + if not display: + return display + import phonemize + + words = [(raw, phonemize.normalize_word(raw)) for raw in text.split()] + words = [(raw, word) for raw, word in words if word] + chunks = display.split() + if len(words) != len(chunks): + return display + out = [] + for i, ((raw, word), chunk) in enumerate(zip(words, chunks)): + starts_sentence = i == 0 or words[i - 1][0][-1] in ".!?:" + article = word == "a" and ("a" in raw or starts_sentence) + out.append("ə" if article and chunk.strip("ˈˌ") == "eɪ" else chunk) + return " ".join(out) + + def assert_textbook(ipa): """Raise when a rewritten string still carries an espeak-only symbol.""" leftover = TEXTBOOK_ONLY.intersection(ipa) @@ -243,10 +268,12 @@ def apply_to_banks(bank_dir, records): displays = [] for item in bank.get(list_key, []): if folder == "dialogues": - for i in range(len(item.get("turns", []))): - displays.append(by_key.get(f'{item["id"]}#t{i}')) + for i, turn in enumerate(item.get("turns", [])): + display = by_key.get(f'{item["id"]}#t{i}') + displays.append(weak_article(turn.get("text", ""), display)) else: - displays.append(by_key.get(item.get("id"))) + said = item.get("text") or " ".join(item.get("paragraphs", [])) + displays.append(weak_article(said, by_key.get(item.get("id")))) gaps += sum(1 for d in displays if not d) new_text, count, changed = _insert_display(text, displays) if count != len(displays): diff --git a/tools/content/textbook_ipa_test.py b/tools/content/textbook_ipa_test.py index d8bd8d1..37a6c09 100644 --- a/tools/content/textbook_ipa_test.py +++ b/tools/content/textbook_ipa_test.py @@ -57,6 +57,32 @@ def test_rewrite_is_idempotent(self): self.assertEqual(once, textbook_ipa.to_textbook(once), ipa) +class WeakArticleTest(unittest.TestCase): + def test_the_article_is_a_schwa_not_the_letter_name(self): + self.assertEqual( + "hˈæv ə ɡˈʊd flˈaɪt", + textbook_ipa.weak_article("Have a good flight!", "hˈæv ˈeɪ ɡˈʊd flˈaɪt"), + ) + + def test_a_capital_a_is_the_article_only_at_the_start_of_a_sentence(self): + self.assertEqual( + "ə mˈæn ˈɪz hˈɪə", + textbook_ipa.weak_article("A man is here.", "ˈeɪ mˈæn ˈɪz hˈɪə"), + ) + self.assertEqual( + "ɡˈəʊ. ə kˈæt", + textbook_ipa.weak_article("Go. A cat", "ɡˈəʊ. ˈeɪ kˈæt"), + ) + self.assertEqual( + "plˈæn ˈeɪ", + textbook_ipa.weak_article("plan A", "plˈæn ˈeɪ"), + ) + + def test_misaligned_display_is_left_alone(self): + self.assertEqual("ˈeɪ", textbook_ipa.weak_article("a b", "ˈeɪ")) + self.assertIsNone(textbook_ipa.weak_article("a", None)) + + class GoldenTest(unittest.TestCase): """The owner's hard cases, pinned so the notation cannot drift."""