Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

📦 English inflection library for noun (plural to singular and singular to plural), verb (gerund, present & past) and adjectives (comparative & superlative) transformations/conjugation.

License

NotificationsYou must be signed in to change notification settings

FinNLP/en-inflectors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

npmnpmlicenseDavid

Demo

Here's a quick demo:http://en-inflectors.surge.sh/

Installation

npm install en-inflectors --save

Usage

  • 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)

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
  • 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)
  • Verb conjugation

    1. Dictionary lookup (known irregularities + 4000 common verbs)
    2. If the passed verb is identified as infinitive, it 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.

How accurate is it?

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

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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp