当前位置: 首页>>代码示例>>Python>>正文


Python Node.match_outgoing方法代码示例

本文整理汇总了Python中py2neo.Node.match_outgoing方法的典型用法代码示例。如果您正苦于以下问题:Python Node.match_outgoing方法的具体用法?Python Node.match_outgoing怎么用?Python Node.match_outgoing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在py2neo.Node的用法示例。


在下文中一共展示了Node.match_outgoing方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from py2neo import Node [as 别名]
# 或者: from py2neo.Node import match_outgoing [as 别名]
class GraphNode:

    def __init__(self, node=None):

        if node is None:
            self.node = Node()
        else:
            self.node = node

    def id(self):
        """
        :return: node's unique Id
        """

        return self.node._id

    def labels(self):
        """
        :return: labels set
        """
        return self.node.labels

    def degree(self):
        """
        :return: number of relations
        """
        return self.node.degree

    def property(self, key):
        """
        :param key: property name
        :return: property value
        """
        return self.node.properties[key]

    def properties(self):
        """
        :return: node's properties dict
        """
        return self.node.properties

    def relationships(self):
        """
        :return: node's relationships iterator
        """
        for rel in self.node.match():
            i_rel = GraphRelation(rel)
            yield i_rel

    def outgoing_relationships(self):
        """
        :return: node's outgoing relationships iterator
        """
        for rel in self.node.match_outgoing():
            i_rel = GraphRelation(rel)
            yield i_rel
开发者ID:dkleinbe,项目名称:Graph42,代码行数:58,代码来源:GraphDatabase.py

示例2: node

# 需要导入模块: from py2neo import Node [as 别名]
# 或者: from py2neo.Node import match_outgoing [as 别名]
class User:
    
    """
    Creates a User
    User has attributes Name, Version and Last Login
    When user is creates, a database node is created in Neo4j
    When user is infected, the node is remove and replaced by new node (version update)
    """
    
    # Initializer
    def __init__(self):
        
        # Give user a full name. Generated randomly
        self.name =  unicodedata.normalize('NFKD', names.get_full_name()).encode('ascii','ignore')
        
        # Current base version of the website
        self.khanAcademyVersion = 'A'
        
        # keep all students in a set
        self.students = set()
        
        # keep all coaches in a set
        self.coaches = set()
        
        # Number of loggins, int days ago
        self.lastLogin = random.randint(0,50)
        
        ######################DATABASE#######################
        
        # Save this user as a node in the graph database
        self.databaseNode = Node("UserA", name = self.name, khanAcademyVersion = self.khanAcademyVersion, LastLogin = self.lastLogin)
        graph.create(self.databaseNode)
        
        
        
    def isCoaching(self, student):
        
        if (student != self and (student not in self.students or self not in student.coaches)):
            self.students |= {student}
            student.coaches |= {self}
        
        ######################DATABASE#######################
            graph.create(Relationship(self.databaseNode, "IS_COACHING", student.databaseNode))
        
    
    def isStudent(self, coach):
        
        if (coach != self and (self not in coach.students or coach not in self.coaches)):
            coach.students |= {self}
            self.coaches |= {coach}
        
        ######################DATABASE#######################
            graph.create(Relationship(coach.databaseNode, "IS_COACHING", self.databaseNode))
    
    #Class method for user infection    
    def infect(self):
        
        # Deploys new version of Khan Academy to this user
        self.khanAcademyVersion = 'B'
        
        ######################DATABASE#######################
        
        # save all relationships, ingoing and outgoing of this node
        incomingRel = self.databaseNode.match_incoming(rel_type="IS_COACHING")
        outgoingRel = self.databaseNode.match_outgoing(rel_type="IS_COACHING")
        
        # create a node that is of typer UserN
        self.databaseNode = Node("UserB", name = self.name, khanAcademyVersion = self.khanAcademyVersion, LastLogin = self.lastLogin)
        graph.create(self.databaseNode)     
        
        # Build the same relationships as the UserA node
        for r in incomingRel:
            startNode = r.start_node
            graph.create(Relationship(startNode, "IS_COACHING", self.databaseNode))
        for r in outgoingRel:
            endNode = r.end_node
            graph.create(Relationship(self.databaseNode, "IS_COACHING", endNode))
        
        
        # Delete the old node
        cypher.execute("MATCH (u :UserA {khanAcademyVersion: {khanAcademyVersion}, name: {name}})-[r]-() DELETE r", khanAcademyVersion = 'A', name = self.name)
        cypher.execute("MATCH n WHERE (n.khanAcademyVersion = {khanAcademyVersion} AND n.name = {name}) DELETE n", khanAcademyVersion = 'A', name = self.name)
开发者ID:nrkfeller,项目名称:user_infection,代码行数:84,代码来源:userclass.py


注:本文中的py2neo.Node.match_outgoing方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。