|
C# Plural Singular
Home :: ASP.NET :: C# :: Plural to Singular
Do you need to convert words (nouns) from singular to plural and/or convert words from plural to singular? Here's a C# class to do it for you!
Ideal for database searches to ensure accurate recordsets are returned whether (or not) your visitors enter a plural or singular word to search on.
You can't just add an 's' on the end of a word to create a plural.
How does it work? There are rules by which plurals are constructed. With a bit of string parsing we can deduce the plural of a noun.
Of course there are some words that do not conform (irregular nouns) so we have a dictionary to cope with those. There are only 100 such words so this is far more lightweight than looking up in a 'real' dictionary. I did think of hooking into an Office .dic file but thought better of it!
Being a singleton class means it is cached (well a single instance is on the garbage collected heap) for fast access without further instantiations.
Use in conjuction with Stopwords to create a fantastic search algorithm.
It's not perfect, but it is pretty close! here's the source code (Word .doc)
| word | singular | plural |
| man | man | men | | a | a | a | | to | to | to | | boy | boy | boys | | Girls | girl | Girls | | Children | child | Children | | people | person | people | | babies | baby | babies | | church | church | churches | | buzzes | buzz | buzzes | | family | family | families | | boxes | box | boxes | | baby | baby | babies | | fox | fox | foxes | | bushes | bush | bushes | | mice | mouse | mice |
The above is a test. Note that two letter words aren't touched (and likewise, if a word is already a plural/singular it is not converted).
Next >> Google Weather
|