Back
English a vs an: the rule follows sound, not the first letter
SiTech AI Team3 წთ. საკითხავი

English a vs an: the rule follows sound, not the first letter

A short post from Red Blob Games dissects a trivial-looking problem in procedural text generation: choosing between a and an. The deciding factor is not the first letter but the first sound of the spoken word.

The programming blog Red Blob Games has published a short post about a problem that looks trivial until you try to automate it: deciding whether a word takes a or an in generated text.

The rule follows sound, not spelling

The obvious approach is to check whether the first letter is a vowel, but that produces an unicorn. The real rule applies to the spoken word: unicorn begins with a vowel letter but a consonant sound, written Y in cmudict and /j/ in the IPA, so it takes a. The opposite case is hour, which starts with a consonant letter but a vowel sound (cmudict AW, IPA /aʊ/) and therefore gets an.

Implementing the rule properly therefore needs a pronunciation dictionary rather than a string check, and that is where the project began.

A day with 32,455 words

The author downloaded cmudict and compared the first-sound rule with the naive first-letter rule. The first attempt produced a large pile of mismatches, so the list was pruned deliberately: proper names (3,133), single letters (26), secondary pronunciations (9,114, including the American and British readings of herb), punctuation such as possessives and contractions (8,574), initialisms (10) and two manual exclusions. A further 81,852 entries were set aside as well.

That left 32,455 words, of which, to the author's surprise, only 129 needed exceptions. They are easy to recognise once listed: words beginning with eu and ew such as eucalyptus and ewe, the heir family, most of the honor and honest group, hour, once and one, and a long tail of u words including unicorn, uniform, unique, union, university, urine, useful and usual, alongside uranium, utensil, uterus, utility, utopia and even yttrium.

Two d3 visualisations accompany the project page: one showing whether the first two letters of a word are enough to decide, the other showing how many letters have to be inspected. The answer to the first question is a clear no, and the chart fills with red branches where pronunciation flips between vowel and consonant.

Hand-written rules instead of a decision tree

The author hoped to reduce the exceptions to a minimal decision tree, suspecting the problem is related to DFA minimisation, but did not manage it and wrote the rules by hand instead: eu and ew count as consonant sounds, heir, homage, hones and hono as vowel sounds, with special cases for herb and its compounds.

The post also carries a candid note on how the code was written. No language model was involved, though in hindsight it should have been: one-off code written to answer a single question does not need to be clean or maintainable, only correct. An LLM, the author writes, could have parsed cmudict and built the d3.js charts, leaving more time for a better trie analysis algorithm.

SSiTech

SiTech — AI-powered web development

We build fast, modern websites and bring AI into real business workflows. Have a project or a question? We'd love to help.