Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java API for plural forms of English words

Are there any Java API(s) which will provide plural form of English words (e.g. cacti for cactus)?

like image 917
Joe Avatar asked May 06 '11 05:05

Joe


People also ask

Can API be plural?

The plural of API is APIs.

How do you change singular to plural in java?

The code below converts from singular to plural, how can it be modified to convert from plural to singular ? Maybe try pluralWord. setPlural(false); instead of pluralWord.

Can the word java be plural?

The noun java can be countable or uncountable. In more general, commonly used, contexts, the plural form will also be java. However, in more specific contexts, the plural form can also be javas e.g. in reference to various types of javas or a collection of javas.


3 Answers

Check Evo Inflector which implements English pluralization algorithm based on Damian Conway paper "An Algorithmic Approach to English Pluralization". The library is tested against data from Wiktionary and reports 100% success rate for 1000 most used English words and 70% success rate for all the words listed in Wiktionary.

If you want even more accuracy you can take Wiktionary dump and parse it to create the database of singular to plural mappings. Take into account that due to the open nature of Wiktionary some data there might by incorrect.

Example Usage:

English.plural("Facility", 1)); // == "Facility"
English.plural("Facility", 2)); // == "Facilities"
like image 93
Sławek Avatar answered Oct 26 '22 11:10

Sławek


jibx-tools provides a convenient pluralizer/depluralizer.

Groovy test:

NameConverter nameTools = new DefaultNameConverter();
assert nameTools.depluralize("apples") == "apple"
nameTools.pluralize("apple") == "apples"
like image 23
Jonathan Schneider Avatar answered Oct 26 '22 11:10

Jonathan Schneider


I know there is simple pluralize() function in Ruby on Rails, maybe you could get that through JRuby. The problem really isn't easy, I saw pages of rules on how to pluralize and it wasn't even complete. Some rules are not algorithmic - they depend on stem origin etc. which isn't easily obtained. So you have to decide how perfect you want to be.

like image 2
Gabriel Ščerbák Avatar answered Oct 26 '22 11:10

Gabriel Ščerbák