RC RANDOM CHAOS

The a-or-an problem: sound beats spelling, and only 129 words break the rule

· via Hacker News

Original source

English: A vs. An

Hacker News →

Choosing between the English articles “a” and “an” looks trivial until you try to automate it. The naive approach — check whether the first letter is a vowel — fails on words like “unicorn” (a consonant /j/ sound behind a vowel letter) and “hour” (a vowel sound behind a consonant letter). The real rule keys off the spoken sound, not the written character, which is exactly the kind of edge case that trips up procedural text generation.

To build a reliable a_or_an() function, the author leaned on pronunciation data from cmudict rather than orthography, then measured how far the exceptions actually spread. The surprising result: across a 32,455-word list, only 129 words needed special handling, and those exceptions cluster in ways that can be compressed into a compact lookup (the author explores a trie-based simplification and d3.js visualizations).

The write-up doubles as a candid engineering note. The author flags this as throwaway, one-off code whose only requirement is correctness, not maintainability — and admits in hindsight that an LLM would have been a reasonable tool for the grunt work of parsing cmudict and relearning d3, freeing time for the more interesting trie optimization.

Read the full article

Continue reading at Hacker News →

This is an AI-generated summary. Read the original for the full story.