Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

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

Download this file

index.txt    144 lines (119 with data), 5.4 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
.. $Id$
..
.. Copyright Š 2008 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: Pyke Syntax
page-description:
The syntax of Pyke's three different kinds of source files.
/description
section-pages: , kfb_syntax, krb_syntax/index, kqb_syntax
format: rest
encoding: utf8
output-encoding: utf8
include: yes
initialheaderlevel: 2
/restindex
===========
Pyke Syntax
===========
Source Files
============
Pyke has three different kinds of source files for the three main types of
`knowledge bases`_:
#. *Knowledge Fact Base* (KFB) files for `fact bases`_.
#. *Knowledge Rule Base* (KRB) files for `rule bases`_.
#. *Knowledge Question Base* (KQB) files for `question bases`_.
Each type of source file ends in a different file suffix: ``.kfb``,
``.krb`` or ``.kqb``.
Place all of these source files into a directory structure. Then include this
directory as an argument to the `knowledge_engine.engine`_ 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.
The ``.kfb`` and ``.kqb`` files are compiled into Python pickles_ with
``.fbc`` and ``.qbc`` suffixes.
The ``.krb`` files are compiled into up to three ``.py`` source files.
The names of these ``.py`` files are the same as the ``.krb`` file, but with
different endings:
- ``_fc`` (if there are any forward-chaining_ rules)
- ``_bc`` (if there are any backward-chaining_ rules) and
- ``_plans`` (if any of the backward-chaining rules have a plan_)
These ``.py`` files are then automatically imported to define the rule base.
This causes Python to compile them into ``.pyc`` or ``.pyo`` files.
Subsequent runs of the `knowledge_engine.engine`_ constructor only recompile
the Pyke source files that have changed since the last time they were compiled.
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.
Syntax 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. **But** it is understood that if *a* ends in a comma,
the last comma is optional.
IDENTIFIER
Any legal Python identifier. Example: *foobar*
NUMBER
Any legal Python integer or floating point literal.
Examples: *123*, *3.14*.
STRING
Any legal Python string literal.
Examples: *'Hi Mom!'*, *u"Hi Dad!\\n"*, *r'''don't gobble my \\'s!'''*,
*ur"""leave \\'s alone!"""*.
TEXT
Only used in KQB files. This signifies any text (any characters) other
than the delimiter characters containing the ``TEXT``.
PARAMETRIZED_TEXT
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 ``PARAMETRIZED_TEXT`` character on the first
line. All ``PARAMETRIZED_TEXT`` is treated as a `string.Template`_ and
may include ``$IDENTIFIER`` or ``${IDENTIFIER}`` parameters. All other
``$`` characters must be doubled (``$$``).
REGEXP_TEXT
Only used in KQB files. This signifies any text (any characters) excluding
an unescaped backslash (``\``) at the end. These are given to the Python's
``re`` module as regular expressions and must follow Python's
`regular expression syntax`_.
NL
One or more newlines.
INDENT
The following text must be indented to a higher level (more) than the
previous text.
DEINDENT
The following text must be indented one less level than the previous text.
Lexical Structure
=======================
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.
The two notable exceptions to Python conventions are:
#. Identifiers may be used as strings, without requiring quotes.
- So ``foobar`` is the same as ``'foobar'``.
#. Singleton tuples do not require a trailing comma.
- So ``(1)`` is the same as ``(1,)``.