[9f7068]: doc / html / knowledge_bases / question_bases.html Maximize Restore History

Download this file

question_bases.html    222 lines (206 with data), 9.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Question Bases</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="../stylesheets/pyke.css" type="text/css" />
</head>
<body>
<table id="page-table">
<thead class="head">
<tr id="header1"><th id="header" colspan="3">
&nbsp;
</th></tr>
<tr id="header2">
<th id="crumb-left"></th>
<th id="crumb-line">
<div id="nav">
<ul>
<li><a href="../index.html">Home</a></li>
<li>&gt;</li>
<li><a href="index.html">Knowledge Bases</a></li>
<li>&gt;</li>
<li>Question Bases</li>
</ul>
</div>
</th>
<th id="crumb-right"></th>
</tr>
</thead>
<tbody id="body">
<tr id="body-tr">
<td id="left-nav">
<div id="left-nav-div">
<div class="title-nav"><a href="../index.html">Home</a></div><div class="nav-branch">
<div class="normal-nav"><a href="../about_pyke/index.html">About Pyke</a></div>
<div class="normal-nav"><a href="../logic_programming/index.html">Logic Programming</a></div>
<div class="title-nav"><a href="index.html">Knowledge Bases</a></div><div class="nav-branch">
<div class="normal-nav"><a href="fact_bases.html">Fact Bases</a></div>
<div class="normal-nav"><a href="rule_bases.html">Rule Bases</a></div>
<div class="normal-nav"><a href="question_bases.html">Question Bases</a></div>
<div class="normal-nav"><a href="special.html">Special</a></div>
</div>
<div class="normal-nav"><a href="../pyke_syntax/index.html">Pyke Syntax</a></div>
<div class="normal-nav"><a href="../using_pyke/index.html">Using Pyke</a></div>
<div class="normal-nav"><a href="../examples.html">Examples</a></div>
<div class="normal-nav"><a href="../PyCon2008-paper.html">PyCon 2008 Paper</a></div>
</div>
</div>
<div id="icons">
<div id="project-page">
<a href="http://sourceforge.net/projects/pyke/">Pyke Project Page</a>
</div>
Please Make a Donation:<br />
<a href="http://sourceforge.net/donate/index.php?group_id=207724">
<img src="http://images.sourceforge.net/images/project-support.jpg"
width="88" height="32" border="0"
alt="Support This Project" /> </a> <br /><br />
Hosted by: <br />
<a href="http://sourceforge.net/projects/pyke">
<img src="http://sflogo.sourceforge.net/sflogo.php?group_id=207724&amp;type=14"
width="150" height="40"
alt="Get Python Knowledge Engine (PyKE) at SourceForge.net. Fast, secure and Free Open Source software downloads" /></a>
</div>
</td>
<td id="main-td">
<div id="main">
<a name="startcontent" id="startcontent"></a>
<div class="document" id="question-bases">
<h1 class="title">Question Bases</h1>
<p>Question bases contain questions for end users. These questions can be of
various types (e.g., yes/no, multiple_choice). The questions may be
parametrized, with the parameter values substituted into the question text
when the question is asked. In this case, different parameter values are
treated as different question <a class="reference external" href="../logic_programming/statements.html">statements</a>.</p>
<p>The answers to all questions are automatically remembered so that if multiple
rules ask the same question, the end user only sees it once. These answers
are erased when an <a class="reference external" href="../using_pyke/index.html#setting-up-different-cases">engine.reset</a> is done.</p>
<p>Finally, questions may have <em>reviews</em> attached to them to automatically
display different canned messages (with parameter substitution) depending on
the end user's answer.</p>
<div class="section" id="kqb-files">
<h2>KQB files</h2>
<p>Each question base is defined by a <a class="reference external" href="../pyke_syntax/kqb_syntax.html">.kqb file</a>. The name of each question
base is the filename of the .kqb file (with the <tt class="docutils literal"><span class="pre">.kqb</span></tt> suffix removed).
This must be a legal Python identifier.</p>
<p>These .kqb files are compiled and loaded automatically when you create your
<a class="reference external" href="../using_pyke/creating_engine.html">knowledge_engine.engine</a> object.</p>
<p>The .kqb file contains all of the information about the question needed to
ask the question, validate the answer, and output the appropriate <em>review</em>
text.</p>
<p>The .kqb file also specifies which parameter contains the answer. All
parameters, except this one, must be bound to values before testing the
question.</p>
</div>
<div class="section" id="example">
<h2>Example</h2>
<p>In writing a program to diagnose car problems, you might have a
<tt class="docutils literal"><span class="pre">user_question</span></tt> question base with questions like:</p>
<pre class="literal-block">
engine_starts($ans)
Can you start the engine?
---
$ans = yn
mileage($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
</pre>
<p>These would look like the following <a class="reference external" href="../logic_programming/statements.html">statements</a> within <a class="reference external" href="../logic_programming/rules/index.html">rules</a>:</p>
<pre class="literal-block">
user_question.engine_starts(True)
user_question.mileage($mileage)
user_question.noise_from('under the hood', False)
</pre>
</div>
<div class="section" id="presenting-questions-to-your-end-users">
<h2>Presenting Questions to Your End Users</h2>
<p>Pyke provides two modules to actually present a question to your end user:</p>
<ul>
<li><p class="first">ask_tty</p>
<p>This presents the question on stdout and reads stdin for the answer.</p>
</li>
<li><p class="first">ask_wx</p>
<p>This presents the question in a dialog box for use with <a class="reference external" href="http://www.wxpython.org/">wxpython</a>.</p>
</li>
</ul>
<p>You may write your own module to present questions to end users. Look at the
modules provided by Pyke for guidance.</p>
<p>To ask a question, Pyke looks for an <tt class="docutils literal"><span class="pre">ask_module</span></tt> attribute on:</p>
<ol class="arabic simple">
<li>the question_base object, then</li>
<li>the <a class="reference external" href="../using_pyke/creating_engine.html">knowledge_engine.engine</a> object</li>
</ol>
<p>If the <a class="reference external" href="../using_pyke/creating_engine.html">knowledge_engine.engine</a> object does not have an <tt class="docutils literal"><span class="pre">ask_module</span></tt>
attribute, ask_tty is imported (by default) and stored there.</p>
<!-- This code is hidden. It will add '' to sys.path, change to the doc.examples
directory and store the directory path in __file__ for the code section
following:
>>> import sys
>>> if '' not in sys.path: sys.path.insert(0, '')
>>> import os
>>> os.chdir("../../examples")
>>> __file__ = os.getcwd() -->
<p>Here's an example of setting this attribute:</p>
<pre class="literal-block">
&gt;&gt;&gt; from pyke import knowledge_engine
&gt;&gt;&gt; from pyke import ask_wx
&gt;&gt;&gt; engine = knowledge_engine.engine(__file__)
&gt;&gt;&gt; engine.ask_module = ask_wx
</pre>
<!-- ADD_LINKS MARKER -->
</div>
</div>
<!-- <div id="return-to-top">
<a href="#">Return to Top</a>
</div>
-->
</div>
</td>
<td id="right-nav">
<div id="right-nav-div">
<h3>More:</h3>
<div class="right-item"><a href="fact_bases.html">Fact Bases</a><p>Explanation of facts and fact bases.</p>
</div>
<div class="right-item"><a href="rule_bases.html">Rule Bases</a><p>Explanation of rule bases, overview of .krb files and how these files
are compiled and loaded into your Python program.</p>
</div>
<div class="right-item"><a href="question_bases.html">Question Bases</a><p>Explanation of question bases and .kqb files.</p>
</div>
<div class="right-item"><a href="special.html">Special</a><p>Explanation of the <tt class="docutils literal"><span class="pre">special</span></tt> knowledge base.</p>
</div>
</div>
</td>
</tr>
</tbody>
<tfoot id="foot">
<tr id="foot2">
<td id="copyright" colspan="3">
Copyright &copy; 2007-2009 Bruce Frederiksen
</td>
</tr>
</tfoot>
</table>
<div id="last-modified">
Page last modified
Fri, Mar 05 2010.
</div>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ?
"https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost +
"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-6310805-1");
pageTracker._trackPageview();
} catch(err) {}
</script>
</body>
</html>