neo4jStruct2Digraph
Convert graph or relationship structure from Neo4j database to directed graph
Description
creates
a directed graph from the structure G
= neo4jStruct2Digraph(s
)s
. With the
directed graph, run graph network analytics using MATLAB®. For
example, to visualize the graph, see Graph Plotting and Customization.
Examples
Create a Neo4j® database connection using the URL http://localhost:7474/db/data
, user name neo4j
, and password matlab
.
url = 'http://localhost:7474/db/data'; username = 'neo4j'; password = 'matlab'; neo4jconn = neo4j(url,username,password);
Check the Message
property of the Neo4j connection object neo4jconn
. The blank Message
property indicates a successful connection.
neo4jconn.Message
ans = []
Search for incoming relationships using the Neo4j database connection neo4jconn
and origin node identifier nodeid
.
nodeid = 1;
direction = 'in';
relinfo = searchRelation(neo4jconn,nodeid,direction);
Convert the relationship information into a directed graph. G
is a digraph
object that contains two tables for edges and nodes.
G = neo4jStruct2Digraph(relinfo)
G = digraph with properties: Edges: [2×3 table] Nodes: [3×3 table]
Access the table of edges.
G.Edges
ans=2×3 table
EndNodes RelationType RelationData
__________ ____________ ____________
'0' '1' 'knows' [1×1 struct]
'2' '1' 'knows' [1×1 struct]
Access the table of nodes.
G.Nodes
ans=3×3 table
Name NodeLabels NodeData
____ __________ ____________
'0' 'Person' [1×1 struct]
'1' 'Person' [1×1 struct]
'2' 'Person' [1×1 struct]
Find the shortest path between all nodes in G
.
d = distances(G)
d = 3×3
0 1 Inf
Inf 0 Inf
Inf 1 0
Close the database connection.
close(neo4jconn)
Create a Neo4j® database connection using the URL http://localhost:7474/db/data
, user name neo4j
, and password matlab
.
url = 'http://localhost:7474/db/data'; username = 'neo4j'; password = 'matlab'; neo4jconn = neo4j(url,username,password);
Check the Message
property of the Neo4j connection object neo4jconn
. The blank Message
property indicates a successful connection.
neo4jconn.Message
ans = []
Search for a subgraph using the Neo4j database connection neo4jconn
and node label nlabel
.
nlabel = {'Person'};
graphinfo = searchGraph(neo4jconn,nlabel);
Convert the graph information into a directed graph. G
is a digraph
object that contains two tables for edges and nodes.
G = neo4jStruct2Digraph(graphinfo)
G = digraph with properties: Edges: [8×3 table] Nodes: [7×3 table]
Access the table of edges.
G.Edges
ans=8×3 table
EndNodes RelationType RelationData
__________ ____________ ____________
'0' '1' 'knows' [1×1 struct]
'0' '2' 'knows' [1×1 struct]
'1' '3' 'knows' [1×1 struct]
'2' '1' 'knows' [1×1 struct]
'3' '4' 'knows' [1×1 struct]
'3' '5' 'knows' [1×1 struct]
'5' '4' 'knows' [1×1 struct]
'5' '9' 'knows' [1×1 struct]
Access the table of nodes.
G.Nodes
ans=7×3 table
Name NodeLabels NodeData
____ __________ ____________
'0' 'Person' [1×1 struct]
'1' 'Person' [1×1 struct]
'2' 'Person' [1×1 struct]
'3' 'Person' [1×1 struct]
'4' 'Person' [1×1 struct]
'5' 'Person' [1×1 struct]
'9' 'Person' [1×1 struct]
Find the shortest path between all nodes in G
.
d = distances(G)
d = 7×7
0 1 1 2 3 3 4
Inf 0 Inf 1 2 2 3
Inf 1 0 2 3 3 4
Inf Inf Inf 0 1 1 2
Inf Inf Inf Inf 0 Inf Inf
Inf Inf Inf Inf 1 0 1
Inf Inf Inf Inf Inf Inf 0
Close the database connection.
close(neo4jconn)
Create a Neo4j® database connection using the URL http://localhost:7474/db/data
, user name neo4j
, and password matlab
.
url = 'http://localhost:7474/db/data'; username = 'neo4j'; password = 'matlab'; neo4jconn = neo4j(url,username,password);
Check the Message
property of the Neo4j connection object neo4jconn
. The blank Message
property indicates a successful connection.
neo4jconn.Message
ans = []
Search for a subgraph using the Neo4j database connection neo4jconn
and node label nlabel
.
nlabel = {'Person'};
graphinfo = searchGraph(neo4jconn,nlabel);
Convert the graph information into a directed graph using the node names in the subgraph. Convert node names into a cell array of character vectors nodenames
. G
is a digraph
object that contains two tables for edges and nodes.
names = [graphinfo.Nodes.NodeData{:}];
nodenames = {names(:).name};
G = neo4jStruct2Digraph(graphinfo,'NodeNames',nodenames)
G = digraph with properties: Edges: [8×3 table] Nodes: [7×3 table]
Access the table of edges.
G.Edges
ans=8×3 table
EndNodes RelationType RelationID
__________________ ____________ __________
'User1' 'User3' 'knows' 1
'User1' 'User2' 'knows' 0
'User3' 'User4' 'knows' 3
'User2' 'User3' 'knows' 2
'User4' 'User5' 'knows' 5
'User4' 'User6' 'knows' 4
'User6' 'User5' 'knows' 6
'User6' 'User7' 'knows' 8
Access the table of nodes.
G.Nodes
ans=7×3 table
Name NodeLabels NodeData
_______ __________ ____________
'User1' 'Person' [1×1 struct]
'User3' 'Person' [1×1 struct]
'User2' 'Person' [1×1 struct]
'User4' 'Person' [1×1 struct]
'User5' 'Person' [1×1 struct]
'User6' 'Person' [1×1 struct]
'User7' 'Person' [1×1 struct]
Find the shortest path between all nodes in G
.
d = distances(G)
d = 7×7
0 1 1 2 3 3 4
Inf 0 Inf 1 2 2 3
Inf 1 0 2 3 3 4
Inf Inf Inf 0 1 1 2
Inf Inf Inf Inf 0 Inf Inf
Inf Inf Inf Inf 1 0 1
Inf Inf Inf Inf Inf Inf 0
Close the database connection.
close(neo4jconn)
Input Arguments
Graph or relationship information, specified as a structure
returned by searchGraph
or searchRelation
.
Data Types: struct
Node names in a Neo4j database, specified as a cell array of character vectors or string array.
Example: ["User6","User7"]
Data Types: cell
| string
Output Arguments
Directed graph, returned as a digraph
object.
Version History
Introduced in R2016b
See Also
neo4j
| searchNode
| searchGraph
| searchRelation
| distances
| close
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)