Flora-2: An Expressive Knowledge Representation System

Written by on October 28, 2018 in Flora-2, Homeopathy, Knowledge Representation, Programming with 0 Comments

I am always on the lookout for a good Knowledge Representation (KR) system that facilitates modeling and reasoning about real-world knowledge. I have experience with KnowledgeWorks available in LispWorks since I have used it in a few projects. I have also taken a cursory look at PowerLoom and Racer. Last week, I came across Flora-2 and its commercial counterpart ErgoAI from Coherent Knowledge, and decided to check out Flora-2 first. ErgoAI adds several extra capabilities on top of Flora-2 and comes with a 90-day trial license. I hope to experiment with that product later.

Here are some of the attractive features of Flora-2:

* Crisp, expressive syntax

* Partitioning knowledge through module system

* Frames and Object IDs

* Object-orientation with multiple inheritance

* Higher-order syntax

* Reification

* Transaction logic

I downloaded and installed the Windows version from here.

Installation went smoothly (I did not use the default installation directory, but chose a different one for practical reasons).

To start the program, we have to execute runflora.bat located in the flora2 directory. I usually launch the application by double clicking on this file from my File Explorer.

Here is the command shell:

Flora Initial Terminal

Flora Interactive Terminal

We type in commands and queries at the flora2 prompt and the system responds accordingly.

Before we proceed further, of course, we need a Knowledge Base (KB) to work with. After considering a few areas, I finally chose an example from Homeopathy. I practise homeopathy and have even written a repertorization software called iCure many years ago. Therefore, I know the challenges in modelling remedy characteristics and felt it would be a good idea to see how Flora-2 can help in this task.

A word of caution is appropriate here. I am quite raw when it comes to Flora-2, and even though I have gone through the documentation a couple of times, I still feel I haven’t understood some of the finer features of the language. I am sure my modeling capabilities will improve as I spend more time with the product. Nevertheless, I am happy with what I have been able to achieve so far!

The example I have chosen is from the excellent book Pointers to the Common Remedies by Dr. M.L.Tyler. This is a mini therapeutics handbook and has chapters covering several ailments. I have attempted to model 4 remedies from the section Acute Rheumatism (Adults).

Let us look at my rendering of the remedy Aconite:

Modeling Aconite

Modelling Aconite

The representation I am using is called a Frame (actually, a data frame in this case). This format allows us to conveniently and succinctly capture different properties of an object. The object we are talking about is Aconite(Rheumatism(adult)). Those familiar with homeopathy know that the same remedy can cure many ailments if the specific characteristics are present in each case. What this means is the remedy Aconite can cure not just Rheumatism as in this example, but other ailments such as Cough, Fever, Measles, etc., provided the symptoms agree.

So, I decided to add a qualifier to each remedy, indicating the specific ailment we are modelling. Thus, we can have frames for Aconite(Cough), Aconite(Cough(Children))Aconite(Fever), and so on. The qualifier can be complex.

Now, looking inside the frame structure, we have several attributes (or properties) describing the object being talked about. Each of these attributes describes the characteristics and modalities of the remedy that would make it applicable to the current situation. For example, in the case of Aconite (in the context of adult rheumatism), a person who requires this remedy (as opposed to another, say Nux Vomica) is likely to have high fever, inflamed joints, affected parts being swollen and sensitive to touch, and is likely to be mentally anxious and restless. It is also likely that the ailment started after the patient got exposed to cold air.

I hope you can see the characteristics of the remedy quite clearly in this representation. That is the power of a highly expressive KR system such as Flora-2. Of course, I would be able to describe this same knowledge directly in Prolog, but it wouldn’t be this crisp. Indeed, Flora-2 converts this representation into an underlying Prolog format (XSB Prolog), but that is not important to the modeller, since it is a matter of implementation detail (although it does give us an idea of the kind of reasoning we can do with the system).

Let us look at another remedy Bryonia.

Modelling Bryonia

Modelling Bryonia

You can see that this remedy has some attributes in common with Aconite, but there are some new attributes too. For example, Bryonia typically affects synovial membranes (joints, pleura, pericardium and meninges). A patient requiring Bryonia is likely to be mentally irritable (unlike restlessness and anxiety of Aconite), with a white coated tongue and would keep drinking a lot of water. One similarity with Aconite is that the affected part is inflamed in this case too.

There are two convincing reasons why this representation is preferable to natural language representation:

* It is much more readable

* It is possible to do formal reasoning with this representation

The descriptions of other two remedies Nux Vomica and Colchicum also follow same format, and hence there is no need to go into the details. However, a minor aspect regarding the description of Num Vomica might be worth mentioning. See below.

Modelling Nux Vomica

Modelling Nux Vomica

The attributes lumbago and vertigo are essentially boolean valued. I could have written them as lumbago -> true and vertigo -> true, but that is not necessary. This is another nice feature in Flora-2. The attributes can be as simple as such boolean attributes, or they can be complex functions (read the documentation for details).

Having discussed the representation of remedy characteristics, I want to touch upon another interesting aspect of the model. We saw that Bryonia affects synovial membranes, for example, pleura. So if we want to find out which remedies have affinity for pleura, we want to get those remedies that have affinity for synovial membranes. How do we represent this knowledge?

We can easily write a rule in Flora-2 to capture this:

A Rule

A Rule

Such an elegant syntax! We will see how this is useful when I show examples of querying the KB in Flora-2.

OK. Let us now see how to load our KB into Flora-2 system and ask queries.

We can load a KB by enclosing the full pathname in square brackets, followed by a period (“.”) in the Flora-2 prompt. See the following figure:

Loading A KB File

Loading A KB File

Now that the KB file is loaded, we can pose queries about the KB. Let us start with a simple query: What are the “Rheumatism” remedies?

?rem(Rheumatism(?_))[].

The question mark denotes a variable. If it is followed by an identifier, then the variable will have a binding when the query is satisfied by the KB. A question mark that stands by itself, or is followed by “_” is an anonymous variable: it will match anything that occurs in that place but it will not be bound to any value. It is convenient to use such an anonymous variable when we are not interested to know what it matches. 

So, in the above query, we are interested in the name of the remedy, but not what type of Rheumatic remedy it is – whether it is for adults or children, etc. When I enter this query in Flora-2 prompt, this is what I get:

Answer to Query-1

Answer to Query-1

 Next query: ?rem(?_)[affinity_for -> synovial_membrane].

This translates to: Find all remedies (Rheumatism or otherwise) that have affinity for the synovial membrane. Here is the answer:

Answer to Query-2

Answer to Query-2

Third question: ?rem(?_)[pain -> {stitching}, part -> {inflamed}].

I suppose you can guess the question: Which are the remedies that have stitching pains, with inflammation of affected parts? 

Answer to Query-3

Answer to Query-3

The system correctly determines that Bryonia is the matching remedy.

A tricky question this time: ?rem(?_)[affinity_for -> pleura].

Guessed the question?: Which remedies have affinity for “pleura”?

The reason this question is tricky and interesting is because there is no direct match of attribute values in KB. The query will be satisfied only if the system can determine that any remedy that has affinity for synovial membrane will have affinity for pleura. If you remember, we have explicitly added such a rule to the KB to facilitate this type of reasoning. Therefore, Flora-2 has no problem in determining the correct response:

Answer to Query-4

Answer to Query-4

Quite nice, isn’t it?

Here is our last question: ?rem[? -> {face -> hot}, ? -> {chilly}].

This is also an interesting question. We are asking for remedies that have face->hot and chilly for some set of attributes, without mentioning the names of the attributes. This saves some typing, but this is a weak question and might match irrelevant remedies if we are not careful. I am giving this example to show how much flexibility exists in Flora-2‘s query formulation. Here is the answer:

Answer to Query-5

Answer to Query-5

Now that we are done interacting with Flora-2, let us quit the system. To quit the interactive session, type “\halt.” at the prompt.

Quitting Flora-2 Session

Quitting Flora-2 Session

When you go through my KB model, you will find that I have only used the basic features of Flora-2. No object-orientation and no other exotic feature! Other advanced features might be applicable when modelling more complex domains and problems. It is even possible that if I start looking at other remedies and other ailments discussed in the book, I might find more interesting ways to model remedy characteristics. That is precisely how the real-world model evolves. 

At this point, I do not know how Flora-2 performs in the context of large knowledge bases. If I were to convert the entire book of M.L.Tyler (that I have been discussing) into Flora-2 syntax, I expect it will result in a few hundred remedy descriptions. Can Flora-2 handle those well? Maybe ErgoAI can? No idea. But that is not important for now.

Overall, I am quite impressed with Flora-2. I am hoping that in the next several weeks, I will find the time to model other interesting problems using the system, and perhaps even write my own program to interact with Flora-2 engine instead of going through the interactive console that comes as default. So keep watching this space!

You can download my homeopathy KB here.

Have a nice weekend!

Tags: , , , , , ,

About the Author

About the Author: .

Subscribe

If you enjoyed this article, subscribe now to receive more just like it.

Subscribe via RSS Feed

Leave a Reply

Your email address will not be published. Required fields are marked *

Top