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


Python Node.properties['fName']方法代码示例

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


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

示例1: loadFromFiles

# 需要导入模块: from py2neo import Node [as 别名]
# 或者: from py2neo.Node import properties['fName'] [as 别名]
def loadFromFiles(csvfiles):
    with open(csvfiles[0],'r') as n: #names.csv
        reader = csv.reader(n)
        reader.next()
        for row in reader:
            if(len(graph_db.cypher.execute("MATCH (n:user) WHERE n.userID = " + row[0] + " return n")) == 0):#if user doesn't exist, create user
                person = Node("user","userID", userID=int(row[0]))
                person.properties['lName'] = row[2]
                person.properties['fName'] = row[1]
                graph_db.create(person)
    
    with open(csvfiles[1],'r') as n: #organizations.csv
        reader = csv.reader(n)
        reader.next()
        for row in reader:
            if(len(graph_db.cypher.execute("MATCH (n:user) WHERE n.userID = " + row[0] + " return n")) != 0): #if user exists, add organization of user
                user = graph_db.merge_one("user","userID", int(row[0]))
                
                if(len(graph_db.cypher.execute("MATCH (n {organization:\"" + row[1] + "\"}) return n")) == 0): #if organization doesn't exist, create it
                    p_organization = Node("organization", "organization", organization=row[1])
                    worksAt = Relationship(user, "WORKS AT", p_organization)
                    graph_db.create(worksAt)
                    
                    if(len(graph_db.cypher.execute("MATCH (n {organizationType:\"" + row[2] + "\"}) return n")) == 0): #if organization type doesn't exist, create it
                        org_type = Node("organizationType","organizationType",organizationType=row[2])
                        partOf = Relationship(p_organization,"PART OF",org_type)
                        graph_db.create(partOf)
                    else: #if it does exist, merge
                        if(len(graph_db.cypher.execute("MATCH (a{organization:\""+row[1]+"\"})--(b{organizationType:\"" + row[2] + "\"}) return a")) == 0):
                            org_type = graph_db.merge_one("organizationType","organizationType",row[2])
                            partOf = Relationship(p_organization,"PART OF",org_type)
                            graph_db.create(partOf)
                    
                else:#if organization exists, merge with existing
                    if(len(graph_db.cypher.execute("MATCH (a{userID:"+row[0]+"})--(b{organization:\"" + row[1] + "\"}) return a")) == 0):#makes sure any duplicate relationships aren't created
                        p_organization = graph_db.merge_one("organization", "organization", row[1])
                        worksAt = Relationship(user, "WORKS AT", p_organization)
                        graph_db.create(worksAt)
                        
                    if(len(graph_db.cypher.execute("MATCH (a{organization:\""+row[1]+"\"})--(b{organizationType:\"" + row[2] + "\"}) return a")) == 0):#makes sure any duplicate relationships aren't created
                        org_type = graph_db.merge_one("organizationType","organizationType",row[2])
                        partOf = Relationship(p_organization,"PART OF",org_type)
                        graph_db.create(partOf)
    
    with open(csvfiles[2],'r') as n: #projects.csv
        reader = csv.reader(n)
        reader.next()
        for row in reader:
            if(len(graph_db.cypher.execute("MATCH (n:user) WHERE n.userID = " + row[0] + " return n")) != 0):
                user = graph_db.merge_one("user","userID", int(row[0]))
                if(row[1] == ""): #skips entry if user isn't working on project
                    continue
                if(len(graph_db.cypher.execute("MATCH (n {project:\"" + row[1] + "\"}) return n")) == 0): #if project doesn't exist, create it
                    p_project = Node("project", "project", project=row[1])
                    worksOn = Relationship(user, "WORKS ON", p_project)
                    graph_db.create(worksOn)
                else:#if project exists, add user to project
                    if(len(graph_db.cypher.execute("MATCH (a{userID:"+row[0]+"})--(b{project:\"" + row[1] + "\"}) return a")) == 0): 
                        p_project = graph_db.merge_one("project","project",row[1])
                        worksOn = Relationship(user, "WORKS ON", p_project)
                        graph_db.create(worksOn)
    
    with open(csvfiles[4],'r') as n: #skills.csv
        reader = csv.reader(n)
        reader.next()
        for row in reader:
            if(len(graph_db.cypher.execute("MATCH (n:user) WHERE n.userID = " + row[0] + " return n")) != 0):#only add skill to user if user exists
                user = graph_db.merge_one("user","userID", int(row[0]))
                if(len(graph_db.cypher.execute("MATCH (n {skill:\"" + row[1] + "\"}) return n")) == 0): #if skill doesn't exist ,create it
                    p_skill = Node("skill", "skill", skill=row[1])
                    hasSkill = Relationship(user, "HAS", p_skill)
                    hasSkill.properties['level'] = int(row[2])
                    graph_db.create(hasSkill)
                else:#add skill to user if skill exists
                    if(len(graph_db.cypher.execute("MATCH (a{userID:"+row[0]+"})--(b{skill:\"" + row[1] + "\"}) return a")) == 0): 
                        p_skill = graph_db.merge_one("skill","skill",row[1])
                        hasSkill = Relationship(user, "HAS", p_skill)
                        hasSkill.properties['level'] = int(row[2])
                        graph_db.create(hasSkill)
                    
    with open(csvfiles[3],'r') as n: #interests.csv
        reader = csv.reader(n)
        reader.next()
        for row in reader:
            if(len(graph_db.cypher.execute("MATCH (n:user) WHERE n.userID = " + row[0] + " return n")) != 0):
                user = graph_db.merge_one("user","userID", int(row[0]))
                
                if(len(graph_db.cypher.execute("MATCH (n {interest:\"" + row[1] + "\"}) return n")) == 0): #if interest doesn't exist, create it
                    p_interest = Node("interest", "interest", interest=row[1])
                    hasInterest = Relationship(user, "HAS", p_interest)
                    hasInterest.properties['level'] = int(row[2])
                    graph_db.create(hasInterest)
                else:#if interest exists, add interest to user
                    if(len(graph_db.cypher.execute("MATCH (a{userID:"+row[0]+"})--(b{interest:\"" + row[1] + "\"}) return a")) == 0): 
                        p_interest = graph_db.merge_one("interest","interest",row[1])
                        hasInterest = Relationship(user, "HAS", p_interest)
                        hasInterest.properties['level'] = int(row[2])
                        graph_db.create(hasInterest)
    with open(csvfiles[5],'r') as n:#distance.csv
        reader = csv.reader(n)
#.........这里部分代码省略.........
开发者ID:ShoebRehman,项目名称:BigData-ProjectOne,代码行数:103,代码来源:Neo4JSandbox.py


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