mirror of https://gitee.com/bigwinds/arangodb
193 lines
4.8 KiB
Plaintext
193 lines
4.8 KiB
Plaintext
!CHAPTER Graph Constructors and Methods
|
|
|
|
**Warning: This Chapter is Deprecated**
|
|
|
|
The graph module provides basic functions dealing with graph structures. The
|
|
examples assume
|
|
|
|
arango> var Graph = require("org/arangodb/graph").Graph;
|
|
|
|
arango> g = new Graph("graph", "vertices", "edges");
|
|
Graph("graph")
|
|
|
|
`Graph(name, vertices, edges)`
|
|
|
|
Constructs a new graph object using the collection vertices for all vertices and the collection edges for all edges. Note that it is possible to construct two graphs with the same vertex set, but different edge sets.
|
|
|
|
`Graph(name)`
|
|
|
|
Returns a known graph.
|
|
|
|
*Examples*
|
|
|
|
arango> var Graph = require("org/arangodb/graph").Graph;
|
|
|
|
arango> new Graph("graph", db.vertices, db.edges);
|
|
Graph("graph")
|
|
|
|
arango> new Graph("graph", "vertices", "edges");
|
|
Graph("graph")
|
|
|
|
`graph.addEdge( out, in, id)`
|
|
|
|
Creates a new edge from out to in and returns the edge object. The identifier id must be a unique identifier or null. out and in can either be vertices or their IDs
|
|
|
|
`graph.addEdge( out, in, id, label)`
|
|
|
|
Creates a new edge from out to in with label and returns the edge object. out and in can either be vertices or their IDs
|
|
|
|
`graph.addEdge( out, in, id, data)`
|
|
|
|
Creates a new edge and returns the edge object. The edge contains the properties defined in data. out and in can either be vertices or their IDs
|
|
|
|
`graph.addEdge( out, in, id, label, data)`
|
|
|
|
Creates a new edge and returns the edge object. The edge has the label label and contains the properties defined in data. out and in can either be vertices or their IDs
|
|
|
|
*Examples*
|
|
|
|
arango> v1 = g.addVertex(1);
|
|
Vertex(1)
|
|
|
|
arango> v2 = g.addVertex(2);
|
|
Vertex(2)
|
|
|
|
arango> e = g.addEdge(v1, v2, 3);
|
|
Edge(3)
|
|
arango> e = g.addEdge(v1, v2, 4, "1->2", { name : "Emil");
|
|
Edge(4)
|
|
|
|
`graph.addVertex( id)`
|
|
|
|
Creates a new vertex and returns the vertex object. The identifier id must be a unique identifier or null.
|
|
|
|
`graph.addVertex( id, data)`
|
|
|
|
Creates a new vertex and returns the vertex object. The vertex contains the properties defined in data.
|
|
|
|
*Examples*
|
|
|
|
Without any properties:
|
|
|
|
arango> v = g.addVertex("hugo");
|
|
Vertex("hugo")
|
|
With given properties:
|
|
|
|
arango> v = g.addVertex("Emil", { age : 123 });
|
|
Vertex("Emil")
|
|
|
|
arango> v.getProperty("age");
|
|
123
|
|
|
|
`graph.getEdges()`
|
|
|
|
Returns an iterator for all edges of the graph. The iterator supports the methods hasNext and next.
|
|
|
|
*Examples*
|
|
|
|
arango> f = g.getEdges();
|
|
[edge iterator]
|
|
|
|
arango> f.hasNext();
|
|
true
|
|
|
|
arango> e = f.next();
|
|
Edge("4636053")
|
|
|
|
graph.getVertex( id)
|
|
Returns the vertex identified by id or null.
|
|
|
|
*Examples*
|
|
|
|
arango> g.addVertex(1);
|
|
Vertex(1)
|
|
|
|
arango> g.getVertex(1)
|
|
Vertex(1)
|
|
|
|
`graph.getVertices()`
|
|
|
|
Returns an iterator for all vertices of the graph. The iterator supports the methods hasNext and next.
|
|
|
|
*Examples*
|
|
|
|
arango> f = g.getVertices();
|
|
[vertex iterator]
|
|
|
|
arango> f.hasNext();
|
|
true
|
|
|
|
arango> v = f.next();
|
|
Vertex(18364)
|
|
|
|
`graph.removeVertex( vertex, waitForSync)`
|
|
|
|
Deletes the vertex and all its edges.
|
|
|
|
*Examples*
|
|
|
|
arango> v1 = g.addVertex(1);
|
|
Vertex(1)
|
|
|
|
arango> v2 = g.addVertex(2);
|
|
Vertex(2)
|
|
|
|
arango> e = g.addEdge(v1, v2, 3);
|
|
Edge(3)
|
|
|
|
arango> g.removeVertex(v1);
|
|
|
|
arango> v2.edges();
|
|
[ ]
|
|
|
|
`graph.removeEdge( vertex, waitForSync)`
|
|
|
|
Deletes the edge. Note that the in and out vertices are left untouched.
|
|
|
|
*Examples*
|
|
|
|
arango> v1 = g.addVertex(1);
|
|
Vertex(1)
|
|
|
|
arango> v2 = g.addVertex(2);
|
|
Vertex(2)
|
|
|
|
arango> e = g.addEdge(v1, v2, 3);
|
|
Edge(3)
|
|
|
|
arango> g.removeEdge(e);
|
|
|
|
arango> v2.edges();
|
|
[ ]
|
|
|
|
`graph.drop( waitForSync)`
|
|
|
|
Drops the graph, the vertices, and the edges. Handle with care.
|
|
|
|
`graph.getAll()`
|
|
|
|
Returns all available graphs.
|
|
|
|
`graph.geodesics( options)`
|
|
|
|
Return all shortest paths An optional options JSON object can be specified to control the result. options can have the following sub-attributes:
|
|
|
|
* grouped: if not specified or set to false, the result will be a flat array. If set to true, the result will be an array containing arrays of paths, grouped for each combination of source and target.
|
|
* threshold: if not specified, all paths will be returned. If threshold is true, only paths with a minimum length of 3 will be returned
|
|
|
|
`graph.measurement( measurement)`
|
|
|
|
Calculates the diameter or radius of a graph. measurement can either be:
|
|
|
|
* diameter: to calculate the diameter
|
|
* radius: to calculate the radius
|
|
|
|
`graph.normalizedMeasurement( measurement)`
|
|
|
|
Calculates the normalized degree, closeness, betweenness or eccentricity of all vertices in a graph measurement can either be:
|
|
|
|
* closeness: to calculate the closeness
|
|
* betweenness: to calculate the betweenness
|
|
* eccentricity: to calculate the eccentricity
|
|
|