Are there any Java API(s) which will provide plural form of English words (e.g. cacti
for cactus
)?
-
1For which natural languages, and which programming languages? – May 06 '11 at 05:51
-
3Also, the plural forms of cactus are cacti (single i) and cactuses according to the New Oxford American Dictionary. – May 06 '11 at 05:56
-
We are looking at words in the English language and our programming environment is based on Java – Joe May 06 '11 at 05:59
-
1I’m not sure whether there is a library for Java. In case there isn’t, a good starting point is the Lingua::EN::Inflect Perl module, available [here](http://search.cpan.org/~dconway/Lingua-EN-Inflect-1.893/lib/Lingua/EN/Inflect.pm). Hopefully someone’s ported Inflect to Java. – May 06 '11 at 06:06
7 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"

- 524
- 4
- 12

- 1,450
- 14
- 14
-
Fantastic, I was about to begun hacking together an algorithm based on that paper myself. Thanks @Slawek for pointing this out. – Sean Connolly Jan 19 '13 at 17:56
-
The amount of English words it supports seems limited based on the source on github – cosbor11 Feb 11 '16 at 09:25
-
1
jibx-tools provides a convenient pluralizer/depluralizer.
Groovy test:
NameConverter nameTools = new DefaultNameConverter();
assert nameTools.depluralize("apples") == "apple"
nameTools.pluralize("apple") == "apples"

- 26,852
- 13
- 75
- 99
-
do not recommend that, it does not even work for `mouse`, it converts the word to `mouses`, which is incorrect – idmitriev Sep 06 '18 at 06:39
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.

- 18,240
- 8
- 37
- 52
-
Maybe, if you are going to do something yourself, you can find some information here: http://english.stackexchange.com/ – Gabriel Ščerbák Jun 25 '11 at 16:16
considering java, have a look at modeshapes Inflector-Class as member of the package org.modeshape.common.text. Or google for "inflector" and "randall hauch".

- 433
- 1
- 5
- 18
-
I compare the library to jibx-tools. The library is better. In some words, for example `leaves`, jibx-tools is better. – diguage Mar 03 '18 at 01:26
If you can harness javascript, I created a lightweight (7.19 KB) javascript for this. Or you could port my script over to Java. Very easy to use:
pluralizer.run('goose') --> 'geese'
pluralizer.run('deer') --> 'deer'
pluralizer.run('can') --> 'cans'
https://github.com/rhroyston/pluralizer-js
BTW: It looks like cacti to cactus is a super special conversion (most ppl are going to say '1 cactus' anyway). Easy to add that if you want to. The source code is easy to read / update.

- 16,778
- 6
- 77
- 91
-
Thanks Ronnie. I need a pluralizer for C#, and your seems to be the most easily understandable of all I have seen otherwise, to convert. Decent work! – Stanislav Koncebovski Sep 26 '22 at 12:23
Its hard to find this kind of API. rather you need to find out some websservice which can serve your purpose. Check this. I am not sure if this can help you.. (I tried to put word cacti and got cactus somewhere in the response).

- 758
- 4
- 10
Wolfram|Alpha return a list of inflection forms for a given word.
See this as an example:
http://www.wolframalpha.com/input/?i=word+cactus+inflected+forms
And here is their API:

- 5,983
- 3
- 55
- 68

- 13,726
- 12
- 39
- 47
-
7This is not a API. is there Even a public API for wolframAlpha? I would have thought they would try and avoid that – Frames Catherine White Feb 12 '12 at 13:27