Skip to content

Commit 593d899

Browse files
derek73claude
andcommitted
Document removing or replacing a shipped case mask
customize.rst showed how to add a capitalization_exceptions mask but not how to drop or replace one. A mask belongs to the word, not a reading, so remove(word, kind=...) leaves it in place; filtering the pair out of capitalization_exceptions drops it, and appending a pair replaces it, the later pair for a key winning. Doctests pin all three, using the Mac masks #1014 shipped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b22063a commit 593d899

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

‎docs/customize.rst‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,47 @@ though, so it recases every other name with that particle too:
288288
>>> str(parse("ludwig van beethoven").capitalized(van_lex))
289289
'Ludwig Van Beethoven'
290290

291+
Removing or replacing a shipped mask
292+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
293+
294+
The shipped masks come with the vocabulary. Among them are the Gaelic
295+
surnames opening Mac that most of their bearers write with the inner
296+
capital (``MacDonald``, ``MacGregor``). Since 3.0, case repair
297+
title-cases any other name opening Mac (``Machado``, ``Mackenzie``),
298+
while ``Mc`` keeps its capital (``McDonald``).
299+
300+
A mask belongs to the word, not to one of its readings, so removing the
301+
word's reading with ``remove()`` leaves the mask in place. To drop a
302+
mask, filter its pair out of ``capitalization_exceptions``:
303+
304+
.. doctest::
305+
306+
>>> str(parse("RONALD MACDONALD").capitalized())
307+
'Ronald MacDonald'
308+
>>> no_mac = dataclasses.replace(
309+
... default,
310+
... capitalization_exceptions=tuple(
311+
... pair for pair in default.capitalization_exceptions
312+
... if pair[0] != "macdonald"))
313+
>>> str(parse("RONALD MACDONALD").capitalized(no_mac))
314+
'Ronald Macdonald'
315+
>>> reading_gone = default.remove("macdonald", kind="family")
316+
>>> str(parse("RONALD MACDONALD").capitalized(reading_gone))
317+
'Ronald MacDonald'
318+
319+
To write a word some other way, append your own pair, as above. When
320+
two pairs share a key, the later one replaces the earlier, so you don't
321+
need to remove the shipped pair first:
322+
323+
.. doctest::
324+
325+
>>> phd_caps = dataclasses.replace(
326+
... default,
327+
... capitalization_exceptions=tuple(default.capitalization_exceptions)
328+
... + (("phd", "PHD"),))
329+
>>> str(parse("john smith phd").capitalized(phd_caps))
330+
'John Smith PHD'
331+
291332
How a key matches a word
292333
^^^^^^^^^^^^^^^^^^^^^^^^
293334

0 commit comments

Comments
 (0)