當前位置: 首頁>>代碼示例>>Python>>正文


Python py2neo.Node方法代碼示例

本文整理匯總了Python中py2neo.Node方法的典型用法代碼示例。如果您正苦於以下問題:Python py2neo.Node方法的具體用法?Python py2neo.Node怎麽用?Python py2neo.Node使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在py2neo的用法示例。


在下文中一共展示了py2neo.Node方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: printGraph

# 需要導入模塊: import py2neo [as 別名]
# 或者: from py2neo import Node [as 別名]
def printGraph(graphity):

	# TODO add more info to print, alias and stuff, sample info
	# print dangling APIs
	# print dangling strings
	
	for item in graphity.nodes(data=True):
		print item[0]
		if 'alias' in item[1]:
			print "Node alias: " + item[1]['alias']
	
		# mix up API calls and strings and sort by offset
		callStringMerge = item[1]['calls'] + item[1]['strings']
		callStringMerge.sort(key=lambda x: x[0])
	
		for cx in callStringMerge:
			print cx


# Printing all the meta info to cmdline 
開發者ID:GDATAAdvancedAnalytics,項目名稱:r2graphity,代碼行數:22,代碼來源:graphityOut.py

示例2: make_disease_nodes

# 需要導入模塊: import py2neo [as 別名]
# 或者: from py2neo import Node [as 別名]
def make_disease_nodes(self, diseases_dict):
        i = 1
        for disease in diseases_dict:
            if i % 50 == 0:
                print("create disease node count=%d" % i)
            node = Node("Disease", name=disease['name'], intro=disease['intro'],
                        cause=disease['cause'], prevent=disease['prevent'], nursing=disease['nursing'],
                        insurance=disease['insurance'], easy_get=disease['easy_get'], get_way=disease['get_way'],
                        get_prob=disease['get_prob'], treat=disease['treat'], treat_prob=disease['treat_prob'],
                        treat_period=disease['treat_period'], treat_cost=disease['treat_cost'],
                        treat_detail=disease['treat_detail']
                        )
            self.g.create(node)
            i += 1
        print("create total disease node count=%d" % (i - 1))
        return 
開發者ID:pengyou200902,項目名稱:Doctor-Friende,代碼行數:18,代碼來源:create_graph.py

示例3: _create_node

# 需要導入模塊: import py2neo [as 別名]
# 或者: from py2neo import Node [as 別名]
def _create_node(self, label, nodes):
        """
        建立節點
        :param label:
        :param nodes:
        :return:
        """
        count = 0
        for node_name in nodes:
            node = Node(label, name=node_name)
            self.g.create(node)
            count += 1
            print(count, len(nodes))
        return 
開發者ID:shibing624,項目名稱:dialogbot,代碼行數:16,代碼來源:build_medicalgraph.py

示例4: _create_diseases_nodes

# 需要導入模塊: import py2neo [as 別名]
# 或者: from py2neo import Node [as 別名]
def _create_diseases_nodes(self, disease_infos):
        """創建知識圖譜中心疾病的節點"""
        count = 0
        for disease_dict in disease_infos:
            node = Node("Disease", name=disease_dict['name'], desc=disease_dict['desc'],
                        prevent=disease_dict['prevent'], cause=disease_dict['cause'],
                        easy_get=disease_dict['easy_get'], cure_lasttime=disease_dict['cure_lasttime'],
                        cure_department=disease_dict['cure_department']
                        , cure_way=disease_dict['cure_way'], cured_prob=disease_dict['cured_prob'])
            self.g.create(node)
            count += 1
            print(count)
        return 
開發者ID:shibing624,項目名稱:dialogbot,代碼行數:15,代碼來源:build_medicalgraph.py

示例5: build_db

# 需要導入模塊: import py2neo [as 別名]
# 或者: from py2neo import Node [as 別名]
def build_db(self):
        """
        This method removes data from database and build new graph with in-memory data in application server.
        :return: None
        """
        self.db.graph.delete_all()  # delete all existing nodes and relationships
        queue = deque()
        tx = self.db.graph.begin()
        self.logger.info('Start updating database.')
        node = Node('TrieNode', 'ROOT',
                    isword=False,
                    name='',
                    )
        node['count'] = self.__root.total_counts()
        tx.create(node)  # create root in neo4j
        queue.append((node, self.__root))
        count = 0

        while queue:
            db_node, cur = queue.popleft()
            for child in cur.children:
                prefix = cur.children[child].prefix
                db_node_child = Node('TrieNode',
                                     name=prefix,
                                     isword=cur.children[child].isWord,
                                     count=cur.children[child].total_counts()
                                     )
                queue.append((db_node_child, cur.children[child]))
                tx.create(db_node_child)
                count += 1
                tx.create(Database.Parent(db_node, db_node_child))

        tx.commit()
        if not self.testing:
            # self.logger.info('Finished building database. Number of nodes created is {count}'.format(count=count))
            self.logger.info(f'Finished building database. Number of nodes created is {count}')

        if self.testing and tx.finished():
            self.logger.info('Transaction finished.') 
開發者ID:weihesdlegend,項目名稱:Autocomplete-System,代碼行數:41,代碼來源:Server.py

示例6: update_db

# 需要導入模塊: import py2neo [as 別名]
# 或者: from py2neo import Node [as 別名]
def update_db(self):
        """
        Update database with latest application server usage
        :return: None
        """
        root = self.__root
        g = self.db.graph

        def dfs(node, parent):
            """update node info to database"""
            if not node:
                return
            db_node = self._selector.match('TrieNode', name=node.prefix).first()
            if not db_node:
                tx = g.begin()
                db_node = Node('TrieNode',
                               name=node.prefix,
                               isword=node.isWord,
                               count=node.total_counts())
                tx.create(db_node)
                parent_db_node = self._selector.match('TrieNode', name=parent.prefix).first()
                tx.create(Database.Parent(parent_db_node, db_node))
                tx.commit()
            else:
                db_node['count'] = node.total_counts()
                g.push(db_node)
            for child in node.children:
                dfs(node.children[child], node)

        dfs(root, None) 
開發者ID:weihesdlegend,項目名稱:Autocomplete-System,代碼行數:32,代碼來源:Server.py

示例7: create_nodes

# 需要導入模塊: import py2neo [as 別名]
# 或者: from py2neo import Node [as 別名]
def create_nodes(self, label, entities_names):
        i = 1
        for entity in entities_names:
            if i % 500 == 0:
                print("create %s node count=%d" % (label, i))
            node = Node(label, name=entity)
            self.g.create(node)
            i += 1
        print("create total %s node count=%d" % (label, i - 1))
        return 
開發者ID:pengyou200902,項目名稱:Doctor-Friende,代碼行數:12,代碼來源:create_graph.py

示例8: look_and_create

# 需要導入模塊: import py2neo [as 別名]
# 或者: from py2neo import Node [as 別名]
def look_and_create(name):
    end = matcher.match("Jinyong", name=name).first()
    if end is None:
        end = Node('Jinyong', name=name)           
    return end 
開發者ID:liuyuzhangolvz,項目名稱:novel-kg,代碼行數:7,代碼來源:mongo2neo.py

示例9: insertAiroData

# 需要導入模塊: import py2neo [as 別名]
# 或者: from py2neo import Node [as 別名]
def insertAiroData(self, data):
        print("Inserting node data!")
        bssidNodes, stationNodes = data[0][0], data[0][1]
        for b in bssidNodes:
            try:
                bNode = Node(b['type'], name=b['name'], bssid=b['bssid'], oui=b['oui'], encryption=b["encryption"], speed=b['speed'], channel=b['channel'], auth=b['auth'], cipher=b['cipher'], lan=b['lan'])
                bNode.add_label("Device")
                self.graph.create(bNode)
            except ClientError:
                pass
        
        for essids, s in stationNodes:
            sNode = self.graph.nodes.match("Device", bssid=s['bssid']).first()
            if sNode is None:
                sNode = Node(s["type"], name=s['name'], bssid=s['bssid'], FirstTimeSeen=s['fts'], LastTimeSeen=s['lts'],Power=s['pwr'], NumPackets=s['pkts'], Association=s['assoc'], oui=s['oui'])
                sNode.add_label("Device")
            else:
                sNode['FirstTimeSeen'] = s['fts']
                sNode['LastTimeSeen'] = s['lts']
                sNode['Power'] = s['pwr']
                sNode['NumPackets'] = s['pkts']
                sNode['Association'] =s['assoc']
                self.graph.push(sNode)
                sNode = self.graph.nodes.match("Device", bssid=s['bssid']).first()

            for essid in essids: 
                nExisting = self.graph.nodes.match("Device", name=essid).first()
                if len(essid) > 0:
                    newProbe = Node("AP", name=essid)
                    newProbe.add_label("Device")
                    self.graph.create(Relationship(sNode, "Probes", nExisting or newProbe))
            
            if s['assoc'] is not None:
                aExisting = self.graph.nodes.match("Device", bssid=s['assoc']).first()
                newAssoc = Node("AP", bssid=s['assoc'])
                newAssoc.add_label("Device")
                self.graph.create(Relationship(sNode, "AssociatedTo", aExisting or newAssoc))
        
        print("Database updated!") 
開發者ID:daddycocoaman,項目名稱:BeaconGraph,代碼行數:41,代碼來源:neoHandler.py

示例10: add_nlucell

# 需要導入模塊: import py2neo [as 別名]
# 或者: from py2neo import Node [as 別名]
def add_nlucell(self, label="NluCell", name=None, content=None, topic="", tid="", \
        ftid="", behavior="", parameter="", url="", tag="", keywords="", api="", txt="", \
        img="", button="", description="", delimiter='|'):
        """Add nlucell node in graph.
        根據 name, topic, tid 確認節點是否已存在,存在則覆蓋,不存在則追加。
        問題不能為空,避免因知識庫表格填寫格式不對而導致存入空問答對
        """
        assert name is not None, "name must be string."
        assert content is not None, "content must be string."
        for question in name.split(delimiter):
            question = question.strip()
            if question: # 問題不能為空
                # 根據 name, topic, tid 確認節點是否已存在
                match_tid = "''" if tid == '' else str(tid)
                node = self.selector.select("NluCell").where("_.name ='" + question + "'", \
                    "_.topic ='" + topic + "'", "_.tid =" + match_tid).first()
                if node: # 存在則覆蓋
                    # node['name'] = question
                    node['content'] = content
                    # node['topic'] = topic
                    # node['tid'] = tid
                    node['ftid'] = ftid
                    node['behavior'] = behavior
                    node['parameter'] = parameter
                    node['url'] = url
                    # node['tag'] = tag
                    node['keywords'] = keywords
                    node['api'] = api
                    node['txt'] = txt
                    node['img'] = img
                    node['button'] = button
                    node['description'] = description
                    self.graph.push(node)
                else: # 不存在則追加
                    tag = get_tag(question, self.user)
                    node = Node(label, name=question, content=content, topic=topic, \
                        tid=tid, ftid=ftid, behavior=behavior, parameter=parameter, \
                        url=url, tag=tag, keywords=keywords, api=api, txt=txt, img=img, \
                        button=button, description=description, hot=0)
                    self.graph.create(node) 
開發者ID:Decalogue,項目名稱:chat,代碼行數:42,代碼來源:graph.py

示例11: add_ts

# 需要導入模塊: import py2neo [as 別名]
# 或者: from py2neo import Node [as 別名]
def add_ts(self, label="TestStandard", question=None, content=None, context="", \
    behavior="", parameter="", url=""):
        """
        Add test standard node in graph.
        """
        assert question is not None, "question must be string."
        assert content is not None, "content must be string."
        for item in question.split():
            item = item.strip()
            if item: # 問題不能為空,避免因知識庫表格填寫格式不對而導致存入空問答對
                node = Node(label, question=item, content=content, context=context, \
                behavior=behavior, parameter=parameter, url=url)
                self.graph.create(node) 
開發者ID:Decalogue,項目名稱:chat,代碼行數:15,代碼來源:graph.py

示例12: add_to_memory

# 需要導入模塊: import py2neo [as 別名]
# 或者: from py2neo import Node [as 別名]
def add_to_memory(self, question="question", userid="A0001"):
        """Add user question to memory.
        將用戶當前對話加入信息記憶。

        Args:
            question: 用戶問題。
                Defaults to "question".
            userid: 用戶唯一標識。
                Defaults to "userid".
        """
        previous_node = self.graph.find_one("Memory", "qa_id", self.qa_id)
        self.qa_id = get_current_time()
        node = Node("Memory", question=question, userid=userid, qa_id=self.qa_id)
        if previous_node:
            relation = Relationship(previous_node, "next", node)
            self.graph.create(relation)
        else:
            self.graph.create(node)

    # def extract_navigation(self, question):
        """Extract navigation from question。從問題中抽取導航地點。
        從導航地點列表選取與問題匹配度最高的地點。
        QA匹配模式:(模糊匹配/全匹配)

        Args:
            question: User question. 用戶問題。
        """
        # result = dict(question=question, name='', content=self.iformat(random_item(self.do_not_know)), \
            # context="", tid="", ftid="", url="", behavior=0, parameter="", txt="", img="", button="", valid=1)
        
        # 模式1:模糊匹配
        # temp_sim = 0
        # sv1 = synonym_cut(question, 'wf')
        # if not sv1:
            # return result
        # for location in self.locations:
            # sv2 = synonym_cut(location, 'wf')
            # if sv2:
                # temp_sim = similarity(sv1, sv2, 'j')
            # 匹配加速,不必選取最高相似度,隻要達到閾值就終止匹配
            # if temp_sim > 0.92:
                # print("Navigation location: " + location + " Similarity Score: " + str(temp_sim))
                # result["content"] = location
                # result["context"] = "user_navigation"
                # result["behavior"] = int("0x001B", 16)
                # return result
        
        # 模式2:全匹配,判斷“去”和地址關鍵詞是就近的動詞短語情況
        # for location in self.locations:
            
            # keyword = "去" + location
            # if keyword in question:
                # print("Original navigation")
                # result["name"] = keyword
                # result["content"] = location
                # result["context"] = "user_navigation"
                # result["behavior"] = int("0x001B", 16)
                # return result
        # return result 
開發者ID:Decalogue,項目名稱:chat,代碼行數:61,代碼來源:qa.py


注:本文中的py2neo.Node方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。