https://github.com/encryptorcode/pluralize
Pluralize and singularize any word.
https://github.com/encryptorcode/pluralize
nlp pluralize plurals
Last synced: 5 months ago
JSON representation
Pluralize and singularize any word.
- Host: GitHub
- URL: https://github.com/encryptorcode/pluralize
- Owner: encryptorcode
- License: mit
- Created: 2020-03-30T03:03:41.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-10-13T20:45:43.000Z (over 5 years ago)
- Last Synced: 2025-07-06T21:07:39.694Z (12 months ago)
- Topics: nlp, pluralize, plurals
- Language: Java
- Size: 22.5 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pluralize
[](https://mvnrepository.com/artifact/io.github.encryptorcode/pluralize)
[](https://travis-ci.org/encryptorcode/pluralize)
[](https://coveralls.io/github/encryptorcode/pluralize?branch=master)
[](https://github.com/encryptorcode/pluralize/blob/master/LICENSE)
> Pluralize and singularize any word.
## Installation
### Maven
```xml
io.github.encryptorcode
pluralize
${pluralize.version}
```
## Why?
This module uses a pre-defined list of rules, applied in order, to singularize or pluralize a given word. There are many cases where this is useful, such as any automation based on user input. For applications where the word(s) are known ahead of time, you can use a simple ternary (or function) which would be a much lighter alternative.
## Usage
* `word: string` The word to pluralize
* `count: number` How many of the word exist
* `inclusive: boolean` Whether to prefix with the number (e.g. 3 ducks)
Examples:
```java
import io.github.encryptorcode.pluralize.Pluralize;
import static io.github.encryptorcode.pluralize.Pluralize.*;
public class Example{
public static void main(String[] args){
pluralize("test"); //=> "tests"
pluralize("test", 0); //=> "tests"
pluralize("test", 1); //=> "test"
pluralize("test", 5); //=> "tests"
pluralize("test", 1, true); //=> "1 test"
pluralize("test", 5, true); //=> "5 tests"
pluralize("蘋果", 2, true); //=> "2 蘋果"
// Example of new plural rule:
Pluralize.plural("regex"); //=> "regexes"
Pluralize.addPluralRule(p("gex$"), "gexii");
Pluralize.plural("regex"); //=> "regexii"
// Example of new singular rule:
Pluralize.singular("singles"); //=> "single"
Pluralize.addSingularRule(p("singles"), "singular");
Pluralize.singular("singles"); //=> "singular"
// Example of new irregular rule, e.g. "I" -> "we":
Pluralize.plural("irregular"); //=> "irregulars"
Pluralize.addIrregularRule("irregular", "regular");
Pluralize.plural("irregular"); //=> "regular"
// Example of uncountable rule (rules without singular/plural in context):
Pluralize.plural("paper"); //=> "papers"
Pluralize.addUncountableRule("paper");
Pluralize.plural("paper"); //=> "paper"
// Example of asking whether a word looks singular or plural:
Pluralize.isPlural("test"); //=> false
Pluralize.isSingular("test"); //=> true
}
}
```
## Credits
The actual javascript version of this library is maintained at [blakeembrey/pluralize](https://github.com/blakeembrey/pluralize).
I've only helped to translate the code to Java. Also, I assure to have the least deviations from the actual code written and maintained by [@blakeembrey](https://github.com/blakeembrey)
## License
MIT