A library to process noun, verb and adjectives transformations/conjugation.

Related tags

Utilities grammer
Overview

Grammer

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

Platform Test Pub Package License: MIT Issue Forks Stars

This library is MIT licensed. So, it's free to use anytime, anywhere without any consent, because Open Source is love ❤️ .

Lets Get Started

1. Add dependency

Add this to your package's pubspec.yaml file:

dependencies:
  grammer: ^1.0.2

2. Import it

Now in your Dart code, you can use:

  import 'package:grammer/grammer.dart';

Usage

Adjective

var instance = Grammer('big');
instance.comparative(); // bigger
instance.superlative(); // biggest

Verb

 Grammer('rallied').conjugate('VBP'); // rally
 Grammer('fly').conjugate('VBD'); // flew
 Grammer('throw').conjugate('VBN'); // thrown
 Grammer('rally').conjugate('VBS'); // rallies
 Grammer('die').conjugate('VBG'); // dying

// or you can use the aliases
 Grammer('rallied').toPresent(); // rally
 Grammer('fly').toPast(); // flew
 Grammer('throw').toPastParticiple(); // thrown
 Grammer('rally').toPresentS(); // rallies
 Grammer('die').toGerund(); // dying

Noun

final grammerA = Grammer('bus');
final grammerB = Grammer('ellipses');
final grammerC = Grammer('money');

grammerA.isCountable(); // true
grammerB.isCountable(); // true
grammerC.isCountable(); // false

grammerA.isNotCountable(); // false
grammerB.isNotCountable(); // false
grammerC.isNotCountable(); // true

grammerA.isSingular(); // true
grammerB.isSingular(); // false
grammerC.isSingular(); // true

grammerA.isPlural(); // false
grammerB.isPlural(); // true
grammerC.isPlural(); // true

// note that uncountable words return true
// on both plural and singular checks

grammerA.toSingular(); // bus (no change)
grammerB.toSingular(); // ellipsis
grammerC.toSingular(); // money (no change)


grammerA.toPlural(); // [busses, buses]
grammerB.toPlural(); // ellipses (no change)
grammerC.toPlural(); // money (no change)

How does it work

Adjective

1. Checks against a dictionary of known irregularities (e.g. little/less/least)
2. Applies changes based on:
	* Number of syllables
	* word ending

Noun

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

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 like maskedlocation, 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 positives please submit an issue.

And of course, You can clone this repository, install grammer and test it (dart test) for yourself, and you'll see how it passes the 9900 tests successfully.

License

License: The MIT License (MIT) - Copyright (c) 2022 Kawaljeet Singh

Inspiration

(A migration of en-inflectors in Type-script.)

You might also like...

This library contains methods that make it easy to consume Mpesa Api.

This library contains methods that make it easy to consume Mpesa Api. It's multi-platform, and supports CLI, server, mobile, desktop, and the browser.

Dec 15, 2021

An alternative random library for Dart.

Randt Randt library for Dart... Description Use Randt to get a random integer from a list, generate random integer in a specific range and generate ra

Nov 21, 2021

A comprehensive, cross-platform path manipulation library for Dart.

A comprehensive, cross-platform path manipulation library for Dart. The path package provides common operations for manipulating paths: joining, split

Dec 29, 2022

Boilerplate-free form validation library

Valform Boilerplate-free form validation library. Preface Why? Why not Formz? Why Valform? Getting started Simple Usage Inspiration Why? There is no c

Nov 14, 2021

Boilerplate-free form validation library

Trigger Boilerplate-free form validation library. Preface Why? Why not Formz? Why Trigger? Getting started Simple Usage Inspiration Why? There is no c

Nov 14, 2021

A fast algorithm for finding polygon pole of inaccessibility implemented as a Dart library.

polylabel Dart port of https://github.com/mapbox/polylabel. A fast algorithm for finding polygon pole of inaccessibility implemented as a Dart library

Nov 13, 2021

Redux Compact is a library that aims to reduce the massive amount of boilerplate that follows maintaining a Flutter Redux application.

Redux Compact Redux Compact is a library that aims to reduce the massive amount of boilerplate that follows maintaining a Flutter Redux application. T

Apr 8, 2022

Dart library for unescaping HTML-encoded strings

html_unescape A Dart library for unescaping HTML-encoded strings. Supports: Named Character References ( ) 2099 of them Decimal Character Referen

Dec 20, 2022

The `TypedEventNotifier` library allows notifying listeners with an object.

The TypedEventNotifier library allows notifying listeners with an object. listeners can be subscribed to only a special type or group of objects.

Nov 13, 2021
Owner
Kawaljeet Singh
In love with Flutter, I'm passionate to learn new technologies and enjoys challenges.
Kawaljeet Singh
The diozz package helps you to deal with APIs easily and speed up the process of writing code.

Diozz The diozz package helps you to deal with APIs easily and speed up the process of writing code. Installation Diozz Use that command in the termin

Mohamed Abu.elezz 4 Nov 13, 2022
Utility to process H264 profile-level-id values

h264_profile_level_id Dart utility to process H264 profile-level-id values based on Google's libwebrtc C++ code. API import 'package:h264_profile_leve

Ibragim Abbasov 2 Apr 22, 2022
Application that simplifies the search process in several supermarkets, allowing the user to define the shopping list in a few minutes.

economiz Application that solves the price research process in different supermarkets, facilitating and simplifying this process for the user. Getting

Guilherme Henrique 1 Dec 29, 2021
The Dart Time Machine is a date and time library for Flutter, Web, and Server with support for timezones, calendars, cultures, formatting and parsing.

The Dart Time Machine is a date and time library for Flutter, Web, and Server with support for timezones, calendars, cultures, formatting and parsing.

null 2 Oct 8, 2021
Library for help you make userbot or bot telegram and support tdlib telegram database and only support nodejs dart and google-apps-script

To-Do telegram client dart ✅️ support multi token ( bot / userbot ) ✅️ support bot and userbot ✅️ support telegram-bot-api local server ✅️ support tel

Azka Full Snack Developer:) 73 Jan 7, 2023
Fluro is a Flutter routing library that adds flexible routing options like wildcards, named parameters and clear route definitions.

Fluro is a Flutter routing library that adds flexible routing options like wildcards, named parameters and clear route definitions.

Luke Pighetti 3.5k Jan 4, 2023
Scribble is a lightweight library for freehand drawing in Flutter supporting pressure, variable line width and more!

Scribble Scribble is a lightweight library for freehand drawing in Flutter supporting pressure, variable line width and more! A

Tim Created It. 73 Dec 16, 2022
A library for YAML manipulation with comment and whitespace preservation.

Yaml Editor A library for YAML manipulation while preserving comments. Usage A simple usage example: import 'package:yaml_edit/yaml_edit.dart'; void

Dart 17 Dec 26, 2022
Flutter library to add gestures and animations to each Shape you draw on your canvas in your CustomPainter

Flutter library to bring your CustomPainter ?? to Life ✨ ⚡️ touchable library gives you the ability to add various gestures and animations to each Sha

Natesh Bhat 190 Jan 7, 2023
A Dart library to parse Portable Executable (PE) format

pefile A Dart library to parse Portable Executable (PE) format Usage A simple usage example: var pe = pefile.parse('C:\\Windows\\System32\\notepad.exe

null 4 Sep 12, 2022