Last active
January 16, 2018 14:11
-
-
Save gkarugi/d0c3e539bce224e6963a08f2c137b0b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Run the program by running go. | |
go :- hypothesize(Bird), | |
write('I guess that the bird is: '), | |
write(Bird), nl, undo. | |
/* hypotheses to be tested */ | |
hypothesize(chicken) :- chicken, !. | |
hypothesize(eagle) :- eagle, !. | |
hypothesize(vulture) :- vulture, !. | |
hypothesize(turkey) :- turkey, !. | |
hypothesize(ostrich) :- ostrich, !. | |
hypothesize(penguin) :- penguin, !. | |
hypothesize(quail) :- quail, !. | |
hypothesize(unknown). /* no diagnosis */ | |
/* animal identification rules */ | |
chicken :- domestic, | |
verify(has_comb), | |
verify(domesticated_fowl). | |
eagle :- fly, not_domestic, | |
verify(flies_very_high), | |
verify(sharp_eye_sight). | |
vulture :- fly, not_domestic, | |
verify(scavenger), | |
verify(bald_head). | |
turkey :- domestic, | |
verify(large_wattle), | |
verify(use_in_thanksgiving_dinner). | |
ostrich :- not_domestic, | |
verify(has_long_legs), | |
verify(has_long_neck). | |
penguin :- fly, not_domestic, | |
verify(does_not_fly), | |
verify(swims), | |
verify(is_black_and_white). | |
quail :- domestic, | |
verify(small_bird), | |
verify(white_eye_strip). | |
/* classification rules */ | |
fly :- verify(flies). | |
domestic :- verify(found_at_home). | |
not_domestic :- verify(found_in_the_wild). | |
/* how to ask questions */ | |
ask(Question) :- | |
write('Does the bird have the following attribute: '), | |
write(Question), write('? '), | |
read(Response), nl, | |
( (Response == yes ; Response == y) | |
-> assert(yes(Question)) ; | |
assert(no(Question)), fail). | |
:- dynamic yes/1,no/1. | |
/* How to verify something */ | |
verify(S) :- (yes(S) -> true ; (no(S) -> fail ; ask(S))). | |
/* undo all yes/no assertions */ | |
undo :- retract(yes(_)),fail. | |
undo :- retract(no(_)),fail. | |
undo. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment