%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Knowledge Representation and Reasoning CSC 486/2506, Fall 2006
%
% Sample file for Question 4, Assignment 2 (Prolog implementation)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% classify(C): C is a list with two elements. The first one is the
%              concept name, the second one is a description.
%
% for instance this is a possible pair
%
%      [concept1 [all,adult,male,[all,rich]]]
%
% YOU SHOULD IMPLEMENT THIS PREDICATE. THE PREDICATE SHOULD 
% NORMALIZE THE DESCRIPTION AND INSERT THE CONCEPT INTO THE HIERARCHY
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% this implementation only prints the set of clauses, you should
% implement your program here.
classify(C):- writeln(C).

%		<<< HERE YOU SHOULD WRITE YOUR PROGRAM >>

                
                
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% printConcepts: should print all known concepts with their 
%                corresponding already normalized description
%
% for instance it should print things like this:
%
%      Concept concept20 is [all,adult,male,rich]
%
% YOU SHOULD IMPLEMENT THIS PREDICATE. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
printConcepts:- writeln('Nothing yet..').

%		<<< HERE YOU SHOULD WRITE YOUR PROGRAM >>
                

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% printHierarchy: should print the hierarchy by saying, for each
%                 known concept, under which concept is directly
%                 situated.
%
% this is the result for the example given in the guidelines:
%
%     Concept c1 is directly below concept thing
%     Concept c2 is directly below concept c1
%     Concept c3 is directly below concept c1
%     Concept c4 is directly below concept c2
%     Concept c5 is directly below concept thing
%     Concept c6 is directly below concept c5
%
% YOU SHOULD IMPLEMENT THIS PREDICATE. 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
printHierarchy:- writeln('Nothing yet..').

%		<<< HERE YOU SHOULD WRITE YOUR PROGRAM >>
                

                

                
                
                
                
                

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%           OBS: You should not modify anything below 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% buildHierarchy(File): 
%                takes a file name, calls classify/1 for each pair
%                in the file, and finally calls printConcepts/0 and
%                printHierarchy/0 to show the results.
%
%
% This should work under SWI and Quintus Prolog (tested)
%
% DO NOT CHANGE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
buildHierarchy(File) :-
        open(File,read,R),	  % Opens the file
        read_and_classify(R),     % Reads and classify
	close(R),                 % Close the file
        printConcepts,            % Print all known concepts with their descr.
        nl,
        printHierarchy.           % Print the hierarchy

read_and_classify(R):- read(R, C),
                       (C = [end] -> true ; 
                                     (classify(C), read_and_classify(R)) ).
	



