Skip to content

Commit

Permalink
Issue598 (#599)
Browse files Browse the repository at this point in the history
* Add rule for nouns ending in -nses

* Added tests for plural of expense and defense
  • Loading branch information
Hugo-ter-Doest authored Apr 1, 2021
1 parent ebd9b0d commit 36a646c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/natural/inflectors/noun_inflector.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ const NounInflector = function () {
// handkerchief - handkerchiefs / handkerchieves
this.singularForms.regularForms.push([/(.*)ves$/i, '$1f'])

// expenses - expense
// defenses - defense
this.singularForms.regularForms.push([/(.*)nses$/i, '$1nse'])

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
8 changes: 8 additions & 0 deletions spec/noun_inflector_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,5 +357,13 @@ describe('noun inflector', function () {
expect(myInflector.singularize('wharves')).toBe('wharf')
expect(myInflector.singularize('handkerchieves')).toBe('handkerchief')
})

it('should handle words ending in rf', function () {
const myInflector = new NounInflector()
expect(myInflector.singularize('expenses')).toBe('expense')
expect(myInflector.singularize('defenses')).toBe('defense')
expect(myInflector.pluralize('expense')).toBe('expenses')
expect(myInflector.pluralize('defense')).toBe('defenses')
})
})
})

0 comments on commit 36a646c

Please sign in to comment.