HW-2

I was able to rewrite the program from my first homework assignment to work with sets, which proved to be a much more efficient approach.  Unfortunately, that efficiency allowed me to more quickly be dissatisfied with the results.  I was able to filter many different text through each other, but the syntactical commonalities tend to be cliche or often used phrases, in the example of filtering the bible through gatsby common phrases included

set(['on the other side of', 'of men and women and', 'on the third day that', 'from the other side of', 'the other end of the', 'He stretched out his hand', 'the ends of the earth', 'of the house, as though', 'on the edge of the', 'from the top of the', 'and put it on the', 'at the head of the', 'and the voice of the', 'the other side of the', 'for the rest of the'])

When filtered through the bible looking for a 6 word common phrases, Gatsby becomes:

At this moment a voice, unmistakably Wolfshiem’s called “Stella!” from the other side of the door.
The first supper–there would be another one after midnight–was now being served, and Jordan invited me to join her own party who were spread around a table on the other side of the garden. There were three married couples and Jordan’s escort, a persistent undergraduate given to violent innuendo and obviously under the impression that sooner or later Jordan was going to yield him up her person to a greater or lesser degree. Instead of rambling this party had preserved a dignified homogeneity, and assumed to itself the function of representing the staid nobility of the countryside–East Egg condescending to West Egg, and carefully on guard against its spectroscopic gayety.

Which isn’t very interesting.  Running the old testament through The Wasteland returned one commonality,‘on the other side of’, which, of course, we have seen before.  I think the fundamental flaw here is the idea that this process would be recognizable.  If anything, I learned that the English language really is pretty cool because its very rare that even a 6 word phrase is used in two different sources.

So this morning I had a different idea, which was to take a text and turn it into a haiku version of itself, by counting the most used verb, noun and adjective, and then using them to create a three line poem.  I probably can’t do this, but here I used some of the examples from class to try.  I couldn’t find lists of verbs or nouns, and I imagine this is kind of difficult, but I created some three liners with just adjectives.

The poems created with the three most popular adjectives are not very interesting because the internal logic is completely opaque:

And the dry stone no sound of water
With a dead sound on the final stroke of nine
Stirring the pattern on the coffered ceiling

himself up a little and they fell off by themselves
somebody called – it was his mother – “it’s quarter to seven
made the sound muffled and not too noticeable

And see thy blood warm when thou feel’st it cold
Art left the prey of every vulgar thief
‘Thy end is truth’s and beauty’s doom and date

So I went back and made some using three instances of the most popular adjective, which makes the internal logic clear (although the word that ends up being the most popular adjective is often pretty uninteresting) and the poems a bit more interesting.  On the whole, not very satisfying.

And see thy blood warm when thou feel’st it cold
Despite of wrinkles this thy golden time
To stand in thy affairs, fall by thy side

himself up a little and they fell off by themselves
little legs would find a use
“Grete, come with us in here for a little while”, said Mrs

And the dry stone no sound of water
With a dead sound on the final stroke of nine
With a dead sound on the final stroke of nine

This is the code for the first version, using the top three adjectives:

# hw-2.4

import sys
args = sys.argv

txt_file = args[1]
txt_read = open(txt_file, 'r')
txt_lines = txt_read.readlines()

def load_adjectives():
  adj = set()
  for line in open('adjectives'):
    line = line.strip()
    adj.add(line)
  return adj

adj_set = load_adjectives()
adj_used = dict()
adj_list = list()
#print type(adj_used)

for line in txt_lines:
  line = line.strip()
  adjs = [s for s in line.split(" ") if s.lower() in adj_set]
  if len(adjs) > 0:
	for a in adjs:
		if a in adj_used:
			adj_used[a] += 1
		else:
			adj_used[a] = 1

sorted_keys = sorted(adj_used.keys(), key=lambda k: adj_used[k])
max_a = sorted_keys[-1]
#print max_a

for line in txt_lines:
	line = line.strip()
	i = line.find(max_a)
	if i != -1:
		#print line
		#print 'n'
		h = line.find(".", i)
		if h != -1:
			adj_list.append(line[0:h])

print adj_list[0]

max_b = sorted_keys[-2]
b_list = list()
#print max_b

for line in txt_lines:
	line = line.strip()
	i = line.find(max_b)
	if i != -1:
		#print line
		#print 'n'
		h = line.find(".", i)
		if h != -1:
			b_list.append(line[0:h])

print b_list[0]

max_c = sorted_keys[-3]
c_list = list()
#print max_c

for line in txt_lines:
	line = line.strip()
	i = line.find(max_c)
	if i != -1:
		#print line
		#print 'n'
		h = line.find(".", i)
		if h != -1:
			c_list.append(line[0:h])

print c_list[0]

And the code for the second version, basically the same thing:

# hw-2.5

import sys
args = sys.argv

txt_file = args[1]
txt_read = open(txt_file, 'r')
txt_lines = txt_read.readlines()

def load_adjectives():
  adj = set()
  for line in open('adjectives'):
    line = line.strip()
    adj.add(line)
  return adj

adj_set = load_adjectives()
adj_used = dict()
adj_list = list()
#print type(adj_used)

for line in txt_lines:
  line = line.strip()
  adjs = [s for s in line.split(" ") if s.lower() in adj_set]
  if len(adjs) > 0:
	for a in adjs:
		if a in adj_used:
			adj_used[a] += 1
		else:
			adj_used[a] = 1

sorted_keys = sorted(adj_used.keys(), key=lambda k: adj_used[k])
max_a = sorted_keys[-1]
print max_a

for line in txt_lines:
	line = line.strip()
	i = line.find(max_a)
	if i != -1:
		#print line
		#print 'n'
		h = line.find(".", i)
		if h != -1:
			adj_list.append(line[0:h])

print adj_list[0]
print adj_list[1]
print adj_list[-1]
Advertisements

Author: owen ribbit

poop

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s