class AuthorNode(DjangoNode): author_id = neomodel.IntegerProperty( unique_index=True) # This correspond one-to-one to Author model in SQL coauthors = neomodel.Relationship('AuthorNode', 'COAUTHOR', model=Coauthorship) papers = neomodel.RelationshipTo('DocumentNode', 'OWNS')
class Relation(neomodel.StructuredRel, EveCompatibilityMixin): """ Node model for relations in the graph. """ label = neomodel.StringProperty( ) # Text that should be displayed about this edge data = neomodel.JSONProperty( ) # Dictionary with more detailed data about this relation weight = neomodel.IntegerProperty(default=1)
class Location(neomodel.StructuredNode): location_id = neomodel.IntegerProperty(unique_index=True) name = neomodel.StringProperty(required=True) parent = neomodel.RelationshipTo("Location", "IS_IN", neomodel.ZeroOrOne, model=LocationRelationship) def __str__(self): return self.name
class User(neomodel.StructuredNode): id_str = neomodel.StringProperty(unique_index=True, required=True) name = neomodel.StringProperty(required=False) screen_name = neomodel.StringProperty(required=False) followers_count = neomodel.IntegerProperty(required=False) friends_count = neomodel.IntegerProperty(required=False) modified = neomodel.DateTimeProperty(required=False) created_at = neomodel.DateTimeProperty(required=False) description = neomodel.StringProperty(required=False) location = neomodel.StringProperty(required=False) coordinates = neomodel.ArrayProperty(required=False, default=[]) time_zone = neomodel.StringProperty(required=False) url = neomodel.StringProperty(required=False) lang = neomodel.StringProperty(required=False) follows = neomodel.RelationshipTo('User', 'FOLLOWS') posts = neomodel.RelationshipTo('Tweet', 'POSTS') def save(self): self.modified = datetime.datetime.now() super(User, self).save()
class Entity(neomodel.StructuredNode, EveCompatibilityMixin): """ Node model for entities in the graph. """ uid = neomodel.UniqueIdProperty() # Unique ID for this database entry category = neomodel.StringProperty( ) # Category of this entity (Person, Organization...) label = neomodel.StringProperty( ) # Text that should be displayed about this node data = neomodel.JSONProperty( ) # Dictionary with more detailed data about this entity relations = neomodel.Relationship("Entity", "CONNECTED_WITH", model=Relation) weight = neomodel.IntegerProperty(default=1)
class Movie(neo.StructuredNode): uid = neo.IntegerProperty() title = neo.StringProperty() vote = neo.StringProperty() overview = neo.StringProperty() poster = neo.StringProperty() date = neo.StringProperty() language = neo.StringProperty() producer = neo.RelationshipTo('Producer', 'PRODUCE_BY', cardinality=ZeroOrOne) compositor = neo.RelationshipTo('Compositor', 'COMPOSED_BY', cardinality=ZeroOrOne) director = neo.RelationshipTo('Director', 'LEAD_BY', cardinality=ZeroOrOne) actors = neo.RelationshipTo('Actor', 'PLAYED_BY', cardinality=ZeroOrMore) genres = neo.RelationshipTo('Genre', 'OWN', cardinality=ZeroOrMore) keywords = neo.RelationshipTo('Keyword', 'IS', cardinality=ZeroOrMore) @property def serialize(self): return { 'id': self.uid, 'title': self.title, 'vote_average': self.vote, 'overview': self.overview, 'poster_path': self.poster, 'release_date': self.date, 'original_language': self.language } @classmethod def related_base(cls, name, selection): return neo.db.cypher_query( f"""MATCH (Base {{name:"{name}"}})--(m:Movie)--(b:Base) WHERE NOT m.uid IN {selection} RETURN m, collect(b) LIMIT 50""")[0] @classmethod def matrix(cls, selection_ids): return neo.db.cypher_query(f"""MATCH (p)-[r]-(m:Movie) WHERE m.uid in {selection_ids} WITH p, Count(r) AS CountRelation RETURN p, CountRelation ORDER BY CountRelation DESC LIMIT 30""")
class BaseEntity(neomodel.StructuredNode): name = neomodel.StringProperty(unique_index=True) variants = neomodel.JSONProperty() best_variant = neomodel.StringProperty() count = neomodel.IntegerProperty(default=1) weight = neomodel.FloatProperty(default=0) create_at = neomodel.DateTimeFormatProperty(format=DATETIME_FORMAT, default_now=True) # GOD attributes: relation from head (self) to Tail (other) used_for = neomodel.RelationshipTo(neomodel.StructuredNode, 'used_for', model=UsedFor) part_of = neomodel.RelationshipTo(neomodel.StructuredNode, 'part_of', model=PartOf) feature_of = neomodel.RelationshipTo(neomodel.StructuredNode, 'feature_of', model=FeatureOf) compare = neomodel.RelationshipTo(neomodel.StructuredNode, 'compare', model=Compare) hyponym_of = neomodel.RelationshipTo(neomodel.StructuredNode, 'hyponym_of', model=HyponymOf) evaluate_for = neomodel.RelationshipTo(neomodel.StructuredNode, 'evaluate_for', model=EvaluateFor) refer_to = neomodel.RelationshipTo(neomodel.StructuredNode, 'refer_to', model=ReferTo) appear_in = neomodel.RelationshipTo(neomodel.StructuredNode, 'appear_in', model=AppearIn) author_of = neomodel.RelationshipTo(neomodel.StructuredNode, 'author_of', model=AuthorOf) affiliate_with = neomodel.RelationshipTo(neomodel.StructuredNode, 'affiliate_with', model=AffiliateWith) cite = neomodel.RelationshipTo(neomodel.StructuredNode, 'cite', model=Cite) related_to = neomodel.RelationshipTo(neomodel.StructuredNode, 'related_to', model=RelatedTo)
class Company(nm.StructuredNode): name = nm.StringProperty(unique_index=True, require=True) symbol = nm.StringProperty() market = nm.StringProperty() list_date = nm.IntegerProperty() updated = nm.DateTimeProperty(default_now=True) concept = nm.RelationshipTo('Concept', 'COMPONENT_OF', cardinality=nm.ZeroOrMore, model=ComponentRel) industry = nm.RelationshipTo('Industry', 'COMPONENT_OF', cardinality=nm.ZeroOrMore, model=ComponentRel) index = nm.RelationshipTo('Industry', 'COMPONENT_OF', cardinality=nm.ZeroOrMore, model=ComponentRel) customer = nm.RelationshipTo('Company', 'SUPPLIES_TO', cardinality=nm.ZeroOrMore) product = nm.RelationshipTo('Product', 'PRODUCES', model=ProductRel)
class ProductRel(nm.StructuredRel): updated = nm.DateTimeProperty(default_now=True) rating = nm.IntegerProperty() contribution = nm.IntegerProperty()
class Paper(BaseEntity): # cc = neomodel.IntegerProperty() # abstract = neomodel.StringProperty() paper_id = neomodel.IntegerProperty(required=True) arxiv_id = neomodel.StringProperty()
class ParentModel(nm.StructuredNode): name = nm.StringProperty(unique_index=True) age = nm.IntegerProperty()
class Concept(nm.StructuredNode): name = nm.StringProperty(unique_index=True, require=True) rating = nm.IntegerProperty() heat = nm.IntegerProperty()
class Fund(nm.StructuredNode): name = nm.StringProperty(unique_index=True, require=True) rating = nm.IntegerProperty() company = nm.RelationshipTo('Company', 'STAKES', model=StakeRel)
class ComponentRel(nm.StructuredRel): updated = nm.DateTimeProperty(default_now=True) rating = nm.IntegerProperty() relevancy = nm.IntegerProperty() weight = nm.FloatProperty()
class Index(nm.StructuredNode): name = nm.StringProperty(unique_index=True, require=True) symbol = nm.StringProperty() market = nm.StringProperty() list_date = nm.IntegerProperty() updated = nm.DateTimeProperty(default_now=True)
class BaseRelation(neomodel.StructuredRel): count = neomodel.IntegerProperty(default=1) weight = neomodel.FloatProperty(default=0) create_at = neomodel.DateTimeFormatProperty(format=DATETIME_FORMAT, default_now=True) flag_violation = neomodel.BooleanProperty(default=False) from_papers = neomodel.ArrayProperty(neomodel.IntegerProperty(), default=[])
class Coauthorship(neomodel.StructuredRel): num_papers = neomodel.IntegerProperty(default=0)
class DocumentNode(DjangoNode): document_id = neomodel.IntegerProperty( unique_index=True) # one-to-one to Document model in SQL authors = neomodel.RelationshipFrom('AuthorNode', 'OWNS')