如何在Prolog中应用通用量词?

Thi*_*uda 5 prolog

假设你有一个疾病诊断Prolog程序,从疾病和症状之间的许多关系开始:

causes_of(symptom1, Disease) :-
    Disease = disease1;
    Disease = disease2.
causes_of(symptom2, Disease) :-
    Disease = disease2;
    Disease = disease3.
causes_of(symptom3, Disease) :-
    Disease = disease4.

has_symptom(person1, symptom1).
has_symptom(person1, symptom2).
Run Code Online (Sandbox Code Playgroud)

我怎样才能创建一个头部'has_disease(人,疾病)'的规则,如果该人患有该疾病的所有症状,该规则将返回true?使用上面的示例,以下是示例输出:

has_disease(person1, Disease).
   Disease = disease2.
Run Code Online (Sandbox Code Playgroud)

Orb*_*ing 6

嗯,这可能是一个更简单的方法,因为我的Prolog技能充其量只是次要的.

has_disease(Person, Disease) :- atom(Disease),
    findall(Symptom, has_symptom(Person, Symptom), PersonSymptoms),
    findall(DSymptom, causes_of(DSymptom, Disease), DiseaseSymptoms),
    subset(DiseaseSymptoms, PersonSymptoms).

has_diseases(Person, Diseases) :-
    findall(Disease, (causes_of(_, Disease), has_disease(Person, Disease)), DiseaseList),
    setof(Disease, member(Disease, DiseaseList), Diseases).
Run Code Online (Sandbox Code Playgroud)

被称为如下:

?- has_diseases(person1, D).
D = [disease1, disease2, disease3].
Run Code Online (Sandbox Code Playgroud)

首先使用findall/3谓词来查找一个人的所有症状,然后再次查找疾病所具有的所有症状,然后快速检查疾病的症状是否是该人的一部分.

我编写has_disease/2谓词的方式使它无法列出疾病列表.所以我创建了has_diseases/2一个findall,它可以在任何可以找到的疾病上执行另一个,has_disease/2用作检查.一个setof/3调用用于最后得到疾病列表,并责令其为了方便独特的效果.

NB.在atom/1has_disease/2原始只是保证一个变量不通过在Disease,因为它没有在这种情况下工作,至少不适合我.