animal_kb.pl

% from Winston & Horn's LISP
 
% Rules for animal identification.  The first three rules are an
% input loop.  Enter attributes that match the patterns in the rules.
% For example: has(robie,hair), or lays_eggs(suzie).  These facts will
% help identify robie and suzie.  Enter "end" to end the input loop.
%
% The attributes can also be put in the list of initial_data.
% Example:
%
% initial_data([
%	has(dennis,hair),
%	has(dennis,hoofs),
%	has(dennis,black_stripes),
%	parent(dennis,diana)
%	]).
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%	
% MY INITIAL DATA
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
initial:-
		jpl_datums_to_array([
  'has(animal,feathers)',
  'has(animal,hair)',
  'gives(animal,milk)',
  'has(animal,feathers)',
  'flies(animal)',
  'lays_eggs(animal)',
  'eats_meat(animal)',
  'has(animal,pointed_teeth)',
  'has(animal,claws)',
  'has(animal,forward_eyes)',
  'has(animal,hoofs)',
  'chews_cud(animal)',
  'has(animal,tawny_color)',
  'has(animal,dark_spots)',
  'has(animal,tawny_color)',
  'has(animal,black_stripes)',
  'has(animal,long_neck)',
  'has(animal,long_legs)',
  'has(animal,dark_spots)',
  'does_not_fly(animal)',
  'has_attr(animal,black_and_white)',
  'swims(animal)',
  'flies_well(animyal)',
  'parent(animal,parent)',
  'even_toed(animal)',
  'has_attr(animal,slow)',
  'has(animal,ears)'],L),
				jpl_new('miw2.MyCBForm',[L,'Choose facts:'],D),
				jpl_call(D,getChecked,[],_),
				jpl_get('miw2.MyCBForm',termos,{C}),
			    assert(initial_data(C)).
 
 :- initial.
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 
rule 1:
  [1: goal(animal_id)]
  ==>
  [assert(read_facts),
   retract(1)].
 
rule 2:
  [1: end,
   2: read_facts]
  ==>
  [retract(all)].
 
rule 3:
  [1: read_facts]
  ==>
  [prompt('Attribute ? ',X),
   assert(X)].
 
rule id1: 
  [1: has(X,hair)]
  ==>
  [assert(isa(X,mammal)),
   retract(all)].
 
rule id2: 
  [1: gives(X,milk)]
  ==>
  [assert(isa(X,mammal)),
   retract(all)].
 
rule id3: 
  [1: has(X,feathers)]
  ==>
  [assert(isa(X,bird)),
   retract(all)].
 
rule id4: 
  [1: flies(X),
   2: lays_eggs(X)]
  ==>
  [assert(isa(X,bird)),
   retract(all)].
 
rule id5: 
  [1: eats_meat(X)]
  ==>
  [assert(isa(X,carnivore)),
   retract(all)].
 
rule id6: 
  [1: has(X,pointed_teeth),
   2: has(X,claws),
   3: has(X,forward_eyes)]
  ==>
  [assert(isa(X,carnivore)),
   retract(all)].
 
rule id7: 
  [1: isa(X,mammal),
   2: has(X,hoofs)]
  ==>
  [assert(isa(X,ungulate)),
   retract(all)].
 
rule id8: 
  [1: isa(X,mammal),
   2: chews_cud(X)]
  ==>
  [assert(isa(X,ungulate)),
   assert(even_toed(X)),
   retract(all)].
 
rule id9: 
  [1: isa(X,mammal),
   2: isa(X,carnivore),
   3: has(X,tawny_color),
   4: has(X,dark_spots)]
  ==>
  [assert(isa(X,cheetah)),
   retract(all)].
 
rule id10: 
  [1: isa(X,mammal),
   2: isa(X,carnivore),
   3: has(X,tawny_color),
   4: has(X,black_stripes)]
  ==>
  [assert(isa(X,tiger)),
   retract(all)].
 
rule id11: 
  [1: isa(X,ungulate),
   2: has(X,long_neck),
   3: has(X,long_legs),
   4: has(X,dark_spots)]
  ==>
  [assert(isa(X,giraffe)),
   retract(all)].
 
rule id12: 
  [1: isa(X,ungulate),
   2: has(X,black_stripes)]
  ==>
  [assert(isa(X,zebra)),
   retract(all)].
 
rule id13: 
  [1: isa(X,bird),
   2: does_not_fly(X),
   3: has(X,long_neck),
   4: has(X,long_legs),
   5: has_attr(X,black_and_white)]
  ==>
  [assert(isa(X,ostrich)),
   retract(all)].
 
rule id14: 
  [1: isa(X,bird),
   2: does_not_fly(X),
   3: swims(X),
   4: has_attr(X,black_and_white)]
  ==>
  [assert(isa(X,penguin)),
   retract(all)].
 
rule id15: 
  [1: isa(X,bird),
   2: flies_well(X)]
  ==>
  [assert(isa(X,albatross)),
   retract(all)].
 
rule id16: 
  [1: isa(Animal,Type),
   2: parent(Animal,Child)]
  ==>
  [assert(isa(Child,Type)),
   retract(all)].
 
rule id17: 
  [1: even_toed(X),
   2: has_attr(X,slow),
   3: isa(X,ungulate)]
  ==>
  [assert(isa(X,sloth)),
   retract(all)].
pl/miw/miw08_ruleruntimeg/animal_kb.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