Mcsam

Description

McSAM

Source: The Art of Prolog

Download

Program source code: mcsam.pl

Listing

/*
	mcsam(Story,Script) :-
		Script describes Story.
*/
 
mcsam(Story,Script) :-  
	find(Story,Script,Defaults),
        match(Script,Story),
        name_defaults(Defaults).
 
find(Story,Script,Defaults) :- 
	filler(Slot,Story),
        trigger(Slot,Name),
        script(Name,Script,Defaults).
/*
	match(Script,Story) :-
		Story is a subsequence of Script.
*/
 
match(Script,[]).
match([Line|Script],[Line|Story]) :- match(Script,Story).
match([Line|Script],Story) :- match(Script,Story).
 
/*
	filler(Slot,Story) :-
		Slot is a word in Story.
*/
 
filler(Slot,Story) :- 
	member([Action|Args],Story),
        member(Slot,Args),
        nonvar(Slot).
 
/*
	name_defaults(Defaults) :-
		Unifies default pairs in Defaults.
*/
 
name_defaults([]).
name_defaults([[N,N]|L]) :-  name_defaults(L).
name_defaults([[N1,N2]|L]) :-  N1 \== N2, name_defaults(L).
 
%	Testing and Data
 
test_mcsam(Name,UnderstoodStory) :-
	story(Name,Story), mcsam(Story,UnderstoodStory).
 
story(test,[[ptrans, john, john, X1, leones],
       [ingest, X2, hamburger, X3],
       [ptrans, Actor, Actor, X4, X5] ]).
 
script(restaurant,
       [ [ptrans, Actor, Actor, Earlier_place, Restaurant],
         [ptrans, Actor, Actor, Door, Seat],
         [mtrans, Actor, Waiter, Food],
         [ingest, Actor, Food, [mouth, Actor] ],
         [atrans, Actor, Money, Actor, Waiter],
         [ptrans, Actor, Actor, Restaurant, Gone] ],
       [ [Actor, customer], [Earlier_place, place1],
         [Restaurant, restaurant], [Door, door],
         [Seat, seat], [Food, meal], [Waiter, waiter],
         [Money, check], [Gone, place2] ] ).
 
trigger(leones, restaurant).  trigger(waiter, restaurant).
 
 
%	Program 14.16: McSAM

Comments

pl/prolog/pllib/mcsam.txt · ostatnio zmienione: 2017/07/17 08:08 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0