npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

grandiloquent

v1.5.16

Published

A grammar manupulation library

Downloads

82

Readme

grandiloquent

License

gran·dil·o·quent : (adj.) Marked by fancy, extravagant, or pretentious speech, especially when trying to impress others. : (n.) A grammar parsing and manipulation library

Table of Contents

  1. Install
  2. Introduction
  3. Donate
  4. Pronouns
  5. Verbs
  6. Part of Speech Tagging
  7. Sentence Meta
  8. Transform Sentences
  9. Paragraphs
  10. License

Install

$ npm install --save grandiloquent

Introduction

Grandiloquent is a grammar manipulation library. You can use it to change the person or number of pronouns, and to transform verbs between tenses. This is particularly useful for creating grammar correction applications, preprocessing text for NLP or sentiment analysis applications, creating chatbots, etc.

Donate

Grandiloquent is a labor of love, and if you find it useful, please consider making a small donation. A cup of coffee or a beer is all it takes!

Donate

Examples

Here are a few examples:

const grandiloquent = require('grandiloquent');

Pronouns

let pronoun = grandiloquent.pronoun('they');

pronoun.setGender('female'); //pronoun default gender for singular

pronoun.toSingular();
console.log(pronoun.toString()); //she

//Methods are chainable
let chain = grandiloquent
  .pronoun('it')
  .setGender('female') //she
  .toPlural() //they
  .toFirstPerson() //we

console.log(pronoun.toString()); //we

Verbs

let verb = grandiloquent.verb('walks');

verb.toBase(); //verb is mutated
console.log(verb.toString()); //walk

verb.toPast();
console.log(verb.toString()); //walked

verb.toFuture();
console.log(verb.toString()); //will walk

console.log(verb.getTense('had been going')); //past perfect progressive

//Grandiloquent is fairly flexible with what you can pass in
let verb = grandiloquent
  .verb('to boldly go')
  .toPastPerfectProgressive();

console.log(verb.toString()); //had been going

//As of 1.2.4, you can keep the adverb after transformation
let verb = grandiloquent
  .verb('to boldly go')
  .keepAdverb()
  .toPastPerfectProgressive();

console.log(verb.toString()); //had been boldly going

//If you hate split infinitives, don't worry, order is preserved
let verb = grandiloquent
  .verb('to go boldly')
  .keepAdverb()
  .toPastPerfectProgressive();

console.log(verb.toString()); //had been going boldly

//You can pass an instance of grandiloquent.pronoun.model to verb methods
let pronoun = grandiloquent
  .pronoun('we')
  .setGender('or')
  .toSingular() //I
  .toThirdPerson() //he or she

let verb = grandiloquent
  .verb('circumnavigate')
  .toFuturePerfectProgressive(pronoun);
console.log(verb.toString()); //he or she will have been circumnavigating

Part of Speech Tagging

Grandiloquent includes an experimental pattern-based part of speech tagger. Using part of speech tokens described in the Brown Corpus and a rules-based approach inspired by the Brill Tagger, this tagger tests an approach that attempts to avoid a large lexicon file in favor of more pattern-based matching. Starting with a list of the top 2000 English words manually tagged, the tagger uses regular expressions to guess parts of speech for other words. Since some words can have more than one possible part of speech, patterns for groups of words are used to guess the most likely combination of tags.

var sentence = grandiloquent
  .sentence('My name is Jonas.');
console.log(sentence.tagged);

Outputs

[
    {
        "word": "My",
        "index": 0,
        "tags": {
            "all": [
                "PP$"
            ],
            "current": "PP$"
        },
        "meta": {
            "pos": "possessive personal pronoun (my, our)",
            "reason": "pattern",
            "pattern": {
                "0": "PP$",
                "1": "NN",
                "2": "VBZ"
            }
        }
    },
    {
        "word": "name",
        "index": 1,
        "tags": {
            "all": [
                "NN",
                "VB",
                "JJ"
            ],
            "current": "NN"
        },
        "meta": {
            "reason": "pattern",
            "pos": "singular or mass noun",
            "pattern": {
                "0": "PP$",
                "1": "NN",
                "2": "VBZ"
            }
        }
    },
    {
        "word": "is",
        "index": 2,
        "tags": {
            "all": [
                "VBZ"
            ],
            "current": "VBZ"
        },
        "meta": {
            "pos": "verb, 3rd. singular present",
            "reason": "pattern",
            "pattern": {
                "0": "PP$",
                "1": "NN",
                "2": "VBZ"
            }
        }
    },
    {
        "word": "Jonas",
        "index": 3,
        "tags": {
            "all": [
                "NP"
            ],
            "current": "NP"
        },
        "meta": {
            "pos": "proper noun or part of name phrase",
            "reason": null
        }
    },
    {
        "word": ".",
        "index": 4,
        "tags": {
            "all": [],
            "current": null
        },
        "meta": {
            "reason": null
        }
    }
]

Sentence Meta

let sentence = grandiloquent
  .sentence('Are you the legal guardian of John Connor?');

console.log(sentence.isQuestion()); //true

let sentence = grandiloquent
  .sentence('I was sleeping when you came home.');

console.log(sentence.hasSubordinateClause()); //true

let verb = grandiloquent
  .sentence('While you walked to the car, I called Uber to pick me up.')
  .getMainVerb();

console.log(verb.word); //called

let verb = grandiloquent
  .sentence('Fortunately most doctors agree that diet and exercise are good for your health.')
  .getSubjectPhrase()
  .toString();

console.log(verb.word); //most doctors

let verb = grandiloquent
  .sentence('I cannot understand why you called Uber to pick me up.')
  .getSubjectVerbPhrase()
  .toString();

console.log(verb.word); //I can not understand

Transform Sentences

let sentence = grandiloquent
  .sentence('I walked.')
  .append('to the store')
  .toString();

console.log(sentence); //I walked to the store.

let sentence = grandiloquent
  .sentence('I walked to the store.')
  .prepend('Yesterday')
  .toString();

console.log(sentence); //Yesterday I walked to the store.

let sentence = grandiloquent
  .sentence('I walked to the store.')
  .insert('slowly', 2)
  .toString();

console.log(sentence); //I walked slowly to the store.

let sentence = grandiloquent
  .sentence('I walked to the store.')
  .insert('slowly', {after: '$mainVerb'})
  .toString();

console.log(sentence); //I walked slowly to the store.

let sentence = grandiloquent
  .sentence('I walked to the store.')
  .prepend('Yesterday')
  .toString();

console.log(sentence); //Yesterday I walked to the store.

let sentence = grandiloquent
  .sentence('I walked to the store')
  .insert('slowly', {after: '$mainVerb'})
  .toString();

console.log(sentence); //I walked slowly to the store

let sentence = grandiloquent
  .sentence('After eating breakfast, Joe walked home.')
  .insert('Bill', {replace: '$subject'})
  .toString();

console.log(sentence); //After eating breakfast, Bill walked home.

let sentence = grandiloquent
  .sentence('After eating breakfast, Joe walked home.')
  .replace('$subject', 'Bill')
  .toString();

console.log(sentence); //After eating breakfast, Bill walked home.

let sentence = grandiloquent
  .sentence('After eating breakfast, the student walked home.')
  .transform('$subject', 'toPlural')
  .toString();

console.log(sentence); //After eating breakfast, the students walked home.

let sentence = grandiloquent
  .sentence('The student walks home.')
  .transform('$mainVerb', 'toPast')
  .toString();

console.log(sentence); //The student walked home.

let sentence = grandiloquent
  .sentence('After lunch the student will walk home.')
  .transform('$mainVerbPhrase', 'toPast')
  .toString();

console.log(sentence); //After lunch the student walked home.

let sentence = grandiloquent
  .sentence('After lunch the student will walk home while his teacher grades papers.')
  .transform('$allVerbPhrases', 'toPast')
  .toString();

console.log(sentence); //After lunch the student walked home while his teacher graded papers.

Paragraphs

Paragraph methods split strings into component sentences, with some methods to operate on those sentences in context.

let paragraph = grandiloquent
  .paragraph('I came. I saw. I conquered.');

console.log(paragraph.sentences[1].input); //I saw

A coreference is a link between a pronoun (e.g. she, he, her, him) and its noun.

let paragraph = grandiloquent
  .paragraph('Jane saw Bob play the guitar. She was very impressed.')
  .resolveCoreferences();

console.log(paragraph.sentences[1].tagged[0].coreference.word); //Jane

let paragraph = grandiloquent
  .paragraph('Jane saw Bob play the guitar. She was very impressed.')
  .resolveCoreferences()
  .replaceCoreferences();

console.log(paragraph.sentences[1].current); //Jane was very impressed

License

Grandiloquent.js is freely distributable under the terms of the MIT license.