Thursday, January 11, 2007 1:24 PM
DmitryR
Simple English Noun Pluralizer in C#
When working on Web Services support for Dynamic Languages I needed a simple pluralizer for English nouns, and I did put one together that I would like to share.
The algorithm is very simple:
1) There is a list of special nouns that is looked up first.
2) There is a list of suffix substitutions that is a applied next.
3) Everything else gets 's' appended.
Please download the attached ZIP file, compile the .cs file (it requires .NET Framework v2.0) and run it:
C:\temp>csc Pluralizer.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.
C:\temp>Pluralizer.exe
> class
classes
> type
types
> werewolf
werewolves
> leaf
leaves
> index
indices
>
Please give it a try and let me know for what words (or classes of words) it fails