Posted By

philkav on 12/18/09

AI Assignment - Monthy Python Skit

/ Published in: Prolog

`%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%	What have the romans ever done for us?      %%%%%%	Written by : Philip Kavanagh	            %%%%%%%      DT228/4 - C06412882		            %%%%%% %%	Prologue Assignment December 2009           %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 			-- INSTRUCTIONS --		   	     %%%%% Prolog will print a statement, prompts user for input. 	     %%%%%% User enters a sentance and ends it with a full stop,              %%%%%%% exclamation point or question mark. Prolog will then decide       %%%%%%%% whether or not the answer is valid and will return it's decision. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% %% said(X) :- assert(X, "a", X), retract said(Y), assert said(X) %% ----- Function called BY THE MAIN FUNCTION (See last line of code) the first time the program is runfirstRun:-	nl,write('REG : They bled us white, the bastards. They\'ve taken everything we had. And not just from us! From our fathers,and from our father\'s fathers.'),	nl,write('LOR : And from our father\'s father\'s fathers.'),	nl,write('REG : Yeah.'),	nl,write('LOR : And from our father\'s father\'s father\'s fathers.'),	nl,write('REG : Yeah, all right Stan, don\'t delay with the point. And what have they ever given us in return?'),	nl,write('REG : What have the romans ever done for us?'),nl,run. %% ----- this is the programs baserun:- 	write('YOU : '),getSentance(_),nl,run. %% ----- To end the program. (This may be incorrectly applied).quit:- 	break.   %% ----- read list and pick keywords -----%% ----- Search recursively through the list - If you find the word, cut out, otherwise search the remainder of the list.%% ----- exclamation mark '!' is used to cut.	contains([aqueduct|_])    :- !,write('REG : Oh. Yeah, yeah, they did give us the aqueduct, ah, that\'s true,'),apartFrom,assert(#(aqueduct)),listing(#).	contains([sanitation|_])  :- !,write('REG : Yeah, all right, I\'ll grant you the sanitation,'),apartFrom,assert(#(sanitation)),listing(#).	contains([roads|_])       :- !,write('REG : Oh, yeah, obviously the roads. I mean the roads go without saying, don\'t they? '),apartFrom,assert(#(roads)),listing(#).	contains([irrigation|_])  :- !,write('REG : Yeah, yeah, all right, fair enough - irrigation too... '),apartFrom,assert(#(irrigation)),listing(#).	contains([medicine|_])    :- !,write('REG : Yes, ok - medicine! '),apartFrom,assert(#(medicine)),listing(#).	contains([education|_])   :- !,write('REG : Well sure yeah, education I suppose? '),apartFrom,assert(#(education)),listing(#).	contains([wine|_])        :- !,write('REG : Yes and the wine... '),apartFrom,assert(#(wine)),listing(#).	contains([publicbaths|_]) :- !,write('REG : And the publicbaths, ok'),apartFrom,assert(#(publicbaths)),listing(#).	contains([order|_])	  :- !,write('REG : Brought order, very well '),apartFrom,assert(#(order)),listing(#).	contains([peace|_]) 	  :- !,write('REG : Oh, peace! Shut Up!'),nl,write('________________'),nl,nl,write('---End Scene---'),nl,write('________________'),nl,nl,quit.%% ----- recursion and NOT case	contains([Head|Tail]) 	  :- contains(Tail), !.	contains(_) 			  :- write('REG : The Romans had nothing to do with that!').  	apartFrom:-write('Well apart from the : ').  %% ----- this function reads in the things and creates a list from them -----	readIntoList1([Head|Tail]):-read(X),not(X=end),Head=X,readIntoList1(Tail).	readIntoList1([]). 	readIntoList2([Head|Tail]):-read(X),not(X=end),Head=X,readIntoList2(Tail).	readIntoList2([]).  %% ----- Here we are converting the list format to a proper output format -----%% ----- Instead of [this, is, a, list] beign displayed, it will say : this is a list	writeSentance([H|T]):-name(H,[Fl|Lt]),Cap is Fl-32,name(X,[Cap|Lt]),write(X),writeSentanceTail(T).	writeSentanceTail([]):-write('.').	writeSentanceTail([H|T]):-write(', '),write(H),writeSentanceTail(T).  %% ----- these functions are where we turn sentances into lists in order to process each individual word ----- 	getSentance([W|Ws]):-get0(Char),readWord(Char,W,C1),restOfSentance(W,C1,Ws),contains([W|Ws]). 	restOfSentance(W,_,[]):-lastword(W),!.	restOfSentance(_,C,[W1|Ws]):-readWord(C,W1,C1),restOfSentance(W1,C1,Ws). 	readWord(C,W,C1):-single_character(C),!,name(W,[C]),get0(C1).	readWord(C,W,C2):-in_word(C,NewC),!,get0(C1),restOfWord(C1,Cs,C2),name(W,[NewC|Cs]).	readWord(_,W,C2):-get0(C1),readWord(C1,W,C2). 	restOfWord(C,[NewC|Cs],C2):-in_word(C,NewC),!,get0(C1),restOfWord(C1,Cs,C2).	restOfWord(C,[],C). 	%%---------------(ASCII) allow : 	single_character(44). %% comma       ','	single_character(58). %% colon       ':'	single_character(33). %% exclamation '!'	single_character(59). %% semi-colon  ';'	single_character(63). %% question    '?'	single_character(46). %% full-stop   '.' 	%%-- The characters are between : 	in_word(C,C):-C > 96,C < 123.      %% lowercase letters	in_word(C,C):-C > 47,C < 58.       %% Numbers	in_word(39,39).			   %% single inverted comma	in_word(45,45).			   %% hyphenation	in_word(C,L):-C>64,C<91,L is C+32. %% uppercase letters 	lastword('.').	lastword('!').	lastword('?'). %% ----- end of sentance to list -----     %% ----- will load when the program is run -----:-dynamic(#(X)),nl,firstRun.`