Skip to content

Commit

Permalink
Added some cases to the noun inflector (issue #500) (#593)
Browse files Browse the repository at this point in the history
* Added some cases to the noun inflector (issue #500)

* Some spaces in comments

* Whitespace
  • Loading branch information
Hugo-ter-Doest authored Mar 25, 2021
1 parent c107151 commit 32dfd43
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 803 deletions.
50 changes: 50 additions & 0 deletions lib/natural/inflectors/noun_inflector.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,56 @@ const NounInflector = function () {
this.pluralForms.regularForms.push([/^(?!talis|.*hu)(.*)man$/i, '$1men'])
this.pluralForms.regularForms.push([/(.*)/i, '$1s'])

// Words ending in -ff or -ffe you just add s to make the plural.
// Sheriffs | Giraffes
// this.pluralForms.regularForms.push([/(.+ffe?)$/i, '$1s'])

// words ending in f that just add s:
// roof - roofs
// chief - chiefs
// oaf -oafs
// this.pluralForms.regularForms.push([/([^f]+f)$/i, '$1s'])

// Example of words using the -f / -fe to -ves rule
// leaf - leaves
// wolf - wolves
// calf - calves
// half - halves
// knife - knives
// loaf - loaves
// life - lives
// wife - wives
// shelf - shelves
// thief - thieves
// yourself - yourselves
this.addIrregular('leaf', 'leaves')
this.addIrregular('wolf', 'wolves')
this.addIrregular('calf', 'calves')
this.addIrregular('half', 'halves')
this.addIrregular('knife', 'knives')
this.addIrregular('loaf', 'loaves')
this.addIrregular('life', 'lives')
this.addIrregular('wife', 'wives')
this.addIrregular('shelf', 'shelves')
this.addIrregular('thief', 'thieves')
this.addIrregular('yourself', 'yourselves')

// Some words have multiple valid plural forms endings with -ves or -s:
// scarf - scarfs/scarves
// dwarf - dwarfs / dwarves
// wharf - wharfs / wharves
// handkerchief - handkerchiefs / handkerchieves
// this.pluralForms.regularForms.push([/(.*r)f/i, '$1ves'])

// Singular inflections

// Some words have multiple valid plural forms endings with -ves or -s:
// scarf - scarfs/scarves
// dwarf - dwarfs / dwarves
// wharf - wharfs / wharves
// handkerchief - handkerchiefs / handkerchieves
this.singularForms.regularForms.push([/(.*)ves$/i, '$1f'])

this.singularForms.regularForms.push([/([^v])ies$/i, '$1y'])
this.singularForms.regularForms.push([/ives$/i, 'ife'])
this.singularForms.regularForms.push([/(antenn|formul|nebul|vertebr|vit)ae$/i, '$1a'])
Expand Down
Loading

0 comments on commit 32dfd43

Please sign in to comment.