[c203b8]: doc / source / krb_syntax / index.txt Maximize Restore History

Download this file

index.txt    175 lines (134 with data), 5.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
.. $Id$
..
.. Copyright Š 2007 Bruce Frederiksen
..
.. Permission is hereby granted, free of charge, to any person obtaining a copy
.. of this software and associated documentation files (the "Software"), to deal
.. in the Software without restriction, including without limitation the rights
.. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
.. copies of the Software, and to permit persons to whom the Software is
.. furnished to do so, subject to the following conditions:
..
.. The above copyright notice and this permission notice shall be included in
.. all copies or substantial portions of the Software.
..
.. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
.. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
.. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
.. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
.. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
.. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
.. THE SOFTWARE.
restindex
crumb: KRB Syntax
page-description:
Syntax of the knowledge rule base (KRB) files, which is where you
write your rules.
/description
section-pages: , fc_rule, bc_rule, pattern, compound_premise, python_premise
format: rest
encoding: utf8
output-encoding: utf8
include: yes
/restindex
===================
KRB Syntax
===================
This section describes the syntax for defining rules_ in the KRB files.
Legend
==============
To describe this syntax, the following punctuation is used:
'*any_chars*'
required punctuation or keyword: *any_chars*
*a* | *b*
alternation: *a* or *b*
[*a*]
optional *a*
{*a*}
one or more *a*'s. If *a* ends in a comma, the last comma is optional.
NL
means one or more newlines
Lexical Structure
=======================
The KRB 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 (except complex numbers). It also uses the
same rules for forming identifiers.
The two notable exceptions to python conventions are:
#. Identifiers may be used as strings, without requiring quotes.
- ``foobar`` is the same as ``'foobar'``
#. Singleton tuples do not require a trailing comma.
- ``(1)`` is the same as ``(1,)``
Keywords
==================
========= =========== =========
as foreach taking
assert in True
bc_extras None use
check plan_extras when
extending python with
False step without
fc_extras
========= =========== =========
Syntax of the Entire KRB File
===================================
::
file ::= [NL]
['extending' IDENTIFIER ['without' {IDENTIFIER,}] NL]
[{fc_rule}
['fc_extras' NL INDENT
{<python_statement> NL}
DEINDENT]]
[{bc_rule}
['bc_extras' NL INDENT
{<python_statement> NL}
DEINDENT]
['plan_extras' NL INDENT
{<python_statement> NL}
DEINDENT]]
The KRB file has three optional parts. It must contain at least one rule_
(either forward-chaining_ or backward-chaining_).
The filename (minus the .krb extension) is the name of the `rule base`_.
This must be a legal python identifier.
Extending clause
-----------------
The optional ``extending`` clause, if used, is the first line of the file.
This defines the parent `rule base`_ that this `rule base`_ inherits_ from.
It may also specify a list of backward-chaining_ goal names to be excluded
from this inheritance.
Forward-Chaining Section
--------------------------
If the krb file contains any forward-chaining_ rules_, a python source file
will be created named <rb_name>_fc.py, where <rb_name> is the `rule base`_
name.
The syntax of a forward-chaining_ rule_ (fc_rule_) is defined elsewhere__.
The ``fc_extras`` can only be used if there are forward-chaining_ rules_.
This allows you to add other python code (for example, ``import`` statements)
to the generated python source file.
.. __: fc_rule_
Backward-Chaining Section
--------------------------
If the krb file contains any backward-chaining_ rules_, a python source file
will be created named <rb_name>_bc.py, where <rb_name> is the `rule base`_
name.
The syntax of a backward-chaining_ rule_ (bc_rule_) is defined elsewhere__.
The ``bc_extras`` can only be used if there are backward-chaining_ rules_.
This allows you to add other python code (for example, ``import`` statements)
to the generated python source file.
In addition, if any of the backward-chaining_ rules_ have plan_ code (for
example, a ``with`` clause or subgoals in the ``when`` clause that produce
plans_), a python source file will be created name <rb_name>_plans.py, where
<rb_name> is the `rule base`_ name.
You use the ``plan_extras`` to include arbitrary python code in this plans
file.
.. __: bc_rule_
.. _backward-chaining: ../overview/rules/backward_chaining.html
.. _bc_rule: bc_rule.html
.. _fc_rule: fc_rule.html
.. _forward-chaining: ../overview/rules/forward_chaining.html
.. _inherits: ../overview/knowledge_bases/rule_bases.html#rule-base-inheritance
.. _plan: ../overview/plans.html
.. _plans: plan_
.. _rule: ../overview/rules/index.html
.. _rules: rule_
.. _rule base: ../overview/knowledge_bases/rule_bases.html