hn.today

English: A vs. An

redblobgames.com139 points177 comments
Screenshot of English: A vs. An

This explains how to pick the English indefinite article for procedural text generation: use a_or_an(word) to decide whether to output a or an. The key is that the choice depends on the spoken initial sound, not the written first letter. Common counterexamples illustrate this: unicorn starts with the letter u but a consonant Y sound (so a unicorn), while hour starts with h but an initial vowel sound (so an hour). A simple letter-based check produces mistakes, so the function must consult pronunciation information.

To see how often letter-vs-sound mismatches occur, the author parsed the CMU Pronouncing Dictionary, built tree-style visualizations (including checks of whether the first one or two letters suffice), and analyzed 32,455 words. Only 129 words required explicit exceptions, a surprisingly small fraction. The write-up documents how those exceptions group, shows visualizations of letter-prefix determinism, and discusses implementation notes like trie simplification. The author also admits not using LLMs for the code work and reflects that an LLM might have saved time on some parts such as the trie algorithm and parsing/d3 work.

Read on redblobgames.com177 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Other

End the H-1B Program

End the H-1B Program

The H-1B, H-4 EAD, and OPT programs have led to the transfer of over $109 billion annually from American wages to foreign workers, occupying over a million U.S. jobs and half a million housing units. Critics argue these programs suppress wages, limit career opportunities for Americans, and restrict housing availability for U.S. families. (end-h1b.com)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.