home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / prolog / library / prolo_c / exampl51.pro < prev    next >
Text File  |  1986-10-06  |  3KB  |  118 lines

  1. /* Program 51 */
  2. /*
  3.   For a more complete sample expert system, see
  4.   the program GENI.PRO on the LIBRARY DISK
  5. */
  6. database
  7.     xpositive(symbol,symbol)
  8.     xnegative(symbol,symbol)
  9.  
  10. predicates
  11.     run
  12.     animal_is(symbol)
  13.     it_is(symbol)
  14.     positive(symbol,symbol)
  15.     negative(symbol,symbol)
  16.     clear_facts
  17.     remember(symbol,symbol,symbol)
  18.     ask(symbol,symbol)
  19.  
  20. goal
  21.     run.
  22.  
  23. clauses
  24.     run:-
  25.         animal_is(X),!,
  26.         write("\nYour animal may be a(n) ",X),
  27.         nl,nl,clear_facts.
  28.  
  29.     run:-
  30.         write("\nUnable to determine what"),
  31.         write(" your animal is. \n\n"),clear_facts.
  32.  
  33.     positive(X,Y) if xpositive(X,Y),!.
  34.     positive(X,Y) if not(negative(X,Y)),! and ask(X,Y).
  35.     negative(X,Y) if xnegative(X,Y),!.
  36.  
  37.     ask(X,Y):-
  38.         write(X," it ",Y,"\n"),
  39.         readln(Reply),
  40.         remember(X,Y,Reply).
  41.  
  42.     remember(X,Y,yes):-
  43.         asserta(xpositive(X,Y)).
  44.  
  45.     remember(X,Y,no):-
  46.         asserta(xnegative(X,Y)),
  47.         fail.
  48.  
  49.     clear_facts:-
  50.         retract(xpositive(_,_)),fail.
  51.  
  52.     clear_facts:-
  53.         retract(xnegative(_,_)),fail.
  54.  
  55.     clear_facts:-
  56.         write("\n\nPlease press the space bar to Exit"),
  57.         readchar(_).
  58.  
  59.     animal_is(cheetah) if
  60.         it_is(mammal),
  61.         it_is(carnivore),
  62.         positive(has,tawny_color),
  63.         positive(has,black_spots),!.
  64.  
  65.     animal_is(tiger) if
  66.         it_is(mammal) and
  67.         it_is(carnivore) and
  68.         positive(has,tawny_color) and
  69.         positive(has,black_stripes),!.
  70.  
  71.     animal_is(giraffe) if
  72.         it_is(ungulate) and
  73.         positive(has,long_neck) and
  74.         positive(has,long_legs) and
  75.         positive(has,dark_spots),!.
  76.  
  77.     animal_is(zebra) if
  78.         it_is(ungulate) and
  79.         positive(has,black_stripes),!.
  80.  
  81.     animal_is(ostrich) if
  82.         it_is(bird) and
  83.         not(positive(does,fly)) and
  84.         positive(has,long_neck) and
  85.         positive(has,long_legs),!.
  86.  
  87.     animal_is(penguin) if
  88.         it_is(bird) and
  89.         not(positive(does,fly)) and
  90.         positive(does,swim) and
  91.         positive(has,black_and_white_color),!.
  92.  
  93.     animal_is(albatross) if
  94.         it_is(bird) and
  95.         positive(does,fly),
  96.         positive(does,fly_well),!.
  97.  
  98.     it_is(mammal) if
  99.         positive(has,hair),
  100.         positive(does,give_milk),!.
  101.  
  102.     it_is(carnivore) if
  103.         it_is(mammal),
  104.         positive(does,eat_meat),
  105.         positive(has,pointed_teeth),
  106.         positive(has,claws),!.
  107.  
  108.     it_is(ungulate) if
  109.         it_is(mammal),
  110.         positive(has,hooves),
  111.         positive(does,chew_cud),!.
  112.  
  113.     it_is(bird) if
  114.         not(positive(has,hair)),
  115.         not(positive(does,give_milk)),
  116.         positive(has,feathers),
  117.         positive(does,lay_eggs),!.
  118.