English Inflectors Library
For noun (plural to singular and singular to plural) and verb (gerund, present & past) transformations.
How accurate is it?
First of all, unless you have a dictionary of all the words and verbs there are in the English you can't really write a regular expression or an algorithm and expect to have a 100% success rate. English has been adopting words form a lot of different languages (French, Greek and Latin for example) and each one these languages has it's own rules of pluralization and singularization.
Even with dictionaries you'll have the problem of complex and made up words like geo-location
, and you might have to add dictionaries for specialties (like medicine which does actually have it's own dictionary).
However, I think what you'll find in this library is what can be achieved with the least amount of compromise.
I've used a set of rules (for detection/transformation) in combination with an exceptions list.
However, testing the library was more challenging than what I was anticipating. If you have any case inaccuracy or false positives please submit an issue.
And of course, You can clone this repository, install mocha
and test it for yourself, and you'll see how it passes the 9508 tests successfully.
Installation
npm install en-inflectors --save
Plural and singular detection
const inflectors = require("en-inflectors");
inflectors.isSingular("nuclei");
inflectors.isPlural("plateaux");
inflectors.isCountable("steam");
How it works:
- Search for the given word in the uncountable words.
- Search for the given word against a dictionary of known and common exceptions.
- Detect the given word against a set of RegExp rules.
Note: All uncountable words like sheep, deer, tuna and steam will return false
for both plural and singular detection.
Plural to singular transformation
const inflectors = require("en-inflectors");
inflectors.singularize("mice");
inflectors.singularize("geese");
inflectors.singularize("rivers");
Singular to plural transformation
const inflectors = require("en-inflectors");
inflectors.pluralize("location");
inflectors.pluralize("hoax");
inflectors.pluralize("wharf");
How it works:
- Search for the given word in the uncountable words.
- Search for the given word against a dictionary of known and common exceptions.
- Apply singularization/pluralization rules.
Verb conjugation
Verb conjugation can take a verb (in any tense) and convert it into the required tense.
const inflectors = require("en-inflectors");
inflectors.conjugate("playing","VBP");
inflectors.conjugate("playing","VBZ");
inflectors.conjugate("transcribes","VBD");
inflectors.conjugate("goes","VBN");
inflectors.conjugate("went","VBG");
where:
- VBP: is the present/infinitive form.
- VBZ: is the present with the third person "s".
- VBP: is the past form.
- VBD: is the past participle form.
- VBG: is the gerund form.
Or you can use the aliases:
const inflectors = require("en-inflectors");
inflectors.present("playing");
inflectors.presentS("playing");
inflectors.past("transcribes");
inflectors.pastParticiple("goes");
inflectors.gerund("went");
Note
For better, more accurate results, pass the verb in it's infinitive form (go
instead of goes
). although this library has been written to be agnostic about the form of the inputs, but the test results has proven that it's quite hard to achieve that with full accuracy.
Additional functionalities
const inflectors = require("en-inflectors");
inflectors.uncountableWords;
inflectors.verbsTable;
inflectors.infinitives;
License
License: The MIT License (MIT) - Copyright (c) 2017 Alex Corvi