class Rhash proposal
paolo veronelli
paolo_veronelli at yahoo.it
Thu Jul 15 10:01:23 EDT 2004
The strenght of dictionaries is the key research (obviously)
The possibility of transparent nesting given by Rhashes pays off in
building tree of orederd informations.Ordered so that you can easily find
and store informations in it.
It's nothing more than a simple but useful database which you dedicate to
your views of the world you are trying to simulate.
The focus point in using dictionaries is that we want to deal with complex
informations which cannot be simplified in a record (an instance of a
class).
It looks like every python object is nothing more than a dictionary,which
has constraints on nestings.This paradigma can be broken by using Rhashes
which have no constraints.
The other side of the story,is that keys have no specific meanings and the
code has to take in account some topological propreties of the Rhash
layout to work with it.
Particularly,the meaning of every level of nesting has to be known to the
code.
In my latest job the Rhash 'world' has the resources as first level,the
name of the resources.
The second is the predicate level,so querying it gives all the predicates
applicable to the resource choosen.
The other levels,are polymorphic and parseable only by pieces of code
binded to the predicate level......
Naturally using nested dictionaries is not very useful if the code
performs mere calculations,where the input is primitive.
But if we deal with large and polimorphic informations which want to drive
the code and we are reading __metaclass__ looking for light,they can help.
The RDF reasoner I'm buiding has only 3 classes all derived from Rhash
with some other Rhashes inside.It works and,mostly ,the code is readable
(?).
m=Rhash()
m['Lerat']['isa']['human']=None
m['Lerat']['isa']['walker']=None
m['Lerat']['likes']['music']['blues']=None
m['Lerat']['likes']['music']['ambient']=None
m['Lerat']['sleeps']=None
print m
{'Lerat': {'isa': {'walker': None, 'human': None}, 'likes': {'music':
{'blues': None, 'ambient': None}}, 'sleeps': None}}
This is a better example maybe.
Thanks for comments Paolino
--
....lotta dura per la verdura
More information about the Python-list
mailing list