Created
December 13, 2015 19:07
-
-
Save controversial/bc144e4c939f17dd364f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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