I have a .NET application where, given a noun, I want it to correctly prefix that word with “a” or “an”. How would I do that?
Before you think the answer is to simply check if the first letter is a vowel, consider phrases like:
- an honest mistake
- a used car
You probably can’t get much better than this – and it’ll certainly beat most rule-based systems.
Edit: I’ve implemented this in JS/C#. You can try it in your browser, or download the small, reusable javascript implementation it uses. The .NET implementation is package
AvsAnon nuget. The implementations are trivial, so it should be easy to port to any other language if necessary.Turns out the "rules" are quite a bit more complex than I thought:
…which just goes to underline that a rule based system would be tricky to build!