class Post(nm.StructuredNode): uid = nm.StringProperty(unique_index=True, default=uuid4) create_datetime = nm.DateTimeProperty(default_now=True) content = nm.StringProperty(required=True) comments = nm.Relationship('Comment', 'COMMENTED') written_by = nm.Relationship('User', 'WRITTEN_BY')
class User(nm.StructuredNode): uid = nm.StringProperty(index=True, default=uuid4) create_datetime = nm.DateTimeProperty(default_now=True) email = nm.StringProperty(unique_index=True, required=True) password = nm.StringProperty(required=True) name = nm.StringProperty(required=True) liked_posts = nm.RelationshipTo('Post', 'LIKED', model=Like) followings = nm.RelationshipTo('User', 'FOLLOW')
class News(neomodel.StructuredNode): headline = neomodel.StringProperty(unique_index=True, required=True) url = neomodel.StringProperty(required=False) publisher = neomodel.StringProperty(required=False) created_at = neomodel.DateTimeProperty(required=False) keywords = neomodel.ArrayProperty(neomodel.StringProperty(), required=False) score = neomodel.FloatProperty(required=False) cites = neomodel.RelationshipTo('Company', 'CITES')
class PipelineRunInfo(neomodel.StructuredNode): """ Define a model for pipeline run information. """ uid = neomodel.UniqueIdProperty() # Unique ID for this database entry run_id = neomodel.StringProperty( ) # ID for this pipeline run, created with sentence IDs involved in this run timestamp = neomodel.StringProperty( ) # Timestamp for the current pipeline run article_ids = neomodel.ArrayProperty( ) # List of sentence IDs involved in this pipeline run
class Recipe(nm.StructuredNode): r_id = nm.UniqueIdProperty() title = nm.StringProperty() description = nm.StringProperty() requires = nm.RelationshipTo('Ingredient', 'REQUIRES', model=Requires) def to_dict(self): return { 'r_id': self.r_id, 'title': self.title, 'description': self.description }
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 BasePerson(neomodel.StructuredNode): """ Base class for defining some basic sort of an actor. """ name = neomodel.StringProperty(required = True, unique_index = True) friends_with = neomodel.RelationshipTo("BasePerson", "FRIENDS_WITH", model = PersonalRelationship)
class PilotPerson(BasePerson): """ A pilot person specialises BasePerson by adding the type of airplane they can operate. """ airplane = neomodel.StringProperty(required=True)
class Company(neomodel.StructuredNode): id_str = neomodel.StringProperty(unique_index=True, required=True) name = neomodel.StringProperty(required=False) created_at = neomodel.DateTimeProperty(required=False) modified = neomodel.DateTimeProperty(required=False) description = neomodel.StringProperty(required=False) brand_score = neomodel.FloatProperty(required=False) tweet_score = neomodel.FloatProperty(required=False) news_score = neomodel.FloatProperty(required=False) stock_price = neomodel.FloatProperty(required=False) stock_change = neomodel.FloatProperty(required=False) mkt_cap = neomodel.FloatProperty(required=False) def save(self): self.modified = datetime.datetime.now() super(Company, self).save() return self
class specificModelClass3(baseModelClass2): '''Models another class that is a specialisation of baseModelClass2 NOTE: This class is a specialisation of baseModelClass2, therefore it is also perfectly valid as an "attachment" to someLink ''' yetAnotherAttribute = neomodel.StringProperty(index=True)
class specificModelClass2(baseModelClass2): '''Models a class that is a specialisation of baseModelClass2 NOTE: This class is a specialisation of baseModelClass2, therefore it is perfectly valid to be "attached" at someLink. ''' anotherAttribute = neomodel.StringProperty(unique_index=True)
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 EventNode(neomodel.StructuredNode): ## event name --> Type field ## event target --> Value field ## other properties are currently empty # properties Id = neomodel.UniqueIdProperty() Type = neomodel.StringProperty() Kind = neomodel.StringProperty() Code = neomodel.StringProperty() Range = neomodel.StringProperty() Location = neomodel.StringProperty() Value = neomodel.StringProperty() Raw = neomodel.StringProperty() Async = neomodel.StringProperty() SemanticType = neomodel.StringProperty()
class DOMSnapshot(neomodel.StructuredNode): ## html path --> Location field ## html code --> Code field ## other properties are currently empty # properties Id = neomodel.UniqueIdProperty() Type = neomodel.StringProperty() Kind = neomodel.StringProperty() Code = neomodel.StringProperty() Range = neomodel.StringProperty() Location = neomodel.StringProperty() Value = neomodel.StringProperty() Raw = neomodel.StringProperty() Async = neomodel.StringProperty() SemanticType = neomodel.StringProperty()
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 Tweet(neomodel.StructuredNode): id_str = neomodel.StringProperty(unique_index=True, required=True) created_at = neomodel.DateTimeProperty(required=False) modified = neomodel.DateTimeProperty(required=False) retweeted = neomodel.BooleanProperty(required=False) retweet_id_str = neomodel.StringProperty(required=False, default='') reply_id_str = neomodel.StringProperty(required=False, default='') quote_id_str = neomodel.StringProperty(required=False, default='') mention_ids_str = neomodel.ArrayProperty(required=False, default=[]) text = neomodel.StringProperty(required=False) coordinates = neomodel.ArrayProperty(required=False, default=[]) lang = neomodel.StringProperty(required=False) features = neomodel.JSONProperty(required=False, default={}) sentiment_polarity = neomodel.FloatProperty(required=False) sentiment_subjectivity = neomodel.FloatProperty(required=False) retweets = neomodel.RelationshipTo('Tweet', 'RETWEETS') mentions = neomodel.RelationshipTo('User', 'MENTIONS') replies = neomodel.RelationshipTo('Tweet', 'REPLIES') tags = neomodel.RelationshipTo('Hashtag', 'TAGS') contains = neomodel.RelationshipTo('Link', 'CONTAINS') quotes = neomodel.Relationship('Tweet', 'QUOTES') tweet_about = neomodel.RelationshipTo('Company', 'TWEETS') def save(self): self.modified = datetime.datetime.now() super(Tweet, self).save() return self
class CookieNode(neomodel.StructuredNode): ## cookie name --> Raw field ## cookie value --> Value field ## cookie httpOnly --> Type field ## other properties are currently empty # properties Id = neomodel.UniqueIdProperty() Type = neomodel.StringProperty() Kind = neomodel.StringProperty() Code = neomodel.StringProperty() Range = neomodel.StringProperty() Location = neomodel.StringProperty() Value = neomodel.StringProperty() Raw = neomodel.StringProperty() Async = neomodel.StringProperty() SemanticType = neomodel.StringProperty()
class Event(neomodel.StructuredNode): name = neomodel.StringProperty(unique_index=True, required=True) weighting = neomodel.FloatProperty(required=False) modified = neomodel.DateTimeProperty(required=False) related_to = neomodel.RelationshipTo('Company', 'ABOUT') tweet_from = neomodel.RelationshipFrom('Tweet', 'TWEET_FROM') cited_from = neomodel.RelationshipFrom('News', 'CITE_FROM') def save(self): self.modified = datetime.datetime.now() super(Event, self).save() return self
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 RequestNode(neomodel.StructuredNode): ## request method --> Type field ## request kind (e.g., xmlhttprequest) --> Kind field ## request URL --> Value field ## request body --> Raw field ## request status code --> Code field ## other properties are currently empty # properties Id = neomodel.UniqueIdProperty() Type = neomodel.StringProperty() Kind = neomodel.StringProperty() Code = neomodel.StringProperty() Range = neomodel.StringProperty() Location = neomodel.StringProperty() Value = neomodel.StringProperty() Raw = neomodel.StringProperty() Async = neomodel.StringProperty() SemanticType = neomodel.StringProperty()
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 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 SomeEntity(neomodel.StructuredNode): """ A bare minimum entity specified in neomodel to demonstrate the error condition and how to enter it. """ serial_num = neomodel.UniqueIdProperty() payload = neomodel.StringProperty(unique_index=True)
class Link(neomodel.StructuredNode): url = neomodel.StringProperty(unique_index=True, required=True)
class Hashtag(neomodel.StructuredNode): text = neomodel.StringProperty(unique_index=True, required=True)
class BaseOtherPerson(neomodel.StructuredNode): """ An obviously "wrong" class of actor to befriend BasePersons with. """ car_color = neomodel.StringProperty(required=True)
class TechnicalPerson(BasePerson): """ A Technical person specialises BasePerson by adding their expertise. """ expertise = neomodel.StringProperty(required=True)
class Ingredient(nm.StructuredNode): name = nm.StringProperty() keyword = nm.StringProperty(required=True) def to_dict(self): return {'keyword': self.keyword, 'name': self.name}
class Requires(nm.StructuredRel): quant = nm.FloatProperty() unit = nm.StringProperty()