I'm trying to input a table and need to put the range of the age in the library. How can I do it in Prolog?
`patients(Z,20,5,0):-Z#<19,Z#>0.
patients(Z,39,6,2):-Z#<39,Z#>20.`
It completely depends on what you want to do. The above are just facts, so you can represent them as Prolog facts, i.e. clauses without a body.
Filling in the facts for the relation (which may be called patient_stats
) is exactly like entering a relation into an RDBMS:
% patient_stats(AgeGroupId, NumOfCases, NumOfHospitalizations, NumOfDeaths)
patient_stats(age_group_a,20,5,0).
patient_stats(age_group_b,39,6,2).
% etc..
% age_group(LowestIncl,HighestIncl)
age_group(age_group_a,0,19).
age_group(age_group_b,20,39).
% etc...
Now you can perform joins, use library(aggregate)
, the usual fun.
For example, with the above facts, we can get a list of tagged values:
join_patient_stats_x_age_group(Found) :-
findall([low_age(LowestInct),
high_age(HighestIncl),
num_cases(NumOfCases)],
(age_group(G,LowestInct,HighestIncl),
patient_stats(G, NumOfCases, _,_)),
Found).
Then:
?- join_patient_stats_x_age_group(F).
F = [[low_age(0), high_age(19), num_cases(20)],
[low_age(20), high_age(39), num_cases(39)]].