Fix incorrect singularization for words ending with -ves (arrives/drives/curves/behaves) and add tests#1704
Fix incorrect singularization for words ending with -ves (arrives/drives/curves/behaves) and add tests#1704jesi318 wants to merge 2 commits intoHumanizr:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 864f993ce9
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| _default.AddSingular("(hive)s$", "$1"); | ||
| _default.AddSingular("(tive)s$", "$1"); | ||
| _default.AddSingular("([lr]|hoo|lea|loa|thie)ves$", "$1f"); | ||
| _default.AddSingular("(lea|loa|cal|hal|sel|el|shel|wol|thie|dwar|hoo)ves$", "$1f"); |
There was a problem hiding this comment.
Preserve -rves nouns when singularizing
The new allow-list in the -ves -> -f singular rule is now narrower than the existing plural rule, which creates a regression for words ending in -rf/-lf that are not enumerated here. For example, "scarf".Pluralize() still becomes "scarves" via (?:([^f])fe|([lr])f)$, but "scarves".Singularize() now misses this rule and falls through to (.+)ves$ -> $1ve, returning "scarve". This breaks round-tripping for valid inflections and should be fixed by restoring generic coverage (or adding the missing stems) in the singular rules.
Useful? React with 👍 / 👎.
Here is a checklist you should tick through before submitting a pull request:
mainbranch (more info below)fixes #<the issue number>build.cmdorbuild.ps1and ensure there are no test failuresSummary
Fixes a bug where arrives.Singularize() → arrife (and similar: drives → drife, curves → curf, behaves → behafe etc) by adjusting the singularization rule set and ordering.
Adds unit tests that assert correct singular forms for common -ves cases and true -fe exceptions.
Why this change was made/ Root Cause
_default.AddSingular("([^f])ves$", "$1fe"); is a greedy rule which matched other strings mentioned in the issue above
What I changed
Reworked -ves singular rules in Vocabularies.Defaultso exceptions for nouns that map to -f/-fe (knife→knives, wife→wives, leaf→leaves, etc.) are handled before the general catch-all that converts -ves → -ve (verbs/adjectives like arrive/drive/curve/behave).
Replaced overly-generic pattern(s) that caused verbs to be mis-singularized with a combination of:
Explicit stem-based rules for known -f/-fe nouns, and
A general (.+)ves$ -> $1ve catch-all for remaining -ves cases.
Corrected the incorrect test yield return ["safe", "saves"]; to yield return ["safe", "safes"]; (which makes it grammattically correct according to me) and added a rule for it since it was an edge case . Please let me know if I'm wrong.
Added a focused unit test method Singularize_Ves_EdgeCases in InflectorTests.cs