Reputation: 943
I have following facts in Prolog. symptom (A,B,C): symptom A in region B can be caused by virus C (abbreviation, full name)
symptom(delirium,mind,virus(rbs, rabies)).
symptom(delirium,mind,virus(tbe, tick-borne-encephalitis)).
symptom(discomfort,mind,virus(rbs, rabies)).
...
I want to ask what type of viruses can for example cause a specific symptom. For this I want to declare a rule 'causedBy(X,Y)' where in query I could send the symptom and it gives me the list of possible viruses.
The question is how can I just send the symptom and get the list of only abbreviations of possible viruses?
Upvotes: 1
Views: 775
Reputation: 726809
You can do it like this:
causedBy(X,Y) :- symptom(X, _, virus(Y, _)).
(demo in SWI Prolog on ideone).
The process of unification is recursive, you can nest names as deeply as you need for unifying with your facts. In this case, virus(Y, _)
is nested inside symptom/3
call to "extract" only the first element of the virus
pair.
Upvotes: 1