Programmatically determine whether an object is described by "a" or "an"?
P粉764785924
2023-08-25 09:15:32
<p>I have a database of nouns (e.g. "house", "exclamation point", "apple") that need to be output and described in an application. It's difficult to put together a natural-sounding sentence to describe an item without using "a" or "an" - "the house is big," "the exclamation mark is small," etc. </p>
<p>Is there any function, library or hack I can use in PHP to determine whether A or AN is more appropriate to describe any given noun? </p>
I need this for a C# project, so here is the Python code mentioned above. Make sure to include
using System.Text.RegularExpressions;
in your source file.What you want is to identify the appropriate indefinite article.
Lingua::EN::Inflect
is a Perl module that performs well. I've extracted the relevant code and pasted it below. It's just a bunch of cases and some regular expressions, so porting to PHP shouldn't be difficult. A friend ported it to Python If anyone is interested, click here .