diff --git a/.claude/skills/tetrak-translit-georgian/SKILL.md b/.claude/skills/tetrak-translit-georgian/SKILL.md index 7ffd684..4dc06c6 100644 --- a/.claude/skills/tetrak-translit-georgian/SKILL.md +++ b/.claude/skills/tetrak-translit-georgian/SKILL.md @@ -128,11 +128,11 @@ Per scheme: - **ISO 9984** (`iso_9984`, the 2026 edition) is the national system made reversible: a middle dot separates the letter pairs the standard lists (`z·h` is `ზჰ`, not `ჟ`), and `read()` skips it. The list misses two - sequences, `dzh` (`ძჰ` or `დჟ`) and `tsh` (`ცჰ` or `თშ`); reading back - takes the first, and a test pins that. Its Table 4 example for every - letter is a test in `tests/test_transliterate.py`. Choose it for - round-tripping, but see the defect below: it is reversible except for - those two sequences. + sequences, `tsh` (`თშ` or `ცჰ`) and `dzh` (`დჟ` or `ძჰ`); reading back + takes the first of each, the one Georgian words have, and tests pin + that. Its Table 4 example for every letter is a test in + `tests/test_transliterate.py`. Choose it for round-tripping, but see + the defect below: borrowed names with `ცჰ` or `ძჰ` do not read back. ### The defect in ISO 9984:2026 @@ -140,19 +140,32 @@ The standard claims full reversibility, and **it is not reversible as published**. Its middle-dot list (4.2) leaves out `დ` before `ჟ` and `თ` before `შ`, so `dzh` and `tsh` each read back two ways: -| Latin | Reading 1 | Reading 2 | +| Latin | In Georgian words | In borrowed names only | |---|---|---| -| `dzh` | `ძ` + `ჰ` | `დ` + `ჟ` | -| `tsh` | `ც` + `ჰ` | `თ` + `შ` | +| `tsh` | `თ` + `შ` | `ც` + `ჰ` | +| `dzh` | `დ` + `ჟ` | `ძ` + `ჰ` | -Neither pair in reading 1 is listed, so `ძჰ` and `ცჰ` get no dot. Reading -2 is `d` + `zh` and `t` + `sh`, which are not listed either. +None of the four pairs is listed, so none gets a dot. + +**`tsh` is everywhere in real text.** The postposition `-ში` ("in") +attaches to any noun in `-თ`: `საათში` (in an hour), `წუთში` (in a +minute), `საფრანგეთში` (in France). Compounds have it too: `ხუთშაბათი` +(Thursday), `თვითშეფასება`. `ცჰ` appears only in borrowed names, mostly +German: `ალცჰაიმერი` (Alzheimer), `ერცჰერცოგი` (archduke, *Erzherzog*), +`ლანცჰუთი` (Landshut). `დჟ` and `ძჰ` are both rare and both foreign +(`ადჟარია`, `რედჟეპოვა`; `აძჰილი`). Counted in the titles of the Georgian +Wikipedia, November 2026: 82 distinct words with `თშ` against 19 with +`ცჰ`; seven with `დჟ` against one with `ძჰ`. This was found with an exhaustive check of every two- and three-letter Georgian sequence: render it, read it back, compare. Those are the only two collisions. **Adding the pairs `დჟ` and `თშ` to the list fixes both**, and with them the check comes back clean. Stephen reported this to BSI on -2026-10-12. +2026-10-12. The reply, in November 2026, agreed that the list should have +included `tsh` and `dzh`, said it will be corrected when the standard is +next revised, and called the sequences "purely theoretical". For `tsh` +that is wrong, as the words above show. The reply did not say which +letters the revision will dot. What the library does about it: @@ -160,17 +173,30 @@ What the library does about it: `ka/iso_9984.py` holds only the standard's pairs. Don't add `დჟ` and `თშ` on our own initiative: output would then differ from what a conforming implementation writes. -- **Reading back takes the first reading** (`ძჰ`, `ცჰ`), and - `test_sequences_the_standards_list_leaves_ambiguous` pins that, so a - change in behaviour can't slip through unnoticed. +- **Reading back takes the reading Georgian words have** (`თშ`, `დჟ`), + through the scheme's `readings` field (`{"tsh": "თშ", "dzh": "დჟ"}`), + which the engine tries before the shorter units. Until this was added + the engine took the digraph first (`ცჰ`, `ძჰ`) and every word with + `-თში` read back wrong. Rendering is not touched. +- **Borrowed names with `ცჰ` or `ძჰ` do not read back** + (`altshaimeri` → `ალთშაიმერი`), and + `test_borrowed_names_with_the_other_reading_do_not` declares that. A + middle dot typed by hand settles it (`alts·haimeri`), because `read()` + skips the dot wherever it stands. Don't try to guess from context: + `ხუთშაბათი` and `ალცჰაიმერი` both have `tsha`. - `reversible=True` stays, because that is what the standard claims. The - module docstring and `docs/schemes.md` name the two exceptions. + module docstring and `docs/schemes.md` name the exceptions. - **When an amendment or corrigendum is published**, add the pairs it - gives to `separate`, and bump the scheme `version`. Change the pinned - test to round-trip `დჟ` and `თშ`, then update this section, the - docstring and `docs/schemes.md`. Rendering `დჟ` and `თშ` changes (a dot + gives to `separate`, and bump the scheme `version`. If it dots the + common pairs (`თშ`, `დჟ`), swap `readings` to the other pair, since an + undotted `tsh` then means `ცჰ`; if it dots `ცჰ` and `ძჰ`, leave + `readings` as it is (the validator refuses a reading of a separated + pair, so the wrong choice fails at import). Then all four round-trip: + move the borrowed names into the round-trip test and update this + section, the docstring and `docs/schemes.md`. Rendering changes (a dot appears), so the commit is `feat(ka)!` with a `BREAKING CHANGE` - footer. `fold()` is not affected, because it never sees the dot. + footer. `fold()` is not affected, because it never sees the dot and + both readings of each sequence reach one key. - **ISO 9984:1996** (`iso_9984_1996`) is one letter per letter with háčeks: `j` is `ძ` and `ǰ` is `ჯ`; `c` is `წ` and `c'` is `ც`; `x` is `ხ`. Kept for data made under it. @@ -223,8 +249,8 @@ scheme it belongs to. - **The apostrophe direction**, above. Check which system a Latin form came from before deciding a table is wrong. -- **"Fixing" ISO 9984:2026's dot list**: `dzh` and `tsh` reading back as - `ძჰ` and `ცჰ` is the standard's defect, not ours. Leave `separate` alone +- **"Fixing" ISO 9984:2026's dot list**: `altshaimeri` reading back as + `ალთშაიმერი` is the standard's defect, not ours. Leave `separate` alone until an amendment is published (see the defect section above). - **ISO `x` and `j`**: `x` is `ხ` (not a *ks*), `j` is `ძ` (not `ჯ`). Both are mapped in `_LETTERS` so the fold is unaffected, but a reader will trip. diff --git a/docs/schemes.md b/docs/schemes.md index beb76e7..d58f016 100644 --- a/docs/schemes.md +++ b/docs/schemes.md @@ -209,12 +209,23 @@ ejective, so for most words it gives exactly the national spelling (U+00B7) between two letters that would otherwise read as a digraph: `z·h` is `ზ` and `ჰ`, not `ჟ`. The standard lists the pairs (`გ`, `ზ`, `ს` or `ქ` before `ჰ`; `თ` before `ს`; `დ` before `ზ`), and the dot is -skipped when reading back. Two sequences the list does not cover still -read two ways, `dzh` (`ძჰ` or `დჟ`) and `tsh` (`ცჰ` or `თშ`); reading -back takes the first of each. It also defines fourteen letters that +skipped when reading back. It also defines fourteen letters that standard Georgian does not use, the five archaic letters as ALA-LC has them among them. +Two sequences the list does not cover still read two ways: `tsh` is `თშ` +or `ცჰ`, and `dzh` is `დჟ` or `ძჰ`. We write them as the standard does, +with no dot, and read each back as the first of its pair, which is the +one Georgian words have. `თშ` is in every noun ending in `თ` that takes +the postposition `-ში` (`საათში`, in an hour; `საფრანგეთში`, in France) +and in compounds such as `ხუთშაბათი`, Thursday. `ცჰ` and `ძჰ` turn up +only in borrowed names, mostly German: `ალცჰაიმერი` (Alzheimer) is +written `altshaimeri` and reads back as `ალთშაიმერი`. Among the titles of +the Georgian Wikipedia in November 2026 we counted 82 words with `თშ` +against 19 with `ცჰ`, and seven with `დჟ` against one with `ძჰ`. To read +one of those names back, put a middle dot in by hand: `alts·haimeri` +reads as `ალცჰაიმერი`. The fold gives the same key for either reading. + ### ISO 9984:1996 The first edition, which the 2026 edition cancelled and replaced. It is diff --git a/src/tetrak_translit/engine.py b/src/tetrak_translit/engine.py index 8deb68c..4205823 100644 --- a/src/tetrak_translit/engine.py +++ b/src/tetrak_translit/engine.py @@ -190,6 +190,10 @@ def _inverse(scheme: Scheme) -> list[tuple[str, str]]: for mark, latin in scheme.punctuation.items(): if latin: pairs.setdefault(unicodedata.normalize("NFD", latin.lower()), mark) + # A sequence the standard leaves with two readings is longer than either + # of its parts, so it is tried before them. + for latin, units in scheme.readings.items(): + pairs[unicodedata.normalize("NFD", latin.lower())] = units inverse = sorted(pairs.items(), key=lambda item: -len(item[0])) _INVERSES[scheme.id] = (scheme, inverse) return inverse diff --git a/src/tetrak_translit/ka/iso_9984.py b/src/tetrak_translit/ka/iso_9984.py index 8738930..5cde1f3 100644 --- a/src/tetrak_translit/ka/iso_9984.py +++ b/src/tetrak_translit/ka/iso_9984.py @@ -14,8 +14,18 @@ ``ჰ``, which is not ``zh`` (``ჟ``). The standard lists the pairs: ``გ``, ``ზ``, ``ს`` or ``ქ`` before ``ჰ``, ``თ`` before ``ს`` and ``დ`` before ``ზ``. Two sequences the list does not cover still read two ways: -``dzh`` is ``ძ`` and ``ჰ`` or ``დ`` and ``ჟ``, and ``tsh`` is ``ც`` and -``ჰ`` or ``თ`` and ``შ``; reading back takes the first. +``tsh`` is ``თ`` and ``შ`` or ``ც`` and ``ჰ``, and ``dzh`` is ``დ`` and +``ჟ`` or ``ძ`` and ``ჰ``. The table is written as published, with no dot +in either, and reading back takes the first of each, which is the one +Georgian itself has: ``თშ`` is in every noun in ``-თ`` that takes the +postposition ``-ში`` (``საათში``, in an hour; ``საფრანგეთში``, in +France) and in compounds (``ხუთშაბათი``, Thursday). The other reading +turns up only in borrowed names, mostly German (``ალცჰაიმერი``, +Alzheimer; ``ერცჰერცოგი``, archduke), and those do not read back: the +titles of the Georgian Wikipedia in November 2026 had 82 words with +``თშ`` against 19 with ``ცჰ``, and seven with ``დჟ`` against one with +``ძჰ``. A middle dot typed by hand settles either one, since the dot is +skipped in reading: ``ts·h`` reads as ``ცჰ``. Table 5 gives the historical and phonetic letters that standard Georgian does not use. The first six are unchanged from the first edition. @@ -89,9 +99,14 @@ }, separator="·", separate=frozenset({("გ", "ჰ"), ("ზ", "ჰ"), ("ს", "ჰ"), ("ქ", "ჰ"), ("თ", "ს"), ("დ", "ზ")}), + # The two sequences the standard's list leaves ambiguous, read as the + # letters Georgian words have (see the module docstring). + readings={"tsh": "თშ", "dzh": "დჟ"}, notes=( "Reversible, and since 2026 built on the national system: the apostrophe marks " "the ejective, and a middle dot separates letters that would read as a digraph " - "(z·h is ზჰ, not ჟ). Choose it for round-tripping and data exchange." + "(z·h is ზჰ, not ჟ). Choose it for round-tripping and data exchange. Two " + "sequences the standard leaves ambiguous are read as Georgian words have them: " + "tsh as თშ and dzh as დჟ, so a borrowed name with ცჰ or ძჰ does not read back." ), ) diff --git a/src/tetrak_translit/script.py b/src/tetrak_translit/script.py index 90c71d3..8d03a83 100644 --- a/src/tetrak_translit/script.py +++ b/src/tetrak_translit/script.py @@ -31,6 +31,7 @@ import re from collections.abc import Mapping from dataclasses import dataclass, field +from itertools import pairwise @dataclass(frozen=True) @@ -178,6 +179,11 @@ class Scheme: ``z·h`` for ``ზ`` and ``ჰ`` so that it is not ``zh``, ``ჟ``. Skipped when reading back. separate: The pairs of units, in order, that take the separator. + readings: Latin sequences a reversible standard's own rules leave + with two readings, each to the letters reading back takes for + it, as ISO 9984:2026's ``tsh`` is read ``თშ`` and not ``ცჰ``. + Rendering is not affected. Each entry must be what the table + writes for those letters. rules: Conditional renderings, tried before the table (see :class:`Rule`). punctuation: Marks the standard renders where they stand, to their @@ -204,6 +210,7 @@ class Scheme: after_vowel: Mapping[str, str] = field(default_factory=dict) separator: str = "" separate: frozenset[tuple[str, str]] = frozenset() + readings: Mapping[str, str] = field(default_factory=dict) rules: tuple[Rule, ...] = () punctuation: Mapping[str, str] = field(default_factory=dict) sentence_final: Mapping[str, str] = field(default_factory=dict) @@ -240,6 +247,20 @@ def __post_init__(self) -> None: ) if stray: raise ValueError(f"{self.id} separate names unknown units {stray!r}") + if self.readings and not self.reversible: + raise ValueError(f"{self.id} names readings but is not reversible") + for latin, units in self.readings.items(): + stray = sorted(set(units) - set(self.letters)) + if stray: + raise ValueError(f"{self.id} reading {latin!r} names unknown units {stray!r}") + if any(pair in self.separate for pair in pairwise(units)): + raise ValueError(f"{self.id} reading {latin!r} is of letters the table separates") + written = "".join(self.letters[unit] for unit in units) + if written != latin: + raise ValueError( + f"{self.id} reading {latin!r} is not what the table writes for " + f"{units!r}, which is {written!r}" + ) stray = sorted({rule.unit for rule in self.rules} - set(self.letters) - set(self.digraphs)) if stray: raise ValueError(f"{self.id} rules name unknown units {stray!r}") diff --git a/tests/test_fold.py b/tests/test_fold.py index b74c40d..ceeb5ff 100644 --- a/tests/test_fold.py +++ b/tests/test_fold.py @@ -185,6 +185,13 @@ def test_a_reversible_scheme_hint_works_for_georgian(self) -> None: assert fold("Mc'xet'a", scheme="ka/iso_9984_1996") == fold("მცხეთა") assert fold("Mtskheta", scheme="ka/iso_9984") == fold("მცხეთა") + def test_either_reading_of_iso_9984s_ambiguous_sequences_folds_the_same(self) -> None: + """tsh is თშ or ცჰ and dzh is დჟ or ძჰ; the key does not depend on which.""" + assert fold("saatshi", scheme="ka/iso_9984") == fold("საათში") + assert fold("altshaimeri", scheme="ka/iso_9984") == fold("ალცჰაიმერი") + assert fold("adzharia", scheme="ka/iso_9984") == fold("ადჟარია") + assert fold("adzhili", scheme="ka/iso_9984") == fold("აძჰილი") + def test_separators_are_gone_before_the_digraphs_are_merged(self) -> None: """ISO 9984:2026's middle dot and ALA-LC 2022's soft sign.""" for latin, georgian in (("t·s", "თს"), ("d·z", "დზ"), ("z·h", "ზჰ")): diff --git a/tests/test_schemes.py b/tests/test_schemes.py index beb7660..d9058b8 100644 --- a/tests/test_schemes.py +++ b/tests/test_schemes.py @@ -123,6 +123,32 @@ def test_a_positional_rule_on_an_unknown_unit_is_refused(self) -> None: with pytest.raises(ValueError, match="unknown units"): Scheme(**self.table(initial={"q": "q"})) # type: ignore[arg-type] + def test_a_reading_of_an_ambiguous_sequence_is_accepted(self) -> None: + Scheme(**self.table(reversible=True, readings={"ab": "ab"})) # type: ignore[arg-type] + + def test_a_reading_on_a_lossy_table_is_refused(self) -> None: + with pytest.raises(ValueError, match="not reversible"): + Scheme(**self.table(readings={"ab": "ab"})) # type: ignore[arg-type] + + def test_a_reading_the_table_would_not_write_is_refused(self) -> None: + with pytest.raises(ValueError, match="not what the table writes"): + Scheme(**self.table(reversible=True, readings={"ba": "ab"})) # type: ignore[arg-type] + + def test_a_reading_of_unknown_letters_is_refused(self) -> None: + with pytest.raises(ValueError, match="unknown units"): + Scheme(**self.table(reversible=True, readings={"aq": "aq"})) # type: ignore[arg-type] + + def test_a_reading_of_letters_the_table_separates_is_refused(self) -> None: + with pytest.raises(ValueError, match="separates"): + Scheme( + **self.table( # type: ignore[arg-type] + reversible=True, + separator="·", + separate=frozenset({("a", "b")}), + readings={"ab": "ab"}, + ) + ) + class TestFinalRule: """A rule that holds only at the end of a word, as ALA-LC Syriac drops a diff --git a/tests/test_transliterate.py b/tests/test_transliterate.py index 14bacdc..b637056 100644 --- a/tests/test_transliterate.py +++ b/tests/test_transliterate.py @@ -176,11 +176,51 @@ def test_the_historical_letters_of_table_5(self) -> None: assert to_script("ēywẖōfȳʔĝʕⁿæʸʷ", "ka/iso_9984") == "ჱჲჳჴჵჶჷჸჹჺჼჽჾჿ" def test_sequences_the_standards_list_leaves_ambiguous(self) -> None: - """dzh and tsh read two ways; reading back takes the digraph first.""" - assert transliterate("დჟ", "ka/iso_9984") == transliterate("ძჰ", "ka/iso_9984") - assert transliterate("თშ", "ka/iso_9984") == transliterate("ცჰ", "ka/iso_9984") - assert to_script("dzh", "ka/iso_9984") == "ძჰ" - assert to_script("tsh", "ka/iso_9984") == "ცჰ" + """tsh and dzh read two ways; reading back takes the one Georgian has.""" + assert transliterate("თშ", "ka/iso_9984") == transliterate("ცჰ", "ka/iso_9984") == "tsh" + assert transliterate("დჟ", "ka/iso_9984") == transliterate("ძჰ", "ka/iso_9984") == "dzh" + assert to_script("tsh", "ka/iso_9984") == "თშ" + assert to_script("dzh", "ka/iso_9984") == "დჟ" + + @pytest.mark.parametrize( + ("text", "latin"), + [ + ("საათში", "saatshi"), + ("წუთში", "ts'utshi"), + ("საფრანგეთში", "saprangetshi"), + ("ხუთშაბათი", "khutshabati"), + ("თვითშეფასება", "tvitshepaseba"), + ("ადჟარია", "adzharia"), + ], + ) + def test_georgian_words_with_those_sequences_round_trip(self, text: str, latin: str) -> None: + assert transliterate(text, "ka/iso_9984") == latin + assert to_script(latin, "ka/iso_9984") == text + + @pytest.mark.parametrize( + ("text", "latin", "read"), + [ + ("ალცჰაიმერი", "altshaimeri", "ალთშაიმერი"), + ("ერცჰერცოგი", "ertshertsogi", "ერთშერცოგი"), + ("აძჰილი", "adzhili", "ადჟილი"), + ], + ) + def test_borrowed_names_with_the_other_reading_do_not( + self, text: str, latin: str, read: str + ) -> None: + """The standard's defect, declared: these stay wrong until it is amended.""" + assert transliterate(text, "ka/iso_9984") == latin + assert to_script(latin, "ka/iso_9984") == read + + def test_a_typed_middle_dot_settles_either_reading(self) -> None: + assert to_script("alts·haimeri", "ka/iso_9984") == "ალცჰაიმერი" + assert to_script("saat·shi", "ka/iso_9984") == "საათში" + assert to_script("adz·hili", "ka/iso_9984") == "აძჰილი" + + def test_the_ejectives_are_not_caught_by_those_readings(self) -> None: + assert to_script("ts'h", "ka/iso_9984") == "წჰ" + assert to_script("t'sh", "ka/iso_9984") == "ტშ" + assert to_script("TSH", "ka/iso_9984") == "თშ" # The ALA-LC 2022 Armenian table's own examples: its punctuation rules