Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

en-inflectors

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

en-inflectors - npm Package Compare versions

Comparing version 1.0.6 to 1.0.7

4

dist/adjective/transform.js

@@ -10,3 +10,3 @@ "use strict";

continue;
else if (regexp_rules_1["default"][i].comp)
else
return regexp_rules_1["default"][i].comp(input);

@@ -21,5 +21,5 @@ }

continue;
else if (regexp_rules_1["default"][i].supr)
else
return regexp_rules_1["default"][i].supr(input);
}
};
import * as verbsList from "./verb/solve_lookup";
declare class Inflector {
import nonCountables from "./noun/list_uncountable";
declare class Inflectors {
word: string;

@@ -19,5 +20,4 @@ constructor(word: string);

isNotCountable: () => Boolean;
infinitives: verbsList.conjugationObject;
nonCountables: string[];
}
export { Inflector };
declare const infinitives: verbsList.conjugationObject;
export { Inflectors, infinitives, nonCountables };

@@ -9,4 +9,5 @@ "use strict";

var list_uncountable_1 = require("./noun/list_uncountable");
var Inflector = (function () {
function Inflector(word) {
exports.nonCountables = list_uncountable_1["default"];
var Inflectors = (function () {
function Inflectors(word) {
var _this = this;

@@ -27,8 +28,8 @@ this.comparative = function () { return adjective.comparative(_this.word); };

this.isNotCountable = function () { return countableDetection.isNotCountable(_this.word); };
this.infinitives = verbsList.VBP;
this.nonCountables = list_uncountable_1["default"];
this.word = word;
this.word = (word || "").toLowerCase();
}
return Inflector;
return Inflectors;
}());
exports.Inflector = Inflector;
exports.Inflectors = Inflectors;
var infinitives = verbsList.VBP;
exports.infinitives = infinitives;
{
"name": "en-inflectors",
"version": "1.0.6",
"version": "1.0.7",
"description": "",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

# 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

@@ -26,111 +12,121 @@

## Plural and singular detection
## Usage
* **Import the library**
```javascript
// javascript
const inflectors = require("en-inflectors");
inflectors.isSingular("nuclei");
// > false
inflectors.isPlural("plateaux");
// > true
inflectors.isCountable("steam");
// > false
const Inflectors = inflectors .Inflectors
```
```typescript
// typescript
import inflectors = require("en-inflectors");
const Inflectors = inflectors .Inflectors
```
**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.
* **Instantiate the class**
```javascript
let instance = new Inflectors("book");
```
> Note: All uncountable words like **sheep**, **deer**, **tuna** and **steam** will return `false` for both plural and singular detection.
* **Adjective Inflection**
```javascript
let instance = new Inflectors("big");
instance.comparative(); // bigger
instance.superlative(); // biggest
```
## Plural to singular transformation
* **Verb Conjugation**
```javascript
const inflectors = require("en-inflectors");
inflectors.singularize("mice");
// > mouse
inflectors.singularize("geese");
// > goose
inflectors.singularize("rivers");
// > river
```
new Inflectors("rallied").conjugate("VBP"); // rally
new Inflectors("fly").conjugate("VBD"); // flew
new Inflectors("throw").conjugate("VBN"); // thrown
new Inflectors("rally").conjugate("VBS"); // rallies
new Inflectors("die").conjugate("VBP"); // dying
## Singular to plural transformation
// or you can use the aliases
new Inflectors("rallied").toPresent(); // rally
new Inflectors("fly").toPast(); // flew
new Inflectors("throw").toPastParticiple(); // thrown
new Inflectors("rally").toPresentS(); // rallies
new Inflectors("die").toGerund(); // dying
```
* **Noun Inflection**
```javascript
const inflectors = require("en-inflectors");
inflectors.pluralize("location");
// > locations
inflectors.pluralize("hoax");
// > hoaxes
inflectors.pluralize("wharf");
// > wharves
```
const instanceA = new Inflectors("matrix");
const instanceB = new Inflectors("ellipses");
const instanceC = new Inflectors("money");
**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.
instanceA.isCountable(); // true
instanceB.isCountable(); // true
instanceC.isCountable(); // false
instanceA.isNotCountable(); // false
instanceB.isNotCountable(); // false
instanceC.isNotCountable(); // true
## Verb conjugation
instanceA.isSingular(); // true
instanceB.isSingular(); // false
instanceC.isSingular(); // true
Verb conjugation can take a verb (in any tense) and convert it into the required tense.
instanceA.isPlural(); // false
instanceB.isPlural(); // true
instanceC.isPlural(); // true
```javascript
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
```
// note that uncountable words return true
// on both plural and singular checks
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.
instanceA.toSingular(); // bus (no change)
instanceB.toSingular(); // ellipsis
instanceC.toSingular(); // money (no change)
Or you can use the aliases:
```javascript
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
instanceA.toPlural(); // buses
instanceB.toPlural(); // ellipses (no change)
instanceC.toPlural(); // money (no change)
```
> __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.
## How does it work
* **Adjective inflection**
1. Checks against a dictionary of known irregularities (e.g. little/less/least)
2. Applies inflection based on:
* Number of syllables
* word ending
## Additional functionalities
* **Noun inflection**
1. Dictionary lookup (known irregularities e.g. octopus/octopi & uncountable words)
2. Identifies whether the word is plural or singular based on:
* Dictionary
* Machine learned regular expressions
3. Applies transformation based on ending and word pattern (vowels, consonants and word endings)
```javascript
const inflectors = require("en-inflectors");
* **Verb conjugation**
1. Dictionary lookup (known irregularities + 4000 common verbs)
2. If the passed verb is identified as infinitive then applies regular expression transformations that are based on word endings, vowels and consonant phonetics.
3. Tries to trim character from the beginning of the verb, thus solving prefixes (e.g. undergoes, overthrown)
4. Tries to stem the word and get the infinitive form, then apply regular expression transformations.
5. Applies regular expressions.
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
```
## 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 let alone verb conjugation.
Even with dictionaries you'll have the problem of complex and made up words like `maskedlocation`, 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 **9900** tests successfully.
## License
License: The MIT License (MIT) - Copyright (c) 2017 Alex Corvi
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc