r/synonym

Intro

Reddit is a weird place.  Sometimes incredibly thoughtful, other times incredibly hateful.  Often mundane yet consistently alluring (for me, anyway).  It’s an insular, enclosed space where self-reference is the norm, where outsiders often leave befuddled.  What drives this sense of community and insularity is the comments.  To be ‘in’ on a reddit gag, you must spend some time trawling post after post and reading the top few comments from the top posts.  Thus, when a self-reference pops up, you’re likely to be familiar with whatever is being referenced.  The comments make reddit what it is.  So what better source material to work with?  I couldn’t think of any, so a-reddit-we-will-go.

The concept for my poetic form is simple – it’s mean to take in a single sentence, then transform the sentence by substituting synonyms for each word.  The first line will have one word, and each successive line will add one more word from the original sentence, but swap it out for a synonym, until the entire sentence is reconstructed, yet forever altered.

I call my program r/synonym and here’s what it does, specifically:

  1. Takes a subreddit name as a CLI input
  2. Fetches the current top post from that subreddit and grabs the top comment from that post
  3. Synonyms are fetched for each word from Wordnik
  4. The first word is grabbed from the sentence, and a random synonym (if available) is swapped in and printed on it’s own line
  5. The second line takes the first two words from the original comment, swaps for random synonyms, then prints
  6. This continues until the entire sentence is printed out, adding an extra word for each new line
  7. Each successive line is padded with whitespace to add some extra visual distinction between lines

Results

From /r/environment – Not formatted as it was an early run of the program, but I liked the output

Bernie understands what it is going to take to fix the climate. I don't think the other candidates have any inkling what we are in for.
Bernie
Bernie perceive
Bernie perceive what
Bernie comprehend what it
Bernie understands what it is
Bernie support partly it is pregnancy
Bernie hear something it is traveling consequence
Bernie assume something it is childbearing apposition seize
Bernie perceive something it is childbearing connection employ effect
Bernie perceive whatever it is going limit seize accord fixed
Bernie learn something it is gestation limit engage to settle the
Bernie support partly it is -ways effect take consequence fix the climate.
Bernie perceive what it is obtainable limit choose connection fix the climate. ego
Bernie comprehend somewhat it is obtainable effect capture limit place the climate. ego finish
Bernie perceive partly it is pregnancy end employ accord fix the clime I effect guess
Bernie understands somewhat it is departure antithesis employ limit prepare the clime I don't believe the
Bernie interpret thing it is current consequence seize connection prepare the climate. ego effect imagine the second
Bernie interpret thing it is childbearing antithesis interest antithesis place the dwell ego cause suppose the different candidates
Bernie comprehend something it is doings effect employ to establish the climate. I accomplish contemplate the second candidates effect
Bernie support thing it is current effect take connection arrange the climate. ego cause suppose the otherwise candidates get any
Bernie interpret whatever it is gestation consequence attack end adjust the dwell ego cause ponder the otherwise candidates obtain any intimation
Bernie comprehend whatever it is departure to choose antithesis fix the climate. ego make believe the additional candidates obtain any intimation something
Bernie perceive whatsoever it is going end attack to solidified the clime ego slay contemplate the different candidates require any hint whatsoever we
Bernie learn thing it is behavior accord choose consequence prepare the climate. I don muse the opposite candidates effect any hint whatever we decametre
Bernie explain partly it is going end taken apposition prepare the dwell I accomplish cogitate the else candidates possess any inkling thing we art in
Bernie understands somewhat it is -ways antithesis seize end fix the dwell ego achieve guess the else candidates exact any intimation somewhat we thou harvest because 

 

From /r/environment too

Sorry... Thanks for the money.
 mean
    dismal Thanks
        melancholy Thanks since
            hurt Thanks for the
                dismal Thanks because the property

from /r/aww

Was the mother still around?
 Was
    Was the
        Was the genetrix
            Was the generatrix serene
                Was the genitrix quiet circularly

From /r/gif

"Who are you wearing today?" could be a pretty loaded question to ask a member of the Faceless Men.
 any
   any art
      "Who are singular
         any decametre thou use
            one with thee wearing now
               any with thee garments now could
                  one used yer garments now could signify
                     "Who art dialect garments today?" could signify on
                        "Who used yer use now could exist of mean
                           "Who with ye grinding today?" could exist in stout fuddled
                              "Who art you consumption now could happen of mean crocked point
                                 any decametre ye consumption now could exist by contemptible affluent question to
                                    any art thee grinding today?" could be into neat loaded point to entreat
                                       "Who with thee conduct today?" could signify into considerable moneyed doubt extent ask on
                                          "Who with yer conduct now could signify to fine moneyed subject limit beg at element
                                             one used yer conduct today?" could exist a fine loaded topic accord implore a premise from
                                                any thou archaic clothes today?" could exist at neat blotto investigation opposition implore on premiss from the
                                                   "Who decametre dialect garments now could happen by neat pixilated discussion antithesis exhibit by limb of the Faceless
                                                      "Who art thou conduct now could signify to despicable pissed investigation consequence exhibit into premise by the Faceless man

 

Analysis

The output is often a jumbled mess.  Which was a bit of shame.  It seems wordnik is pretty loose with the definition of synonym.  For example, their list of synonyms for the word Person contains Billiewagtail, wight, and hypostasis.  Not words that immediately jump to mind when I think person.  But in theory, this seemingly arbitrarly list of synonyms might produce some pretty weird and interesting results, right?  Well, sort of.  I was overall kind of disappointed with the output I was getting.  Sure there are lines that I can pick out as interesting, but the poems (if you could call them that) as a whole just don’t work.  It seems to actually work best on really short lines, as the increasing length of the input sentences not only increases the opportunities for pure jibberish, but increases the change of reader-weariness.  The more nonsense the reader is presented with, the more likely they are to just dismiss the poem entirely and move on.  Short input sentences don’t require as much of a leap from the reader, and are therefore more successful.

The way the program was written, it’s impossible to know how long the input sentence is, so an improvement could be made to check the length of a pulled comment, and if it’s too long, grab a different comment and check again.

With that said, I actually quite enjoy this poem:

Sorry... Thanks for the money.
 mean
    dismal Thanks
        melancholy Thanks since
            hurt Thanks for the
                dismal Thanks because the property

I think what I like about this one is the flow between a few of the lines.  It’s repetative, but in certain spots it can be read right through the line breaks and it changes the feeling entirely.

Code

# SYNONYMIZE
# RWET midterm - Jamie Charry
# 
# Procedure
#   1. Take a sentence, split on each word.  
#   2. Each word becomes the start of a new line.
#   3. For each line, generate a new sentence based on the first word
#   4. Theoretically could repeat a few times


import praw     # Reddit API wrapper
import sys      # For grabbing CLI args
from random import choice

# Wordnik API Wrapper
from wordnik import *
apiUrl = 'http://api.wordnik.com/v4'
apiKey = 'd8479b7cd7f56c763800601719e00e5d1a92a0278680e1b8b'
client = swagger.ApiClient(apiKey, apiUrl)
wordApi = WordApi.WordApi(client)

# Configure praw
r = praw.Reddit(user_agent='to_generate_poetry')

# first CL arg is the subreddit to scrape
# Get top post from a specific subreddit, only get 1 post
submissions = r.get_subreddit(sys.argv[1]).get_top(limit=1)

# A list is returned, so go through it and get the item inside
for sub in submissions: 
    print sub   # sub references a post
    first_comment = sub.comments[0].body    # Hold reference to the top comment

# Split the comment by word
word_array = first_comment.split()

# List to hold ever growing sentences
full_list = []
for count in range(len(word_array)):
    # For every loop, add another word from the word_array to the sentence
    full_list.append(word_array[:count+1])

# Get synonyms for every word from wordnik
synonyms = {}
for word in word_array:
    syn = wordApi.getRelatedWords(word, relationshipTypes='synonym', useCanonical='true')
    # syn = wordApi.getRelatedWords(word, relationshipTypes='equivalents', useCanonical='true')
    try:
        # Save list of synonyms into dict with words as the key
        syn[0].words.append(word)
        synonyms[word] = syn[0].words
    except TypeError: 
        # If no synonyms were found, save in an empty list
        synonyms[word] = []

print ' '.join(word_array)

transformed_list = []
line_counter = 0
for line in full_list:
    word_counter = 0
    for word in line:
        try:
            rand_syn = choice(synonyms[word])
        except:
            rand_syn = word
        line[word_counter] = rand_syn
        word_counter += 1
    full_list[line_counter] = line
    line_counter += 1

padding_counter = 0
spacing = 4
if len(sys.argv) >= 3:
    spacing = int(sys.argv[2])
for line in full_list:
    string = ' '.join(line)
    print ('{0:<'+str(padding_counter*4)+'}'+string).format(' ')
    padding_counter += 1

 

Leave a Reply

Your email address will not be published. Required fields are marked *