系列文章目录
前言
随着人工智能的不断发展,图这门技术也越来越重要,很多人都开启了学习图,本文就介绍了图的常用数据库neo4j。
以下是本篇文章正文内容,下面案例可供参考
一、neo4j是什么?
图数据库的一种。
二、使用步骤
1.连接图数据库
代码如下(示例):
#连接图数据库
import pandas as pd
from py2neo import Graph, Node, Relationship
def connect_graph():
graph = Graph("http://*.*.*.*:7474", username = "neo4j", password = ' password')
return (graph)
graph = connect_graph()
2.图遍历
路径遍历:
def all_paths_(graph):
all_paths = pd.DataFrame(graph.run("MATCH p = (n:Cust{})-[r:guarantee*..5]->(m) where SIZE(apoc.coll.toSet(NODES(p))) = length(p)+1 RETURN m.Cust_id as id, REDUCE(s=[], x in NODES(p) | s + x.Cust_id) as path, length(p) + 1 as path_len, n.Cust_id as start ").data())
all_paths['path'] = (['->'.join(x) for x in all_paths['path']])
all_paths = all_paths.drop_duplicates()[:]
return (all_paths)
all_paths = all_paths_(graph)
总结
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pyneo连接图数据库的使用.