1
0
Fork 0

- added function to remove a single edge definition from a graph\n- some docu

This commit is contained in:
gschwab 2014-06-10 13:30:07 +02:00
parent 801cc84ce2
commit 4bcca3408a
3 changed files with 147 additions and 41 deletions

View File

@ -42,46 +42,11 @@ To add further edge definitions to the array one must call:
!SUBSUBSECTION Undirected Relation
```js
graph._undirectedRelationDefinition(relationName, vertexCollections);
```
Define an undirected relation.
The *relationName* defines the name of this relation and references to the underlying edge collection.
The *vertexCollections* is an Array of document collections holding the vertices.
Relations are allowed in both directions among all collections in *vertexCollections*.
Example Call:
```js
> graph._undirectedRelationDefinition("eats", ["Human", "Animal"]);
{
collection: "eats",
from: ["Human", "Animal"],
to: ["Human", "Animal"]
}
```
<!-- @startDocuBlock JSF_general_graph_undirectedRelationDefinition -->
!SUBSUBSECTION Directed Relation
```js
graph._directedRelationDefinition(relationName, fromVertexCollections, toVertexCollections);
```
Define a directed relation.
The *relationName* defines the name of this relation and references to the underlying edge collection.
The *fromVertexCollections* is an Array of document collections holding the start vertices.
The *toVertexCollections* is an Array of document collections holding the target vertices.
Relations are only allowed in the direction from any collection in *fromVertexCollections* to any collection in *toVertexCollections*.
Example Call:
```js
> graph._directedRelationDefinition("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"]);
{
collection: "has_bought",
from: ["Customer", "Company"],
to: ["Groceries", "Electronics"]
}
```
<!-- @startDocuBlock JSF_general_graph_undirectedRelationDefinition -->
!SUBSUBSECTION Complete Example to create a graph

View File

@ -1284,9 +1284,9 @@ AQLGenerator.prototype.next = function() {
////////////////////////////////////////////////////////////////////////////////
/// @startDocuBlock JSF_general_graph_undirectedRelationDefinition
/// Define an undirected relation.
///
///
/// `general-graph._undirectedRelationDefinition(relationName, vertexCollections)`
/// *Define an undirected relation.*
///
/// Defines an undirected relation with the name *relationName* using the
/// list of *vertexCollections*. This relation allows the user to store
@ -1338,6 +1338,27 @@ var _undirectedRelationDefinition = function (relationName, vertexCollections) {
////////////////////////////////////////////////////////////////////////////////
/// Define an directed relation.
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @startDocuBlock JSF_general_graph_directedRelationDefinition
///
/// `general-graph._directedRelationDefinition(relationName, fromVertexCollections, toVertexCollections)`
/// *Define a directed relation.*
///
/// The *relationName* defines the name of this relation and references to the underlying edge collection.
/// The *fromVertexCollections* is an Array of document collections holding the start vertices.
/// The *toVertexCollections* is an Array of document collections holding the target vertices.
/// Relations are only allowed in the direction from any collection in *fromVertexCollections*
/// to any collection in *toVertexCollections*.
///
/// @EXAMPLES
///
/// @EXAMPLE_ARANGOSH_OUTPUT{generalGraphDirectedRelationDefinition}
/// var graph = require("org/arangodb/general-graph");
/// graph._directedRelationDefinition("has_bought", ["Customer", "Company"], ["Groceries", "Electronics"]);
/// @END_EXAMPLE_ARANGOSH_OUTPUT
/// @endDocuBlock
///
////////////////////////////////////////////////////////////////////////////////
var _directedRelationDefinition = function (
@ -1398,6 +1419,7 @@ var _extendEdgeDefinitions = function (edgeDefinition) {
edgeDefinition.push(args[x]);
});
};
////////////////////////////////////////////////////////////////////////////////
/// @brief create a new graph
////////////////////////////////////////////////////////////////////////////////
@ -2375,6 +2397,82 @@ Graph.prototype._amountCommonProperties = function(vertex1Example, vertex2Exampl
return returnHash;
};
////////////////////////////////////////////////////////////////////////////////
/// @startDocuBlock JSF_general_graph__deleteEdgeDefinition
/// Deletes an edge definition defined by the edge collection of a graph. If the
/// collections defined in the edge definition (collection, from, to) are not used
/// in another graph, the
///
/// `general-graph.__deleteEdgeDefinition(edgeCollectionName, dropCollections)`
///
/// *edgeCollectionName* - string : name of edge collection defined in *collection* of the edge
/// definition.
/// *dropCollections* - bool : True, all collections are removed, if not used in another edge
/// definition (including other graphs). Deflaut: true.
///
/// @EXAMPLES
///
/// @EXAMPLE_ARANGOSH_OUTPUT{general_graph__deleteEdgeDefinition}
/// var examples = require("org/arangodb/graph-examples/example-graph.js");
/// var ed1 = examples._directedRelationDefinition("myEC1", ["myVC1"], ["myVC2"]);
/// var ed2 = examples._directedRelationDefinition("myEC2", ["myVC1"], ["myVC3"]);
/// var g = examples._create("myGraph", [ed1, ed2]);
/// g._deleteEdgeDefinition("myEC1", true);
/// @END_EXAMPLE_ARANGOSH_OUTPUT
///
/// @endDocuBlock
///
////////////////////////////////////////////////////////////////////////////////
Graph.prototype._deleteEdgeDefinition = function(edgeCollection, dropCollections) {
var edgeDefinitions = this.__edgeDefinitions,
vertexCollections = [],
definitionFound = false,
index;
edgeDefinitions.forEach(
function(edgeDefinition, idx) {
if (edgeDefinition.collection === edgeCollection) {
definitionFound = true;
if (dropCollections !== false) {
//get all vertex collections
var vertexCols = edgeDefinition.from.concat(edgeDefinition.to);
vertexCols.forEach(
function(vertexCol) {
if (vertexCollections.indexOf(vertexCol) === -1) {
vertexCollections.push(vertexCol);
}
}
);
}
}
}
);
if (definitionFound) {
edgeDefinitions.splice(index, 1);
this.__edgeDefinitions = edgeDefinitions;
db._graphs.update(this.__name, {edgeDefinitions: this.__edgeDefinitions});
}
if (dropCollections !== false) {
if (checkIfMayBeDropped(edgeCollection, this.__name, getGraphCollection().toArray())) {
db._drop(edgeCollection);
}
vertexCollections.forEach(
function(vC) {
if (checkIfMayBeDropped(vC, this.__name, getGraphCollection().toArray())) {
db._drop(vC);
}
}
);
}
};
////////////////////////////////////////////////////////////////////////////////
/// @brief print basic information for the graph
////////////////////////////////////////////////////////////////////////////////

View File

@ -413,10 +413,49 @@ function GeneralGraphCreationSuite() {
// This should remove edges
assertEqual(g[rn].count(), 1);
graph._drop(gn, true);
},
test_deleteEdgeDefinitionFromExistingGraph: function() {
var gN1 = "UnitTestEdgeDefDeleteGraph1",
gN2 = "UnitTestEdgeDefDeleteGraph2",
ec1 = "UnitTestEdgeDefDeleteEdgeCol1",
ec2 = "UnitTestEdgeDefDeleteEdgeCol2",
ec3 = "UnitTestEdgeDefDeleteEdgeCol3",
vc1 = "UnitTestEdgeDefDeleteVertexCol1",
vc2 = "UnitTestEdgeDefDeleteVertexCol2",
vc3 = "UnitTestEdgeDefDeleteVertexCol3",
vc4 = "UnitTestEdgeDefDeleteVertexCol4",
vc5 = "UnitTestEdgeDefDeleteVertexCol5";
try {
graph._drop(gN1);
graph._drop(gN2);
} catch(ignore) {
}
var dr1 = graph._directedRelationDefinition(ec1, [vc1], [vc1, vc2]),
dr2 = graph._directedRelationDefinition(ec2, [vc3], [vc4, vc5]),
dr3 = graph._directedRelationDefinition(ec3, [vc4], [vc5]),
g1 = graph._create(gN1, [dr1, dr2, dr3]),
g2 = graph._create(gN2, [dr3]);
g1._deleteEdgeDefinition(ec1, false);
assertEqual([dr2, dr3], g1.__edgeDefinitions);
g1._deleteEdgeDefinition(ec2, true);
assertEqual([dr3], g1.__edgeDefinitions);
assertTrue(db._collection(vc3) === null);
assertFalse(db._collection(vc4) === null);
assertFalse(db._collection(vc5) === null);
try {
graph._drop(gN1);
graph._drop(gN2);
} catch(ignore) {
}
}
};
}
// -----------------------------------------------------------------------------
@ -2221,11 +2260,15 @@ function GeneralGraphCommonNeighborsSuite() {
/// @brief executes the test suites
////////////////////////////////////////////////////////////////////////////////
/*
jsunity.run(GeneralGraphCommonNeighborsSuite);
jsunity.run(GeneralGraphAQLQueriesSuite);
jsunity.run(EdgesAndVerticesSuite);
*/
jsunity.run(GeneralGraphCreationSuite);
/*
jsunity.run(ChainedFluentAQLResultsSuite);
*/
return jsunity.done();