Code:
% Author: Jeremy Giberson
% Date: 4/22/2004
%uncontestable facts, for associations.
%color associations
axioms(color, red).
axioms(color, blue).
axioms(color, black).
axioms(color, white).
axioms(color, green).
%size associations
axioms(size, small).
axioms(size, medium).
axioms(size, large).
axioms(size, very_large).
%weight associations
axioms(weight, heavy).
axioms(weight, light).
object_color(box, red).
object_color(car, blue).
object_color(watch, black).
object_color(mouse, white).
object_size(box, medium).
object_size(car, large).
object_size(watch, small).
object_size(mouse, small).
object_description(box, is_square).
object_description(car, provides_transport).
object_description(watch, keeps_time).
object_description(mouse, furry_creature).
%query the fact list to see if the Object is a Property.
%Object = car, box, animal, watch, etc.
%Property = big, small, blue, red, heavy, etc.
is_the(Object, Property) :- object_color(Object, Property);
object_size(Object, Property);
object_description(Object, Property).
%querry axioms list to dertermine what a property might be.
%Value is a property, not an object. Red, big, small, furry etc. NOT car, box, watch etc.
what_is_a(Value) :- axioms(color, Value), write(Value), write(' is a color.'), nl; % a color?
axioms(size, Value), write(Value), write(' is a size.'), nl; % a size?
%..... % insert more axiom tests here
write('it is unknown what '), write(Value), write(' is.'), nl. % unknown, not define axiom
%See if there is an Object in the list of facts, that has the attribute of Property, display that object if it exists.
what_is(Property) :- is_the(Object, Property), write('The '), write(Object), write(' is '), write(Property).
%See if there is an Object in the list of facts, that has ANY '_' attribute, display so if there is.
is_there_a(Object) :- is_the(Object, _), write('There is a '), write(Object).
%Find and list all the objects in the fact list thave a certain property. The logic here is tricky.
%The help_what_are() function is what actually searches for, and displays all the objects in the fact list,
%it relies on a false statement (1 < 0) at its tail to force it to keep searching the facts. It will always
%return No--regardless of if it finds matching objects. To correct this, I add an wrapper function what_are()
%that nots the result of help_what_are() (now always Yes.). To correctly print yes or no on the result of the search
%i tag the matching query of the helper function as an AND to the call. If there is a match the method will print Yes.
%if there is not, it will print No.
what_are(Property) :- not(help_what_are(Property)), is_the(_, Property).
help_what_are(Property) :- is_the(Object, Property), write(Object), write(' is '), write(Property), nl, 1 < 0.