[97f053]: doc / html / pyke_syntax / index.html Maximize Restore History

Download this file

index.html    211 lines (199 with data), 11.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
<!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>Pyke 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>Pyke Syntax</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="normal-nav"><a href="krb_syntax/index.html">KRB Syntax</a></div>
<div class="normal-nav"><a href="kqb_syntax.html">KQB Syntax</a></div>
</div>
<div class="normal-nav"><a href="../using_pyke.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"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=207724&amp;type=3" width="125" height="37" border="0" alt="SourceForge.net Logo" /></a> -->
<a href="http://sourceforge.net"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=207724&amp;type=4" width="125" height="37" border="0" alt="SourceForge.net Logo" /></a>
</div>
</td>
<td id="main-td">
<div id="main">
<a name="startcontent" id="startcontent"></a>
<div class="document" id="pyke-syntax">
<h1 class="title">Pyke Syntax</h1>
<div class="section">
<h2><a id="source-files" name="source-files">Source Files</a></h2>
<p>Pyke has three different kinds of source files for the three main types of
<a class="reference" href="../knowledge_bases/index.html">knowledge bases</a>:</p>
<ol class="arabic simple">
<li><em>Knowledge Fact Base</em> (KFB) files for <a class="reference" href="../knowledge_bases/fact_bases.html">fact bases</a>.</li>
<li><em>Knowledge Rule Base</em> (KRB) files for <a class="reference" href="../knowledge_bases/rule_bases.html">rule bases</a>.</li>
<li><em>Knowledge Question Base</em> (KQB) files for <a class="reference" href="../knowledge_bases/question_bases.html">question bases</a>.</li>
</ol>
<p>Each type of source file ends in a different file suffix: <tt class="docutils literal"><span class="pre">.kfb</span></tt>,
<tt class="docutils literal"><span class="pre">.krb</span></tt> or <tt class="docutils literal"><span class="pre">.kqb</span></tt>.</p>
<p>Place all of these source files into a directory structure. Then include this
directory as an argument to the <a class="reference" href="../using_pyke.html#initializing-pyke">knowledge_engine.engine</a> constructor.
This will recursively search your directory for these three types of source
files, compile them, and load them into the engine. How you organize these
files into subdirectories is up to you -- the directory structure does not
matter to Pyke.</p>
<p>The <tt class="docutils literal"><span class="pre">.kfb</span></tt> and <tt class="docutils literal"><span class="pre">.kqb</span></tt> files are compiled into Python <a class="reference" href="http://docs.python.org/lib/module-pickle.html">pickles</a> with
<tt class="docutils literal"><span class="pre">.fbc</span></tt> and <tt class="docutils literal"><span class="pre">.qbc</span></tt> suffixes.</p>
<p>The <tt class="docutils literal"><span class="pre">.krb</span></tt> files are compiled into up to three <tt class="docutils literal"><span class="pre">.py</span></tt> source files.
The names of these <tt class="docutils literal"><span class="pre">.py</span></tt> files are the same as the <tt class="docutils literal"><span class="pre">.krb</span></tt> file, but with
different endings:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">_fc</span></tt> (if there are any <a class="reference" href="../logic_programming/rules/forward_chaining.html">forward-chaining</a> rules)</li>
<li><tt class="docutils literal"><span class="pre">_bc</span></tt> (if there are any <a class="reference" href="../logic_programming/rules/backward_chaining.html">backward-chaining</a> rules) and</li>
<li><tt class="docutils literal"><span class="pre">_plans</span></tt> (if any of the backward-chaining rules have a <a class="reference" href="../logic_programming/plans.html">plan</a>)</li>
</ul>
<p>These <tt class="docutils literal"><span class="pre">.py</span></tt> files are then automatically imported to define the rule base.
This causes Python to compile them into <tt class="docutils literal"><span class="pre">.pyc</span></tt> or <tt class="docutils literal"><span class="pre">.pyo</span></tt> files.</p>
<p>Subsequent runs of the <a class="reference" href="../using_pyke.html#initializing-pyke">knowledge_engine.engine</a> constructor only recompile
the Pyke source files that have changed since the last time they were compiled.</p>
<p>The name of each knowledge base is the filename of the Pyke source file with
the suffix removed. This must be a legal Python identifier.</p>
</div>
<div class="section">
<h2><a id="syntax-legend" name="syntax-legend">Syntax Legend</a></h2>
<p>To describe this syntax, the following punctuation is used:</p>
<dl class="docutils">
<dt>'<em>any_chars</em>'</dt>
<dd>Required punctuation or keyword: <em>any_chars</em>.</dd>
<dt><em>a</em> | <em>b</em></dt>
<dd>Alternation: <em>a</em> or <em>b</em>.</dd>
<dt>[<em>a</em>]</dt>
<dd>Optional <em>a</em>.</dd>
<dt>{<em>a</em>}</dt>
<dd>One or more <em>a</em>'s. <strong>But</strong> it is understood that if <em>a</em> ends in a comma,
the last comma is optional.</dd>
<dt>IDENTIFIER</dt>
<dd>Any legal Python identifier. Example: <em>foobar</em></dd>
<dt>NUMBER</dt>
<dd>Any legal Python integer or floating point literal.
Examples: <em>123</em>, <em>3.14</em>.</dd>
<dt>STRING</dt>
<dd>Any legal Python string literal.
Examples: <em>'Hi Mom!'</em>, <em>u&quot;Hi Dad!\n&quot;</em>, <em>r'''don't gobble my \'s!'''</em>,
<em>ur&quot;&quot;&quot;leave \'s alone!&quot;&quot;&quot;</em>.</dd>
<dt>TEXT</dt>
<dd>Only used in KQB files. This signifies any text (any characters) other
than the delimiter characters containing the <tt class="docutils literal"><span class="pre">TEXT</span></tt>.</dd>
<dt>PARAMETRIZED_TEXT</dt>
<dd>Only used in KQB files. This signifies any text (any characters) through
the end of the line and all text on subsequent lines that are indented at
least as much as the first <tt class="docutils literal"><span class="pre">PARAMETRIZED_TEXT</span></tt> character on the first
line. All <tt class="docutils literal"><span class="pre">PARAMETRIZED_TEXT</span></tt> is treated as a <a class="reference" href="http://docs.python.org/lib/node40.html">string.Template</a> and
may include <tt class="docutils literal"><span class="pre">$IDENTIFIER</span></tt> or <tt class="docutils literal"><span class="pre">${IDENTIFIER}</span></tt> parameters. All other
<tt class="docutils literal"><span class="pre">$</span></tt> characters must be doubled (<tt class="docutils literal"><span class="pre">$$</span></tt>).</dd>
<dt>REGEXP_TEXT</dt>
<dd>Only used in KQB files. This signifies any text (any characters) excluding
an unescaped backslash (<tt class="docutils literal"><span class="pre">\</span></tt>) at the end. These are given to the Python's
<tt class="docutils literal"><span class="pre">re</span></tt> module as regular expressions and must follow Python's
<a class="reference" href="http://docs.python.org/lib/re-syntax.html">regular expression syntax</a>.</dd>
<dt>NL</dt>
<dd>One or more newlines.</dd>
<dt>INDENT</dt>
<dd>The following text must be indented to a higher level (more) than the
previous text.</dd>
<dt>DEINDENT</dt>
<dd>The following text must be indented one less level than the previous text.</dd>
</dl>
</div>
<div class="section">
<h2><a id="lexical-structure" name="lexical-structure">Lexical Structure</a></h2>
<p>The lexical structure is much like Python. Like Python, indenting is
significant. It uses the same commenting, line continuation and literal
formats for strings and numbers (but doesn't use complex numbers). It also
uses the same rules for forming identifiers.</p>
<p>The two notable exceptions to Python conventions are:</p>
<ol class="arabic simple">
<li>Identifiers may be used as strings, without requiring quotes.<ul>
<li>So <tt class="docutils literal"><span class="pre">foobar</span></tt> is the same as <tt class="docutils literal"><span class="pre">'foobar'</span></tt>.</li>
</ul>
</li>
<li>Singleton tuples do not require a trailing comma.<ul>
<li>So <tt class="docutils literal"><span class="pre">(1)</span></tt> is the same as <tt class="docutils literal"><span class="pre">(1,)</span></tt>.</li>
</ul>
</li>
</ol>
<!-- 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="kfb_syntax.html">KFB Syntax</a><p>The syntax of <em>Knowledge Fact Base</em> (KFB) files, which is where you
write your universal facts.</p>
</div>
<div class="right-item"><a href="krb_syntax/index.html">KRB Syntax</a><p>Syntax of the <em>Knowledge Rule Base</em> (KRB) files, which is where you
write your rules.</p>
</div>
<div class="right-item"><a href="kqb_syntax.html">KQB Syntax</a><p>The syntax of <em>Knowledge Question Base</em> (KQB) files, which is where you
spell out your end user questions.</p>
</div>
</div>
</td>
</tr>
</tbody>
<tfoot id="foot">
<tr id="foot2">
<td id="copyright" colspan="3">
Copyright &copy; 2007-2008 Bruce Frederiksen
</td>
</tr>
</tfoot>
</table>
<div id="last-modified">
Page last modified Fri, Aug 29 2008.
</div>
</body>
</html>