[Neo] is neo4j the correct tool to store trees?

Tobias Ivarsson tobias.ivarsson at neotechnology.com
Wed Apr 7 10:01:36 CEST 2010


Apparently, gmail (trying to be smart) messed up the formatting of my code,
here it is completely without formatting (along with this message to all the
googlers who are eavesdropping to all emails that pass through gmail: Don't
mess with my source code!)

def get_node_from_path(start, path, include_symlinks=True):
    types = ('CHILD', 'SYMLINK') if include_symlinks else ('CHILD',)
    node = start
    for i, name in enumerate(path.split('/')):
        for rel in node.relationships(*types).out:
            if rel['name'] == name:
                node = rel.end
                break
        else: # The relationships were exhausted - i.e. child not found!
            raise NoSuchPathError('/'.join(path.split('/')[:i]), name)

class NoSuchPathError(Exception):
    def __init__(self, parent, child):
        Exception.__init__(self, '"%s" in "%s"' % (child, parent))

On Wed, Apr 7, 2010 at 9:52 AM, Tobias Ivarsson <
tobias.ivarsson at neotechnology.com> wrote:

> Whow. that's a mouthful, Python to the rescue ;)
>
> Here is how I'd color this bike shed <http://0099cc.bikeshed.org/>:
>
>
> *def* get_node_from_path(start, path, include_symlinks=True)*:*
>     types = ('*CHILD*', '*SYMLINK*') *if* include_symlinks *else* ('*CHILD
> *',)
>     node = start
>     *for* i, name *in* enumerate(path.split('*/*'))*:*
>         *for* rel *in* node.relationships(***types).out*:*
>             *if* rel['*name*'] == name*:*
>                 node = rel.end
>                 *break*
>         *else:* *# The relationships were exhausted - i.e. child not
> found!*
>             *raise* NoSuchPathError('*/*'.join(path.split('*/*')[:i]),
> name)
>
> *class* NoSuchPathError(Exception)*:*
> *    def* __init__(self, parent, child)*:*
>         Exception.__init__(self, '*"%s" in "%s"*' % (child, parent))
>
> On Tue, Apr 6, 2010 at 11:49 PM, Anders Nawroth <anders at neotechnology.com>wrote:
>
>> Hi!
>>
>> Now I finally got around posting my code:
>> http://github.com/neo4j-examples/java-tree-traverse
>>
>> The code is in here:
>>
>> http://github.com/neo4j-examples/java-tree-traverse/blob/master/src/main/java/org/neo4j/examples/treetraverse/TreeTraverse.java
>>
>> Here's an image of the nodespace:
>>
>> http://github.com/neo4j-examples/java-tree-traverse/blob/master/src/main/model/nodespace.png
>>
>>
>> /anders
>> _______________________________________________
>> Neo mailing list
>> User at lists.neo4j.org
>> https://lists.neo4j.org/mailman/listinfo/user
>>
>
>
>
> --
> Tobias Ivarsson <tobias.ivarsson at neotechnology.com>
> Hacker, Neo Technology
> www.neotechnology.com
> Cellphone: +46 706 534857
>



-- 
Tobias Ivarsson <tobias.ivarsson at neotechnology.com>
Hacker, Neo Technology
www.neotechnology.com
Cellphone: +46 706 534857


More information about the User mailing list