[381f18]: doc / html / pyke_syntax / krb_syntax / bc_rule.html Maximize Restore History

Download this file

bc_rule.html    301 lines (285 with data), 17.0 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<!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>Bc_rule Syntax</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">Pyke Syntax</a></li>
<li>&gt;</li>
<li><a href="index.html">KRB Syntax</a></li>
<li>&gt;</li>
<li>Bc_rule</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="normal-nav"><a href="../../knowledge_bases/index.html">Knowledge Bases</a></div>
<div class="title-nav"><a href="../index.html">Pyke Syntax</a></div><div class="nav-branch">
<div class="normal-nav"><a href="../kfb_syntax.html">KFB Syntax</a></div>
<div class="title-nav"><a href="index.html">KRB Syntax</a></div><div class="nav-branch">
<div class="normal-nav"><a href="fc_rule.html">Fc_rule</a></div>
<div class="normal-nav"><a href="bc_rule.html">Bc_rule</a></div>
<div class="normal-nav"><a href="pattern.html">Pattern</a></div>
<div class="normal-nav"><a href="compound_premise.html">Compound Premise</a></div>
<div class="normal-nav"><a href="python_premise.html">Python Premise</a></div>
</div>
<div class="normal-nav"><a href="../kqb_syntax.html">KQB Syntax</a></div>
</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="bc-rule-syntax">
<h1 class="title">Bc_rule Syntax</h1>
<div class="section" id="bc-rule">
<h2>Bc_rule</h2>
<p><a class="reference external" href="../../logic_programming/rules/backward_chaining.html">Backward-chaining</a> <a class="reference external" href="../../logic_programming/rules/index.html">rules</a> have four parts:</p>
<ol class="arabic simple">
<li>A unique name.</li>
<li>A <a class="reference internal" href="#use-clause">use clause</a>.</li>
<li>An optional <a class="reference external" href="bc_rule.html#when-clause">when clause</a>.</li>
<li>An optional <a class="reference external" href="bc_rule.html#with-clause">with clause</a>.</li>
</ol>
<pre class="literal-block">
bc_rule ::= IDENTIFIER NL INDENT
use
[when]
[with]
DEINDENT
</pre>
<p>The <tt class="docutils literal">IDENTIFIER</tt> is the unique name for this <a class="reference external" href="../../logic_programming/rules/index.html">rule</a> and is used as the
corresponding Python function name in the generated &lt;rb_name&gt;_bc.py file
and also for the Python function name of the <a class="reference external" href="../../logic_programming/plans.html">plan</a> function (if any)
associated with the rule. This name will show up in stack traces
associated with exceptions raised during inferencing or plan execution.</p>
</div>
<div class="section" id="use-clause">
<h2>Use Clause</h2>
<p>The <tt class="docutils literal">use</tt> clause is the <strong>then</strong> part of the rule. It identifies the
<em>goal</em> that this rule is prepared to prove.</p>
<pre class="literal-block">
use ::= 'use' IDENTIFIER '(' {pattern,} ')' ['taking' '(' &lt;python_arg_spec&gt; ')'] NL
| 'use' IDENTIFIER '(' {pattern,} ')' NL
INDENT 'taking' '(' &lt;python_arg_spec&gt; ')' NL
DEINDENT
</pre>
<p>Notice that it uses a single <tt class="docutils literal">IDENTIFIER</tt>. The <a class="reference external" href="../../knowledge_bases/rule_bases.html">rule base</a> name is implied
as the <a class="reference external" href="../../knowledge_bases/rule_bases.html#rule-base-categories">rule base category</a> name (the name of the root rule base, see
<a class="reference external" href="index.html#extending-clause">extending clause</a>) for the rule base containing this rule.</p>
<div class="section" id="taking-clause">
<h3>Taking Clause</h3>
<p>The <tt class="docutils literal">use</tt> clause also defines parameters to the <a class="reference external" href="../../logic_programming/plans.html">plan</a> function (if one is
used for this <a class="reference external" href="../../logic_programming/rules/index.html">rule</a>) with the optional <tt class="docutils literal">taking</tt> sub-clause.</p>
<p>The <em>python_arg_spec</em> is not parsed by Pyke, but simply copied to the
output plan function. Do <strong>not</strong> use <tt class="docutils literal">$</tt> with these parameter names (or
their default values).</p>
</div>
</div>
<div class="section" id="when-clause">
<h2>When Clause</h2>
<p>The <tt class="docutils literal">when</tt> clause is the <strong>if</strong> part of the <a class="reference external" href="../../logic_programming/rules/index.html">rule</a>. It defines the
premises that must be true for this rule to succeed.</p>
<p>If the <tt class="docutils literal">when</tt> clause is omitted, the only
requirement for the rule to succeed is that the <tt class="docutils literal">use</tt> clause
<a class="reference external" href="../../logic_programming/pattern_matching/index.html">pattern matches</a> the goal.</p>
<p>If the <tt class="docutils literal">when</tt> clause is specified, the rule succeeds for each combination
of true premises (see <a class="reference external" href="../../logic_programming/rules/index.html#backtracking">backtracking</a>).</p>
<pre class="literal-block">
when ::= 'when' NL INDENT
{bc_premise NL}
DEINDENT
bc_premise ::= ['!'] [ name '.' ] name '(' {pattern,} ')' [ plan_spec ]
| compound_premise
| python_premise
name ::= IDENTIFIER
| '$'IDENTIFIER
</pre>
<p>Here are the links to the definitions for <a class="reference external" href="pattern.html">pattern</a>, <a class="reference external" href="compound_premise.html">compound_premise</a> and
<a class="reference external" href="python_premise.html">python_premise</a>.</p>
<p>If the <em>bc_premise</em> includes the <tt class="docutils literal">!</tt>, an AssertionError will be raised if the
premise fails on the first try. This can help in debugging.</p>
<div class="note">
<p class="first admonition-title">Note</p>
<p class="last">This does not apply when the premise fails on <a class="reference external" href="../../logic_programming/rules/index.html#backtracking">backtracking</a> (in which case
it has already succeeded at least once).</p>
</div>
<p>If a single <em>name</em> is used in the <em>bc_premise</em>,
the <a class="reference external" href="../../knowledge_bases/rule_bases.html#rule-base-categories">rule base category</a> for the current <a class="reference external" href="../../knowledge_bases/rule_bases.html">rule base</a> (the root rule base
name, see <a class="reference external" href="index.html#extending-clause">extending clause</a>) is assumed.</p>
<p>If two <em>names</em> are used in the <em>bc_premise</em>, the first may name a rule
base category or some other <a class="reference external" href="../../knowledge_bases/index.html">knowledge base</a>.</p>
<p>If a rule base category name is used (or assumed), the currently <a class="reference external" href="../../knowledge_bases/rule_bases.html#rule-base-activation">active</a>
<a class="reference external" href="../../knowledge_bases/rule_bases.html">rule base</a> for that category is used to prove the premise.</p>
<div class="note">
<p class="first admonition-title">Note</p>
<p>If the rule base category name is omitted, and therefore assumed
to be the current rule base's rule base category, the current rule base
does <em>not</em> have to be the active rule base for that category. It could be
the case that a derived rule base is the active rule base. In that case,
the derived rule base is used to prove the premise.</p>
<p class="last">In this way, different rules may be used to prove the same premise,
depending upon which rule base has been activated.</p>
</div>
<div class="section" id="plan-spec">
<h3>Plan_spec</h3>
<p>A <em>plan_spec</em> is required for each premise that returns a subordinate <a class="reference external" href="../../logic_programming/plans.html">plan</a>.
This shows what should be done with that subordinate <a class="reference external" href="../../logic_programming/plans.html">plan</a> function.</p>
<p>Thus, a rule's plan function is composed first of the collected
python_statements taken from its plan_specs (as described below), followed by
the python_statements within its <a class="reference external" href="bc_rule.html#with-clause">with clause</a> (if any). The inclusion of
any plan_spec containing a python_statement will cause a <a class="reference external" href="../../logic_programming/plans.html">plan</a> function to be
generated for this rule, even if the rule lacks a <tt class="docutils literal">with</tt> clause.</p>
<pre class="literal-block">
plan_spec ::= [ 'step' NUMBER ] NL INDENT
{&lt;python_statement&gt; NL}
DEINDENT
| 'as' '$'IDENTIFIER NL
</pre>
<p>Within each python_statement, the subordinate plan function is indicated by
<tt class="docutils literal">$$</tt>. The result of this function may be assigned to a Python variable,
but not a <a class="reference external" href="pattern.html#pattern-variable">pattern variable</a> (<tt class="docutils literal">$variable</tt>).
Parameters from the rule's <tt class="docutils literal">taking</tt> clause may be passed on to the
subordinate <a class="reference external" href="../../logic_programming/plans.html">plan</a> functions.</p>
<p>When multiple premises have python_statements in their <em>plan_specs</em>, the
python_statements in plan_specs <em>without</em> a <tt class="docutils literal">step</tt> clause are executed first
in the order that they appear in the <tt class="docutils literal">when</tt> clause.</p>
<p>Then the python_statements in plan_specs <em>with</em> a <tt class="docutils literal">step</tt> clause are
executed in ascending NUMBER sequence. It is permissible for the NUMBER
to be negative or a float.</p>
<p>If the <tt class="docutils literal">as</tt> clause is used, the plan function is bound to the
pattern variable as a Python function, but not automatically executed.
This allows you to call the function (or not) when and as many times as you
please. The parameters required are defined in the <tt class="docutils literal">taking</tt> clause of the
rule used to prove the premise.</p>
<div class="note">
<p class="first admonition-title">Note</p>
<p class="last">Within a <a class="reference external" href="compound_premise.html#forall-premise">forall</a> or <a class="reference external" href="compound_premise.html#notany-premise">notany</a> premise, the only <tt class="docutils literal">plan_spec</tt> that may be
used is the <tt class="docutils literal">as</tt> clause.</p>
</div>
</div>
</div>
<div class="section" id="with-clause">
<h2>With Clause</h2>
<p>The <tt class="docutils literal">with</tt> clause contains Python statements to include in the <a class="reference external" href="../../logic_programming/plans.html">plan</a>
produced by this <a class="reference external" href="../../logic_programming/rules/index.html">rule</a>. These Python statements may include
<a class="reference external" href="pattern.html#pattern-variable">pattern variables</a> whose values will be <a class="reference external" href="../../about_pyke/cooking_functions.html">cooked</a> into these statements
when the plan is created.</p>
<pre class="literal-block">
with ::= 'with' NL INDENT
{&lt;python_statement&gt; NL}
DEINDENT
</pre>
<p>The <em>python_statements</em> are included in the rule's plan function after
all of the calls to the subordinate plan functions made from the
<em>plan_specs</em> in the <a class="reference external" href="bc_rule.html#when-clause">when clause</a>.</p>
<p>If the <tt class="docutils literal">with</tt> clause is omitted, but the <tt class="docutils literal">when</tt> clause has <em>plan_specs</em>
(excluding the <em>as</em> clause), a plan function is still generated for this
rule so that the subordinate plan functions are still called.</p>
<p>The <em>python_statements</em> are not parsed. They are simply scanned for <tt class="docutils literal">$</tt>
pattern variables that don't occur within string literals or comments.
The values bound to these variables are <a class="reference external" href="../../about_pyke/cooking_functions.html">cooked</a> into the code to produce the
plan.</p>
<p>Thus, all pattern variables used within <em>python_statements</em> (both in the
<tt class="docutils literal">plan_specs</tt> and the <tt class="docutils literal">when</tt> clause) must be bound to a value. This
value is a constant value that never changes for this <a class="reference external" href="../../logic_programming/plans.html">plan</a>.</p>
<div class="note">
<p class="first admonition-title">Note</p>
<p class="last">This occurs after the entire top-level goal is proven so that it is
permissible to bind these pattern variables to values <em>following</em> the
execution of the rule containing them.</p>
</div>
<!-- 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="fc_rule.html">Fc_rule Syntax</a><p>The syntax of a forward-chaining rule.</p>
</div>
<div class="right-item"><a href="bc_rule.html">Bc_rule Syntax</a><p>The syntax of a backward-chaining rule.</p>
</div>
<div class="right-item"><a href="pattern.html">Pattern Syntax</a><p>The syntax of a pattern used to match data values.</p>
</div>
<div class="right-item"><a href="compound_premise.html">Compound Premise Syntax</a><p>The syntax of compound premises.</p>
</div>
<div class="right-item"><a href="python_premise.html">Python Premise Syntax</a><p>The syntax of a <em>python_premise</em>.</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
Mon, Oct 27 2008.
</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>