inflekt
0.1.0indexedLibrary for inflecting English words by pluralizing and singularizing them, including custom rule support. Includes methods to check word plurality. Direct port of pluralize library.
Library for inflecting English words by pluralizing and singularizing them, including custom rule support. Includes methods to check word plurality. Direct port of pluralize library.
A Kotlin Multiplatform inflection library.
Inflection
/ĭn-flĕk′shən/An alteration of the form of a word by the addition of an affix or by changing the form of a base that indicates grammatical features such as number, person, mood, or tense.
implementation("com.github.dsrees:inflekt:0.1.0")
This library provides extensions for pluralizing and singularizing English words. It also supports adding custom rules.
The singularize method can be used in place of pluralize with a count of 1.
"tests".singularize() // "test"
"tests".singularize(inclusive = true) // "1 test"
"feet".singularize() // "foot"
"Alumni".singularize() // "Alumnus"
In addition to the default rules, you can add your own custom rules. Rules can be defined as matching strings or custom Regex.
Inflekt provides helper methods to check if a word is pluralized or not.
"test".isPlural // false
"test".isSingular // true
Additional examples can be found the in tests.
This library is almost a direct port plurals/pluralize in
both API surface and functionality. If you're familiar with pluralize, then this should feel
familiar. Thanks to all who have contributed to that projected!
// Simple Examples
"test".pluralize() // "tests"
"test".pluralize(0) // "tests"
"test".pluralize(1) // "test"
"test".pluralize(5) // "tests"
"test".pluralize(1, inclusive = true) // "1 test"
"test".pluralize(5, inclusive = true) // "5 tests"
"蘋果".pluralize(2, inclusive = true) // "2 蘋果"
"foot".pluralize() // "feet"
"Alumnus".pluralize() // "Alumni"
// Example of new plural rule
"regex".pluralize() // regexes
Inflekt.addPluralRule(Regex("gex$", RegexOption.IGNORE_CASE), "gexii")
"regex".pluralize() // "regexii"
// Example of new singular rule
"singles".singularize() // "single"
Inflekt.addSingularRule(Regex("singles$", RegexOption.IGNORE_CASE), "singular")
"singles".singularize() // "singular"
// Example of new irregular rule, e.g. "I" -> "we"
"irregular".pluralize() // "irregulars"
Inflekt.addIrregularRule("irregular", "regular")
"irregular".pluralize() // regular
// Example of uncountable rule (rules without singular/plural in context)
"paper".pluralize() // "papers"
Inflekt.addUncountableRule("paper")
"paper".pluralize() // "paper"
Surfaced from shared tags and platforms — no rankings paid for.