Are there any libraries for .NET that deal with determining the Indefinite Article of a noun?
My crude attempt is below, which will probably work for 99% of my usage (which is acceptable) just wondering if there are any established alternatives?
public static string GetIndefinateArticle(string noun)
{
if(string.IsNullOrEmpty(noun))
return noun;
var first = noun[0];
if(first == 'a' ||
first == 'e' ||
first == 'i' ||
first == 'o')
return "an " + noun;
return "a " + noun;
}
Update: Eamon pointed out a duplicate question in the comments: How can I correctly prefix a word with "a" and "an"? I'll leave this Q here and open though, because I still don't really have an answer.
I implemented a library to do this: https://github.com/eamonnerbonne/a-vs-an; it's AvsAn on nuget. It's based on real usage patterns in wikipedia and hence even deals well with tricky things like...
In other words, it usually even will deal reasonably with many things that aren't normal words.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With