There is code to snarf for lab 10, that code is also here.
To get credit for this lab, you will need to do the following by Sunday night.
During today's lab, you'll be running code and then modifying the program you get so that the computer will generate a random story as is done in the game Mad Libs. This is a word game in which the player supplies words or phrases that fit various descriptions, and these words are then used in a story, often to comedic effect. Because the name Mad Lib is copyrighted, we'll use the name Tag-A-Story (you can call these Mad Libs yourself).
For example, suppose the tag-a-story template follows.
The lab in Compsci 101 is <adjective> and I <emotive-verb> it.
With this tag-a-story we might get any of the substitution stories below:
The lab in Compsci 101 is terrible and I love it. The lab in Compsci 101 is long and I crave it. The lab in Compsci 101 is squeamish and I dread it.
You'll be using one tag-a-story to develop and debug your program. Note that words/phrases that will be replaced are delimited by angle-brackets: < and > as shown. We call these delimited words/phrases tags in this lab.
There are three conceptual parts to this lab. These are summarized here and then elaborated on below.
The code in Replacement.py is designed to make it possible to find replacements for tags like <noun> or <name> or <place> and so on. Answer these questions in the online form.
Part A:
First, explain why different stories are generated each time you run Storyline.py. Be general, but include reasons -- is it because of code in Storyline.py or in Replacement.py that the stories are different each time the program runs?
Part B:
In the function getReplacement three comments indicate three parts of the function. The function starts with a global declaration and ends with a return statement, with these three sections in between.
# load the global dictionary if it hasn't been
# shouldn't have <>, but check and be safe
# check on tag, if not a key, try plural
getReplacement
in the module Storyline.py
-- explain the
syntax of the call and its purpose as it's used in Storyline.py
. In
answering this, indicate whether you think the < and > tag delimiters are
part of the string passed to getReplacement
and what your evidence is
for that.
The main part of the program in Storyline.py loads the template you snarfed with file name labtemplate.txt. This template is not creative nor exciting nor did you write it! You should create two new templates. For each you can use Eclipse to create an untitled text file or a new file depending on which menu you use. Create both templates so that they are in the folder named templates that you snarfed.
Part C:
tagreplacements
folder: adjective, animal, color, emotive-verb, food, noun,
place, verb.
tagreplacements
folder,
though your new template will be in the templates folder. If your tag
is <car> you must store replacements in a file named car.txt
Modify Storyline.py
so that it creates two stories: one for each of the
templates you wrote. Be sure that the story with the new <tag> works if
you added tag replacements. Answer these two questions on the lab
form about your templates.
Part D:
You'll need to upload your own template. To do this visit this site: http://www.cs.duke.edu/csed/tag-a-story/upload/
where you'll need to authenticate with your netid. Pick a category and upload your file. You can verify that your file was uploaded by looking at the logfile http://www.cs.duke.edu/csed/tag-a-story/logs.txt. You should do this with the template you made that uses only existing categories.
After you're sure you understand how Replacements.py
and
Storyline.py
work,
you should create your own module: TemplateSource.py
,
to read/load the file
http://www.cs.duke.edu/csed/tag-a-story/logs.txtThen parse it to create a dictionary of categories to URLs and allow the user to choose a category and then pick a random story from that category and print the story generated by the template. This new module will be imported into
Storyline.py
if you can make TemplateSource.py
work.
Answer these questions about the module, then it is optional to write the code that will make your ideas work.
Part E:
Note writing the code for this part is optional, but you should attempt to answer these questions.
After submitting the lab form, then submit the code you wrote with ambient/websubmit. Use lab10 as the submission folder. (Again, the code for Part E is optional).