storeDigraph
Store directed graph in Neo4j database
Description
storeDigraph(
converts a directed graph to a Neo4j® graph and stores it in a Neo4j database using a Neo4j database connection. The variables in the node and edge tables of the
neo4jconn
,G
)digraph
object (except the
EndNodes
variable) become the properties of the nodes and
relationships in the Neo4j graph.
storeDigraph(
specifies additional options using one or more name-value pair arguments. For
example, neo4jconn
,G
,Name,Value
)'GlobalNodeLabel','Person'
stores all nodes in the
directed graph by using the Person
node label.
Examples
Store Directed Graph in Neo4j Database
Create a digraph
object and store its contents in a Neo4j® database. Display the contents of the resulting Neo4j graph.
Assume that you have graph data stored in a Neo4j database that represents a social neighborhood. This database has seven nodes and eight relationships. Each node has only one unique property key name
with a value ranging from User1
through User7
. Each relationship has the type knows
.
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 = []
Create a digraph
object with three nodes, which represents a new Neo4j graph. The nodes represent three additional people: User8
, User9
, and User10
.
G = digraph([1 1 3],[2 3 2],[1 2 3],{'User8','User9','User10'});
Store the data as a Neo4j graph in the Neo4j database.
storeDigraph(neo4jconn,G)
By default, the storeDigraph
function stores the directed graph without node labels. Also, the function stores the relationships with the default relationship type Edge
.
Display information about the Neo4j graph nodes. graphinfo
is a structure that contains node and relationship information.
criteria = ["Edge"];
graphinfo = searchGraph(neo4jconn,criteria);
graphinfo.Nodes
ans=3×3 table
NodeLabels NodeData NodeObject
__________ ____________ ___________________________________
7 [] [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
52 [] [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
47 [] [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
Nodes
is a table that contains these variables:
Node label
Node data
Neo4jNode
object
Display information about the Neo4j graph relationships.
graphinfo.Relations
ans=3×5 table
StartNodeID RelationType EndNodeID RelationData RelationObject
___________ ____________ _________ ____________ _______________________________________
17 7 'Edge' 52 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
18 47 'Edge' 52 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
35 7 'Edge' 47 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
Relations
is a table that contains these variables:
Start node identifier
Relationship type
End node identifier
Relationship data
Neo4jRelation
object
Close the database connection.
close(neo4jconn)
Store Directed Graph with Global Node Labels and Relationship Types
Create a digraph
object and store its contents in a Neo4j® database. Specify a node label to apply to all nodes in the resulting Neo4j graph. Specify a relationship type to apply to all relationships in the resulting Neo4j graph. Display the contents of the graph.
Assume that you have graph data stored in a Neo4j database that represents a social neighborhood. This database has seven nodes and eight relationships. Each node has only one unique property key name
with a value ranging from User1
through User7
. Each relationship has the type knows
.
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 = []
Create a digraph
object with three nodes, which represents a new Neo4j graph. The nodes represent three additional people: User8
, User9
, and User10
.
G = digraph([1 1 3],[2 3 2],[1 2 3],["User8" "User9" "User10"]);
Store the data as a Neo4j graph in the Neo4j database. Specify the node label Person
for each node in the resulting Neo4j graph by using the 'GlobalNodeLabel'
name-value pair argument. Specify the relationship type knows
for each relationship in the graph by using the 'GlobalRelationType'
name-value pair argument.
storeDigraph(neo4jconn,G,'GlobalNodeLabel','Person', ... 'GlobalRelationType','knows')
Display information about the Neo4j graph nodes. graphinfo
is a structure that contains node and relationship information.
criteria = {'Person'};
graphinfo = searchGraph(neo4jconn,criteria);
graphinfo.Nodes
ans=10×3 table
NodeLabels NodeData NodeObject
__________ ____________ ___________________________________
0 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
48 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
1 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
2 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
3 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
4 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
5 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
9 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
49 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
50 'Person' [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
Nodes
is a table that contains these variables:
Node label
Node data
Neo4jNode
object
graphinfo
contains the three additional nodes.
Display information about the Neo4j graph relationships.
graphinfo.Relations
ans=11×5 table
StartNodeID RelationType EndNodeID RelationData RelationObject
___________ ____________ _________ ____________ _______________________________________
1 0 'knows' 1 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
0 0 'knows' 2 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
3 1 'knows' 3 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
2 2 'knows' 1 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
5 3 'knows' 4 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
4 3 'knows' 5 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
6 5 'knows' 4 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
8 5 'knows' 9 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
19 48 'knows' 49 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
7 48 'knows' 50 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
9 50 'knows' 49 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
Relations
is a table that contains these variables:
Start node identifier
Relationship type
End node identifier
Relationship data
Neo4jRelation
object
graphinfo
contains the three additional relationships.
Close the database connection.
close(neo4jconn)
Store Directed Graph with Node Labels and Relationship Types and Return Output
Create a digraph
object by specifying nodes and edges. Then, store the directed graph in a Neo4j® database by specifying node labels and relationship types. Display the contents of the resulting Neo4j graph. Access the graph information using an output argument.
Assume that you have graph data stored in a Neo4j database that represents a social neighborhood. This database has seven nodes and eight relationships. Each node has only one unique property key name
with a value ranging from User1
through User7
. Each relationship has the type knows
.
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 = []
Create a table for nodes. Define the names
variable, which contains the names of three additional people: User8
, User9
, and User10
. Then, define the classification
variable to classify each person as Person
. Also, define the titles
variable, which contains the job title of each person. The first two people are analysts and the third is a technician.
names = {'User8';'User9';'User10'}; classification = {'Person';'Person';'Person'}; titles = {'Analyst';'Analyst';'Technician'}; nodetable = table(names,classification,titles,'VariableNames', ... {'Name','Classification','Title'});
Create a table with two edges. One edge specifies that two people know each other. The other edge specifies that two people work with each other.
edge1 = [1 2]; edge2 = [3 3]; description = {'knows','works with'}; edgetable = table([edge1',edge2'],description', ... 'VariableNames',{'EndNodes','Description'});
Create a digraph
object using the edge and node tables.
G = digraph(edgetable,nodetable);
Store the data in the digraph
object as a Neo4j graph in the Neo4j database. Specify the node labels for each node in the resulting Neo4j graph by using the 'NodeLabel'
name-value pair argument. The graph uses the Classification
and Title
variables of the node table for the node labels. Also, the graph uses the Description
variable of the edge table for the relationship types.
labels = {'Classification';'Title'}; relation = 'Description'; graphinfo = storeDigraph(neo4jconn,G,'NodeLabel',labels, ... 'RelationType',relation)
graphinfo = struct with fields:
Nodes: [3×3 table]
Relations: [2×5 table]
Display information about the Neo4j graph nodes.
graphinfo.Nodes
ans=3×3 table
NodeLabels NodeData NodeObject
__________ ____________ ___________________________________
6 {2×1 cell} [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
52 {2×1 cell} [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
7 {2×1 cell} [1×1 struct] [1x1 database.neo4j.http.Neo4jNode]
Nodes
is a table that contains these variables:
Node label
Node data
Neo4jNode
object
Display information about the Neo4j graph relationships.
graphinfo.Relations
ans=2×5 table
StartNodeID RelationType EndNodeID RelationData RelationObject
___________ ____________ _________ ____________ _______________________________________
17 6 'knows' 7 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
35 52 'works with' 7 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
Relations
is a table that contains these variables:
Start node identifier
Relationship type
End node identifier
Relationship data
Neo4jRelation
object
Close the database connection.
close(neo4jconn)
Input Arguments
neo4jconn
— Neo4j database connection
Neo4jConnect
object
Neo4j database connection, specified as a Neo4jConnect
object created with the function neo4j
.
G
— Directed graph
digraph
object
Directed graph, specified as a digraph
object.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: graphinfo =
storeDigraph(neo4jconn,G,'GlobalNodeLabel','Person','GlobalRelationType','knows')
stores a directed graph and specifies that all nodes in the resulting graph have the
Person
node label and all relationships have the
knows
type.
Note
If you do not specify 'GlobalNodeLabel'
or
'NodeLabel'
, the resulting Neo4j graph contains nodes without labels.
GlobalNodeLabel
— Global node label
character vector | cell array of character vectors | string scalar | string array
Global node label, specified as the comma-separated pair consisting of
'GlobalNodeLabel'
and a character vector, cell
array of character vectors, string scalar, or string array. To specify
one node label, use a character vector or string scalar. To specify
multiple node labels, use a cell array of character vectors or a string
array.
After you execute the storeDigraph
function, each
node in the resulting Neo4j graph contains node labels that you specify using this
name-value pair argument.
Example: "Person"
Example: {'Person','Employee'}
Data Types: char
| string
| cell
NodeLabel
— Node label
character vector | cell array of character vectors | string scalar | string array
Node label, specified as the comma-separated pair consisting of
'NodeLabel'
and a character vector, cell array of
character vectors, string scalar, or string array. To specify one node
label, use a character vector or string scalar. To specify multiple node
labels, specify a cell array of character vectors or a string
array.
To specify different labels for nodes in the resulting Neo4j graph, use this name-value pair argument. The specified
node labels must match the variable names in the table of node
information in the digraph
object.
Example: "Person"
Example: {'Name','Title'}
Data Types: char
| string
| cell
GlobalRelationType
— Global relationship type
'Edge'
(default) | character vector | string scalar
Global relationship type, specified as the comma-separated pair
consisting of 'GlobalRelationType'
and a character
vector or string scalar. To specify the same type of relationship for
all relationships between nodes in the resulting Neo4j graph, use this name-value pair argument.
Note
When specifying the type of relationship, use either the
'GlobalRelationType'
or
'RelationType'
name-value pair argument. You
cannot specify both of these arguments at the same time.
Example: "knows"
Data Types: char
| string
RelationType
— Relationship type
'Edge'
(default) | character vector | string scalar
Relationship type, specified as the comma-separated pair consisting of
'RelationType'
and a character vector or string
scalar. To specify different types of relationships between nodes in the
resulting Neo4j graph, use this name-value pair argument. The specified
types must match the variable names in the table of edge information in
the digraph
object.
Note
When specifying the type of relationship, use either the
'RelationType'
or
'GlobalRelationType'
name-value pair
argument. You cannot specify both of these arguments at the same
time.
Example: 'Description'
Data Types: char
| string
Output Arguments
graphinfo
— Graph information
structure
Graph information in the Neo4j database, returned as a structure with these fields.
Field | Description |
---|---|
| Table that contains node information for each node
in the
The row names in the table are Neo4j node identifiers. |
| Table that contains relationship information for
the nodes in the
The row names in the table are Neo4j relationship identifiers. |
Tips
The
storeDigraph
function stores all MATLAB® objects as JSONstring
equivalents in the Neo4j graph. For example, the function stores the datedatetime('Jan/01/2017')
as"Jan/01/2017"
in the Neo4j graph.
Version History
Introduced in R2018a
See Also
deleteNode
| neo4j
| deleteRelation
| createNode
| createRelation
| addNodeLabel
| removeNodeLabel
| removeNodeProperty
| removeRelationProperty
| setNodeProperty
| setRelationProperty
| close
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)