Java API for plural forms of English words
Asked Answered
E

7

34

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

Endosteum answered 6/5, 2011 at 5:49 Comment(4)
For which natural languages, and which programming languages?Aircrew
Also, the plural forms of cactus are cacti (single i) and cactuses according to the New Oxford American Dictionary.Aircrew
We are looking at words in the English language and our programming environment is based on JavaEndosteum
I’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. Hopefully someone’s ported Inflect to Java.Aircrew
R
0

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:

http://products.wolframalpha.com/api/

Racehorse answered 9/6, 2011 at 5:14 Comment(1)
This is not a API. is there Even a public API for wolframAlpha? I would have thought they would try and avoid thatMetathesize
B
56

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"
Bourne answered 10/1, 2012 at 7:30 Comment(3)
Fantastic, I was about to begun hacking together an algorithm based on that paper myself. Thanks @Slawek for pointing this out.Blockhouse
The amount of English words it supports seems limited based on the source on githubClepsydra
The library can not provide singular form of English word.Spermatophyte
F
6

jibx-tools provides a convenient pluralizer/depluralizer.

Groovy test:

NameConverter nameTools = new DefaultNameConverter();
assert nameTools.depluralize("apples") == "apple"
nameTools.pluralize("apple") == "apples"
Fayalite answered 27/12, 2013 at 21:12 Comment(1)
do not recommend that, it does not even work for mouse, it converts the word to mouses, which is incorrectChromatology
B
2

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.

Botanize answered 25/6, 2011 at 11:43 Comment(1)
Maybe, if you are going to do something yourself, you can find some information here: english.stackexchange.comProtease
D
2

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".

Diseur answered 10/1, 2012 at 14:43 Comment(1)
I compare the library to jibx-tools. The library is better. In some words, for example leaves, jibx-tools is better.Spermatophyte
G
1

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).

Gautama answered 6/5, 2011 at 5:50 Comment(0)
A
1

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.

Adamina answered 5/9, 2017 at 1:59 Comment(1)
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!Consuela
R
0

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:

http://products.wolframalpha.com/api/

Racehorse answered 9/6, 2011 at 5:14 Comment(1)
This is not a API. is there Even a public API for wolframAlpha? I would have thought they would try and avoid thatMetathesize

© 2022 - 2024 — McMap. All rights reserved.