Advanced KWI Programming
KnowledgeWright can call-out for two different purposes:
The normal reasoning process when 'solve' is called looks like this:
{Solve from the top}
Find value for goal A...
Processing rule B...
Processing rule C...
Found value for D...
Found value for E...
Processing rule F...
No value for G...
{Assert value for G}
{Solve from the top again}
Find value for goal A...
Processing rule B...
Processing rule C...
Found value for D...
Found value for E...
Processing rule F...
Found value for G...
No value for H...
For large knowledgebases and very high-performance web-servers, the efficiency can be improved by some advanced programming techniques. An improvement can be made because each time 'solve' is called, the reasoning process is restarted from the top. You can change this process to look like the following instead:
{Solve}
Find value for goal A...
Processing rule B...
Processing rule C...
Found value for D...
Found value for E...
Processing rule F...
Asking value for G...
Asking value for H...
Found value for rule F...
Asking value for I...
The way to do this is to define a call-back predicate named caller_ask which is defined as follows:
caller_ask(user, +FACT, -VALUE, +PROPERTIES)
Instead of processing the actions with KWI call to get_action, you can return a value immediately with caller_ask. FACT is the name of the object. PROPERTIES is the same list of properties that you get from the KWI call to get_action, e.g.
caller_ask(question, colors, VALUE, [prompt = "What are your favorite colors?", question_type = menu_multiple_choices, choices = ["red", "orange", "yellow", "green", "blue", "idigo", "violet"] ])
You return the answer in VALUE in the same format as you would for the KWI call to assert. Then the KnowledgeWright reasoning engine can continue processing.
If your knowledgebase returns intermediate results, that is it has a list of goals to solve instead of a single text object, then similar efficiencies can be achieved by creating a predicate for caller_tell which is defined as follows:
caller_tell(user, +PROPERTIES)
Like caller_ask the PROPERTIES is the same list of properties you get from the KW call to get_action, e.g.
caller_tell(user, [goal = "moods", text = "Your colors indicate you are in a good mood."] )
There are two ways to include your code for caller_ask and caller_tell.
When the KnowledgeWright reasoning engine starts, it will try to load a file named 'kwextensions.plm' in the same directory where the .kb file is located. This is a Prolog object code file created by Amzi! Prolog + Logic Server.
If you are calling your knowledgebase from a host language like Java or Visual Basic, you can define extended predicates named caller_ask/4 and caller_tell/2. You add these predicates when you initialize the Amzi! Logic Server with lsInit and lsLoad. See the Amzi! Logic Server for documentation and samples on how to do this.
Another (and the most difficult) option is to create your own Logic Server Extension. This is a .dll library under Windows and a .so library under Unix. LSX's can be written in almost any language. These are most useful when you want to use a different language to perform input and output than is hosting the application. See the Amzi! Logic Server for documentation and samples on how to do this.
|
|
Copyright ©1995-2006 Amzi!
inc. All Rights Reserved. Privacy Policy.
Amzi!, KnowledgeWright and WebLS are registered
trademarks and Adventure in Prolog, Logic Server, Logic Explorer, Adventure
in Prolog and Subscription Plus are trademarks of Amzi! inc.