is it possible to include a list of node classes in a relationshipto object using neomodel in python

52 views Asked by At

I'm trying to create a graph where multiple node types can have the same type of relationship between them. I have 5 node types; Group (spelled out below), Alias, Software, Technique & Tool. They're all basically set up the same way with the same properties, I'm just leaving them out for readability.

class Group(StructuredNode):
    created = DateTimeFormatProperty(default_now=True, format="%Y-%m-%dT%H:%M:%S.%fZ")
    description = StringProperty()
    ID = StringProperty(index=True)
    modified = DateTimeFormatProperty(default_now=True, format="%Y-%m-%dT%H:%M:%S.%fZ")
    name = StringProperty(unique_index=True, required=True)
    TYPE = StringProperty(index=True, default='review')
    version = IntegerProperty(default=5)
    #relationship properties go here 

class Alias(StructuredNode):
    name = StringProperty(unique_index=True, required=True)
    TYPE = StringProperty(index=True, default='review')
    #relationship properties go here
    
class Software(StructuredNode):
    created = DateTimeFormatProperty(default_now=True, format="%Y-%m-%dT%H:%M:%S.%fZ")
    description = StringProperty()
    ID = StringProperty(index=True)
    modified = DateTimeFormatProperty(default_now=True, format="%Y-%m-%dT%H:%M:%S.%fZ")
    name = StringProperty(unique_index=True, required=True)
    TYPE = StringProperty(index=True, default='review')
    version = IntegerProperty(default=None)
    #relationship properties go here
    
class Technique(StructuredNode):
    created = DateTimeFormatProperty(default_now=True, format="%Y-%m-%dT%H:%M:%S.%fZ")
    description = StringProperty()
    ID = StringProperty(index=True)
    modified = DateTimeFormatProperty(default_now=True, format="%Y-%m-%dT%H:%M:%S.%fZ")
    name = StringProperty(unique_index=True, required=True)
    TYPE = StringProperty(index=True, default='review')
    version = IntegerProperty(default=None)   
    #relationship properties go here
    
class Tool(StructuredNode):
    created = DateTimeFormatProperty(default_now=True, format="%Y-%m-%dT%H:%M:%S.%fZ")
    description = StringProperty()
    ID = StringProperty(index=True)
    modified = DateTimeFormatProperty(default_now=True, format="%Y-%m-%dT%H:%M:%S.%fZ")
    name = StringProperty(unique_index=True, required=True)
    TYPE = StringProperty(index=True, default='review')
    version = IntegerProperty(default=None) 
    #relationship properties go here

I'd like to do something like below where I include a list of all of the possible node types when setting relationships:

    uses = RelationshipTo(['Alias', 'Software', 'Technique', 'Tool'], 'USES')  
    alias = RelationshipTo(['Software', 'Technique', 'Tool'], 'ALIAS')
    revoked_by = RelationshipTo(['Alias', 'Software', 'Technique', 'Tool'], 'REVOKED-BY')

Rather than having to spell out each different relationship type for each node:

   usesalias = RelationshipTo('Alias', 'USES')
   usestool = RelationshipTo('Tool', 'USES')
   usestechnique = RelationshipTo('Technique', 'USES')
   usessoftware = RelationshipTo('Software', 'USES')

   aliassoftware = RelationshipTo('Software', 'Alias')
   aliastool = RelationshipTo('Tool', 'Alias')
   aliastechnique = RelationshipTo('Technique', 'Alias')

   rbalias = RelationshipTo('Alias', 'REVOKED-BY')
   rbtool = RelationshipTo('Tool', 'REVOKED-BY')
   rbtechnique = RelationshipTo('Technique', 'REVOKED-BY')
   rbsoftware = RelationshipTo('Software', 'REVOKED-BY')
   
   ......

0

There are 0 answers