Skip to main content

Pluralization

Posted by tomwhite on July 26, 2006 at 1:14 PM PDT

Singulars and plurals are so different, bless my soul.
Has it ever occurred to you that the plural of "half" is "whole"?

Allan Sherman, One Hippopotami

It's well known that Perl has been heavily influenced by ideas from natural language, which probably explains why it has so many libraries for handling natural language text. Java is less well served, but as our programming tools become more powerful, it is inevitable that they will provide more linguistic support. It would be handy for example if your IDE told you in a not-too-obtrusive way that you had mispelled an identifier.

One linguistic feature that is already in today's tools is pluralization - forming plurals of words. The most famous example is Ruby on Rails, which automatically creates names in the plural for collections of a singular entity. The JAXB 2.0 Reference Implementation also uses pluralization in generating bindings of repeatable XML elements by pluralizing the corresponding Java property name.

Tool builders can now easily add pluralization to their applications using Inflector, a new Java library hosted on java.net. Using it can be as simple as calling:

import static org.jvnet.inflector.Noun.pluralOf;
...
pluralOf("hippopotamus");

The library is also useful for producing natural language messages. For instance, the following code will print the message I bought 10 loaves.

int n = 10;
System.out.printf("I bought %d %s.", n, pluralOf("loaf", n));

(See the documentation for more examples.)

In principle this would be easy to internationalize as Inflector does have multi-language support. However at present Inflector's implementations of pluralization algorithms for different languages are a little thin on the ground. English is practically complete (thanks to Damian Conway's excellent contribution to the subject). There is an implementation for Italian too, but it is incomplete.
So, if you have (grammatical) expertise in a language for which there is no pluralization algorithm, and you would like to get involved, then consider joining the project.

Related Topics >>

Comments

Is there a way to submit the occasional update when ...

Is there a way to submit the occasional update when found?

For example: equipment