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


Python Graph.relationship方法代码示例

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


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

示例1: __init__

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import relationship [as 别名]
class GraphDB:

    def __init__(self,username, password, server, port):
        '''
            username = 'neo4j'
            password = '*'
            server = 'localhost'
            port = '7474'
        '''
        self.username = username
        self.password = password
        self.server = server
        self.port = port
        self.con_url = 'http://'+username+':'+password+'@'+server+':'+port+'/db/data/'
        self.graph = Graph(self.con_url)

         ##TODO: move these to constants.py when IPYTHON not required
        self.metaprops = {
        'RESOLVEDUUID':'_resolvedWithUUID_',
        'RESOLVEDRELID':'_resolvedWithRELID_',
        'RESOLVEDHENID':'_resolvedWithHENID_', ##for hyper edge node
        'RESOLVEDHERID':'_resolvedWithHERID_', ##for hyper edge relation
        }

    #Done: Multiple each time want to ask something
    #Else: works on old data only
    ##Wont use this
    def getGraph(self):
        return self.graph

    ##NOT TO BE USED
    #this is how we use the intenal ids of the graph
    ##should we use it?? most people say no
    ## anyways, made the method for future use
    ## Use : getNodeByInternalId(graph, 152)
    def getNodeByInternalId(self,id):
        a = self.graph.node(id) #getting by id given internally by neo4j
        a.pull()
        return a


    ##NOT TO BE USED
    ## similar to above
    ## Use : getRelByInternalId(graph, 4)
    def getRelByInternalId(self,id):
        a = self.graph.relationship(id)
        a.pull()
        return a

    def getNodeByUniqueID(self, uniquelabel, idName, idVal, isIDString=False):
        ##TODO: move uuid to props
        query = "match (n:"+uniquelabel+" {"
        if isIDString:
            query = query+ idName+":'"+str(idVal)+"'}) return n"
        else:
            query = query+ idName+":"+str(idVal)+"}) return n"
        rc = self.graph.cypher.execute(query)
        return rc[0][0]


    def getRelationByUniqueID(self, idName, idVal, isIDString=False):
        ##TODO: move uuid to props
        query = "match ()-[r {"
        if isIDString:
            query = query+ idName+":'"+str(idVal)+"'}]->() return r"
        else:
            query = query+ idName+":"+str(idVal)+"}]->() return r"
        rc = self.graph.cypher.execute(query)
        return rc[0][0]


    def isPropList(self, node, prop):
        return type(node[prop]) is list

    ##has a counter brother in nexusapis flask app
    def isValidNonMetaProp(self, propname):
        if propname[0]=='_' or propname[-1]=='_':
            return False
        return True

    ##copy meta = True
    def copyNode(self, node, copymeta = True, exceptions = []):
        #exceptions are the props that should be included no matter what, if they have underscore or not!
        naya = Node()
        for label in node.labels:
            naya.labels.add(label)
        for prop in exceptions:
            if prop in node.properties:
                naya[prop] = node[prop]
        for prop in node.properties:
            if not copymeta:
                if self.isValidNonMetaProp(prop):
                    naya[prop] = node[prop]
            else:
                naya[prop] = node[prop]
        return naya

    def copyNodeAsItIs(self, node):
        return self.copyNode(node)
        #         naya = Node()
#.........这里部分代码省略.........
开发者ID:amartyaamp,项目名称:power_networks,代码行数:103,代码来源:graphdb.py


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