I’m trying to create a fuzzy logic in Swi prolog for obtain the % of having COVID, based on number of symptoms, number of contacts and strict contacts. I’m also working with an ontology, so I’m taking data from there (so I know the number of symp,contacts and strict contatcs a Patient has). I tried with Bousi Prolog, but it gives me different problem , for example it doesn’t recognise some predicates that i have to use . In swi prolog this is what I did, but it doesn’t seem a very fuzzy logic. Any help on how I can implement rules for that?
:- use_module(library(clpfd)).
:- consult(fatti). % consult facts from ontology
sintomi_fuzzy(X,Y):-
( X in 0..0 -> Y is 0 ;
X in 1..2 -> Y is 0.45 ;
X >= 3 -> Y is 0.6 ).
strict_contacts(X,Y):-
( X in 0..0 -> Y is 0 ;
X in 1..2 -> Y is 0.5 ;
X >= 3 -> Y is 0.8 ).
no_strict_contacts(X,Y):-
( X in 0..0 -> Y is 0 ;
X in 1..2 -> Y is 0.3 ;
X >= 3 -> Y is 0.4 ).
cerca_sintomi(Patient,List):- % find symptoms
findall(Symptoms,propertyAssertion('http://www.isibang.ac.in/ns/codo#hasSymptom',Patient,Symptoms),List).
lunghezza_lista([], 0). % La lunghezza di una lista vuota è 0
lunghezza_lista([_|Coda], Lunghezza) :-
lunghezza_lista(Coda, LunghezzaCoda),
Lunghezza is LunghezzaCoda + 1 .
verifica_relazioni(Patient,[], []).
verifica_relazioni(Patient,[Testa|Coda], ListaRisultato) :-
propertyAssertion('http://www.isibang.ac.in/ns/codo#hasCovid',Testa,literal(type('http://www.w3.org/2001/XMLSchema#boolean',true))),
verifica_relazioni(Patient,Coda, ListaRisultatoCoda), % Continua a controllare la coda della lista
ListaRisultato = [Testa | ListaRisultatoCoda]. % Aggiungi Testa alla lista risultato
verifica_relazioni(Patient,[_|Coda], ListaRisultato) :-
verifica_relazioni(Patient,Coda, ListaRisultato).
trova_relazioni(Patient,L1):-
findall(People,propertyAssertion('http://www.isibang.ac.in/ns/codo#hasRelationship',Patient,People),L1).
find_prob(Patient,P):-
# S is the Y from sympthoms (the probability to have covid with X symptoms)
# C is the Y from strict contacts ( ..)
# C1 is the Y from contacts (..)
trova_relazioni(Patient,L1),
verifica_relazioni(Patient,L1,Ris),
lunghezza_lista(Ris,N1), % N1 is number of contacts the patient has
cerca_sintomi(Patient,List),
lunghezza_lista(List,N), % N is number of symptoms the patients has
sintomi_fuzzy(N,S),
strict_contacts(2,C),
no_strict_conctacts(n1,C1),
(C1 > 0 -> P is (S + C + C1) / 3 ;
P is (S + C) / 2 ).