Category Archives: Programming A to Z

Useful Want Ads!

For my first Twitterbot, I decided to make a program to generate classified ads. I took a lot of inspiration from Magic Realism Bot and Art Assignment Bot, and it seemed to me that a good way to begin was to look for places that text appears in small chunks with certain conventions of form and content, and play with those to create something interesting. Classified ads seemed to be an ideal genre for a number of reasons, most notably because they tend to be very terse and to the point (having been charged-for by the letter in the pre-internet age, a weirdly perfect analog to the 140 permitted characters of Twitter), and their lingo provides a rich opportunity for constructing bizarre statements.

The first ad type I have created is a job posting. I tried to walk a line between randomness (which might create something funny or surprising, but might also get tediously silly) and over-determination (which would be boring). I also took pains to try to vary the structure and content of the tweets (drawing from a list of available sentences, providing a couple potential structures for each sentence, weighting vocabulary items to prevent them from reappearing immediately, sometimes adding an article here or there) to keep them from becoming too rote too quickly. The result is a mishmash, but I think it’s on the way to becoming interesting.

Sample tweets:

“Established hedge fund looking for a snake oil salesperson. Key responsibilities: flim-flam, light housekeeping. Must provide own transport.”

“Home-based business looking for a woodchuck walker. Base pay is 12000 lei per week. Discretion assured.”

My intention is to continue the project to include multiple types of classified ads – next will be missed connections, followed by personal ads, real estate listings, items for sale… who knows?

As far as the bones of it go, at the moment it’s a little more hard-coded than I would like, with a fairly limited vocabulary. The two ways to improve this that I can see are either to just keep  adding different words and tweaked structures, or to try to let the computer figure out content and structure by reading Tweets, craigslist postings, etc.. The latter is obviously the far harder of the two, but I’d be interested in giving it a shot.

A Machine for Shuffling Poems

1)  Pick a poem.

2) Get two pieces of paper.

3) Look at the first word of the poem – what part of speech is it? You can be as specific or as vague as you’d like. On one piece of paper, write the part of speech as though it were the first word of your poem; on the other, write the part of speech and then the word from your poem under it.

4) Repeat for every word in your poem. When you come to a part of speech you haven’t yet encountered, make a new column; when you come to a repeated part of speech, toss the new word in with its fellows. Preserve punctuation.

5) You should now have a dummy poem that looks like:

“Noun noun verb adjective adverb!

Noun conjunction noun verb, etc.”

6) Use an algorithm of your choice to shuffle the elements of each part-of-speech group.

7) Fill the poem back in using the words in order from the appropriate group. If you’ve done this correctly, you shouldn’t have any words left over.

8) Read and determine whether you have increased, decreased, or left unchanged the sense of the poem.


So here it is in action!

I chose a current favorite poem, a super-bleak piece of Victorian humor by WE Henley:

Madam Life’s a piece in bloom
Death goes dogging everywhere:
She’s the tenant of the room,
He’s the ruffian on the stair.

You shall see her as a friend,
You shall bilk him once or twice;
But he’ll trap you in the end,
And he’ll stick you for her price.

With his kneebones at your chest,
And his knuckles in your throat,
You would reason — plead — protest!
Clutching at her petticoat;

But she’s heard it all before,
Well she knows you’ve had your fun,
Gingerly she gains the door,
And your little job is done.

I broke it down into to components – the structure:

poemstructure

and the ingredients:

2016-09-12-22-44-57

I then shuffled the list orders using a simple p5 sketch, and the results are… I think even “interesting” is probably pushing things a bit far. But it’s recognizable as language, at least, and every now and then there’s a nice turn of phrase. Here it is:

Job throat knows a piece of bloom
End’s dogging twice:
He goes the madam in the death,
She’s a tenant on the price.

She would protest you in the fun,
You shall plead her once but well;
Or you shall reason it with the stair,
And he’ll see you at your petticoat.

At your kneebones as your chest,
And her knuckles in his ruffian,
You’ll bilk – trap – stick!
Clutching for her friend;

And he’s had him all gingerly,
Everywhere you is she’ve heard your room,
Before she’s the door,
But his done life gains little.