bbop-graph
Advanced tools
Comparing version 0.0.12 to 0.0.13
@@ -6,3 +6,3 @@ //// | ||
var gulp = require('gulp'); | ||
var jsdoc = require('gulp-jsdoc'); | ||
//var jsdoc = require('gulp-jsdoc'); | ||
var mocha = require('gulp-mocha'); | ||
@@ -14,2 +14,3 @@ var uglify = require('gulp-uglify'); | ||
var del = require('del'); | ||
var shell = require('gulp-shell'); | ||
@@ -53,5 +54,13 @@ var paths = { | ||
// Completely dependent on clean before running doc. | ||
// gulp.task('jsdoc', ['clean'], function(cb) { | ||
// gulp.src(paths.docable, paths.readme) | ||
// .pipe(jsdoc('./doc')); | ||
// cb(null); | ||
// }); | ||
// TODO: Ugh--do this manually until gulp-jsdoc gets its act together. | ||
gulp.task('jsdoc', ['clean'], function(cb) { | ||
gulp.src(paths.docable, paths.readme) | ||
.pipe(jsdoc('./doc')); | ||
gulp.src('') | ||
.pipe(shell([ | ||
'./node_modules/.bin/jsdoc --verbose --template ./node_modules/jsdoc-baseline --readme ./README.md --destination ./doc/ ./lib/*.js' | ||
])); | ||
cb(null); | ||
@@ -114,2 +123,8 @@ }); | ||
// Rerun doc build when a file changes. | ||
gulp.task('watch-test', function() { | ||
gulp.watch(paths.docable, ['test']); | ||
gulp.watch(paths.tests, ['test']); | ||
}); | ||
// The default task (called when you run `gulp` from cli) | ||
@@ -116,0 +131,0 @@ //gulp.task('default', ['watch', 'scripts', 'images']); |
@@ -27,3 +27,3 @@ /** | ||
// Common point for assigning the defaul predicate in here. | ||
// Common point for assigning the default predicate in here. | ||
var default_predicate = 'points_at'; | ||
@@ -41,3 +41,3 @@ | ||
* @param {string} new_label - (optional) a user-friendly description of the node | ||
* @returns {node} new bbop model node | ||
* @returns {this} new bbop model node | ||
*/ | ||
@@ -215,4 +215,4 @@ function node(new_id, new_label){ | ||
* | ||
* @param {} value - (optional) new value for this property to take | ||
* @returns {} string | ||
* @param {String} value - (optional) new value for this property to take | ||
* @returns {String} string | ||
*/ | ||
@@ -351,2 +351,29 @@ edge.prototype.type = function(value){ | ||
/** | ||
* Create a clone of the graph. | ||
* | ||
* @returns {graph} bbop model graph | ||
*/ | ||
graph.prototype.clone = function(){ | ||
var anchor = this; | ||
var new_graph = anchor.create_graph(); | ||
// Collect the nodes and edges. | ||
each(anchor.all_nodes(), function(node){ | ||
//console.log('nid: ' + node.id()); | ||
new_graph.add_node(node.clone()); | ||
}); | ||
each(anchor.all_edges(), function(edge){ | ||
//console.log('eid: ' + edge.subject()); | ||
new_graph.add_edge(edge.clone()); | ||
}); | ||
// Collect other information. | ||
new_graph.default_predicate = anchor.default_predicate; | ||
new_graph._id = anchor._id; | ||
return new_graph; | ||
}; | ||
/** | ||
* Getter/setter for the graph id. | ||
@@ -364,3 +391,3 @@ * | ||
* | ||
* @param {} node - <node> to add to the graph | ||
* @param {node} node - node to add to the graph | ||
*/ | ||
@@ -443,3 +470,3 @@ graph.prototype.add_node = function(node){ | ||
* | ||
* @param {} edge - <edge> to add to the graph | ||
* @param {edge} edge - edge to add to the graph | ||
*/ | ||
@@ -614,3 +641,3 @@ graph.prototype.add_edge = function(edge){ | ||
* | ||
* @returns {} array of nodes | ||
* @returns {Array} array of {node} | ||
*/ | ||
@@ -624,3 +651,3 @@ graph.prototype.all_nodes = function(){ | ||
* | ||
* @returns {} array of edges | ||
* @returns {Array} array of {edge} | ||
*/ | ||
@@ -634,3 +661,3 @@ graph.prototype.all_edges = function(){ | ||
* | ||
* @returns {} array of predicates (strings) | ||
* @returns {Array} array of predicates (strings) | ||
*/ | ||
@@ -644,3 +671,3 @@ graph.prototype.all_predicates = function(){ | ||
* | ||
* @returns {} array of extrnal nodes by id | ||
* @returns {Array} array of strings: external nodes by id | ||
*/ | ||
@@ -667,3 +694,3 @@ graph.prototype.all_dangling = function(){ | ||
* | ||
* @returns {} boolean | ||
* @returns {Boolean} boolean | ||
*/ | ||
@@ -782,5 +809,5 @@ graph.prototype.is_complete = function(){ | ||
* | ||
* @param {string} sub_id - the subject_id of the edge we're looking for | ||
* @param {string} obj_id - the object_id of the edge we're looking for | ||
* @returns {} list of predicate ids (as strings) | ||
* @param {String} sub_id - the subject_id of the edge we're looking for | ||
* @param {String} obj_id - the object_id of the edge we're looking for | ||
* @returns {Array} list of predicate ids (as strings) | ||
*/ | ||
@@ -809,5 +836,5 @@ graph.prototype.get_predicates = function(sub_id, obj_id){ | ||
* | ||
* @param {} in_edges - the edges we want the subjects or objects of | ||
* @param {} target - 'subject' or 'object' | ||
* @returns {} array of <node> | ||
* @param {Array} in_edges - list if {edge} we want the subjects or objects of | ||
* @param {String} target - 'subject' or 'object' | ||
* @returns {Array} list of {node} | ||
*/ | ||
@@ -865,5 +892,5 @@ graph.prototype.edges_to_nodes = function(in_edges, target){ | ||
* BUG/TODO: Could I speed this up by my moving some of the | ||
* calculation into the add_node and add_edge methods? O(|#nodes|) | ||
* calculation into the add_node and add_edge methods? O(|num(nodes)|) | ||
* | ||
* @returns {} array of <node> | ||
* @returns {Array} list of {node} | ||
*/ | ||
@@ -904,5 +931,5 @@ graph.prototype.get_root_nodes = function(){ | ||
* BUG/TODO: Could I speed this up by my moving some of the | ||
* calculation into the add_node and add_edge methods? O(|#nodes|) | ||
* calculation into the add_node and add_edge methods? O(|num(nodes)|) | ||
* | ||
* @returns {} array of <node> | ||
* @returns {Array} list of {node} | ||
*/ | ||
@@ -928,3 +955,3 @@ graph.prototype.get_leaf_nodes = function(){ | ||
* | ||
* @returns {} array of <node> | ||
* @returns {Array} array of {node} | ||
*/ | ||
@@ -1040,3 +1067,3 @@ graph.prototype.get_singleton_nodes = function(){ | ||
* | ||
* @returns {} array of <node> | ||
* @returns {Array} list of {node} | ||
*/ | ||
@@ -1067,3 +1094,3 @@ graph.prototype.get_parent_nodes = function(nb_id, in_pred){ | ||
* @param {String} in_pred - (optional) over this predicate, defaults to all | ||
* @returns {} array of <node> | ||
* @returns {Array} list of {node} | ||
*/ | ||
@@ -1070,0 +1097,0 @@ graph.prototype.get_child_nodes = function(nb_id, in_pred){ |
{ | ||
"name": "bbop-graph", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"license": "BSD-3-Clause", | ||
@@ -23,3 +23,3 @@ "description": "General purpose (mathematical) graph library in JavaScript.", | ||
"type": "git", | ||
"url": "https://github.com/berkeleybop/bbop-graph" | ||
"url": "git+https://github.com/berkeleybop/bbop-graph.git" | ||
}, | ||
@@ -44,3 +44,6 @@ "engines": { | ||
"gulp-rename": "^1.2.2", | ||
"gulp-uglify": "^1.2.0" | ||
"gulp-shell": "^0.4.2", | ||
"gulp-uglify": "^1.2.0", | ||
"jsdoc": "^3.3.0", | ||
"jsdoc-baseline": "git://github.com/hegemonic/jsdoc-baseline.git#74d1dc8075" | ||
}, | ||
@@ -47,0 +50,0 @@ "bundleDependencies": [], |
@@ -567,2 +567,34 @@ //// | ||
}); | ||
it('graph clones are perfect', function(){ | ||
var n1 = new model.node('a', 'Albl'); | ||
n1.type('foo'); | ||
n1.metadata({'a': 1}); | ||
var n2 = new model.node('b', 'Blbl'); | ||
n2.type('bar'); | ||
n2.metadata({'b': 1}); | ||
var e = new model.edge('a', 'b', 'is_a'); | ||
e.type('bib'); | ||
e.metadata({'c': 1}); | ||
var g = new model.graph(); | ||
g.id('gid'); | ||
g.default_predicate = 'pred'; | ||
g.add_node(n1); | ||
g.add_node(n2); | ||
g.add_edge(e); | ||
var g_clone = g.clone(); | ||
//console.log(g); | ||
//console.log(g_clone); | ||
assert.equal(g.id(), g_clone.id(), 'clone has same id'); | ||
assert.equal(g.default_predicate, g_clone.default_predicate, 'clone has same pred'); | ||
assert.deepEqual(g.all_nodes(), g_clone.all_nodes(), 'clone has dupe nodes'); | ||
assert.deepEqual(g.all_edges(), g_clone.all_edges(), 'clone has dupe edges'); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6285350
25729
13