- Notifications
You must be signed in to change notification settings - Fork20
📦 English inflection library for noun (plural to singular and singular to plural), verb (gerund, present & past) and adjectives (comparative & superlative) transformations/conjugation.
License
FinNLP/en-inflectors
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
For noun (plural to singular and singular to plural), verb (gerund, present & past) and adjective (comparative, superlative) transformations.
Here's a quick demo:http://en-inflectors.surge.sh/
npm install en-inflectors --save- Import the library
// javascriptconstInflectors=require("en-inflectors").Inflectors;
// typescriptimport{Inflectors}from"en-inflectors";
- Instantiate the class
letinstance=newInflectors("book");
- Adjective Inflection
letinstance=newInflectors("big");instance.comparative();// biggerinstance.superlative();// biggest
- Verb Conjugation
newInflectors("rallied").conjugate("VBP");// rallynewInflectors("fly").conjugate("VBD");// flewnewInflectors("throw").conjugate("VBN");// thrownnewInflectors("rally").conjugate("VBS");// ralliesnewInflectors("die").conjugate("VBP");// dying// or you can use the aliasesnewInflectors("rallied").toPresent();// rallynewInflectors("fly").toPast();// flewnewInflectors("throw").toPastParticiple();// thrownnewInflectors("rally").toPresentS();// ralliesnewInflectors("die").toGerund();// dying
- Noun Inflection
constinstanceA=newInflectors("bus");constinstanceB=newInflectors("ellipses");constinstanceC=newInflectors("money");instanceA.isCountable();// trueinstanceB.isCountable();// trueinstanceC.isCountable();// falseinstanceA.isNotCountable();// falseinstanceB.isNotCountable();// falseinstanceC.isNotCountable();// trueinstanceA.isSingular();// trueinstanceB.isSingular();// falseinstanceC.isSingular();// trueinstanceA.isPlural();// falseinstanceB.isPlural();// trueinstanceC.isPlural();// true// note that uncountable words return true// on both plural and singular checksinstanceA.toSingular();// bus (no change)instanceB.toSingular();// ellipsisinstanceC.toSingular();// money (no change)instanceA.toPlural();// busesinstanceB.toPlural();// ellipses (no change)instanceC.toPlural();// money (no change)
Adjective inflection
- Checks against a dictionary of known irregularities (e.g. little/less/least)
- Applies inflection based on:
- Number of syllables
- word ending
Noun inflection
- Dictionary lookup (known irregularities e.g. octopus/octopi & uncountable words)
- Identifies whether the word is plural or singular based on:
- Dictionary
- Machine learned regular expressions
- Applies transformation based on ending and word pattern (vowels, consonants and word endings)
Verb conjugation
- Dictionary lookup (known irregularities + 4000 common verbs)
- If the passed verb is identified as infinitive, it then applies regular expression transformations that are based on word endings, vowels and consonant phonetics.
- Tries to trim character from the beginning of the verb, thus solving prefixes (e.g. undergoes, overthrown)
- Tries to stem the word and get the infinitive form, then apply regular expression transformations.
- Applies regular expressions.
First of all, unless you have a dictionary of all the words and verbs that exist in 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 from a lot of different languages (French, Greek and Latin for example), and each one of these languages has its own rules of pluralization and singularization, let alone verb conjugation.
Even with dictionaries you'll have the problem of complex and made up words likemaskedlocation, and you might have to add dictionaries for specialties (like medicine which does actually have its 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 anticipated. If you have any case inaccuracy or false positivesplease submit an issue.
And of course, You can clone this repository, installmocha and test it for yourself, and you'll see how it passes the9900 tests successfully.
License: The MIT License (MIT) - Copyright (c) 2017 Alex Corvi
About
📦 English inflection library for noun (plural to singular and singular to plural), verb (gerund, present & past) and adjectives (comparative & superlative) transformations/conjugation.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.