Page 1 of 1

### How to create an expert system in visual prolog

Posted: 26 Dec 2014 9:32
I am a newbie in prolog and would like friends to help me with my project, I have successfully built a prolog program to get information from the user to diagonize tuberculosis but I do not know how to set the rules that should be followed to tell the user he or she has tuberculosis

Take for instance the user logs in his information such as Name, Age and then states how high his cough, weight loss etc. is.

I want to set the following rules to clarify that the user has typhoid
Rule 01: IF cough > 3 weeks = high and weight loss = high and fever = high and drenching night sweats = mild and loss of appetite = high and anaemia = mild and sputum AFB = high and mantoux = moderate THEN TB = very high.

Rule 02: IF cough > 3 weeks = moderate and weight loss = low and fever = low and drenching night sweats = low and loss of appetite = low and anaemia = low and sputum AFB = low and mantoux = low THEN TB = low.

Please how do i set this rules and can someone please link me to a tutorial and an example on it.

I would be very grateful thanks in advance

Posted: 29 Dec 2014 13:06
off the top of my head, here is one way to do this: (not tested and may not be 100% syntactically correct)

Code: Select all

``````constants
low =1.
mild = 2.
high = 3.
moderate = 4.

Predicate
tb_test(integer Weeks, integer WL, integer Fever, integer NS, integer LOA, integer Sputnum ...).

Clauses
tb_test(Weeks, high, high, mild, high, ...) = veryHigh :-  % rule 1
Weeks >3.
tb_test(Weeks, moderate, low, low, low, ...) = low :-  % rule 2
Weeks >3.``````
....

***********************
basically, set up a predicate with the number or arguments matching the number of conditions. In the case of Weeks, it is a duration so you can put that condition check in the body of the clause. The rest seem to be defined scalar values (high, moderate, low, etc.). Call the predicate from wherever you have collected all the conditions.

You would need to create a rule for each combination of conditions. This can be long and tedious and all rules are then 'hard coded.'

This approach will give you a deeper understanding of rules processing. Once you get a firm foundation under your belt, there are many ways this can be optimized and made more abstract (i.e., an abstract rule with no 'hard coded' conditions that still gives the same results).

### Thanks

Posted: 1 Jan 2015 11:17
Thanks very much am so grateful, I av not been able to reply the message because of bad internet connections where I come from.

I downloaded the two books from this website. I am hoping if you could give me a link to a good book on how to create an expert system with visual prolog, cause am willing to learn.

Dont know much on functional programming although am quite good with object oriented programming would love to learn more.

Thanks and HAPPY NEW YEAR to you guys