Beispiel #1
0
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')
Beispiel #2
0
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
Beispiel #3
0
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')
Beispiel #4
0
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)
Beispiel #5
0
class Comment(nm.StructuredNode):
    create_datetime = nm.DateTimeProperty(default_now=True)
    content = nm.StringProperty(required=True)

    written_by = nm.Relationship('User', 'WRITTEN_BY')
Beispiel #6
0
class ASTNode(neomodel.StructuredNode):

    # 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()

    # Abstract Syntax Tree (AST) relationships
    ASTConnectionsTo = neomodel.RelationshipTo('ASTNode',
                                               'AST_parentOf',
                                               model=RelationshipSchema)
    ASTConnectionsFrom = neomodel.RelationshipFrom('ASTNode',
                                                   'AST_parentOf',
                                                   model=RelationshipSchema)
    ASTConnections = neomodel.Relationship('ASTNode',
                                           'AST_parentOf',
                                           model=RelationshipSchema)

    # Control Flow Graph (CFG) relationships
    CFGConnectionsTo = neomodel.RelationshipTo('ASTNode',
                                               'CFG_parentOf',
                                               model=RelationshipSchema)
    CFGConnectionsFrom = neomodel.RelationshipFrom('ASTNode',
                                                   'CFG_parentOf',
                                                   model=RelationshipSchema)
    CFGConnections = neomodel.Relationship('ASTNode',
                                           'CFG_parentOf',
                                           model=RelationshipSchema)

    # Program Dependence Graph (PDG) relationships
    PDGConnectionsTo = neomodel.RelationshipTo('ASTNode',
                                               'PDG_parentOf',
                                               model=RelationshipSchema)
    PDGConnectionsFrom = neomodel.RelationshipFrom('ASTNode',
                                                   'PDG_parentOf',
                                                   model=RelationshipSchema)
    PDGConnections = neomodel.Relationship('ASTNode',
                                           'PDG_parentOf',
                                           model=RelationshipSchema)

    # Inter-Procedural Call Graph (IPCG) relationships
    IPCGConnectionsTo = neomodel.RelationshipTo('ASTNode',
                                                'CG_parentOf',
                                                model=RelationshipSchema)
    IPCGConnectionsFrom = neomodel.RelationshipFrom('ASTNode',
                                                    'CG_parentOf',
                                                    model=RelationshipSchema)
    IPCGConnections = neomodel.Relationship('ASTNode',
                                            'CG_parentOf',
                                            model=RelationshipSchema)

    # Event Registration of ERDDG relationships
    ERDDGRegistrationConnectionsTo = neomodel.RelationshipTo(
        'ASTNode', 'ERDDG_Registration', model=RelationshipSchema)
    ERDDGRegistrationConnectionsFrom = neomodel.RelationshipFrom(
        'ASTNode', 'ERDDG_Registration', model=RelationshipSchema)
    ERDDGRegistrationConnections = neomodel.Relationship(
        'ASTNode', 'ERDDG_Registration', model=RelationshipSchema)

    # Event Dispatch of ERDDG relationships
    ERDDGDispatchConnectionsTo = neomodel.RelationshipTo(
        'ASTNode', 'ERDDG_Dispatch', model=RelationshipSchema)
    ERDDGDispatchConnectionsFrom = neomodel.RelationshipFrom(
        'ASTNode', 'ERDDG_Dispatch', model=RelationshipSchema)
    ERDDGRegistrationConnections = neomodel.Relationship(
        'ASTNode', 'ERDDG_Registration', model=RelationshipSchema)

    # Event Dependency of ERDDG relationships
    ERDDGDependencyConnectionsTo = neomodel.RelationshipTo(
        'ASTNode', 'ERDDG_Dependency', model=RelationshipSchema)
    ERDDGDependencyConnectionsFrom = neomodel.RelationshipFrom(
        'ASTNode', 'ERDDG_Dependency', model=RelationshipSchema)
    ERDDGDependencyConnections = neomodel.Relationship(
        'ASTNode', 'ERDDG_Dependency', model=RelationshipSchema)

    # ------------------------------------------------------------------------------------------------ #
    #					General Methods
    # ------------------------------------------------------------------------------------------------ #

    def get_line(self):
        """
		@return {list|None}: [(a, b)] where a, b are the start and end lines for the code of the AST node 
		
		"""
        if self.location is not None:
            loc = eval(self.location)
            return [loc.start.line, loc.end.line]

        return None

    def is_cfg_node(self):
        # TODO
        pass

    def has_cfg_edge(self):
        # TODO
        pass

    def has_pdg_edge(self):
        # TODO
        pass

    # ------------------------------------------------------------------------------------------------ #
    #					Edge Traversals
    # ------------------------------------------------------------------------------------------------ #

    def get_connections_by_ast(self,
                               direction=neomodel.match.OUTGOING,
                               **kwargs):
        """
		@param {string} direction: neomodel.match.OUTGOING / neomodel.match.INCOMING / neomodel.match.EITHER
		@param **kwargs: positional keyword arguments specifying the constraints on the edges for traversals
		@return {list}: related AST nodes
		"""

        if direction == neomodel.match.OUTGOING:
            return self.ASTConnectionsTo.match(**kwargs).all()
        elif direction == neomodel.match.INCOMING:
            return self.ASTConnectionsFrom.match(**kwargs).all()
        else:
            return self.ASTConnections.match(**kwargs).all()

    def get_connections_by_cfg(self,
                               direction=neomodel.match.OUTGOING,
                               **kwargs):
        """
		@param {string} direction: neomodel.match.OUTGOING / neomodel.match.INCOMING / neomodel.match.EITHER
		@param **kwargs: positional keyword arguments specifying the constraints on the edges for traversals
		@return {list} related CFG nodes
		"""

        if direction == neomodel.match.OUTGOING:
            return self.CFGConnectionsTo.match(**kwargs).all()
        elif direction == neomodel.match.INCOMING:
            return self.CFGConnectionsFrom.match(**kwargs).all()
        else:
            return self.CFGConnections.match(**kwargs).all()

    def get_connections_by_pdg(self,
                               direction=neomodel.match.OUTGOING,
                               **kwargs):
        """
		@param {string} direction: neomodel.match.OUTGOING / neomodel.match.INCOMING / neomodel.match.EITHER
		@param **kwargs: positional keyword arguments specifying the constraints on the edges for traversals
		@return {list} related PDG nodes
		"""

        if direction == neomodel.match.OUTGOING:
            return self.PDGConnectionsTo.match(**kwargs).all()
        elif direction == neomodel.match.INCOMING:
            return self.PDGConnectionsFrom.match(**kwargs).all()
        else:
            return self.PDGConnections.match(**kwargs).all()

    def get_connections_by_ipcg(self,
                                direction=neomodel.match.OUTGOING,
                                **kwargs):
        """
		@param {string} direction: neomodel.match.OUTGOING / neomodel.match.INCOMING / neomodel.match.EITHER
		@param **kwargs: positional keyword arguments specifying the constraints on the edges for traversals
		@return {list} related IPCG nodes
		"""

        if direction == neomodel.match.OUTGOING:
            return self.IPCGConnectionsTo.match(**kwargs).all()
        elif direction == neomodel.match.INCOMING:
            return self.IPCGConnectionsFrom.match(**kwargs).all()
        else:
            return self.IPCGConnections.match(**kwargs).all()

    def get_connections_by_erddg_dispatch(self,
                                          direction=neomodel.match.OUTGOING,
                                          **kwargs):
        """
		@param {string} direction: neomodel.match.OUTGOING / neomodel.match.INCOMING / neomodel.match.EITHER
		@param **kwargs: positional keyword arguments specifying the constraints on the edges for traversals
		@return {list} related nodes via ERDDG Dispatch edges
		"""

        if direction == neomodel.match.OUTGOING:
            return self.ERDDGDispatchConnectionsTo.match(**kwargs).all()
        elif direction == neomodel.match.INCOMING:
            return self.ERDDGDispatchConnectionsFrom.match(**kwargs).all()
        else:
            return self.ERDDGDispatchConnections.match(**kwargs).all()

    def get_connections_by_erddg_registration(self,
                                              direction=neomodel.match.
                                              OUTGOING,
                                              **kwargs):
        """
		@param {string} direction: neomodel.match.OUTGOING / neomodel.match.INCOMING / neomodel.match.EITHER
		@param **kwargs: positional keyword arguments specifying the constraints on the edges for traversals
		@return {list} related nodes via ERDDG Registration edges
		"""

        if direction == neomodel.match.OUTGOING:
            return self.ERDDGRegistrationConnectionsTo.match(**kwargs).all()
        elif direction == neomodel.match.INCOMING:
            return self.ERDDGRegistrationConnectionsFrom.match(**kwargs).all()
        else:
            return self.ERDDGRegistrationConnections.match(**kwargs).all()

    def get_connections_by_erddg_dependency(self,
                                            direction=neomodel.match.OUTGOING,
                                            **kwargs):
        """
		@param {string} direction: neomodel.match.OUTGOING / neomodel.match.INCOMING / neomodel.match.EITHER
		@param **kwargs: positional keyword arguments specifying the constraints on the edges for traversals
		@return {list} related nodes via ERDDG Dependency edges
		"""

        if direction == neomodel.match.OUTGOING:
            return self.ERDDGDependencyConnectionsTo.match(**kwargs).all()
        elif direction == neomodel.match.INCOMING:
            return self.ERDDGDependencyConnectionsFrom.match(**kwargs).all()
        else:
            return self.ERDDGDependencyConnections.match(**kwargs).all()
Beispiel #7
0
class baseModelClass1(neomodel.StructuredNode):
    '''Models a very simple node with an undirected 0..* relationship to a set of baseModelClass2 nodes'''
    someAttribute = neomodel.StringProperty(unique_index=True)
    someLink = neomodel.Relationship("baseModelClass2",
                                     "RELATED_TO",
                                     model=baseModelRelationship)