当前位置: 首页>>代码示例>>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;未经允许,请勿转载。