Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Library to determine indefinite article of a noun? [duplicate]

Tags:

c#

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.

like image 380
Andrew Bullock Avatar asked Apr 06 '10 13:04

Andrew Bullock


1 Answers

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...

  • "an 0800 number"
  • "an ∞ of oregano"
  • "a NASA flight"
  • "an NSA analyst"

In other words, it usually even will deal reasonably with many things that aren't normal words.

like image 123
Eamon Nerbonne Avatar answered Oct 06 '22 04:10

Eamon Nerbonne