Pyke logic programming (16): Question Bank in the Knowledge Base"

Source: Internet
Author: User
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:

  • Ask_tty

    It sends an inquiry through stdout output and receives an answer through stdin input.

  • Ask_wx

    It uses the wxpython dialog box to ask.

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.