Skip to content

Instantly share code, notes, and snippets.

@katsully
Created May 18, 2015 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katsully/d2731e720c3c8ab27979 to your computer and use it in GitHub Desktop.
Save katsully/d2731e720c3c8ab27979 to your computer and use it in GitHub Desktop.
import itertools
import re
from random import randint
from textblob import TextBlob, Word
from pattern.en import conjugate, PAST
story_ballets = []
# read in files
swanlake = open("swanlake.txt")
swan_lines = swanlake.readlines()
story_ballets.append(swan_lines)
swanlake.close()
giselle = open("giselle.txt")
giselle_lines = giselle.readlines()
story_ballets.append(giselle_lines)
giselle.close()
sleepingbeauty = open("sleepingbeauty.txt")
sleeping_lines = sleepingbeauty.readlines()
story_ballets.append(sleeping_lines)
sleepingbeauty.close()
raymonda = open("Raymonda.txt")
raymonda_lines = raymonda.readlines()
story_ballets.append(raymonda_lines)
raymonda.close()
cinderella = open("cinderella.txt")
cinderella_lines = cinderella.readlines()
story_ballets.append(cinderella_lines)
cinderella.close()
guythoughts = open("guythoughts.txt")
lines = guythoughts.readlines()
guys_lines = [lines]
guythoughts.close()
hesintoyou = open("hesintoyou.txt")
lines = hesintoyou.readlines()
guys_lines.append(lines)
hesintoyou.close()
notcute = open("notcute.txt")
lines = notcute.readlines()
guys_lines.append(lines)
notcute.close()
dreams = open("dreams.txt")
guys_lines.append(dreams.readlines())
dreams.close()
righttype = open("righttype.txt")
lines = righttype.readlines()
guys_lines.append(lines)
righttype.close()
unavailable = open("unavailable.txt")
lines = unavailable.readlines()
guys_lines.append(lines)
unavailable.close()
rival = open("rival.txt")
lines = rival.readlines()
guys_lines.append(lines)
rival.close()
lover = open("lover.txt")
lover_lines = lover.readlines()
#guys_lines.append(lines)
lover.close()
drama = open("drama.txt")
lines = drama.readlines()
guys_lines.append(lines)
drama.close()
distance = open("distance.txt")
distance_lines = distance.readlines()
guys_lines.append(distance_lines)
distance.close()
cheating = open("cheating.txt")
lines = cheating.readlines()
guys_lines.append(lines)
cheating.close()
reject = open('rejection.txt')
reject_lines = reject.readlines()
reject.close()
wedding = open("wedding.txt")
wedding_lines = wedding.readlines()
guys_lines.append(wedding_lines)
wedding.close()
highmaint = open("highmaint.txt")
highmaint_lines = highmaint.readlines()
guys_lines.append(highmaint_lines)
highmaint.close()
sugarbaby = open("sugarbaby.txt")
guys_lines.append(sugarbaby.readlines())
sugarbaby.close()
girlfriends = open("girlfriends.txt")
guys_lines.append(girlfriends.readlines())
girlfriends.close()
mom = open("mom.txt")
mom_lines = mom.readlines()
mom.close()
skimpy = open("skimpy.txt")
skimpy_lines = skimpy.readlines()
skimpy.close()
wrongguy = open("wrongguy.txt")
wrongguy_lines = wrongguy.readlines()
guys_lines.append(wrongguy_lines)
wrongguy.close()
def distance():
print distance_lines[0]
print distance_lines[randint(1,len(distance_lines)-1)]
def reject():
print reject_lines[0]
print reject_lines[randint(1,len(reject_lines)-1)]
def wedding():
print wedding_lines[0]
print wedding_lines[randint(1,len(wedding_lines)-1)]
def lover():
print lover_lines[0]
print lover_lines[randint(1,len(lover_lines)-1)]
def mother():
print mom_lines[0]
print mom_lines[randint(1,len(mom_lines)-1)]
def skimpy():
print skimpy_lines[0]
print skimpy_lines[randint(1,len(skimpy_lines)-1)]
def wrongguy():
print wrongguy_lines[0]
print wrongguy_lines[randint(1,len(wrongguy_lines)-1)]
def highmaint():
print highmaint_lines[0]
print highmaint_lines[randint(1,len(highmaint_lines)-1)]
for i in range(4):
random_ballet = story_ballets[randint(0,len(story_ballets)-1)]
section = len(random_ballet) / 5
random_line = random_ballet[randint(i*section, (i+1)*section)]
random_line = random_line.decode('utf-8')
blob = TextBlob(random_line)
propernouns = [word for word,pos in blob.tags if pos == 'NNP']
possivenouns = [word for word,pos in blob.tags if pos == 'PRP$']
possivenouns.extend([word for word in random_line if word.endswith("'s") or word.endswith("s'")])
prepositions = [word for word,pos in blob.tags if pos == 'PRP']
adjs = [word for word,pos in blob.tags if pos == "JJ"]
verbs = [word for word, pos in blob.tags if pos == "VBD" or pos == "VBZ"]
for noun in propernouns:
if noun == "Cinderella" or noun == "Raymonda" or noun == "Aurora" or noun == "Odette" or noun == "Giselle":
if random_line.find("Princess " + noun) != -1:
random_line = random_line.replace("Princess " + noun, "I")
else:
random_line = random_line.replace(noun, "I")
for noun in possivenouns:
if noun == "her":
random_line = random_line.replace(" " + noun, " my")
elif noun == "their":
random_line = random_line.replace(noun, "our")
for prep in prepositions:
if prep =="she" or prep == "She":
random_line = random_line.replace(prep, "I")
elif prep == "they":
random_line = random_line.replace(prep, "we")
elif prep == "his":
idx = random_line.split('').index("his")
if random_line.split(' ')[idx+1] == "daughter":
random_line = random_line.replace("his daughter", 'me')
for adj in adjs:
if adj == "Odette's":
random_line = random_line.replace(adj, "my")
elif adj == "Giselle":
random_line = random_line.replace(adj, "I")
for verb in verbs:
random_line = random_line.replace(" " + verb, " " + conjugate(verb, tense=PAST, parse=True))
loop = True
search_for = []
print "OK, so " + random_line
random_line = re.sub(r'[.,]', '', random_line)
lwords = random_line.lower().rstrip().split(' ')
if 'his' in lwords and ('mother' in lwords or "mother's" in lwords):
mother()
loop = False
elif any(word in lwords for word in ["wedding", "marriage", 'festivity']):
wedding()
loop = False
elif "betrothed" in lwords:
wedding()
loop = False
elif any(word in lwords for word in ["crusade", "goodbye"]):
distance()
loop = False
elif 'reject' in lwords:
reject()
loop = False
elif 'extravagantly' in lwords or 'over-exuberance' in lwords:
skimpy()
loop = False
elif 'abduct' in lwords:
wrongguy()
loop = False
elif 'Queen' in lwords:
print 'HERE'
highmaint()
loop = False
if 'secret' in lwords:
search_for.append(['unfaithful', 'suspicious'])
if 'lilac' in lwords:
search_for.append(['girlfriend'])
if "forgiveness" in lwords:
search_for.append(['forgive', 'apologize'])
if "mistake" in lwords:
search_for.append(['forgive', 'apologize'])
if "knight" in lwords:
search_for.append(["charming"])
if "execution" in lwords:
search_for.append(["off the market"])
if "united" in lwords:
search_for.append(["wedding", "marriage", "married"])
if "rich" in lwords:
search_for.append(["rich"])
if 'envy' in lwords:
search_for.append(['jealous', 'envy'])
if 'jealous' in lwords:
search_for.append(['envy', 'jealous'])
if 'watches' in lwords:
search_for.append(["looks at", "eyes"])
if 'kiss' in lwords:
search_for.append ["lips"]
if 'die' in lwords:
search_for.append(['drama'])
if 'tragic' in lwords:
search_for.append(['drama'])
if 'tragedy' in lwords:
search_for.append(['drama'])
if 'dying' in lwords:
search_for.append(['drama'])
if 'die' in lwords:
search_for.append(['drama'])
if 'alone' in lwords and 'he' in lwords:
search_for.append(['lonely', 'loneliness'])
if 'himself' in lwords:
search_for.append(['alone', 'lonely', 'loneliness'])
if 'suspicion' in lwords:
search_for.append(['unfaithful', 'suspicious', 'cheating', 'snoop'])
if 'suspicious' in lwords:
search_for.append(['unfaithful', 'cheating', 'snoop'])
if 'difficulty' in lwords:
search_for.append(['hard'])
if 'search' in lwords:
search_for.append(['miss'])
if 'captivated' in lwords:
search_for.append(['eyes'])
if 'dreams' in lwords:
search_for.append(['dream'])
if "rags" in lwords or 'rag' in lwords:
search_for.append(['money', 'sugar baby', 'cost'])
if "rags" in lwords or 'rag' in lwords:
search_for.append(['money', 'sugar baby', 'cost'])
if "girlfriends" in lwords:
search_for.append(['girlfriends'])
if "unconscious" in lwords:
search_for.append(['games'])
if 'evil' in lwords:
search_for.append(['nemesis', 'rival'])
if "carabosse" in lwords:
search_for.append(['nemesis', 'rival'])
if "rothbart" in lwords:
search_for.append(['nemesis', 'rival'])
if "stepsisters" in lwords:
search_for.append(['nemesis', 'rival'])
if "rival" in lwords:
search_for.append(['nemesis'])
if not search_for and loop:
if "lover" in lwords or "lovers" in lwords:
lover()
loop = False
search_terms = list(itertools.chain.from_iterable(search_for))
#search_terms2 = list(itertools.chain(nouns, verbs, adjs, advs))
#print search_terms
possible_lines = []
found = False
if loop:
for article in guys_lines:
for line in article[1:]:
if any(word in line for word in search_terms):
possible_lines.append(line)
found = True
if found:
print article[0]
print possible_lines[randint(0,len(possible_lines)-1)]
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment