/*
		Sherlock Homes Case

	Backward Chainer makes deductions.

*/

%=====================================
%
%Facts
%
%=====================================

bodyPart(wilson,wilsonsHand1).
bodyPart(wilson,wilsonsHand2).
bodyPart(wilson,wilsonsArm1).

partType(wilsonsHand1,hand).
partType(wilsonsHand2,hand).
partType(wilsonsArm1,arm).
hasTattoo(wilsonsArm1,wilsonsTattoo1).

right(wilsonsHand2).
left(wilsonsHand1).

tattoo(wilsonsTattoo1).
has_color(wilsonsTattoo1,blue).
has_color(wilsonsTattoo1,hunanPink).

larger(wilsonsHand1,wilsonsHand2).

wearing(wilson,shirt1).
wearing(wilson,jacket1).
jacket(jacket1).
cuff(shirt1,shiny).
elbow(jacket1,smooth).
shirt(shirt1).

has(scot,college_diploma).
has(wilson,college_diploma).


%=====================================
%
%    Rules of Deduction
%
%=====================================


%*************************************************************
%  Given data  that we can observe from a suspect's physical
%  appearance, we would like to answer questions
%  like these:
%
%    1) Where has a suspect been? 
%    2) What kind of work has the suspect done?
%    3) Is the suspect literate?
%    4) Does the suspect have a motive?
%
%   An important concern is that your reasoning
%   can distinguish the semantic difference between
%   negation as failure and "real" negation.
%
%  A related concern is  that rules typically
%  represent necessary but not sufficient conditions.
%  If no rules for a given conclusion succeed does it
%  mean that the conclusion is false. There may be
%  other ways to prove the goal.
%
%  The system should be able to explain its inferences.
%
%***********************************************************


%========================================
% Where has the suspect been?
%
%========================================

%-------------------------------------------------------
% An agent has been to location if the agent
%  has a body part tattooed with tattoo
%  that is produced only in that location.
%-------------------------------------------------------
beenAtLoc(Agent,Location) :-
    bodyPart(Agent,Part),
    hasTattoo(Part,Tattoo),
    producedIn(Tattoo,Location),
    not((producedIn(Tattoo,OtherLocation), 
             Location \= OtherLocation)).

%-----------------------------------------------
% Tattoo Produced in china if it has hunanPink in it.
%-----------------------------------------------
producedIn(Tattoo,china) :-
     tattoo(Tattoo),
     has_color(Tattoo,hunanPink).

/*
%------------------------------------------------------
% An agent has been to location if a reliable
%    eye witnesss  can confirm
%-------------------------------------------------------
beenAtLoc(Agent,Location) :-
    eyeWitnessed(Witness,atLoc(Agent,Location)),
    reliable(Witness).
*/


%=======================================
% Performed Manual Labor if one hand is
%   "larger" than the other.
%     
%=======================================

performed(Agent,manualLabor) :-
    opposingHands(Agent,H1,H2),
    larger(H1,H2).

%---------------------------------------------------------
% Associate an Agent with Agent's opposing
%   body parts.
%---------------------------------------------------------
opposingBodyParts(Agent,P1,P2) :-
    bodyPart(Agent,P1),
    bodyPart(Agent,P2),
    P1 \= P2,
    partType(P1,Type),
    partType(P2,Type).

%---------------------------------------------------
% Opposing Hands is a specialization
%   of opposing body parts.
%---------------------------------------------------
opposingHands(Agent,H1,H2) :-
      opposingBodyParts(Agent,H1,H2),
      partType(H1,hand).


%=======================================
% An agent is literate if the agent has a college-diploma
%  of if the agent writes.
%     
%=======================================
literate(Agent) :-
    has(Agent,college_diploma).

literate(Agent) :-
     writes(Agent).

%=======================================
% An agent writes if the agents cuff is shiny
%   and the agents elbow is smooth.
%     
%=======================================
writes(Agent) :-
    wearing(Agent,Shirt),
    shirt(Shirt),
    cuff(Shirt,shiny),
    wearing(Agent,Jacket),
    jacket(Jacket),
    elbow(Jacket,smooth).

