Computer Poetry • 'My tea sounds like a brick'

Inspired by the great people at Botnik, I decided to create my own poems with code, as a synergy between man and machine. My algorithm (see below) tries to generate grammatically correct sentences that rhyme with eachother. I then combined these sentence-pairings with others to create poems out of them.

The result is a poem-book, filled with metaphors about the allegorically figurative parables of analogies 🤣


The Long Girl with the Sad Squash Rackets

Many answers neatly echo some girls… And the long girl in those helpful teams of quicksands sadly guarantees whorls

A troubled flesh bleakly afforded a picture, But some squash racquets severely frowned a prefecture

An early crayon of the dead bucket in a shiny plant Fervently committed bad vans!


The Linen From Polouse

Fresh men in drugs limply characterised a couple linens…
While the man partially couples the linens (note: that's lazy rhyming!)

A loud patch of a breakable crib longingly trembled a hair…
If a loud wear on the patches partially hares a hare!

A day in a trick sweetly invents the agreeable polouse!!


Of Whispering Stoves

The lucky woods in a rifle solidly presumed a pail,
But pales knottily unveiled a lucky veil.

A mailbox in a few whispering stoves in some alive thrones knavishly protests the apple -
For those in as obediently grappled a chapel.

An ill stove in the noisy maid frantically shone a twig,
For a few fake twigs in sweaters angrily qualify a murmuring zig.

The wild hydrant in those robust boys interestingly armed the defeated language
And some storages bravely voyaged a sacrilege.

As the pocket wonderfully elects the tent.
For an unspent a in the pocket urgently pockets the ten stent.


Jerking the usual honey

Rats questioningly flooded those shops.
While both splendid territorial dominions in the average twig willfully enlarged a couple tops sops.

The winter abnormally concentrated a clean honey
But the fluid clean and jerks usually honey a difficult zucchini

A drum of a pencil of light kittens nicely rounded kites,
So those flavors swiftly anticipated a couple light sights


The Violent Lettuce with delicious elbows

A lettuce violently connected a kite.
If incomes tomorrow supplemented the tonight there's a deep meaning in here somewhere

A witty tent in delicious elbows urgently faded screeching rain,
So the strain on witty rain upliftingly trained a faded strain

A couple gleaming maids frantically cast the basketball,
And the carpenters sometimes snowballed a spitball

The helpless toad enormously shook the adorable popcorn,
While a ball searchingly shoehorns the kind shoehorn


Some random musings

The algorithm created more interesting musings, which didn’t fit into the poems:

The algorithm

The algorithm is short. The algorithm consistently finds Jesus. The algorithm is written in javascript and needs Wordnet and Nonsensical.

const Nonsensical = require("nonsensical");
const nonsensical = new Nonsensical();
const Wordnet = require("wordnetjs");
const wn= new Wordnet();
var rhyme = require("rhymes");

global.window = {
	fetch: (path) => {
		return new Promise(function (resolve, reject) {
			require("fs").readFile(path, "utf8", function (err, data) {
				if (err) {
					reject(err);
				} else {
					resolve({
						json: () => JSON.parse(data)
					});
				}
			});
		})
	}
};
const data_file_paths = {
	noun: './data/noun.json',
	adverb: './data/adverb.json',
	adjective: './data/adjective.json',
	verb: './data/verb.json',
};
wn.load(data_file_paths, function () {

nonsensical.load(data_file_paths, function () {
  let s = nonsensical.generateSentence();
  console.log(s)
  let words = s.split(" ");
  let nouns = []
  let verbs = []
  let adjectives = []
  let lastWord = words[words.length - 1].replace(".", "")
  let rw = rhyme.rhymes(lastWord)
  rw.forEach(function(rhymer) { words[words.length] = rhymer.word;})
  // remove last 's' from word, so it is no longer plural...
  words[words.length] = lastWord.substr(0, lastWord.length - 1)

  words.forEach(function(w){

	let w_class = ""
    try {
	w = w.replace(".", "")
	w_class = wn.pos(w)
	if(!w_class)
	{
	// remove last letter, see if it makes a plural into non-plural so wordnet can find it...
	 let w2 = w.substr(0,w.length-1)
	 w_class = wn.pos(w2)
	 console.log(w2)
	}

	w_class.forEach(function(wc){ // it's possible to be verv, noun adjective (or all of these!)

    if(wc.trim() === "Noun")
	{
	nouns[nouns.length]=w
	}
    if(wc.trim() === "Adjective")
	{
	adjectives[adjectives.length]=w
	}
    if(wc.trim() === "Verb")
	{
	verbs[verbs.length]=w
	}
});
    } catch (e) {console.log(e.message)}
  });

  let rhyming = false;
  let ns = "";
  while (rhyming === false)
  {
    ns = nonsensical.generateSentence({wordSuggestions: {nouns: nouns, adjectives: adjectives, verbs: verbs}, useSuggestionRelatedWordChance: 1/2,
		maxSemanticStepsRemovedFromSuggestions: 3});
    let ns_words = ns.split(" ")
    last_word = ns_words[ns_words.length - 1].replace(".", "")

    rw.forEach(function(wrd) {
      // check if the last word is not the same and rhymes
      if(last_word.trim() === wrd["word"].trim() && last_word.trim() != lastWord)
        rhyming = true
	});
  }
  let glue = ["And", "While", "But", "So", "If", "For", "When"]
  var item = glue[Math.floor(Math.random()*glue.length)];
  console.log(item + " " + ns.toLowerCase())
});
});

I hope one day Morgan Freeman will recite the poems