This doesn't work (from the tutorial page)... any ideas where I'm going wrong? 
Thanks...

import neo4j
from neo4j.util import Subreference
graphdb = neo4j.GraphDatabase( "test_neo4j_db" )

class SubCategoryProducts(neo4j.Traversal):
  types = [neo4j.Outgoing.SUBCATEGORY, neo4j.Outgoing.PRODUCT]
  def isReturnable(self, pos):
      if pos.is_start: return False
      return pos.last_relationship.type == 'PRODUCT'

def attributes(product_node):
  for category in categories(product_node):
      for attr in category.ATTRIBUTE:
          yield attr
 
class categories(neo4j.Traversal):
  types = [neo4j.Incoming.PRODUCT, neo4j.Incoming.SUBCATEGORY]
  def isReturnable(self, pos):
      return not pos.is_start

with graphdb.transaction:
        attribute_subref_node = Subreference.Node.ATTRIBUTE_ROOT(graphdb)
        #attribute_subref_node.ATTRIBUTE_TYPE("Price") #Fails, do I need to 
pass an object?
        #attribute_subref_node.ATTRIBUTE_TYPE("Length")
        #attribute_subref_node.ATTRIBUTE_TYPE("Name")
        
        category_subref_node = Subreference.Node.CATEGORY_ROOT(graphdb, 
Name="Products")
        computers_node = graphdb.node(Name="Computers")
        
        #create some categories
        electronics_node = graphdb.node(Name="Laptops")
        electronics_node.SUBCATEGORY(computers_node)
        
        netbooks_node = graphdb.node(Name="Netbooks")
        netbooks_node.SUBCATEGORY(computers_node)
        
        desktops_node = graphdb.node(Name="Netbooks")
        desktops_node.SUBCATEGORY(computers_node)

        #create some products
        little_dell = graphdb.node(Name="Little Dell", Colour="red", Price=210)
        little_dell.is_a( netbooks_node )
        print little_dell.id
        
        little_acer = graphdb.node(Name="Little Acer", Colour="grey")
        little_acer.is_a( netbooks_node )
        print little_acer.id
        
        little_eee = graphdb.node(Name="Little EEE", Colour="white", Price=200 )
        little_eee.is_a( netbooks_node )
        print little_eee.id

        for rel in computers_node.SUBCATEGORY.outgoing:
                print rel.end['Name']

        for prod in SubCategoryProducts(computers_node):
                print prod['Name']

                for attr in attributes(prod):
                        print attr['Name'], " of type ", attr.end['Name']
                print
      
graphdb.shutdown()











_______________________________________________
Neo4j mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to