Groovy Pluralize Module
A lightweight Groovy extension module that adds the functionality to get plural inflections for words. Suitable for most English applications.
For more robust needs, checkout IBM’s more comprehensive and feature rich International Components for Unicode library.
Installation
Include the jar is in your classpath, or add it as a dependency to your favorite build tool. Groovy does the rest.
Note
|
Requires groovy 2.0 or later. |
compile 'org.millarts:groovy-pluralize-en:0.2.1'
@Grapes(
@Grab(group='org.millarts', module='groovy-pluralize-en', version='0.2.1')
)
<dependency>
<groupId>org.millarts</groupId>
<artifactId>groovy-pluralize-en</artifactId>
<version>0.2.1</version>
</dependency>
Usage
// Plural Inflection
assert 'mustache'.plural() == 'mustaches'
assert 'wolf'.plural() == 'wolves'
// Plural Inflection with Cardinality
assert 'codex'.plural(1) == 'codex'
assert 'codex'.plural(2) == 'codices'
assert 'codex'.plural(8) == 'codices'
// Capitalization
assert 'Life'.plural() == 'Lives'
// Unfortunately, capitalization does not behave consistently for certain words. EG:
assert 'Tooth'.plural() == 'teeth'
Building
This project uses gradle for builds, and includes wrapper scripts so that it is not necessary to explicitly install gradle to build and test the project.
$ ./gradlew tasks (1)
$ ./gradlew jar (2)
$ ./gradlew test (3)
$ ./gradlew check (4)
-
Lists the available tasks for this project
-
Builds the jar
-
Runs tests
-
Runs tests and checks (eg: code quality checks)
Under the Hood
This module uses the evo-inflector project under the hood, which is based off of Damian Conway’s paper An Algorithmic Approach to English Pluralization. It tends to get things right. See the evo-inflector project for more information.
License
This project is licensed under the terms of the Apache License, Version 2.0.
© 2014 David W Millar