Question Bank
The question bank is prepared for the program customer. These "problems" can be of different types, such as "yes/no ?" , "Select the number ?" And so on. The question may contain variable parameters. When you ask the customer, the parameter value replaces the text content in the question. Different parameter values pose different problems.
All answers to questions are automatically recorded. If there are several rules to ask the same question, the customer only needs to answer it once. When the inference engine restarts, all these answers are cleared.
"Question" can be accompanied by some comments and other information. This is prepared in advance, with variable parameters in combination. The attached information is automatically displayed based on the customer's answer.
Kqb File
These problems are defined in the. kqb file. The name of the Question Bank. It is the name of the file with the extension. kqb. The question Library name must be a valid Python identifier.
When you create a knowledge_engine.engine object, the. kqb file is automatically compiled and loaded into the memory.
The information in the. kqb file is all the questions to be asked to the customer, the tests to the answers, and the review Information to be displayed.
The. kqb file specifies which parameter contains the answer to the question. Before asking, except for the answer, other parameters must be restricted to specific values.
Example
You have written a car fault diagnosis program. You can use the question bank named user_question. The problem is as follows:
engine_starts($ans) Can you start the engine? --- $ans = ynmileage($ans) How many miles are on the car? --- $ans = integer(1-999999) 200000- ! Wow, that's a lot of miles!noise_from($location, $ans) Do you hear a noise from $location? --- $ans = yn
These problems seem to be the facts in the following rules:
user_question.engine_starts(True)user_question.mileage($mileage)user_question.noise_from('under the hood', False)
Ask the customer
Pyke has two modules to ask your program users:
You can write a module to ask the customer. See the example in the Pyke user guide.
When Pyke answers a question, you need to find the ask_module ("Reply module") attribute:
- Question_base ("Question Bank") object
- Knowledge_engine.engine ("Knowledge Base inference engine") object
The following is an example of setting the ask_module attribute:
>>> from pyke import knowledge_engine>>> from pyke import ask_wx>>> engine = knowledge_engine.engine(__file__)>>> engine.ask_module = ask_wx