Q0 Set up : svn export http://unbox.org/wisp/var/timm/10/310/src/prolog/4/b : svn add b : svn commit -m "4b ready to go" : For each of the following questions, add lines like this to "run" printf "\n===== 4/b/q1 ========================\n\n" cat myCodeThatAnswersThisQuestion.pl execute : where "execute" is the "test" command shown below. Background stuff Prolog DCGs can contain standard Prolog goals, wrapped in {curly brackets}. :eg. : sentence --> nounphrase,verbphrase, {print(got(sentence))}. If the goals succeed or fail, then this can select different rule. :e.g. :rarely :- random(100) < 10. :sometimes :- random(100) < 33. :usually :- random(100) < 66. :maybe :- random(100) < 50. :often :- random(100) < 90. :always. : : verb --> {sometimes}, [runs]. : verb --> {sometimes}, [swims]. : verb --> [walks]. : Note that if you are going to add such guards, then 1) the last rule must be unguarded so that at least one goal always succeeds. 2) the top level goal has to be wrapped in a "once" goal so that on backtracking, you don't get BOTH a randomly selected clause and the final unguarded clause. : e.g : demo :- once(sentence(S,[])), print(S), nl. 3) The above random trick is NOT good since it means polluting the source code with hard-coded usage frequencies. We'll do better next week. These Prolog goals let us link the sentence generation to the frame system. For example, the following code sets Who to be someone defined in the family frames. nounphrase --> {maybe}, {any(gender of Who=male )}, [Who]. nounphrase --> {any(gender of Who=female)}, [Who]. Q1: People can be cute, pious, brash In Denouement, things happen depending on whether kids are cute, priests are pious, or 'this_girl' is brash (actually, the current grammar says "beautiful" but beauty is in the eye of the beholder so I'm going to go with brash). Modify frame.pl such that every one has an age (kid,adult) and everyone has a profession (politician, priest, pathologist,president) and everyone has an facade (polished, wild, demure, brash, shy). Change Denoumnet such that we can pick any kid, someone with any profession, and someone of any gender. THEN make sire that only if denomuments --> []. denomuments --> {any(hero(H))}, denoument(H). denoument(H) --> {kid(H)}, a_Cute_Little_Kid_Convinces_Them_People_Are_Ok ending. denoument(H) --> {priest(H), pious(H)}, a_Priest_Talks_To_Them_Of_God ending. denoument(H) --> {female(H), facade of H=brash}, they_Fall_In_Love_With_This_Girl. end_Sad_Or_Happy. denoument(H) --> end_Sad_or_Happy. Test shows(30,C,denomuments(C,[])). Q2 : Add stochastic variance modify scifi.pl using the tricks shown in 4/b/english.pl in order to generate random sentences Test shows(30,C,start(C,[])). % or whatever your top-level goal is Q3: Asteroids destroy In collision, if we select "asteroid", then the bigger the asteroid, the less likely we will survive; i.e. the bigger the roid, the less likely that "but_Is_Saved" will be selected. Model this, using the table on asteroid size at http://burro.astr.cwru.edu/stu/asteroid.html. Update the grammar such that if we say "asteroid" it rewrites a asteroid name like 'ceres'. Change the selection rules in And_Then such that larger asteroids tend to destroy us more. Test shows(30,C,collision(C,[])). Q4: Comets attack 1) Create frames for comets Using the table in http://burro.astr.cwru.edu/stu/comets.html, model the distance they approach earth. Select comments in "Floater" based on how close the comets come to us (we'll use "solar approach" as that measure; nearer ones like Ikeya-Seki can strike us more often and further ones like Borrelly can strike us rarely, and if comets don't strike us, we are hit by asteroids or clouds. 2) Update the grammar such that if we say "comet", that gets rewritten to on the comet names in http://burro.astr.cwru.edu/stu/comets.html (note, if names contain upper case, space, dashes, etc then enclose them in single quotes like this 'Hale-Bopp' Test shows(30,C,collision(C,[])).