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

nonsensical

v0.5.0

Published

Generate somewhat grammatical sentences of nonsense

Downloads

177

Readme

Nonsensical

Generates English sentences that are somewhat grammatically correct, or at least grammatically structured.

Try it out on itch.io!

There are lots of lorem ipsum libraries, and "thematic dummy text" generators; there are Markov chain text generators. But they're all lacking in structure, usually entirely. There's RNNs, which are cool and model structure, but they're much less accessible currently. I haven't found any webpages where you can train one, for instance.

Nonsensical gives you structure, you know, something to hold on to, a banister, and a banner, a banner with weird text written on it, that you can wave in the air.

Better than Markov chain text generators: it can be

Nonsensical models the structure of a sentence, inspired by Google's Natural Language Syntax API.

This way it can do subject–verb agreement, for example "The birds chirp" vs "The bird chirps", and make articles and other determiners match up, for example "a/the bird" vs "some/those/the birds", and follow other rules of English.

Although with the random words it chooses acting as context, the apparent structure might end up different than intended.

Sample Output

A secret plot in the charming saddle block anesthesias slammed those lacrimal sacs.
An enlisted woman on the adductive pitch blackness navigated an animatism.
Some spatula-shaped floricultures on the trap destressed the bad park.
A fight in a Malaysian straightenned some rosy-colored flags.
The imbricated throat in an alarming fire brigade queried a Circassian.
Some affixal icicles in a wintertime erred some white yams.
The virtuous sweetener in the ambulatory vase glorifies a downmarket graveyard.
Those cherries in a flying iron boot pursue some Plautuses.
Some stingy snows in those scriptural contraptions construct a Lygodium palmatum.

In the app you can mess around with giving it seed/suggestion/topic words.

Install

npm i nonsensical --save

API

Note: UNSTABLE and not following semver until 1.0 is released

Nonsensical first needs to load WordNet data, so the API isn't immediately available, but once the data is loaded (asynchronously), the rest of the API is synchronous.

You need to copy the data JSON files and specify paths to load them from.

idk if something like this is a good idea or not:

"postinstall": "cp -r node_modules/wordnetjs/data/ data/"

some things to consider: cross-platform-ness of the copy command, location of the module that has the data (might be in a sub node_modules folder? depending on npm version?), when postinstall runs

maybe this package could provide a bin script to copy the wordnet data to a directory..

In Node it should really use the version of wordnet.js not forked and ported for browser usage. Currently the API works using webpack (and should work with browserify or other bundlers), run in the browser, but in Node there's no window.fetch. It's hacked it to work in npm-start.js

var Nonsensical = require("nonsensical");
var nonsensical = new Nonsensical();
var dataFilePaths = {
	noun: './data/noun.json',
	adverb: './data/adverb.json',
	adjective: './data/adjective.json',
	verb: './data/verb.json',
};
nonsensical.load(dataFilePaths, function () {
	// generate a sentence!
	console.log(nonsensical.generateSentence());
	// generate a sentence related to felines!
	console.log(nonsensical.generateSentence({
		wordSuggestions: {
			nouns: ["cat", "kitty", "mouse", "fur", "bird", "house"],
			verbs: ["purr", "pet", "hiss", "catch", "chase", "sleep"],
			adjectives: ["soft", "warm"]
		},
		useSuggestionRelatedWordChance: 1/2,
		maxSemanticStepsRemovedFromSuggestions: 3
	}));
});

nonsensical.load(dataFilePaths, callback)

Loads WordNet data from the given file paths.

You wait for the callback before calling generateSentence.

nonsensical.generateSentence(options)

All options are optional, including the options argument itself.

options.wordSuggestions

Default: a built in map of word lists

Suggestions for words to be incorporated into the output, sort of like "topics" when semantic removal steps are enabled. Should be an object with keys nouns, verbs, adjectives, adverbs, or a subset, with arrays of words as values.

options.useSuggestionRelatedWordChance

Default: 1

A chance between 0 and 1 of using a one of your suggested words, versus a word from the default word lists.

options.maxSemanticStepsRemovedFromSuggestions

Default: 0

If this is 1 or higher, Nonsensical will traverse WordNet synonym to synonym, taking up to this number of steps away from the original word.

It won't take a linearly random number of steps away from the original word though, currently.

To-Do

  • Different types of sentences! Different structures!

  • Make the API work reasonably for Node again

  • Make a standalone build for browsers so you don't have to use a bundler

  • Stuff mentioned in source code (TODO, FIXME)

  • Poems would be fun; get some rhymes up in here~~?

  • Constraints on sentences such as length