[4dca5a]: doc / html / logic_programming / statements.html  Maximize  Restore  History

Download this file

267 lines (254 with data), 12.1 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
<!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>Statements</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">Logic Programming</a></li>
<li>&gt;</li>
<li>Statements</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="title-nav"><a href="index.html">Logic Programming</a></div><div class="nav-branch">
<div class="normal-nav"><a href="statements.html">Statements</a></div>
<div class="normal-nav"><a href="pattern_matching/index.html">Pattern Matching</a></div>
<div class="normal-nav"><a href="rules/index.html">Rules</a></div>
<div class="normal-nav"><a href="plans.html">Plans</a></div>
</div>
<div class="normal-nav"><a href="../knowledge_bases/index.html">Knowledge Bases</a></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="statements">
<h1 class="title">Statements</h1>
<p>A <em>statement</em> is a statement of fact, also just called a <em>fact</em>. They are
the bread and butter of Pyke. Statements are the data values that Pyke acts
upon.</p>
<p>You might also think of a statement as a spoken sentence. For example, the
Pyke <a class="reference external" href="../examples.html#family-relations">family_relations</a> example deals with sentences like:</p>
<pre class="literal-block">
&quot;Bruce is the son of Thomas (his father) and Norma (his mother).&quot;
</pre>
<p>But we condense the sentence down to it's essence. In this case, the sentence
revolves around three things: Bruce, Thomas and Norma. All of the rest of the
words can be condensed into a single identifier that identifies the
relationship between these three things:</p>
<pre class="literal-block">
son_of(Bruce, Thomas, Norma)
</pre>
<p>We can give these condensed sentence structures any names that we want. In
this case, I chose <tt class="docutils literal"><span class="pre">son_of</span></tt>. I might have also chosen &quot;parents_of&quot;, which
might conjure the following English sentence:</p>
<pre class="literal-block">
&quot;The parents of Bruce are Thomas (his father) and Norma (his mother).&quot;
</pre>
<p>Or:</p>
<pre class="literal-block">
&quot;Bruce's parents are Thomas (his father) and Norma (his mother).&quot;
</pre>
<p>But the <tt class="docutils literal"><span class="pre">son_of</span></tt> form carries the additional information that Bruce is a son
rather than a daughter. So this is the form used in the family_relations
example.</p>
<div class="caution">
<p class="first admonition-title">Caution!</p>
<p class="last">Statements are not functions!
When we wear our Python hats, <tt class="docutils literal"><span class="pre">son_of(Bruce,</span> <span class="pre">Thomas,</span> <span class="pre">Norma)</span></tt> looks like a
function call! We might expect that it can be executed to <em>do</em> something
and possibly return a value. But when we wear our Pyke hats, this is just
a statement, or a piece of data. It doesn't <em>do</em> anything and it <strong>never</strong>
returns a value!</p>
</div>
<p>Note that it makes perfect sense to have several statements defining the same
relationship between their arguments:</p>
<pre class="literal-block">
son_of(Bruce, Thomas, Norma)
son_of(Michael, Bruce, Marilyn)
son_of(David, Bruce, Marilyn)
</pre>
<p>But this only makes sense if they have different arguments. There is never a
need to state the same fact twice. Thus we can never establish two facts (two
statements) that are identical. If we try to do this, the second one is
silently ignored.</p>
<p>So:</p>
<pre class="literal-block">
son_of(Bruce, Thomas, Norma)
son_of(Bruce, Thomas, Norma)
son_of(Bruce, Thomas, Norma)
</pre>
<p>is exactly the same as:</p>
<pre class="literal-block">
son_of(Bruce, Thomas, Norma)
</pre>
<p>Finally, we see that the position of each argument is important. In our
<tt class="docutils literal"><span class="pre">son_of</span></tt> example, the meaning of each argument is:</p>
<pre class="literal-block">
son_of(son, father, mother)
</pre>
<p>Thus, changing the order of the arguments changes the meaning of the
statement. So:</p>
<pre class="literal-block">
son_of(Bruce, Thomas, Norma)
</pre>
<p>and:</p>
<pre class="literal-block">
son_of(Bruce, Norma, Thomas)
</pre>
<p>mean different things! The first statement says that Thomas is the father of
Bruce, but the second statement says that Norma is the father!</p>
<div class="section" id="syntactic-structure-of-statements">
<h2>Syntactic Structure of Statements</h2>
<p>So we see that statements in Pyke are very structured.</p>
<p>Pyke categorizes statements into <a class="reference external" href="../knowledge_bases/index.html">knowledge bases</a>. You create knowledge
bases to help you organize your statements. A <em>knowledge base</em> in Pyke
roughly corresponds to a <em>module</em> in Python.</p>
<div class="note">
<p class="first admonition-title">Note</p>
<p class="last">Pyke does not allow knowledge bases to contain other knowledge bases, only
information about statements. Thus, there is only one level of knowledge
bases; and beneath each knowledge base, one level of statements.</p>
</div>
<p>So statements have three components:</p>
<ol class="arabic simple">
<li>The name of a knowledge base. For example, <tt class="docutils literal"><span class="pre">family</span></tt>.</li>
<li>The name of a <em>knowledge entity</em>. For example, <tt class="docutils literal"><span class="pre">son_of</span></tt>.</li>
<li>The statement arguments. These are just Python data. Currently in Pyke,
there is a push for these arguments to be immutable.</li>
</ol>
<p>The syntax for a statement looks like this:</p>
<pre class="literal-block">
statement ::= IDENTIFIER '.' IDENTIFIER '(' {argument,} ')'
</pre>
<div class="section" id="knowledge-base">
<h3>Knowledge Base</h3>
<p>The first IDENTIFIER is the name of the knowledge base. In our
family_relations example, this is <tt class="docutils literal"><span class="pre">family</span></tt>.</p>
<div class="note">
<p class="first admonition-title">Note</p>
<p class="last">You'll see that within <a class="reference external" href="rules/backward_chaining.html">backward-chaining rules</a>, the name of the
knowledge base may be omitted. It defaults to the currently selected
<a class="reference external" href="../knowledge_bases/rule_bases.html">rule base</a> for this <a class="reference external" href="../knowledge_bases/rule_bases.html#rule-base-categories">rule base category</a>. You'll learn more about this
later.</p>
</div>
</div>
<div class="section" id="knowledge-entity">
<h3>Knowledge Entity</h3>
<p>The second IDENTIFIER is the name of the <em>knowledge entity</em>. This is the
relationship between the arguments. You could also think of this as the
statement <em>type</em> or <em>topic</em>. For example, <tt class="docutils literal"><span class="pre">son_of</span></tt> is a <em>type</em> of statement
with three arguments: (son, father, mother). Or the (son, father, mother)
arguments are about the <em>topic</em> <tt class="docutils literal"><span class="pre">son_of</span></tt>.</p>
</div>
<div class="section" id="arguments">
<h3>Arguments</h3>
<p>The arguments can be any simple Python data value (numbers, strings, None,
True or False) or tuples of these values (including nested tuples).
Currently, statements are supposed to be immutable, so all of the arguments
are immutable. The arguments relate to the topic, above, to make a complete
statement.</p>
<div class="note">
<p class="first admonition-title">Note</p>
<p class="last"><a class="reference external" href="http://en.wikipedia.org/wiki/Prolog">Prolog</a> allows arguments to be other statements (functors). But Pyke needs
to integrate into Python and Python has no concept of a &quot;statement&quot;. So we
just use tuples in Pyke because Python is very happy with tuples!</p>
</div>
<p>So the complete statement for our family_relations example is:</p>
<pre class="literal-block">
family.son_of(Bruce, Thomas, Norma)
</pre>
<!-- ADD_LINKS MARKER -->
</div>
</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="statements.html">Statements</a><p>What is a <em>statement</em> in Pyke?</p>
</div>
<div class="right-item"><a href="pattern_matching/index.html">Pattern Matching</a><p>Explanation of <em>pattern matching</em> and <em>pattern variables</em>.</p>
</div>
<div class="right-item"><a href="rules/index.html">Rules</a><p>Explanation of <em>rules</em>, <em>forward-chaining</em> and <em>backward-chaining</em>.</p>
</div>
<div class="right-item"><a href="plans.html">Plans and Automatic Program Generation</a><p>Explanation of <em>plans</em> and automatic program generation.</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>

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks