Permalink
Browse files

Merge pull request #1 from jhnphm/master

Small tweaks
  • Loading branch information...
2 parents ea52f42 + ae01866 commit 9a02bb1545f2a7c13e97ce428cffe4a804f78d43 Allison Nelson committed Mar 25, 2012
Showing with 44 additions and 43 deletions.
  1. +44 −43 poemgen.py
View
87 poemgen.py 100644 → 100755
@@ -9,60 +9,61 @@
#for word in nounfile:
# nouns.append(word.rstrip('\n'))
-nouns = ["flower","tree","child","sun","moon","darkness","light","rain","beach","earth","dog","cat","lover","life","love","heart","fish","poetry","music","happiness","peace","serenity","quiet","blossoms","blooms","madness","anger","sadness","dance","books"]; #1
-verbs = ["feel","is","smell","touch","taste","smile","wave","run","live"]; #2
-articles = ["the","a"]; #3
-prepositions = ["on","with","under","in","to","into"]; #4
-adjectives = ["beautiful","shining","slow","lovely","lively","nice","sad"]; #5
-gerunds = ["leaping","growing","loving","shaking","making","living","being","thinking","doing","building","singing"]; #6
-conjunctions = ["and","or"]; #7
+nouns = ["flower","tree","child","sun","moon","darkness","light","rain","beach","earth","dog","cat","lover","life","love","heart","fish","poetry","music","happiness","peace","serenity","quiet","blossoms","blooms","madness","anger","sadness","dance","books"] #1
+verbs = ["feel","is","smell","touch","taste","smile","wave","run","live"] #2
+articles = ["the","a"] #3
+prepositions = ["on","with","under","in","to","into"] #4
+adjectives = ["beautiful","shining","slow","lovely","lively","nice","sad"] #5
+gerunds = ["leaping","growing","loving","shaking","making","living","being","thinking","doing","building","singing"] #6
+conjunctions = ["and","or"] #7
#each number refers to a part of speech listed above, commas are interpreted literally
-sentence_structures = ["35124351","314351","64351","63514351,676","3517351,6","6351,676","3512","3124351"];
+sentence_structures = ["35124351","314351","64351","63514351,676","3517351,6","6351,676","3512","3124351"]
-from random import choice;
-struct = choice(sentence_structures);
+from random import choice
+struct = choice(sentence_structures)
-line = []
def parse_structs(structs):
- for i in range(0,len(struct)):
- curr = struct[i]
- if curr.isdigit():
- if curr == '1':
- line.append(choice(nouns));
- elif curr == '2':
- line.append(choice(verbs));
- elif curr == '3':
- line.append(choice(articles));
- elif curr == '4':
- line.append(choice(prepositions));
- elif curr == '5':
- line.append(choice(adjectives));
- elif curr == '6':
- line.append(choice(gerunds));
- elif curr == '7':
- line.append(choice(conjunctions));
- else:
- print "Invalid part of speech";
- else:
- curr = struct[i]
- if curr == ',':
- line.append(",");
- return line;
+ line = []
+ for i in range(0,len(struct)):
+ curr = struct[i]
+ if curr.isdigit():
+ if curr == '1':
+ line.append(choice(nouns))
+ elif curr == '2':
+ line.append(choice(verbs))
+ elif curr == '3':
+ line.append(choice(articles))
+ elif curr == '4':
+ line.append(choice(prepositions))
+ elif curr == '5':
+ line.append(choice(adjectives))
+ elif curr == '6':
+ line.append(choice(gerunds))
+ elif curr == '7':
+ line.append(choice(conjunctions))
+ else:
+ print "Invalid part of speech"
+ if i == 0:
+ line[0]=line[0][0].capitalize()+line[0][1:]
+ else:
+ line.insert(len(line)-1," ")
+ else:
+ curr = struct[i]
+ if curr == ',':
+ line.append(",")
+ return line
import sys
-sys.stdout.write("\n");
+sys.stdout.write("\n")
for i in range(0,5):
- struct = choice(sentence_structures);
- line = [];
- line = parse_structs(sentence_structures);
- for i in range(0,len(line)):
- sys.stdout.write(line[i] + " ")
- sys.stdout.write("\n")
-sys.stdout.write("\n")
+ struct = choice(sentence_structures)
+ line = parse_structs(sentence_structures)
+ print ''.join(line)
+sys.stdout.write("\n")

0 comments on commit 9a02bb1

Please sign in to comment.