Diff of /doc/html/using_pyke.html [9ac085] .. [0176eb] Maximize Restore

  Switch to unified view

a/doc/html/using_pyke.html b/doc/html/using_pyke.html
...
...
255
<p>Raises <tt class="docutils literal"><span class="pre">pyke.knowledge_engine.CanNotProve</span></tt> if no proof is found.</p>
255
<p>Raises <tt class="docutils literal"><span class="pre">pyke.knowledge_engine.CanNotProve</span></tt> if no proof is found.</p>
256
<pre class="doctest-block">
256
<pre class="doctest-block">
257
&gt;&gt;&gt; my_engine.prove_1('bc_example', 'father_son', ('thomas', 'bogus'), 1)
257
&gt;&gt;&gt; my_engine.prove_1('bc_example', 'father_son', ('thomas', 'bogus'), 1)
258
Traceback (most recent call last):
258
Traceback (most recent call last):
259
    ...
259
    ...
260
CanNotProve: Can not prove bc_example.father_son(thomas, bogus, $ans_0)
260
pyke.knowledge_engine.CanNotProve: Can not prove bc_example.father_son(thomas, bogus, $ans_0)
261
</pre>
261
</pre>
262
</blockquote>
262
</blockquote>
263
<dl class="docutils">
263
<dl class="docutils">
264
<dt><em>some_engine</em>.prove_n(kb_name, entity_name, fixed_args, num_returns)</dt>
264
<dt><em>some_engine</em>.prove_n(kb_name, entity_name, fixed_args, num_returns)</dt>
265
<dd><p class="first">This returns a context manager for a generator yielding 2-tuples, a tuple
265
<dd><p class="first">This returns a context manager for a generator yielding 2-tuples, a tuple
...
...
268
<tt class="docutils literal"><span class="pre">prove_1</span></tt> it does not raise an exception if no proof is found.</p>
268
<tt class="docutils literal"><span class="pre">prove_1</span></tt> it does not raise an exception if no proof is found.</p>
269
<pre class="last doctest-block">
269
<pre class="last doctest-block">
270
&gt;&gt;&gt; from __future__ import with_statement
270
&gt;&gt;&gt; from __future__ import with_statement
271
&gt;&gt;&gt; with my_engine.prove_n('bc_example', 'father_son', ('thomas',), 2) as gen:
271
&gt;&gt;&gt; with my_engine.prove_n('bc_example', 'father_son', ('thomas',), 2) as gen:
272
...     for ans in gen:
272
...     for ans in gen:
273
...         print ans
273
...         print(ans)
274
(('bruce', ()), None)
274
(('bruce', ()), None)
275
(('david', ('grand',)), None)
275
(('david', ('grand',)), None)
276
</pre>
276
</pre>
277
</dd>
277
</dd>
278
</dl>
278
</dl>
...
...
281
<p>Once you've obtained a <a class="reference external" href="logic_programming/plans.html">plan</a> from <tt class="docutils literal"><span class="pre">prove_1</span></tt> or <tt class="docutils literal"><span class="pre">prove_n</span></tt>, you just call
281
<p>Once you've obtained a <a class="reference external" href="logic_programming/plans.html">plan</a> from <tt class="docutils literal"><span class="pre">prove_1</span></tt> or <tt class="docutils literal"><span class="pre">prove_n</span></tt>, you just call
282
it like a normal Python function.  The arguments required are simply those
282
it like a normal Python function.  The arguments required are simply those
283
specified, if any, in the <a class="reference external" href="pyke_syntax/krb_syntax/bc_rule.html#taking-clause">taking clause</a> of the <a class="reference external" href="pyke_syntax/krb_syntax/bc_rule.html">rule</a> proving the top-level
283
specified, if any, in the <a class="reference external" href="pyke_syntax/krb_syntax/bc_rule.html#taking-clause">taking clause</a> of the <a class="reference external" href="pyke_syntax/krb_syntax/bc_rule.html">rule</a> proving the top-level
284
goal.</p>
284
goal.</p>
285
<p>You may call the plan function any number of times.  You may even pickle
285
<p>You may call the plan function any number of times.  You may even pickle
286
the plan for later use.  But the plans are constructed out of
286
the plan for later use.  The plans are constructed out of
287
<a class="reference external" href="http://docs.python.org/library/functools.html">functools.partial</a> functions, so you need to register this with <a class="reference external" href="http://docs.python.org/library/copy_reg.html">copy_reg</a>
287
<a class="reference external" href="http://docs.python.org/library/functools.html">functools.partial</a> functions, which had to be registered with <a class="reference external" href="http://docs.python.org/3.0/library/copyreg.html">copyreg</a>
288
before pickling the plan:</p>
288
before you could pickle them in older Python releases.  But in Python3 it is
289
<blockquote>
289
no longer necessary to register functools.partial to be able to pickle them.</p>
290
<pre class="doctest-block">
291
&gt;&gt;&gt; import copy_reg
292
&gt;&gt;&gt; import functools
293
&gt;&gt;&gt; copy_reg.pickle(functools.partial,
294
...                 lambda p: (functools.partial, (p.func,) + p.args))
295
</pre>
296
</blockquote>
297
<p>No special code is required to unpickle a plan.  Just unpickle and call it.
290
<p>No special code is required to unpickle a plan.  Just unpickle and call it.
298
(Unpickling the plan only imports one small Pyke module to be able to run
291
(Unpickling the plan only imports one small Pyke module to be able to run
299
the plan).</p>
292
the plan).</p>
300
</div>
293
</div>
301
<div class="section" id="tracing-rules">
294
<div class="section" id="tracing-rules">
...
...
345
...     krb_traceback.print_exc(None, sys.stdout)   # sys.stdout needed for doctest
338
...     krb_traceback.print_exc(None, sys.stdout)   # sys.stdout needed for doctest
346
Traceback (most recent call last):
339
Traceback (most recent call last):
347
  File &quot;&lt;doctest using_pyke.txt[37]&gt;&quot;, line 2, in &lt;module&gt;
340
  File &quot;&lt;doctest using_pyke.txt[37]&gt;&quot;, line 2, in &lt;module&gt;
348
    my_engine.prove_1('error_test', 'goal', (), 0)
341
    my_engine.prove_1('error_test', 'goal', (), 0)
349
  File &quot;...knowledge_engine.py&quot;, line 288, in prove_1
342
  File &quot;...knowledge_engine.py&quot;, line 288, in prove_1
350
    return iter(it).next()
343
    return next(iter(it))
351
  File &quot;...knowledge_engine.py&quot;, line 272, in gen
344
  File &quot;...knowledge_engine.py&quot;, line 272, in gen
352
    for plan in it:
345
    for plan in it:
353
  File &quot;...rule_base.py&quot;, line 46, in next
346
  File &quot;...rule_base.py&quot;, line 46, in __next__
354
    return self.iterator.next()
347
    return next(self.iterator)
355
  File &quot;...knowledge_engine.py&quot;, line 40, in from_iterable
356
    for x in iterable: yield x
357
  File &quot;...knowledge_engine.py&quot;, line 40, in from_iterable
358
    for x in iterable: yield x
359
  File &quot;...error_test.krb&quot;, line 26, in rule1
348
  File &quot;...error_test.krb&quot;, line 26, in rule1
360
    goal2()
349
    goal2()
361
  File &quot;...error_test.krb&quot;, line 31, in rule2
350
  File &quot;...error_test.krb&quot;, line 31, in rule2
362
    goal3()
351
    goal3()
363
  File &quot;...error_test.krb&quot;, line 36, in rule3
352
  File &quot;...error_test.krb&quot;, line 36, in rule3
...
...
495
    </tfoot>
484
    </tfoot>
496
  </table>
485
  </table>
497
486
498
  <div id="last-modified">
487
  <div id="last-modified">
499
    Page last modified
488
    Page last modified
500
    Mon, Oct 19 2009.
489
    Tue, Oct 20 2009.
501
490
502
  </div>
491
  </div>
503
492
504
  <script type="text/javascript">
493
  <script type="text/javascript">
505
    var gaJsHost = (("https:" == document.location.protocol) ?
494
    var gaJsHost = (("https:" == document.location.protocol) ?