fix(inflekt): correct -ves singularization (derives -> derife) and audit rules against a 104k-word dictionary - #99
Merged
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
singularize('derives')returnedderife(andolives -> olife,valves -> valf,solves -> solf,thieves -> thiefe), because inflekt delegated straight to theinflectionnpm package, whose Rails-derived rule is([^fo])ves$ -> $1fe. That output is what namedDerifein constructive-db's generated SDK/CLI.The fix is a rule change, not a word list:
-vesnormally just drops thes, and the f/fe stems are the exception, so the rule is inverted and the exception is enumerated:Pluralization is symmetric: only an
F_STEM_PLURALSword takes-ves; every other-f/-feword takes a plains(cafe -> cafes,roof -> roofs,belief -> beliefs), whichinflectionalso got wrong.inflekt's own rules now run before the upstream fallback (previously it only patched Latin suffixes and*base/ssafterwards), so upstream's wrong answers never surface. Compound identifiers transform only the final segment (user_derives -> user_derive,UserDerives -> UserDerive) and case is preserved.Dictionary audit. Rather than fixing one word,
singularize/pluralizewere swept over the full 104k-wordwamericandictionary using the dictionary itself as the oracle (output must be a real word; plural→singular→plural must round-trip). That surfaced whole broken classes beyond-ves:aches -> ach,pies -> py,shoes -> sho,analyses -> analyasis,police -> polouse(the[m|l]icecharacter class also matches|), and-is/-ussingulars (iris,analysis,bus,status) being stripped as if plural. Rule-level fixes cover the general cases; the residue that is genuinely lexical (cookies -> cookienotcooky,ties -> tie, invariants likejeans,gas,atlas) is a generated table:scripts/generate-exceptions.tsreads/usr/share/dict/words, uses the committed__fixtures__/word-frequency-usa.txtto break dictionary ambiguities (cookievscooky), and emits a pair only wheresingularizeByRules(word) !== dictionaryExpected. It imports fromsrc/rules.ts(suffix-only) rather than the public API — comparing against the exception-awaresingularizemade generation self-referential and idempotent-empty.src/exceptions.tsis the output: 747 pairs, byte-identical across consecutive runs.inflektwas not in the CI test matrix, so its tests never ran; added.Link to Devin session: https://app.devin.ai/sessions/60b2dc2dcb71403f9388d9785a9a78cf
Requested by: @pyramation