0

I'm trying to define a knowledge base where a disease has a list of symptoms. Here's a snippet:

import pytholog as pl
diseases_kb = pl.KnowledgeBase()
diseases_kb([
     "disease(diabetes, [frequent_urination, extreme_thirst])",
     "disease(pneumonia, [cough, fever, shortness_of_breath])",
])

However, when I query this:

print(diseases_kb.query(pl.Expr("disease(diabetes, Symptoms)")))

it just returns ['No'].

It looks like, lists are not being recognized by pytholog. I tried using (), list(), whatever syntax that I hope would work but nothing works. The library removes '(' and ')', and splits the queries by ',' which I think is the reason why it's not recognizing lists. Is there a workaround for this?

5
  • disease(diabetes, [frequent_urination, extreme_thirst]) I assume it's because the kb doesn't know by default that a list of things following a disease are called symptoms. So when you ask for Symptoms, the kb has never seen that word before and doesn't know what it is. Anyway, I'm no expert, and this is just a guess. Commented Apr 15, 2023 at 17:57
  • Rules such as disease_symptom(pneumonia, cough) etc. would be easier to understand and work with. No need to create lists yourself. Commented Apr 15, 2023 at 19:04
  • @brebs you're right that it is easier to understand but given a long list of diseases and symptoms, I think it might be more optimal to use a list. As a workaround though, I will be defining them individually. I also need to create a function to see if the set of symptoms a patient has is a subset of a disease's list of symptoms which I think is also easier to do if I can make the symptoms list work. Functions like setof, findall, etc. don't seem to work on pytholog either. (I'm new to logic programming so maybe there's a much easier way?) Commented Apr 16, 2023 at 8:58
  • Why use pytholog, rather than a full-featured Prolog such as swi-prolog.org ? Commented Apr 16, 2023 at 9:10
  • 1
    @brebs Have to deploy it on streamlit since I need to create a shareable user interface for it. Sadly, libraries like pyswip don't correctly work on streamlit, I'm assuming it's because of issues in dependencies. Pytholog is the only one that works but it doesn't have all features. Commented Apr 16, 2023 at 9:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.