english-inflector · Java 17+ · TypeScript

Pluralize English nouns. Deterministically.

A Java library in the spirit of evo-inflector, plus a native TypeScript port with the same pipeline, lexicon and compound table: predictable runtime behaviour, no dependencies, no network calls, no model downloads. A 147,338-entry auditable lexicon, three productive rules, and a diagnostic API that says why a form was chosen.

—
Loading the real TypeScript engine…
Java 17+Zero runtime depsMIT code · CC BY-SA 3.0 dataThread-safe · immutableRelease: 1.4.0

Install

The 1.4.0 artifacts are built from this release. Coordinates: io.github.slayyyyer.morphex:english-inflector-core:1.4.0.


  

Rules-only runtime mode: EnglishInflector.builder().withoutBundledLexicon().build() disables loading the packaged lexicon and uses three productive rules plus your overrides. The lexical resources still ship inside the JAR, so the CC BY-SA 3.0 data attribution and distribution terms still apply.

TypeScript / JavaScript: the native port lives in morphex-ts/ and shares this lexicon and compound table. Install it with npm install morphex. See TypeScript / JavaScript below.

New in 1.4.0: Java and npm now share the same version. No public API or behavior change; the 1.3.0 evidence below still applies.

New in 1.3.0: independent AGID unseen-lemma evidence, ASCII shape fast paths, and a flattened ordered rule dispatch that brings compacted lookup to 79.4 ns/op. The public API and rule precedence are unchanged. The 1.2.0 compound/casing work remains the foundation; the linear selector is still not shipped.

Quickstart

EnglishInflector inflector = EnglishInflector.standard();

inflector.pluralize("child");          // "children"
inflector.pluralize("CHILD");          // "CHILDREN"
inflector.pluralize("UFO");            // "UFOs"
inflector.pluralize("mother-in-law");  // "mothers-in-law"
inflector.pluralize("cat", 1);         // "cat" (source instance kept)
inflector.pluralize("cat", 3);         // "cats"

Inflection r = inflector.analyze("die");
r.plural();          // "dice"
r.alternatives();    // ["dies"]
r.ambiguous();       // true
r.source();          // LEXICON — "lex:die"

TypeScript / JavaScript

A native port in morphex-ts/: same precedence, same 147,338-entry lexicon, same bounded compound table, zero runtime dependencies. Node 18+ and browsers.

npm 1.4.0Node 18+Zero runtime depsTypes included

Install: npm install morphex@1.4.0

import { EnglishInflector } from 'morphex';

const inflector = EnglishInflector.standard();
inflector.pluralize('CHILD');           // 'CHILDREN'
inflector.pluralize('UFO');             // 'UFOs'
inflector.pluralize('mother-in-law');   // 'mothers-in-law'
inflector.pluralize('cat', 1);          // 'cat'

const result = inflector.analyze('die');
result.plural;        // 'dice'
result.alternatives;  // ['dies']
result.ambiguous;     // true
result.stage;         // 'LEXICON'
result.source;        // 'lex:die'

From a checkout: cd morphex-ts && npm install && npm run build. Full API and conformance notes are in morphex-ts/README.md.

Rules-only vs bundled lexicon. The rules-only entry point (morphex/rules, or withoutBundledLexicon()) ships no data at all and loses irregular forms by design. The default package ships a delta artifact containing only entries the three rules do not reproduce; morphex/full is opt-in for complete analyze() metadata. Sizes below are measured by the build scripts on this machine, not estimates.

ArtifactRawGzip
morphex/rules (no data)0 B0 B
Delta lexicon for pluralize() (124,883 entries)1,962,900 B562,893 B
Full lexicon for analyze() (147,338 entries)3,707,556 B785,131 B
Membership sidecar (340,726 hashes, base64)1,817,208 B1,333,152 B
This page's demo bundle (full lexicon, minified ESM)3,735,118 B794,141 B

The demo above loads the full 147,338-entry lexicon; the 1.3 MB membership sidecar is omitted in the browser, so uppercase-initialism inference for unknown acronyms is disabled here. Node builds can load the sidecar with createBundledFullLexicon().

How does it compare?

evo-inflector is a compact, well-loved library; this project grew out of wanting a few more edge cases covered. Two design choices explain the differences: lookup normalization is kept separate from output case restoration, and lexical exceptions are whole-word edits rather than suffix rules, so carp can’t affect scarp and louse can’t affect blouse. That trades a larger data file for fewer surprises. evo-inflector’s smaller, simpler approach may suit you better if you don’t need the extra coverage.

Inputevo-inflector 2.0morphex
GermanGermenGermans
blousebliceblouses
scarpscarpscarps
UFOUFOesUFOs
mother-in-lawmother-in-lawsmothers-in-law
CHILDCHILDrenCHILDREN

Full head-to-head with qualifications → · stock 2.0 output is reproduced in docs/upstream-probe.md

Measured, not claimed

JMH 1.37 on JDK 21, 2 forks, GC profiler.

100%P1 frozen-lexicon accuracy (0/36,241 errors) vs 96.474% stock
97.365%P2 family-holdout accuracy (955/36,241 errors) vs 96.474% stock
81 nsrepeated lookup vs 111 ns stock (1.36× faster)
1.3×slower on compacted regular words (79 vs 60 ns, flattened dispatch)

Packed lexicon retains ~18.2 MiB. External UD English EWT selected-output check: 98.76% overall (evo2 98.12%), 98.88% on the 2,148 full-vocabulary-seen lemmas, 96.69% on 363 compact-artifact hits, and 91.67% on only 36 genuinely unseen lemmas; alternative coverage 98.99%. A larger independent AGID 2016.01.19 stress test has 261 genuinely unseen lemmas: the lexicon and rules-only tie at 95.40% (249/261), evo2 95.02%. AGID is automatically generated and not a corpus; its 93.84% lexicon overall reflects 1,722 MASS/invariant identity returns against generated plurals, not a natural-text regression. Comparisons →

How it works

First match wins. Nothing is guessed.

  1. Caller overrideExact, case-sensitive whole-input match wins.
  2. Exact lexical entry147k-entry TSV, case-insensitive lookup with case-sensitive entries where needed.
  3. Supported compoundBounded table: exact entries, free tails, curated postposed heads. Unmatched input is left alone.
  4. Productive spelling rulesThree: +es after sibilants, consonant-y → ies, default +s, plus bounded backoffs.
  5. Documented fallbackUnsupported shapes are returned unchanged and identified by analyze.

Read the design report →

Reports