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


Python Node.cast方法代码示例

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


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

示例1: test_node_cast

# 需要导入模块: from py2neo import Node [as 别名]
# 或者: from py2neo.Node import cast [as 别名]
def test_node_cast():
    alice = Node("Person", "Employee", name="Alice", age=33)
    assert Node.cast() == Node()
    assert Node.cast(None) is None
    assert Node.cast(alice) is alice
    assert Node.cast("Person") == Node("Person")
    assert Node.cast(name="Alice") == Node(name="Alice")
    assert Node.cast("Person", "Employee", name="Alice", age=33) == alice
    assert Node.cast({"name": "Alice"}) == Node(name="Alice")
    assert Node.cast(("Person", "Employee", {"name": "Alice", "age": 33})) == alice
    assert Node.cast(42) == NodePointer(42)
    assert Node.cast(NodePointer(42)) == NodePointer(42)
开发者ID:JohannesOos,项目名称:py2neo,代码行数:14,代码来源:cast_test.py

示例2: create_company_node

# 需要导入模块: from py2neo import Node [as 别名]
# 或者: from py2neo.Node import cast [as 别名]
def create_company_node(name, tw=None, em=None, fb=None):
    """ Creates a company type node

        Parameters: Name, Twitter Handle, Email Address, Facebook URL
        Returns: Company Node
    """
    properties = {"name" : name}
    properties["facebook"] = [fb] if fb else []
    properties["twitter"] = [tw] if tw else []
    properties["email"] = [em] if em else []
    company = Node.cast("company", properties)

    # searches for company nodes with the same name
    results = list(graph.find("company", "name", name))
    if results:
        # if there are already nodes of the same name in the graph,
        # add the information from the incoming node to the duplicate
        dupe = results[0]
        if fb and not fb in dupe["facebook"]: dupe["facebook"].append(fb)
        if tw and not tw in dupe["twitter"]: dupe["twitter"].append(tw)
        if em and not em in dupe["email"]: dupe["email"].append(em)
        dupe.push()
    else:
        # if there are no nodes of the same name in the graph,
        # add the company node to the graph as it is
        graph.create(company)
开发者ID:karishay,项目名称:advocate_calculator,代码行数:28,代码来源:graph_model.py

示例3: create_node

# 需要导入模块: from py2neo import Node [as 别名]
# 或者: from py2neo.Node import cast [as 别名]
 def create_node(self, node_label, node_dict):
     cur_nid = self.get_max_nid() + 1
     node_dict[ArianeDefinitions.GRAPH_NODE_ID] = cur_nid
     node = Node.cast(node_dict)
     node.labels.add(node_label)
     self.graph.create(node)
     return node, cur_nid
开发者ID:echinopsii,项目名称:net.echinopsii.ariane.community.relmgr,代码行数:9,代码来源:neographDB.py

示例4: peuple

# 需要导入模块: from py2neo import Node [as 别名]
# 或者: from py2neo.Node import cast [as 别名]
 def peuple(self, commune):
     voiesdelacommune = self.voies[commune]
     nbvoiesdelacommune = len(self.voies[commune])
     placecommune = list(self.communes).index(commune)+1
     nbcommunes = len(self.communes)
     cpt = 0
     for v in voiesdelacommune:
         #if not re.compile(".*D59.*").match(v.libelle): continue
         numero = Numero(7, v.libelle, v.sti, v.rivoli[:-1], v.rivoli, None, None)
         cpt += 1
         ## Pour contourner un bug d'espace dans le fichier d'open data..
         if numero.lib_off[0] == " ": numero.lib_off = numero.lib_off[1:]
         try:
             ## On recupere le noeud de rue qui va recevoir ce numero. Ne retourne normalement qu'une rue donc on selectionne le premier et unique resultat avec ,
             #voie, = self.graph.cypher.execute( "match (v:Voie { libelle:'%s' })-[:ORGANISE]-(c:Commune {libcom:'%s'}) return v" % (numero.lib_off, commune) )
             voie, = self.graph.cypher.execute( "match (v:Voie { libelle:'%s' })-[:ORGANISE]-(c:Commune {libcom:'%s'}) return v" % (numero.lib_off, commune) )
         except ValueError as e:
             print("WARNING;%s;  La voie <%s> de la commune <%s> n'existe pas." % (cpt,numero.lib_off,commune) )
             print("%s" % (e) )
             continue
         
         for n in self.nums_dans_rue:
             numero.no = n
             newnum = Node.cast("Numero", numero.to_dict() )
             #print( "    %s ; %s ; %s\n%s" % (n,type(newnum),newnum,voie) )
             ## Le noeud Numero est crée en meme temps que la relation
             arete = self.graph.create( Relationship(voie['v'],"COMPORTE",newnum) )
             
             #if n % 50 == 0 : print( "%s ; %s ; %s" % (n,type(newnum),newnum) )
             #if n % 50 == 0 : print( "  %s" % (arete) )
         if cpt %10 == 0 : print( "Voie %s/%s de la commune %s / %s" % (cpt,nbvoiesdelacommune, placecommune, nbcommunes) )
开发者ID:wh6b,项目名称:study-neo4j-vs-orientdb,代码行数:33,代码来源:generateur_urbanisme.py

示例5: create_node

# 需要导入模块: from py2neo import Node [as 别名]
# 或者: from py2neo.Node import cast [as 别名]
 def create_node(self,graph_db):
     # Ajouter propriétés du type "modified" ?
     fiche_properties = {'doc_position': self.tmp_id, 'titre': self.titre,
                         'auteur': self.auteur, 'contenu': self.contenu, 'date_creation': self.date_creation}
     fiche_node = Node.cast(fiche_properties)
     fiche_node.labels.add(self.node_type)
     self._node = fiche_node
     graph_db.create(self._node)
开发者ID:benjaminh,项目名称:tal4history-neo,代码行数:10,代码来源:Fiche.py

示例6: create_cq

# 需要导入模块: from py2neo import Node [as 别名]
# 或者: from py2neo.Node import cast [as 别名]
 def create_cq(user_node, cq_dict):
     cq_dict['id'] = str(uuid.uuid4())
     cq_dict['created_date'] = datetime.date.today()
     cq_node = Node.cast(GraphLabel.CQ,
                         cq_dict)
     cq_node, = Graph(settings.DATABASE_URL).create(cq_node)
     cq_relationship = Relationship(user_node,
                                    GraphRelationship.SENT,
                                    cq_node)
     Graph(settings.DATABASE_URL).create_unique(cq_relationship)
开发者ID:julianpistorius,项目名称:back-end-api,代码行数:12,代码来源:cq.py

示例7: upsert_user

# 需要导入模块: from py2neo import Node [as 别名]
# 或者: from py2neo.Node import cast [as 别名]
def upsert_user(user):
    """

    :param user: dictionary
    :return:
    """

    drenaj_api_logger.info('Upserting: ' + user['id_str'])

    # for key in user.keys():
    #     print key + ': ' + str(user[key]) + " - " + str(type(user[key]))

    # removing these beacuse neo4j doesn't allow nested nodes.
    if 'entities' in user:
        user['entities'] = bson.json_util.dumps(user['entities'])
    if 'status' in user:
        del user['status']

    # Find the related user. This looks complicated because of {'id_str': '', 'screen_name': 'blabla'} entries
    # coming from create_campaign
    user_node = None
    if 'id_str' in user and 'screen_name' in user and user['id_str'] != '' and user[
        'screen_name'] != '':
        user_node = graph.cypher.execute("MATCH (u:User) WHERE u.id_str = {id_str} RETURN u",
                                         {'id_str': user['id_str']}).one
        if not user_node:
            user_node = graph.cypher.execute(
                "MATCH (u:User) WHERE u.screen_name = {screen_name} RETURN u",
                {'screen_name': user['screen_name']}).one
    # TODO: This is very nasty! Go get learn the proper way!
    elif (type(user['id_str']) == type('STRING') or type(user['id_str']) == type(u'STRING')) and \
                    user['id_str'] != '':
        user_node = graph.cypher.execute("MATCH (u:User) WHERE u.id_str = {id_str} RETURN u",
                                         {'id_str': user['id_str']}).one
    elif (type(user['screen_name']) == type('STRING') or type(user['screen_name']) == type(
            u'STRING')) and user['screen_name'] != '':
        user_node = graph.cypher.execute(
            "MATCH (u:User) WHERE u.screen_name = {screen_name} RETURN u",
            {'screen_name': user['screen_name']}).one

    print user_node

    if user_node:
        # First clearing the user_node properties.
        for key in user_node.properties.keys():
            user_node.properties[key] = None
        # then assigning the new properties
        for key in user.keys():
            user_node.properties[key] = user[key]
        user_node.push()
    else:
        user_node = Node.cast(user)
        user_node.labels.add("User")
        graph.create(user_node)
    return user_node
开发者ID:boun-cmpe-soslab,项目名称:drenaj,代码行数:57,代码来源:drenajneo4jmanager.py

示例8: creerHabitant

# 需要导入模块: from py2neo import Node [as 别名]
# 或者: from py2neo.Node import cast [as 别名]
 def creerHabitant(self, _personne):
     self.nb_habitants += 1
     self.nb_personnes += 1
     habitant = Node.cast("Personne", _personne.to_dict() )
     habitant, = self.graph.create(habitant)
     print ("    %s" % (habitant) )
     
     h = NeoPersonne()
     h.id = habitant._Node__id
     h.node = habitant
     return h
开发者ID:wh6b,项目名称:study-neo4j-vs-orientdb,代码行数:13,代码来源:generateur_peupler_ville.py

示例9: create_organization

# 需要导入模块: from py2neo import Node [as 别名]
# 或者: from py2neo.Node import cast [as 别名]
    def create_organization(self):
        """
        create a new organization
        :return: py2neo Node
        """
        self.id = str(uuid.uuid4())
        new_org_properties = self.org_properties
        new_org_node = Node.cast(GraphLabel.ORGANIZATION, new_org_properties)
        self._graph_db.create(new_org_node)

        return new_org_node
开发者ID:julianpistorius,项目名称:back-end-api,代码行数:13,代码来源:organization.py

示例10: buildVideos

# 需要导入模块: from py2neo import Node [as 别名]
# 或者: from py2neo.Node import cast [as 别名]
def buildVideos(videos):
	for v in videos:
		rels = v['related']
		del v['related']
		node1 = Node.cast(v)
		node1.labels.add(computeLabels(v))


		graph.create(node1)
		for r in rels:
			node2 = Node("video", id=r)
			graph.create((node1, "yRel", node2))
开发者ID:rogerfitz,项目名称:magla,代码行数:14,代码来源:neo4j.py

示例11: create_source

# 需要导入模块: from py2neo import Node [as 别名]
# 或者: from py2neo.Node import cast [as 别名]
    def create_source(self, graph_db):

        # Ajouter propriétés du type "modified" ?
        if self.filename != '':
            source_properties = {'legende': self.legende, 'fichier': self.filename}
        else:
            source_properties = {'legende': self.legende}
        source_node = Node.cast(source_properties)
        source_node.labels.add(self.node_type)
        source_node.labels.add(self.type_source)
        self._node = source_node

        graph_db.create(self._node)
开发者ID:benjaminh,项目名称:tal4history-neo,代码行数:15,代码来源:Source.py

示例12: create_location

# 需要导入模块: from py2neo import Node [as 别名]
# 或者: from py2neo.Node import cast [as 别名]
 def create_location(self):
     # self.id = str(uuid.uuid4())
     # new_location_properties = {
     #     "formatted_address": self.formatted_address,
     #     "name": self.name,
     #     "place_id": self.place_id
     # }
     new_location_node = Node.cast(GraphLabel.LOCATION, self.location_properties)
     try:
         self._graph_db.create(new_location_node)
     except:
         pass
     return new_location_node
开发者ID:julianpistorius,项目名称:back-end-api,代码行数:15,代码来源:location.py

示例13: create_interest

# 需要导入模块: from py2neo import Node [as 别名]
# 或者: from py2neo.Node import cast [as 别名]
    def create_interest(self):
        """
        create an interest node based on the class attributes
        :return: py2neo Node
        """
        #TODO error handling
        self.id = str(uuid.uuid4())
        new_interest_node = Node.cast(GraphLabel.INTEREST, self.interest_properties)
        try:
            self._graph_db.create(new_interest_node)
        except:
            pass

        return new_interest_node
开发者ID:julianpistorius,项目名称:back-end-api,代码行数:16,代码来源:interest.py

示例14: create_group

# 需要导入模块: from py2neo import Node [as 别名]
# 或者: from py2neo.Node import cast [as 别名]
    def create_group(self):
        """
        create new study group or circle
        :return: py2neo Node
        """
        self.id = str(uuid.uuid4())

        new_group_node = Node.cast(GraphLabel.STUDYGROUP, self.group_properties)
        try:
            self._graph_db.create(new_group_node)
        except:
            pass

        return new_group_node
开发者ID:julianpistorius,项目名称:back-end-api,代码行数:16,代码来源:group.py

示例15: create_goal

# 需要导入模块: from py2neo import Node [as 别名]
# 或者: from py2neo.Node import cast [as 别名]
 def create_goal(self):
     """
     create a goal and relate to user
     :return: neo4j.Node
     """
     # goal_node = self.get_goal() #TO GO get goal to prevent duplication?  maybe not needed -- MMMD 11/12/2014
     # if goal_node is None:
     self.unique_id = str(uuid.uuid4())
     new_goal_properties = {
         "title": self.title,
         "description": self.description,
         "unique_id": self.unique_id,
         "start_date": self.start_date,
         "end_date": self.end_date}
     new_goal = Node.cast(AgoraLabel.GOAL, new_goal_properties)
     return new_goal
开发者ID:julianpistorius,项目名称:agora-development,代码行数:18,代码来源:py2neo_goal.py


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