Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- start :- write('-------------------------- Animal Detection Expert System ----------------------'), nl,nl,
- write('Please choose an animal from this list:'), nl,
- write(' [Cheetah, Tiger, Giraffe, Zebra, Ostrich, Penguin, Albatross, Shrimp, Octobus and Dolphin]'), nl,nl,
- 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,
- predictAnimal,
- write('Let us confirm what animal exactly...'), nl,nl,
- animals(Animal),
- write('I guess that the animal is: '),
- write(Animal),
- write(', am I right? ;)'),nl ,undo.
- predictAnimal :- live_on_land, pcheetahandtiger, !.
- predictAnimal :- live_on_land, palbatrossOstrichPenguin, !.
- predictAnimal :- live_on_land, pgiraffeZebra, !.
- predictAnimal :- live_under_water, pshrimpOctDolphin, !.
- live_on_land:- verify(live_on_land) .
- live_under_water:- verify(live_under_water).
- /* Animals Identification Path ! */
- pcheetahandtiger :- live_on_land ,verify(has_hair), write('Our Prediction: Cheetah, Tiger.'), nl, nl, nl.
- pgiraffeZebra :- live_on_land, no(has_hair), write('Our Prediction: Giraffe, Zebra.'), nl, nl,nl.
- pshrimpOctDolphin :- live_under_water, write('Our Prediction: Shrimp, Octobus, Dolphin.'), nl, nl,nl.
- palbatrossOstrichPenguin :- verify(lay_eggs), write('Our Prediction: Albatross, Ostrich, Penguin.'), nl, nl,nl.
- animals(cheetah) :- live_on_land, verify(has_hair), cheetah, !.
- animals(tiger) :- live_on_land, verify(has_hair), tiger, !.
- animals(giraffe) :- live_on_land, giraffe, !.
- animals(zebra) :- live_on_land, zebra, !.
- animals(ostrich) :- live_on_land, ostrich, !.
- animals(penguin) :- live_on_land, penguin, !.
- animals(albatross) :- live_on_land, albatross, !.
- animals(shrimp) :- shrimp, !.
- animals(octobus) :- octobus, !.
- animals(dolphin) :- dolphin, !.
- animals(unknown).
- /* animal identification rules */
- cheetah :- mammal,
- verify(has_dark_spots).
- tiger :- mammal, no(has_dark_spots).
- giraffe :- verify(has_long_neck).
- zebra :- no(has_long_neck).
- ostrich :- bird,
- verify(has_feathers),
- verify(has_long_neck).
- penguin :- bird, no(has_feathers).
- albatross :- bird,
- verify(has_feathers).
- shrimp :- fish, verify(has_6_legs).
- octobus :- fish, verify(has_8_legs).
- dolphin :- fish.
- /* classification rules */
- mammal :- verify(has_hair), !.
- mammal :- no(lay_eggs).
- bird :- verify(lay_eggs), !.
- fish :- live_under_water.
- /* Asking questions */
- ask(Question) :-
- write('Does the animal '),
- write(Question), write('? '),
- read(Response), nl,
- ( (Response == yes ; Response == y)
- -> assert(yes(Question)) ;
- assert(no(Question)), fail).
- :- dynamic yes/1,no/1,allVerified/1.
- /* Verify Loop for each animal! */
- verify(Q):- (yes(Q) -> true ; (no(Q) -> fail ; ask(Q))).
- /* Delete yes and no data to start over afterwards! */
- undo :- retract(yes(_)),fail.
- undo :- retract(no(_)),fail.
- undo.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement