This famous linguist once said that of all the phrases in the English language, of all the endless combinations of words in all of history, that "cellar door" is the most beautiful.
(Drew Barrymore in Donnie Darko)
I honestly have no idea how the phrase "cellar door" popped into my head, but that it did really does speak to that quote. Like (so I'm learning) many new-ish code-slingers, I'm always at a loss of what projects to work on when learning a/my language; all of the ideas I have are too huge or too dull to keep my interest long enough to follow them through. So the epiphany I had this morning was exciting enough to try and bang out in a short period of time: build a Twitter bot that breaks up the last phrase tweeted and uses the new WordsAPI to build a new tweet out of synonyms. A game of Whisper Down the Lane (aka Chinese Whispers??) in tweet form.
In theory, this should be pretty simple to accomplish while still retaining some variety to keep it interesting:
latest = twitter_client.user_timeline.first.full_text
new_tweet = []
count = 0
latest.split(' ').each do | word |
wordsapi_uri = URI("https://www.wordsapi.com/words/#{word}/synonyms?accessToken=#{config["wordsapi_token"]}")
results = JSON.parse(Net::HTTP.get(wordsapi_uri));
new_tweet.push results['synonyms'].sample
end
twitter_client.update new_tweet.join(' ')
To be honest, I was pretty surprised at how succinct it ended up becoming: 27 lines including the require statements and twitter client configurations. So, to take it for a test-spin, I wrapped the word gathering bits in a while counter < 50 loop and let 'er rip, which quickly spun out into:
basement doorway
cellar door
root cellar threshold
origin basement limen
pedigree cellar threshold
bloodline wine cellar doorsill
lineage wine-coloured root cellar doorstep
derivation wine take root basement doorsill
etymologizing vino exact settle cellar doorstep
derivation wine precise sink wine cellar threshold
deriving wine-coloured exact bury wine-coloured wine cellar doorsill
etymologizing wine-colored claim swallow up wine wine-coloured basement doorstep
deriving wine take deglutition astir wine-coloured wine cellar threshold
derivation wine-colored make swallow up wine wine-colored wine cellar doorway
filiation wine induce live with upwards vino wine wine-colored wine cellar door
line of descent vino bring on dwell up wine wine-colored wine wine-coloured root cellar threshold
...
fiction present miscellanea pureblood arranged argument vino lead in improving on fabrication nuclear physical composition 49 close to wine vino wine-colored wine-colored bode unrecorded maw deal wine wine-colored wine cellar mighty hopeful convey taboo atomic number 85 encipher
This kept going until I pulled the ctrl + c emergency brake at the 38 word/280 character mark. All of a sudden, I'm half-way towards reaching my 1,000 word/day quota for WordsAPI and I'm way over my tweet length. I figure these are my options going forward:
This would be the ideal solution... if I hadn't had chosen two of the least synonym-y words words in the English language. Seriously, these are my options:
cellar: "root cellar", "wine cellar", "basement"
door: "doorway", "room access", "threshold"
And limiting those to the one-word options leaves me:
basement: "cellar"
doorway: "door", "room access", "threshold"
threshold: "door", "doorway", "room access", "limen", "brink", "verge", "doorsill", "doorstep"
So it's a crapshoot until I land on threshold, and even then I've got a pretty solid chance at landing back at door. Here's what the code brought me:
basement threshold
cellar limen
basement threshold
cellar verge
basement sceptre
cellar scepter
basement wand
cellar sceptre
basement wand
cellar baton
basement wand
cellar sceptre
...
This is too echo-y for my liking. It's stuck in a loop that it can't seem to get out of. Obviously, I should just change my starting phrase. But a) I already registered @CellarDoorBot, and b) changing it just feels like cheating at this point.
An hourly limit would be 40 words (1,000 queries per day, 24 hours, natch). Randomly choosing the words again feels cheap: the whole point is to observe a phrase mutate over time.
This one I stumbled into and sort-of like. Combining the typeOf results with the synonym results doubles the size of the word-pool, in some cases. The only problem is that the words begin to stray away from the specificity that synonyms bring.
The currently-running implementation augments the first pass of the code w/ two checks: the number of queries and the character length of the phrase. I guess only the character length check is really necessary (any most combination of 40 words is likely to exceed the 140 character limit), but better safe than sorry. This will also constrain the flow into a tweet length, but that's fine too.
- twitter bots are always a good project to jump start some creativity (and they're certainly a smidge easier than building a to-do app)
- blogging about something whilst in the midst of it is surprisingly helpful for figuring things out