Skip to content

fix: singularize/pluralize regular -s nouns like gas/lens (fixes #123) - #127

Open
youdie006 wants to merge 1 commit into
dreamerslab:masterfrom
youdie006:fix/123-singularize-gases
Open

fix: singularize/pluralize regular -s nouns like gas/lens (fixes #123)#127
youdie006 wants to merge 1 commit into
dreamerslab:masterfrom
youdie006:fix/123-singularize-gases

Conversation

@youdie006

Copy link
Copy Markdown

Fixes #123.

Root cause

singularize() applies its rules first-match, front-to-back. For the small class of regular nouns whose singular already ends in -s and whose plural adds -es (gas/gases, lens/lenses), no -es rule matches, so the word falls through to the generic tail rule /s$/ -> '' and gets over-stripped:

inflection.singularize('gases');  // 'gase'  (expected 'gas')
inflection.singularize('lenses'); // 'lense' (expected 'lens')

The same generic rule also mangles the already-singular form (gas -> ga), so the singularize(pluralize(x)) === x round-trip is broken as well.

Fix

Adds start-anchored, bidirectional rules for the safe -s -> -ses class gas|lens|bias|atlas|iris, following the existing summonses/nucleuses convention already in the file (anchored plural convert rule + singular protect rule, symmetric in both directions). Anchoring ^...$ is required so the bare protect rule does not wrongly protect words that merely end in the stem (sagas/omegas/cameras), and so houses -> house / buses -> bus keep working.

This is the same category as the recently merged #125 (analyses -> analysis). If a narrower change is preferred, the class list trims cleanly to just gas|lens.

Verification

  • Red/green: with the fix reverted, the new gases/lenses assertions fail (gase/lense); with the fix, all tests pass.
  • New tests cover both directions, the round-trip, the must-not-regress cases (houses, buses), and the must-not-over-protect cases (sagas, omegas, cameras, analyses).
  • npx vitest run -> 15 passed; npx tsc --noEmit -> clean.

Note: this contribution was prepared with AI assistance and reviewed by me before submission.

singularize() applies its rules first-match, front-to-back. For the small
class of regular nouns whose singular already ends in -s and whose plural
adds -es (gas/gases, lens/lenses), no -es rule matches, so the word falls
through to the generic tail rule /s$/ -> '' and gets over-stripped
(gases -> gase, lenses -> lense). The same generic rule also mangles the
already-singular form (gas -> ga), breaking the singularize(pluralize(x))
=== x round-trip.

Add start-anchored, bidirectional rules for the safe -s -> -ses class
gas|lens|bias|atlas|iris, following the existing summonses/nucleuses
convention already in the file. Anchoring ^...$ keeps the bare protect
rule from wrongly protecting words that merely end in the stem
(sagas/omegas/cameras) and keeps houses -> house / buses -> bus working.

Fixes dreamerslab#123.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

singularize() returns non-words for some regular -se nouns (e.g. gasesgase)

1 participant