Socket
Socket
Sign inDemoInstall

en-inflectors

Package Overview
Dependencies
1
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    en-inflectors

For noun (plural to singular and singular to plural) and verb (gerund, present & past) transformations.


Version published
Weekly downloads
4K
increased by9.63%
Maintainers
1
Install size
415 kB
Created
Weekly downloads
 

Readme

Source

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");
// > false
inflectors.isPlural("plateaux");
// > true
inflectors.isCountable("steam");
// > false

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");
// > mouse
inflectors.singularize("geese");
// > goose
inflectors.singularize("rivers");
// > river

Singular to plural transformation

const inflectors = require("en-inflectors");
inflectors.pluralize("location");
// > locations
inflectors.pluralize("hoax");
// > hoaxes
inflectors.pluralize("wharf");
// > wharves

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");
// > play
inflectors.conjugate("playing","VBZ");
// plays
inflectors.conjugate("transcribes","VBD");
// transcribed
inflectors.conjugate("goes","VBN");
// gone
inflectors.conjugate("went","VBG");
// going

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");
// > play
inflectors.presentS("playing");
// plays
inflectors.past("transcribes");
// transcribed
inflectors.pastParticiple("goes");
// gone
inflectors.gerund("went");
// going

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;
// list all the uncountable words as an array
inflectors.verbsTable;
// verb table with all the tenses can be used for writing your own functionalities
inflectors.infinitives;
// an array of the most common English verbs

License

License: The MIT License (MIT) - Copyright (c) 2017 Alex Corvi

FAQs

Last updated on 03 Feb 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc