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


Python Graph.create方法代码示例

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


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

示例1: PersonLoader

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import create [as 别名]
class PersonLoader(object):

    def __init__(self):
        authenticate("localhost:7474", "neo4j", "1111")
        self.graph_db = Graph(graph_DB_url)
        self.api_url = "http://127.0.0.1:8000/api/v1/person/?format=json"
        self.statement = "MERGE (n:Person {Name:{N}, Identification:{I}, id: {ID}, NonResidentForeigner:{NR}," \
                         "MoreInformation:{MI}}) RETURN n"

    def whipUp(self):
        objects = json.load(urlopen(self.api_url))["objects"]

        for object in objects:
            args = {}
            args["ID"]=object["id"]

            args["I"]=object["Identification"]
            args["NR"]=object["NonResidentForeigner"]
            args["N"]=object["Name"]
            args["MI"]=object["MoreInformation"]
            #args["AD"]=object["Address"]["id"]

            perCh = getPerson(Name=args["N"])
            if perCh!=None:
                continue

            db = self.graph_db.cypher.begin()
            db.append(self.statement, args)
            db.commit()
            address = getAddress(id=int(object["Address"]["id"]))
            person = getPerson(id=int(args["ID"]))

            self.graph_db.create(rel(person.one, "LIVED", address.one))
开发者ID:VadyaVL,项目名称:labs,代码行数:35,代码来源:loadMyDB.py

示例2: createGraph

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import create [as 别名]
	def createGraph(self):
		""" 
		form: 
		(self) --> print

		description: 
		function that creates the neo4j graph

		exemple:
		>>> graphWN..createGraph()
		creating graph...
		graph created

		"""
		print "creating graph..."
		graph = Graph()
		graph.delete_all()
		for synset in self.synset2synonym:
		  word_node = Node("word", literal=self.synset2word[synset])
		  #print synset, self.synset2synonym[synset]
		  #if graph.find(self.synset2word[synset])!=None:
		    #print "Exist"
		    #word_node=graph.find_one("word", 'literal', self.synset2word[synset])
		    #print word_node
		  synset_node = Node("synset", name=synset)
		  word_has_synset = Relationship(word_node, "has_synset", synset_node)
		  if self.synset2synonym[synset][0]!='_EMPTY_':
		    for synonym in self.synset2synonym[synset]:
		      word_syn = Node("word", literal=synonym)
		      synset_has_synonym = Relationship(synset_node, "has_synonym", word_syn)
		      graph.create(synset_has_synonym)
		  graph.create(word_has_synset)
		print "graph created"
开发者ID:muvikt,项目名称:BaseDeDonnees,代码行数:35,代码来源:script.py

示例3: __init__

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import create [as 别名]
class Neo4jConnector:
    _graph_connection = None

    def __init__(self, connectionString=None):
        # set up authentication parameters
        authenticate("localhost:7474", "neo4j", "123")

        self.connectionString = "http://localhost:7474/db/data/"
        self._graph_connection = Graph(connectionString)
        self.error_file = open("Dump/log/dberror.txt", "a")
        return


    def createNodes(self, wikiPage):
        print ("creating node %s" %wikiPage.getTitle())
        try:
            if self._graph_connection is not None:
                alice = Node("article2",name = wikiPage.title,content= wikiPage.getContent())
                self._graph_connection.create(alice)
            else:
                self.error_file.write("create node failed: connection not avaialable".encode('utf-8'))
                print 'create node failed: connection not avaialable'
            return
        except Exception, e:
                self.error_file.write('Search failed: {%s} { %s } \n' % (wikiPage.getTitle(), e.message))
                print 'create node failed: %s %s' % (e.message,e.args)
                pass
开发者ID:MoizRauf,项目名称:OQuant_Wiki_Clustering,代码行数:29,代码来源:NeoConnector.py

示例4: createRelationships

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import create [as 别名]
def createRelationships():
    global relationships
    graph = Graph('http://localhost:7474/db/data')
    for r in relationships:
        NodeA = graph.find_one(r["start"]["collection"],property_key = "_id", property_value = str(r["start"]["_id"]))
        NodeB = graph.find_one(r["end"]["collection"],property_key = "_id", property_value = str(r["end"]["_id"]))
        graph.create(rel(NodeA,r["name"],NodeB))
开发者ID:davidmeza1,项目名称:KA_Interns,代码行数:9,代码来源:Scraper3.py

示例5: SocialFormationLoader

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import create [as 别名]
class SocialFormationLoader(object):

    def __init__(self):
        authenticate("localhost:7474", "neo4j", "1111")
        self.graph_db = Graph(graph_DB_url)
        self.api_url = "http://127.0.0.1:9000/api/v1/socialformation/?format=json"
        self.statement = "MERGE (n:SocialFormation {id: {ID}, Name:{N}, DateReg:{DR}, RegNumb:{RN}}) RETURN n"

    def whipUp(self):
        objects = json.load(urlopen(self.api_url))["objects"]

        for object in objects:
            args = {}
            args["ID"]=object["id"]

            args["N"]=object["Name"]
            args["DR"]=object["DateReg"]
            args["RN"]=object["RegNumb"]

            #print args
            db = self.graph_db.cypher.begin()
            db.append(self.statement, args)
            db.commit()

            sf = getSocialFormation(args["ID"])
            adr = getAddress(id = int(object["Address"]["id"]), Street = object["Address"]["Street"])
            #per = getPerson(id = int(object["Person"]["id"]), Name = (object["Person"]["Surname"] + " " + object["Person"]["Name"]))
            per = getPerson(Name = (object["Person"]["Surname"] + " " + object["Person"]["Name"]))

            if adr != None:
                self.graph_db.create(rel(sf.one, "HAVE_ADDRESS", adr.one))
            if per != None:
                self.graph_db.create(rel(sf.one, "SF_HAVE_PERSON", per.one))
开发者ID:VadyaVL,项目名称:labs,代码行数:35,代码来源:loadSPDB.py

示例6: getTestedNeo4jDB

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import create [as 别名]
def getTestedNeo4jDB(graphDBurl, graphDbCredentials):
    '''Gets a Neo4j url and returns a GraphDatabaseService to the database
    after having performed some trivial tests'''
    try:
        if graphDbCredentials:
            authenticate(*graphDbCredentials)
        graphDb = Graph(graphDBurl)
        #just fetch a Node to check we are connected
        #even in DRY RUN we should check Neo4j connectivity
        #but not in OFFLINE MODE
        if not OFFLINE_MODE:
            _ = iter(graphDb.match(limit=1)).next()
    except StopIteration:
        pass
    except SocketError as ex:
        raise DbNotFoundException(ex, "Could not connect to Graph DB %s."
                                  % graphDBurl)

    if not DRY_RUN and not OFFLINE_MODE:
        try:
            test_node = Node("TEST", data="whatever")
            graphDb.create(test_node)
            graphDb.delete(test_node)
        except Exception as ex:
            raise DBInsufficientPrivileges(\
                    "Failed on trivial operations in DB %s." % graphDBurl)

    return graphDb
开发者ID:lycofron,项目名称:pysql2neo4j,代码行数:30,代码来源:graph.py

示例7: Graph

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import create [as 别名]
class Graph(object):

    def __init__(self, neo4j_uri):
        self.graph = NeoGraph(neo4j_uri)

    def find_node(self, label, node_id):
        args = dict(property_key="node_id", property_value=node_id)
        return self.graph.find_one(label, **args)

    def create_user(self, args):
        node = self.find_node("User", args["username"])
        if not node:
            properties = dict(
                node_id=args["username"],
                name=args["name"],
                city=args["city"]
            )
            node = Node("User", **properties)
            self.graph.create(node)
            return node, True
        return node, False

    def delete_user(self, user):
        node = self.find_node("User", user)
        if node:
            self.graph.delete(node)    
            return True
        return False
开发者ID:uym2,项目名称:dlab-api,代码行数:30,代码来源:graph.py

示例8: __init__

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import create [as 别名]
class Grapher:
    def __init__(self):
        self.graph = Graph()
    
    """Accepts a dict of scanning results and adds the server, its ports and vulerabilities in Neo4jDB"""
    def plot_scan_results(self, res):
        for host in res.keys():
            hostname = res[host][KEY_HOSTNAME]
            server  = Node(SERVER, id=host, address=host, hostname=hostname)
            for attr in res[host].keys():
                if attr not in top_keys:
                    for portno in res[host][attr]:
                        if res[host][attr][portno].get(KEY_STATE, "closed") == OPEN:
                            product = res[host][attr][portno][KEY_PRODUCT]
                            version = res[host][attr][portno][KEY_VERSION]
                            cpe     = res[host][attr][portno][KEY_CPE]
                            vulnerabilities = res[host][attr][portno][KEY_VULNERABILITIES]
                            port = Node(PORT, id=portno, number=portno, protocol=attr, product=product, version=version, cpe=cpe, state=OPEN)        
                            server_has_port = Relationship(server, HAS, port) 
                            self.graph.create(server_has_port)
                            for vulnerability in vulnerabilities:
                                published   = vulnerability[KEY_PUBLISHED]
                                cve         = vulnerability[KEY_CVE] 
                                summary     = vulnerability[KEY_SUMMARY] 
                                vuln        = Node(VULNERABILITY, id=cve, cve=cve, summary=summary, published=published)
                                port_has_vuln = Relationship(port, HAS, vuln)
                                self.graph.create(port_has_vuln)
开发者ID:pombredanne,项目名称:python-server,代码行数:29,代码来源:Grapher.py

示例9: Person

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import create [as 别名]
class Person(object):

    def __init__(self):
        self.graph = Graph()
        #do nothing

    def createPerson(self, name, fullname, occupation, homepage, wikipedia_link):
        person = Node('Person', name=name, fullname=fullname, occupation=occupation, homepage=homepage, wikipedia_link=wikipedia_link)
        self.graph.create(person)
        return person
开发者ID:anishdeena,项目名称:europa,代码行数:12,代码来源:testneo4j.py

示例10: add2neo

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import create [as 别名]
def add2neo(courses):
	authenticate("localhost:7474", 'neo4j', 'admin')
	graph = Graph()
	for course in courses:
		name = course.prefix+course.number

		for pre in course.prereqs:
			print 'adding rel', name, pre
			try:
				graph.create(Relationship(courseNodes[name]['node'], 'REQUIRES', courseNodes[pre]['node']))
			except:
				print 'could not add', name, pre
开发者ID:birdman7260,项目名称:skilltree,代码行数:14,代码来源:process_courses.py

示例11: main1

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import create [as 别名]
def main1():
    authenticate("localhost:7474", "neo4j", "1234")
    graph = Graph(GRAPH_CONNECTION_STRNIG)

    graph.delete_all()

    banana = Node("Fruit", name="banana", colour="yellow", tasty=True)
    graph.create(banana)

    t = graph.merge_one("Fruit", 'name', 'apple')
    t['colour'] = 'green'
    t['tasty'] = True
    t.push()
开发者ID:vovacooper,项目名称:FreeTv,代码行数:15,代码来源:update_tv_data_new.py

示例12: AgoraOrganization

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import create [as 别名]
class AgoraOrganization(object):
    def __init__(self):
        self.name = None
        self.unique_id = None
        self.mission_statement = None
        self.email = None
        self.is_open = False
        self.is_invite_only = False
        self.website = None
        self.graph_db = Graph()

    @property
    def org_node(self):
        return self.graph_db.find_one(AgoraLabel.ORGANIZATION,
                                      property_key='name',
                                      property_value=self.name)

    @property
    def org_members(self):
        """
        list of the members of the organization
        :return: list of tuple of member name, email
        """
        org_members_nodes = self.graph_db.match(start_node=self.org_node,
                                                rel_type=AgoraRelationship.MEMBER_OF,
                                                end_node=None)
        org_members_list = []
        for item in org_members_nodes:
            org_members_list.append((item.end_node["name"], item.end_node["email"]))
        return org_members_list

    def create_organization(self):
        """
        create a new organization
        :return: py2neo Node
        """
        self.unique_id = str(uuid.uuid4())
        new_org_properties = {
            "name": self.name,
            "mission_statement": self.mission_statement,
            "unique_id": self.unique_id,
            "email": self.email,
            "is_open": self.is_open,
            "is_invite_only": self.is_invite_only,
            "website": self.website}

        new_org_node = Node.cast(AgoraLabel.ORGANIZATION, new_org_properties)
        self.graph_db.create(new_org_node)

        return new_org_node
开发者ID:julianpistorius,项目名称:agora-development,代码行数:52,代码来源:py2neo_organization.py

示例13: save_publications_list

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import create [as 别名]
 def save_publications_list(publications):
     """
     Method to save all the publications to neo4j database
     """
     
     graph = Graph()
     
     for publication in publications:
         publication_node = Node("Publication")
         
         for key in publication:
             if key not in ['_id', 'authorsSearched', 'identifiers', 'rank', 'work-citation-type']:
                 publication_node.properties[key] = publication[key]
         
         graph.create(publication_node)
         print 'Inserted Publication: ' + publication['doi']
开发者ID:jasonzou,项目名称:bibliometric,代码行数:18,代码来源:PublicationLoad.py

示例14: createRelationshipWithProperties

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import create [as 别名]
def createRelationshipWithProperties():
    print("Start - Creating Relationships")
    # Authenticate the user using py2neo.authentication
    # Ensure that you change the password 'sumit' as per your database configuration.
    py2neo.authenticate("localhost:7474", "neo4j", "sumit")
    # Connect to Graph and get the instance of Graph
    graph = Graph("http://localhost:7474/db/data/")
    # Create Node with Properties
    amy = Node("FEMALE", name="Amy")
    # Create one more Node with Properties
    kristine = Node("FEMALE",name="Kristine")
    # Create one more Node with Properties
    sheryl = Node("FEMALE",name="Sheryl")
    
    #Define an Object of relationship which depicts the relationship between Amy and Kristine
    #We have also defined the properties of the relationship - "since=2005" 
    #By Default the direction of relationships is left to right, i.e. the -->
    kristine_amy = Relationship(kristine,"FRIEND",amy,since=2005)
    
    #This relationship is exactly same as the earlier one but here we are using "Rev"
    #"py2neo.Rev = It is used to define the reverse relationship (<--) between given nodes
    amy_sheryl=Relationship(amy,Rev("FRIEND"),sheryl,since=2001)
    
    #Finally use graph Object and Create Nodes and Relationship
    #When we create Relationship between, then Nodes are also created. 
    resultNodes = graph.create(kristine_amy,amy_sheryl)
    #Print the results (relationships)
    print("Relationship Created - ",resultNodes)
开发者ID:xenron,项目名称:sandbox-dev-python,代码行数:30,代码来源:CreateRelationship.py

示例15: reblogs_into_neo4j

# 需要导入模块: from py2neo import Graph [as 别名]
# 或者: from py2neo.Graph import create [as 别名]
def reblogs_into_neo4j(reblogs):
    graph = Graph()
    everyone = set()
    for reblog in reblogs:
        everyone.add(reblog['reblogger'])
        everyone.add(reblog['reblogged_from'])
    nodes = {
        name: Node("User", name=name)
        for name in everyone
    }
    for reblog in reblogs:
        print("Creating (%s)-[:RBF]->(%s)" % (reblog['reblogger'], reblog['reblogged_from']))
        reblogger = nodes[reblog['reblogger']]
        reblogged_from = nodes[reblog['reblogged_from']]
        cxn = Relationship(reblogger, "REBLOGGED_FROM", reblogged_from)
        graph.create(cxn)
开发者ID:mkapolka,项目名称:tummy,代码行数:18,代码来源:tt.py


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