Script started on XXX XXX XX 13:28:43 XXXX > cat ts.p % file: ts.p % desc: parsing a template system % with simplification rules :- consult('sr.p'). :- consult('process.p'). % =========================================================== % geometric data base surfaces(block,6). surfaces(pyramid,5). surfaces(frustum,3). surfaces(cone,2). % =========================================================== % retrieval operations % am_holding/2(?Property,?Object) :- dynamic am_holding/2. am_holding(null,nothing). % pickup/2(+Property,+Object) pickup(Property,Object) :- am_holding(_,nothing), retract(am_holding(_,nothing)), assert(am_holding(Property,Object)), write('Got it.'), nl. % putdown/2(+Property,+Object) putdown(Property,Object) :- am_holding(Property,Object), retract(am_holding(Property,Object)), assert(am_holding(null,nothing)), write('Okay, I put down the '), write(Object), write('.'), nl. display_object(Adj1,Obj) :- write(Adj1), write_string(" "), write(Obj). display_holdings :- am_holding(Property,Object), display_object(Property,Object). display_specs(Obj) :- surfaces(Obj,N), write(N). % =========================================================== % translation templates % ----------------------------------------------------------- % interpret/1 % interpret([quit,'!']) :- abort. % if quit! is in source lang % ----- pickup ----- interpret([pick, Color, Shape, '.']) :- pickup(Color,Shape), !. interpret([pick, _, _, '.']) :- write_string("can't do it, got this "), display_holdings, nl. % ----- putdown ----- interpret([put, Color, Shape, '.']) :- putdown(Color,Shape), !. interpret([put, Color, Shape, '.']) :- write_string("can't do it, don't got no "), display_object(Color,Shape). % ----- information on ----- interpret([what, number, surfaces, Color, Shape, '?']) :- am_holding(Color,Shape), !, write_string("the "), display_object(Color,Shape), write_string(" has "), display_specs(Shape), !, write_string(" surfaces."), nl. interpret(_) :- write_string("say what?"), nl. > cat sr.p % file: sr.p % desc: simplification rules for "geometric answer-man" language % ----------------------------------------------------------- % see allowable sentences in file "source-lang" % =========================================================== % simplification rules % ----------------------------------------------------------- % sr(+S,-T) sr([pick, up |X],[pick | X]). sr([put, down |X],[put | X]). sr([how, many, surfaces, are, on |X],[what, number, surfaces | X]). sr([the | X],X). % these rules reduce the input to: % pick Color Shape % put Color Shape % what number surfaces Color Shape % ----------------------------------------------------------- % simplify(+S,-T) simplify(X,Z) :- sr(X,Y), !, simplify(Y,Z). simplify([X|Xs],[X|Zs]) :- simplify(Xs,Zs). simplify([],[]). > pl Welcome to SWI-Prolog (Multi-threaded, Version 5.6.24) Copyright (c) 1990-2006 University of Amsterdam. SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. Please visit http://www.swi-prolog.org for details. For help, use ?- help(Topic). or ?- apropos(Word). ?- ['ts.p']. % sr.p compiled 0.00 sec, 1,876 bytes % io.p compiled 0.01 sec, 8,332 bytes % process.p compiled 0.01 sec, 10,880 bytes % ts.p compiled 0.01 sec, 17,124 bytes Yes ?- doit(queries). Query> DEBUG: read sentence - [pick, up, the, red, block, .] DEBUG: simplified to - [pick, red, block, .] Got it. Query> DEBUG: read sentence - [pick, up, the, green, pyramid, .] DEBUG: simplified to - [pick, green, pyramid, .] can't do it, got this red block Query> DEBUG: read sentence - [put, down, the, red, block, .] DEBUG: simplified to - [put, red, block, .] Okay, I put down the block. Query> DEBUG: read sentence - [pick, up, the, green, pyramid, .] DEBUG: simplified to - [pick, green, pyramid, .] Got it. Query> DEBUG: read sentence - [how, many, surfaces, are, on, the, green, pyramid, ?] DEBUG: simplified to - [what, number, surfaces, green, pyramid, ?] the green pyramid has 5 surfaces. Query> DEBUG: read sentence - [put, down, the, green, pyramid, .] DEBUG: simplified to - [put, green, pyramid, .] Okay, I put down the pyramid. Query> DEBUG: read sentence - [how, are, you, feeling, today, ?] DEBUG: simplified to - [how, are, you, feeling, today, ?] say what? Query> DEBUG: read sentence - [pick, up, the, yellow, cone, .] DEBUG: simplified to - [pick, yellow, cone, .] Got it. Query> DEBUG: read sentence - [how, many, surfaces, are, on, the, yellow, cone, ?] DEBUG: simplified to - [what, number, surfaces, yellow, cone, ?] the yellow cone has 2 surfaces. Query> DEBUG: read sentence - [how, many, surfaces, are, on, the, green, pyramid, ?] DEBUG: simplified to - [what, number, surfaces, green, pyramid, ?] say what? Query> DEBUG: read sentence - [put, down, the, yellow, cone, .] DEBUG: simplified to - [put, yellow, cone, .] Okay, I put down the cone. Query> DEBUG: read sentence - [quit, !] Yes ?- halt. > exit > script done on XXX XXX XX 13:29:55 XXXX