此示例显示如何将存储作为定向图形的一组同事添加到社交邻居中的一组朋友,存储为Neo4j®数据库中的节点和关系。该示例然后显示如何使用Cypher®Query语言查询数据库中的图形,这使您可以创建自定义查询。
For details about the MATLAB® interface to Neo4j, seeNeo4j数据库接口的图表数据库工作流程。
假设您具有存储在代表社交社区的Neo4j数据库中的图形数据。该数据库有七个节点和八个关系。每个节点只有一个唯一的属性键姓名
有一个值范围User1.
通过User7.
。每个关系都有类型知道
。
The local machine hosts the Neo4j database with the port number7474.
那user nameneo4j.
和密码matlab
。该图提供了数据库中数据的可视化表示。
创建neo4j连接对象neo4j.conn
使用URL.http:// localhost:7474 / dB /数据
那user nameneo4j.
和密码matlab
。
url ='http:// localhost:7474 / db / data';用户名='neo4j';password ='matlab';neo4j.conn = neo4j(url,username,password);
检查Message
neo4j连接对象的属性neo4j.conn
。空白Message
属性表示成功的连接。
neo4jconnmessage.
ans = []
通过在MATLAB中创建定向图来定义一组四个同事。创建一个dig
目的that has four nodes and three edges.
s = [1 1 1];t = [2 3 4];g = digraph(s,t);
为节点指定名称。
g.nodes.name = {'User8';'User9';'User10';'User11'};
绘制数字以查看节点和边缘。
情节(g)
将定向图作为Neo4j图。通过使用通过使用的NEO4J图表中所有节点指定两个标签GlobalNodeLabel
名称值对参数。另外,指定类型合作
通过使用MACETING NEO4J图中的所有关系globalrelationtype.
名称值对参数。
graphinfo =存储的照片(Neo4jconn,g,......'globalnodelabel'那{'同事'那'人'},......'GlobalRelationType'那'works with');
在图中显示第一个节点的节点标签。
graphinfo。Nodes.NodeLabels{1}
ANS =.2×1个单元阵列{'Person' } {'Colleague'}
The result is a cell array of character vectors. Each character vector is a node label for the first node.
显示图中的关系。
graphinfo。关系
ANS =.3×5表startnodeid关系型endnodeid关系数据关系___________ _______________________________________________________________________________________1dumber.neo4j.http.neo4jrelation] 23'适用于'32 [1×1 struct] [1x1数据库。neo4j.http.neo4jrelation] 24 31'与'33 [1×1 struct] [1x1 database.neo4j.http.neo4jrelation]一起工作
关系
is a table that contains these variables:
Start node identifier
关系类型
结束节点标识符
关系数据
neo4jrelation
目的
Search for the nodes with the node label人
和物业钥匙姓名
set to the valuesUser7.
andUser8.
by using the Neo4j database connection.
nlabel =.'人';user7 = searchnode(neo4jconn,nlabel,'propertykey'那'name'那......'PropertyValue'那'user7');user8 = searchnode(neo4jconn,nlabel,'propertykey'那'name'那......'PropertyValue'那'User8');
在节点之间添加关系User7.
andUser8.
to connect the group of colleagues to the group of friends.
关系型='知道';关系= CreeaterElation(Neo4jconn,User7,User8,WelationType);
Display the resulting graph in the Neo4j database.
创建一个暗号query to find the people who work with peopleUser7.
知道。Display the names of those people.
query = ['匹配(:person {name:“user7”}) - [:知道] - >(:人) - [:works works]'......'->(potentialContact:Person) RETURN potentialContact.name']; results = executeCypher(neo4jconn,query)
结果=3×1表potentialContact_name _____________________ 'User11' 'User10' 'User9'
User9.
那User10.
那andUser11.
所有人都与某人合作User7.
知道。User7.
知道User8.
,谁合作User9.
那User10.
那andUser11.
。
关闭(Neo4jconn)