View source with raw comments or as raw
    1%% Fever4 - introduce data to the temp register to filter
    2
    3
    4#pred diagnosis(P,D) :: 'The diagnosis of @(P:patient) is @(D)'.
    5diagnosis(P,'fever') :- fever(P,T).
    6diagnosis(P,'no fever') :- no_fever(P,T).
   10fever(Patient,Temp) :-
   11    temp(Patient,Temp),
   12    high_temp(Temp).
   13
   14%% # pred no_fever(P,T) :: 'For @(P:patient), with @(T:temperature) we conclude that there is no fever'.
   15%% # pred not no_fever(P,T) :: 'For @(P:patient), with @(T:temperature) we conclude that there is a fever'.
   16no_fever(Patient,Temp) :-
   17    temp(Patient,Temp),
   18    not high_temp(Temp).
   19
   20#pred high_temp(T) :: 'It is high @(T:temperature)'.
   21#pred not high_temp(T) :: 'It is not high @(T:temperature)'.
   22high_temp(T) :- T #> 38.
   23
   24%# pred temp(P,T) :: 'For @(P:patient) the @(T:temperature)'.
   25temp(P,T) :- temp1(P,T).
   26temp(P,T) :- temp2(P,T).
   27
   28# pred temp1(P,T) :: 'It is known that @(P:patient) has @(T:temperature)'.
   29temp1(P,T) :- reg_person_temp(P,T).
   30# pred temp2(P,T) :: 'It is consider that @(P:patient) has @(T:temperature)'.
   31temp2(P,T) :- not reg_person(P).
   32
   33# pred recent_reg(D) :: 'A register at @(D:time point) is recent'.
   34# pred not recent_reg(D) :: 'A register at @(D:time point) is not recent'.
   35recent_reg(D) :- D #> -3.
   36
   37# pred reg_temp(P,T,D) :: 'There is a register, for @(P:patient), with @(T:temperature), at @(D:time point)'.
   38# pred not reg_temp(P,T,D) :: 'There is no register, for @(P:patient), with @(T:temperature), at @(D:time point)'.
   39reg_temp('Juan',37,-2).
   40reg_temp('Pedro',39,-2).
   41reg_temp('Jose',39,-4).
   42reg_temp('Jose',37,-6).
   43
   44# pred reg_person_temp(P,T) :: 'There is a valid register for @(P:patient) with @(T:temperature)'.
   46reg_person_temp(P,T) :- reg_temp(P,T,D), recent_reg(D).
   47%% # pred reg_person(P) :: 'There is a valid register for @(P:patient)'. %
   48# pred not reg_person(P) :: 'There is no valid register for @(P:patient)'.
   49reg_person(P) :- reg_person_temp(P,T).
   50
   51%%%%%%%%   Queries %%%%%%%
   52
   53#show diagnosis/2, temp/2, reg_temp/3.
   54
   55?- diagnosis('Luisa',D).
   56?- diagnosis('Juan',D).
   57?- diagnosis('Pedro',D).
?- diagnosis('Jose',D). %% The reg of Jose is old
   59?- diagnosis(X,D).