Skip to content

Commit

Permalink
interactive story
Browse files Browse the repository at this point in the history
user defines how the story starts, loop until he QUITs
  • Loading branch information
breznak committed Nov 16, 2013
1 parent f45868b commit ea93deb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions client/linguist.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@

NUM_REPEATS = 5
PRINT_EVERY_REPEAT_N = 1

TERMINATORS = ['.','!','?','|']
NUM_SENTENSES = 5 # number for story sentenses generated
STORY_START = "The dog"
_QUIT = "QUIT"

def clean(s):
return re.sub('\n', '|', s)
Expand Down Expand Up @@ -95,7 +99,7 @@ def runLinguist(datapath):
return model

def tellStory(model, startSent, lenght):
"""feed startSent sequence and then continue to generate the story by the CLA.
"""feed startSent sequence and then continue to generate the story by the CLA.
param model: the trained CLA model
param startSent: starting sequence as a string, eg \"And so he raised the gun\"
param lenght: #sequences to generate. """
Expand Down Expand Up @@ -123,6 +127,12 @@ def tellStory(model, startSent, lenght):
if len(sys.argv) > 1:
datapath = sys.argv[1]
model = runLinguist(datapath)
tellStory(model, 'The dog ', 5)
print('==========================================')
print('Welcome young adventurer, let me tell you a story! ')
while True:
STORY_START = raw_input('Enter story start (QUIT to go to work): ')
if(STORY_START == "QUIT"):
break
tellStory(model, STORY_START, NUM_SENTENSES)
else:
print "Usage: python linguist.py [path/to/data.txt]"

0 comments on commit ea93deb

Please sign in to comment.