Skip to content

Instantly share code, notes, and snippets.

@controversial
Created December 13, 2015 19:07
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 controversial/bc144e4c939f17dd364f to your computer and use it in GitHub Desktop.
Save controversial/bc144e4c939f17dd364f to your computer and use it in GitHub Desktop.
import xml.etree.ElementTree as ET
def getDialogueList(*plays):
dialogues = []
for p in plays:
root = ET.parse("shakespeare/"+p+".xml")
playtitle = root.findtext("TITLE")
playsubt = root.findtext("PLAYSUBT")
print playtitle
dialogue_by_scene = []
acts = root.findall("ACT")
for act in acts:
print " "+act.findtext("TITLE")
scenes = act.findall("SCENE")
for scene in scenes:
print " "+scene.findtext("TITLE")
speeches = scene.findall("SPEECH")
dialogue = ["\n".join([s.text for s in speech.findall("LINE") if s.text]) for speech in speeches]
dialogue_by_scene.append(dialogue)
dialogues.append(dialogue_by_scene)
print "\n\n"
return dialogues
if __name__ == "__main__":
print getDialogueList("j_caesar", "hamlet")
import chatterbot
import parse_shakespeare
bot = chatterbot.ChatBot("Julius Caesar", storage_adapter="chatterbot.adapters.storage.JsonDatabaseAdapter", database="julius_caesar.db")
# dialogue = parse_shakespeare.getDialogueList("j_caesar")[0]
# lines_trained = 0
# for d in dialogue:
# bot.train(d)
# lines_trained += 1
# print "Training scene", lines_trained
locked_bot = bot = chatterbot.ChatBot("Julius Caesar", storage_adapter="chatterbot.adapters.storage.JsonDatabaseAdapter", database="julius_caesar.db", read_only=True)
import time
while 1:
query = raw_input(">")
a = time.time()
locked_bot.get_response(query)
print time.time() - a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment