PyKE, to be a very reusable component, would ideally not require
filesystem access any more than it would require Zope or ZODB. At this
point the logic that handles finding a collection of rule/fact/
question files is a filesystem walker.
On Jan 10, 12:56 pm, dangyogi <
dangy...@gmail.com> wrote:
> On Jan 9, 5:05 pm, Jeremy <
jeremy.mcmil...@gmail.com> wrote:
>
> > Integrating PyKE into Zope, and indeed paving the way for more
> > flexible persistence, probably first requires factoring out the
> > filesystem dependent code into separate routines. I think it might be
> > time to cut a branch.
>
> I am glad that you are excited about this, but there are only a total
> of 7 calls to the built-in "open" function in all of the PyKE source
> code that need to be looked at:
>
> - 3 calls in pyke/krb_compiler/k*parser.py to open the 3 kinds of
> source files (.krb, .kfb and .kqb)
> - 3 calls in pyke/krb_compiler/__init__.py to write .py, .fbc and .qbc
> files, and
> - 1 call in pyke/knowledge_engine.py to open .fbc and .qbc (pickle)
> files.
>
> Each of these is rather trivial to change.
There's those, which don't bother me at all.
The constructor does a lot of stuff that scans the filesystem and
automatically (re)compiles anything that needs compiling. I was
thinking of hoisting all of that up into knowledge_base/rule_base
classes to abstract the interface between the engine and the file/zope/
whatever persistent store.
The idea I'm planning to try is knowledge_engine.engine intializes
itself, but will accept knowledge_bases and rule_bases as arguments
ala
knowledge_engine.engine(rule_base = joe_rules, knowledge_base =
joe_kb)
In the default behavior, it's expected that a new engine will walk the
filesystem starting at '.' or any other given path and compile
everything it finds. I envision an implementation where the engine
doesn't care how the rule_base or knowledge_base got itself ready for
inference and asks the objects that provide the data to do that work
for them. They would figure out how to find the stored data they need,
and then use the compiler to load it for them.
Does that make sense?
Overall, I'm trying to think OOPish and pythonic about how to abstract
the persistence away from the engine, but anything like what I'm
suggesting would need to make sense in a big picture way. Otherwise it
would be stumbling towards a rewrite.
> I don't think that we are quite ready to start a branch yet. And
> besides, an error has been reported that is ending up touching a lot
> of this code dealing with files that hasn't been committed yet. So it
> might be better to wait a few more days. OTOH, if you really want to
> start immediately, I can create the branch now and then you can merge
> the bug fix changes into the branch later. Let me know.
I thought the code would be mostly stable now since you were going to
be otherwise occupied, but I will take your advice and wait for a
bit.
> > My plan-A would be to develop the branch so that all non-Zope specific
> > changes to the PyKE codebase could easily be merged back into the
> > trunk, and the Zope specific stuff would exist as separate files. The
> > code that handles files would sit alongside the Zope stuff, and maybe
> > we want to get pedantic and implement a third storage method.
>
> I plan to branch the whole trunk (including the documentation, unit
> tests and examples). While the Zope work is ongoing, changes on the
> trunk can be merged into the branch (luckily, subversion 1.5 makes
> this much easier and SourceForge is using 1.5 svn servers -- you'll
> need to make sure that you have a 1.5 or later svn client).
I need to upgrade svn from ports. Doing that now.
> Then when the Zope work is done, we can merge the entire branch back
> into trunk. This should put everything back together in one place.
>
> I envision that the Zope work would then be included in all PyKE
> releases from that point on. There may be a pyke/zope directory that
> isn't used by "Plain-PyKE" users, but is still part of the release.
> My assumption here is that the pyke/zope stuff would not grow the PyKE
> release by more than about 50%. If the pyke/zope stuff turns into a
> monster, then we may need to find a Plan B.
>
> So the merge of the branch back into the trunk at the end would bring
> the pyke/zope directory into the trunk.
>
> Does this make sense?
Yes. Agreed.
> One another topic --- Do objects destined for the ZODB need to be
> derived from some kind of zope.persistent class? And, if so, can this
> be done by multiple inheritance:
>
> pyke/knowledge_engine.py:
> class engine(object):
> ...
>
> pyke/zope/knowledge_engine.py
> import pyke.knowledge_engine
>
> class engine(zope.persistent, pyke.knowledge_engine.engine):
> ...
That's exactly how it is supposed to work. However, that is only
necessary when you want/need your classes to be transaction aware. In
practice, I think most implementations just make sure their classes
are pickle-safe and then handle the Zope stuff outside.
Here's my favorite intro:
http://www.zope.org/Members/adytumsolutions/HowToLoveZODB_PartI