Code Monkey home page Code Monkey logo

evo-inflector's Introduction

SWUbanner

Build Status Coverage Status Maven Central

About

Evo Inflector implements English pluralization algorithm based on "Damian Conway's" paper "An Algorithmic Approach to English Pluralization".

There are more or less half a million downloads of Evo Inflector from Maven Central each month. It is used by many high profile projects like Spring and JetBrains and tons of smaller projects.

Usage

The usage is pretty simple:

English.plural("word") == "words"

Additionaly you can use provide a required count to select singular or plural form automatically:

English.plural("foot", 1)) == "foot"
English.plural("foot", 2)) == "feet"

Features

The algorithm tries to preserve the capitalization of the original word, for instance:

English.plural("NightWolf") == "NightWolves"

Limitations:

  • The algorithm cannot reliably detect uncountable words. It will pluralize them anyway.
  • There are words which have the same singular form and multiple plural forms, ex: die (plural dies) - The cubical part of a pedestal; a plinth. die (plural dice) - An isohedral polyhedron, usually a cube

Tests

As part of the unit tests the results of the algorithm are compared with data from Wiktionary.

There are (2021-07-10) 276574 single word english nouns in the English Wiktionary of which:

  • 69.26971% (191582) are countable nouns,
  • 27.56839% (76247) are uncountable nouns,
  • for 2.8863885% (7983) nouns plural is unknown,
  • for 0.27551398% (762) nouns plural is not attested.

Evo Inflector returns correct answer for:

  • 96.24286% (184384) of all countable nouns, see this report,
  • but only for 8.56296% (6529) of uncountable nouns.

In overall it returns correct answer for 69.02782% (190913) of all nouns.

Changes

1.3

  • fix ulum -> ula rule
  • return empty string for empty string input
  • improve preservation of letter capitalization
  • make tests up-to-date with change in Wiktionary

1.2.2

  • fix pluralization of todo

1.2

  • compile with Java 1.6 for better compatibility
  • -s -> -ses, for instance pancreas -> pancrases
  • -ulum -> -ula, for instance baculum -> bacula
  • some minor optimizations
  • better testing with Wiktionary dump

1.1

  • fix for -us ending words, like virus

1.0.1

  • add inflection with count

1.0 Initial revision

License

Evo Inflector is available under Apache License 2.0.

Download

You can download the library from here or use the following Maven dependency:

<dependency>
    <groupId>org.atteo</groupId>
    <artifactId>evo-inflector</artifactId>
    <version>1.3</version>
</dependency>

or the Gradle dependency:

compile group: 'org.atteo', name: 'evo-inflector', version: '1.2.2'

evo-inflector's People

Contributors

bowbahdoe avatar danielonodje avatar ejoebstl avatar odrotbohm avatar olamy avatar oziomajnr avatar sentinelt avatar speechkey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

evo-inflector's Issues

Care to craft a release?

The latest release is more than two years old and a couple of fixes have piled up but can't be used as there's no official release containing those.

Online tool?

It could be great to have this as an online tool!

Check if word is plural/singular

Capability to check if word is singular or plural

assertTrue(English.isSingular("word"));
assertFalse(English.isPlural("word"));

assertFalse(English.isSingular("words"));
assertTrue(English.isPlural("words"));

don't try to pluralize plural words

this library is almost what I need although I wish it could also return the singular versions of plural words. Shouldn't be too hard. I did find an issue though. When passed a word that is already plural, it tries to pluralize it instead of just returning the same string. This is a problem as I'm handling user input and will have no idea if the users have typed in singular or plural to start with.

Ideally I'd want a method that returns a plural if a singular has been input and a singular if a plural has been input.

btw, on the atteo.org page the xml block for maven needs editing, groupid should have an uppercase 'I'. it will cause maven to fail.

Is this repo dead?

I am thinking about using this to a project of mine. Should I consider it as a viable option?

Empty string is converted to "s"

Hi,
if I call English.plural("") I get "s". This maybe is related to this line:
categoryRule(CATEGORY_MAN_MANS, "", "s");

BR,
Kai

Singularization

Would be interesting to have the capability to transform plurals to singular:

System.out.println(English.singular("words")); // == "word"

System.out.println(English.singular("words", 1)); // == "word"
System.out.println(English.singular("words", 2)); // == "words"

License?

What license is evo-inflector?

Can we have a license file / declaration somewhere prominent?

Pluralisation helper

First off, thank you for this rather handy little library, it's made my code much prettier. I use evo-infector, and other similar libraries, with a ternary operator . A common use case might be:

String comments = (amount == 1) ? "comment" : English.plural("comment");

With evo-inflector, I created a helper overloaded method which neatens up my application code::

public plural(String word, int n) {
    return (n == 1) ? word : inflector.getPlural("comment");
}
...

String.format("%d %s commented.", amount, plural("person", amount));

Is this something that could be added to evo-inflector? I've added the method on my local copy so I will be happy to send a pull request if that makes it easier.

Some uppercase words are pluralized to lowercase.

Thank you for working on this challenging problem! I found some uppercase words that are pluralized to lowercase. Instead, I expect a singular like "Foot" would pluralize to "Feet" and not to "feet". Here is a table of some words that preserve case and others that do not.

Singular Plural Preserved
Axis Axes yes
Child Children yes
Foot feet no
Goose geese no
Leaf Leaves yes
Man men no
Mouse Mice yes
Tooth teeth no
Wife Wives yes

To demonstrate, I have attached a small tar-ball containing a command line program to invoke org.atteo.evo.inflector.English.plural("arg") for arbitrary arguments (words): evo-inflector-main.tar.gz

Input validation

If the input is plural already, it fails to recognize it and returns a wrong word. Example for "Client" it returns "Clients" but for "Clients" it returns "Clientses".

evo-inflector unnecessarily compiled against Java 7

Version 1.1 is compiled against Java 7, but after a quick look at the source code I don't think this is necessary.

I'm using 1.0.1 in a project that must be able to run on Java 6, so I'm not able to upgrade.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.