Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

English Language Plural / Singular Transform Function

Tags:

c#

vb.net

Is there any function (VB.NET or C#) that can transform an English word into its singular or to its plural form?

I was thinking of having a database that contains all words in English as well as their plural form but I also think that it is stupid since that will be huge and besides there are rules in English on how to translate a word to its plural form, so why not create a function that does the transformation?

like image 419
dpp Avatar asked Oct 19 '11 05:10

dpp


2 Answers

You can use Humanizer micro library. It's capable of this and a lot more.

Disclaimer: I am the creator of the library.

like image 119
Mehdi Khalili Avatar answered Nov 04 '22 15:11

Mehdi Khalili


In the System.Data.Entity.Design dll there is a namespace called PluralizationServices.

System.Data.Entity.Design.PluralizationServices.PluralizationService.CreateService(CultureInfo.GetCultureInfo("en-us")) will give you an object that exposes the self explanatory Pluralize, Singularize, IsPlural and IsSingular methods.

EF uses it to pluralize and singularize table names.

like image 45
Iain Avatar answered Nov 04 '22 16:11

Iain