Advertisement
Guest User

KBS Project in Prolog Animals

a guest
Apr 25th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 3.02 KB | None | 0 0
  1. start :- write('-------------------------- Animal Detection Expert System ----------------------'), nl,nl,
  2.        write('Please choose an animal from this list:'), nl,
  3.        write('      [Cheetah, Tiger, Giraffe, Zebra, Ostrich, Penguin, Albatross, Shrimp, Octobus and Dolphin]'), nl,nl,
  4.        write('You are thinking of that animal, right? Okay, answer my questions and I will guess that animal in your mind.'),nl,nl,nl,nl,
  5.        predictAnimal,
  6.        write('Let us confirm what animal exactly...'), nl,nl,
  7.        animals(Animal),
  8.        write('I guess that the animal is: '),
  9.        write(Animal),
  10.        write(', am I right? ;)'),nl ,undo.
  11.  
  12. predictAnimal :- live_on_land, pcheetahandtiger, !.
  13. predictAnimal :- live_on_land, palbatrossOstrichPenguin, !.
  14. predictAnimal :- live_on_land, pgiraffeZebra, !.
  15. predictAnimal :- live_under_water, pshrimpOctDolphin, !.
  16.  
  17. live_on_land:- verify(live_on_land) .
  18. live_under_water:- verify(live_under_water).
  19.  /* Animals Identification Path ! */
  20.  
  21. pcheetahandtiger :- live_on_land ,verify(has_hair), write('Our Prediction: Cheetah, Tiger.'), nl, nl, nl.
  22. pgiraffeZebra :- live_on_land, no(has_hair), write('Our Prediction: Giraffe, Zebra.'), nl, nl,nl.
  23. pshrimpOctDolphin :- live_under_water, write('Our Prediction: Shrimp, Octobus, Dolphin.'), nl, nl,nl.
  24. palbatrossOstrichPenguin :- verify(lay_eggs), write('Our Prediction: Albatross, Ostrich, Penguin.'), nl, nl,nl.
  25.  
  26. animals(cheetah) :- live_on_land, verify(has_hair), cheetah, !.
  27. animals(tiger) :- live_on_land, verify(has_hair), tiger, !.
  28. animals(giraffe) :- live_on_land, giraffe, !.
  29. animals(zebra) :- live_on_land, zebra, !.
  30. animals(ostrich) :- live_on_land, ostrich, !.
  31. animals(penguin) :- live_on_land, penguin, !.
  32. animals(albatross) :- live_on_land, albatross, !.
  33. animals(shrimp) :- shrimp, !.
  34. animals(octobus) :- octobus, !.
  35. animals(dolphin) :- dolphin, !.
  36. animals(unknown).
  37.  
  38. /* animal identification rules */
  39.  
  40. cheetah :- mammal,
  41.                   verify(has_dark_spots).
  42. tiger :- mammal, no(has_dark_spots).
  43. giraffe :-  verify(has_long_neck).
  44. zebra :-  no(has_long_neck).
  45. ostrich :- bird,
  46.                verify(has_feathers),
  47.                verify(has_long_neck).
  48. penguin :- bird, no(has_feathers).
  49. albatross :- bird,
  50.                    verify(has_feathers).
  51.  
  52. shrimp :- fish, verify(has_6_legs).
  53. octobus :- fish, verify(has_8_legs).
  54. dolphin :- fish.
  55.  
  56. /* classification rules */
  57.  
  58. mammal :- verify(has_hair), !.
  59. mammal :- no(lay_eggs).
  60. bird :- verify(lay_eggs), !.
  61.  
  62. fish :- live_under_water.
  63.  
  64.  
  65. /* Asking questions */
  66.  
  67. ask(Question) :-
  68.         write('Does the animal '),
  69.         write(Question), write('? '),
  70.          read(Response), nl,
  71.          ( (Response == yes ; Response == y)
  72.          -> assert(yes(Question)) ;
  73.          assert(no(Question)), fail).
  74. :- dynamic yes/1,no/1,allVerified/1.
  75.  
  76. /* Verify Loop for each animal! */
  77.  
  78. verify(Q):- (yes(Q) -> true ; (no(Q) -> fail ; ask(Q))).
  79.  
  80.  
  81.  
  82. /* Delete yes and no data to start over afterwards! */
  83. undo :- retract(yes(_)),fail.
  84. undo :- retract(no(_)),fail.
  85. undo.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement