Q0 Set up : svn export http://unbox.org/wisp/var/timm/10/310/src/prolog/4/c : svn add c : svn commit -m "4c ready to go" : For each of the following questions, add lines like this to "run" printf "\n===== 4/c/q1 ========================\n\n" cat myCodeThatAnswersThisQuestion.pl execute : where "execute" is the "test" command shown below. Background stuff The code in prove.pl contains a version of golorp that implements randomized grammar travesal and attributed grammars. Randomized grammar traversal: - look at the code demos2 in z.pl. This code calls demo2, 20 times: demo2 :- sentence(Sentence1,[]), golorp(sentence(Sentence2,[])), format('\n1 : ~p\n2 : ~p\n',[Sentence1,Sentence2]). - Note how we generate Sentence1 using boring old Prolog but Sentence2 using the golorp randomized prover. - If you look at the grammar "english.pl" you will see none of the silliness of "usually", "sometimes", etc. Attributed grammars - When running demo2, you might see output like this: 1 : [al, runs, quickly, towards, al] 2 : [carla, walks, very, slowly, towards, cuthbert] 1 : [al, runs, quickly, towards, al] 2 : [arthur, runs, very, slowly, towards, arthur] - Note that the output on line 2. If we pick someone who is make (e.g. arthur) then the next random male selected is also arthur. - The core of this magic is the cache/3 fact within english.pl. cache(male([What|X],X),male,What). - This code says that if ever are matching on the grammar head "male" then we are setting a new variable "What". At runtime, this will be matched to whoever comes out of: male --> {gender of Who=male}, [Who]. Q1 Comment the file prove.pl. Use the lecture notes as a start. Explain what is going on for ALL clauses. Q2 It is a little tedios writing the cache/3 fact. The following code automates its generation: makeCache(This,cache(Term,This,What)) :- Term =.. [This,[What|X],X]. For example: :- makeCahce(make,X) X = cache(male([_G267|_G276], _G276), male, _G267). Now we introduce a new kind of neck symbol: "--=". This denotes some rule whose rewrite we want to cache. For example: male --= {gender of Who=male}, [Who]. Write a term_expansion/2 rule that converts male --= {gender of Who=male}, [Who] into two assertions: male --> {gender of Who=male}, [Who] cache(male([_G267|_G276], _G276), male, _G267). Hints: 1) you will need the following in a file loaded BEFORE english.pl :- op(1001,xfx,(--=)). 2) you will need a term_expansion rule that is in file loaded AFTER the above op/3 call and before english.pl is loaded. 3) See 0ops.pl for some examples. 4) If you get syntax errors in your term_expansion, bury "X --= Y" inside (X --= Y). Ditto with "X --> Y". 5) You will need to call expand_term((X --> Y),Z) to get one of your assertions. 6) Somehow, you will need to call makeCache. Test Change the grammar so sentences use more than one verb. Make "verb" an attributed grammar: verb --= [runs]. verb --= [walks]. Now, calling "bash runs" will generate the same verb, every time it is referenced.