bbop-graph
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -1,2 +0,2 @@ | ||
/* | ||
/** | ||
* Purpose: Basic edged graph and operations. | ||
@@ -19,2 +19,3 @@ * | ||
var each = us.each; | ||
var bbop = require('bbop-core'); | ||
@@ -116,3 +117,3 @@ /// | ||
* | ||
* Get a fresh new copy of the current node (using bbop.core.clone for | ||
* Get a fresh new copy of the current node (using bbop.clone for | ||
* metadata object). | ||
@@ -126,3 +127,3 @@ * | ||
tmp_clone.label(this.label()); | ||
tmp_clone.metadata(bbop.core.clone(this.metadata())); | ||
tmp_clone.metadata(bbop.clone(this.metadata())); | ||
return tmp_clone; | ||
@@ -250,3 +251,3 @@ }; | ||
* | ||
* Get a fresh new copy of the current edge (using bbop.core.clone for | ||
* Get a fresh new copy of the current edge (using bbop.clone for | ||
* metadata object). | ||
@@ -261,3 +262,3 @@ * | ||
// Metadata kind of needs to be duped separately. | ||
tmp_clone.metadata(bbop.core.clone(this.metadata())); | ||
tmp_clone.metadata(bbop.clone(this.metadata())); | ||
return tmp_clone; | ||
@@ -928,3 +929,3 @@ }; | ||
//if( nb_id_or_list.length && nb_id_or_list.index ){ | ||
if( bbop.core.is_array(nb_id_or_list) ){ // verify listy-ness | ||
if( us.isArray(nb_id_or_list) ){ // verify listy-ness | ||
for( var l = 0; l < nb_id_or_list.length; l++ ){ | ||
@@ -1011,5 +1012,3 @@ rec_up(nb_id_or_list[l]); | ||
each(json_object.edges, function(edge_raw){ | ||
var e = new edge(edge_raw.sub, | ||
edge_raw.obj, | ||
edge_raw.pred); | ||
var e = new edge(edge_raw.sub, edge_raw.obj, edge_raw.pred); | ||
// Copy out meta. | ||
@@ -1043,3 +1042,3 @@ if(edge_raw.meta){ e.metadata(edge_raw.meta); } | ||
var node = bbop.core.clone(raw_node); | ||
var node = bbop.clone(raw_node); | ||
var ncopy = {}; | ||
@@ -1063,3 +1062,3 @@ | ||
var eset = []; | ||
var ecopy = bbop.core.clone(anchor._edges['array']); | ||
var ecopy = bbop.clone(anchor._edges['array']); | ||
each(anchor.all_edges(), function(node){ | ||
@@ -1090,2 +1089,3 @@ var ecopy = {}; | ||
default_predicate: default_predicate, | ||
node: node, | ||
@@ -1092,0 +1092,0 @@ edge: edge, |
{ | ||
"name": "bbop-graph", | ||
"version": "0.0.2", | ||
"license": "BSD", | ||
"version": "0.0.3", | ||
"license": "BSD-3-Clause", | ||
"description": "General purpose (mathematical) graph library in JavaScript.", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -6,3 +6,2 @@ //// | ||
var assert = require('chai').assert; | ||
var model = new require('..'); | ||
@@ -12,5 +11,5 @@ | ||
describe('trivial creations', function(){ | ||
describe('node', function(){ | ||
it('works at all (thingy)', function(){ | ||
it('works at all', function(){ | ||
@@ -32,277 +31,321 @@ // Setup. | ||
// // Edges. | ||
// (function(){ | ||
describe('edges', function(){ | ||
// // Setup. | ||
// var n1 = new bbop.model.node('a'); | ||
// var n2 = new bbop.model.node('b'); | ||
// var n3 = new bbop.model.node('c'); | ||
// Setup. | ||
var n1 = null; | ||
var n2 = null; | ||
var n3 = null; | ||
var e1 = null; | ||
var e2 = null; | ||
var e3 = null; | ||
// Pre-run. | ||
before(function() { | ||
// Setup. | ||
n1 = new model.node('a'); | ||
n2 = new model.node('b'); | ||
n3 = new model.node('c'); | ||
e1 = new model.edge(n1, n2); | ||
e2 = new model.edge(n2, n3, 'foo'); | ||
e3 = new model.edge('d', 'e', 'bar'); | ||
}); | ||
// var e1 = new bbop.model.edge(n1, n2); | ||
// var e2 = new bbop.model.edge(n2, n3, 'foo'); | ||
// var e3 = new bbop.model.edge('d', 'e', 'bar'); | ||
it('basically functional', function(){ | ||
assert.isDefined(e1, 'at least this would be nice (edge 1)'); | ||
assert.isDefined(e2, 'at least this would be nice (edge 2)'); | ||
assert.isDefined(e2, 'at least this would be nice (edge 3)'); | ||
assert.equal('a', e1.subject_id(), 'is a'); | ||
assert.equal('b', e1.object_id(), 'is b'); | ||
assert.equal('e', e3.object_id(), 'is e'); | ||
assert.equal(model.default_predicate, e1.predicate_id(), 'is p'); | ||
assert.equal('foo', e2.predicate_id(), 'is p 2'); | ||
}); | ||
}); | ||
// mr_t.is_defined(e1, 'at least this would be nice (edge 1)'); | ||
// mr_t.is_defined(e2, 'at least this would be nice (edge 2)'); | ||
// mr_t.is_defined(e2, 'at least this would be nice (edge 3)'); | ||
describe('simple model', function(){ | ||
// mr_t.is_same_atom('a', e1.subject_id(), 'is a'); | ||
// mr_t.is_same_atom('b', e1.object_id(), 'is b'); | ||
// mr_t.is_same_atom('e', e3.object_id(), 'is e'); | ||
var g = null; | ||
var dpred = null; | ||
// mr_t.is_same_atom(bbop.model.default_predicate, e1.predicate_id(), 'is p'); | ||
// mr_t.is_same_atom('foo', e2.predicate_id(), 'is p 2'); | ||
// Pre-run. | ||
before(function() { | ||
// Create graph described below. | ||
// | ||
// a n x z | ||
// / \ | | | ||
// b c | y? <-- y is not extant, just referenced | ||
// || / \| | ||
// || e d | ||
// \\___// <-- non-default relationship (d is_a b) | ||
// \---/ | ||
// | ||
g = new model.graph(); | ||
g.add_node(new model.node('a')); | ||
g.add_node(new model.node('b')); | ||
g.add_node(new model.node('c')); | ||
g.add_node(new model.node('d')); | ||
g.add_node(new model.node('e')); | ||
g.add_node(new model.node('n')); | ||
g.add_node(new model.node('x')); | ||
g.add_node(new model.node('z')); | ||
g.add_edge(new model.edge('b', 'a')); | ||
g.add_edge(new model.edge('c', 'a')); | ||
g.add_edge(new model.edge('d', 'c')); | ||
g.add_edge(new model.edge('e', 'c')); | ||
g.add_edge(new model.edge('d', 'n')); | ||
g.add_edge(new model.edge('d', 'b', 'is_a')); | ||
g.add_edge(new model.edge('y', 'x')); | ||
// })(); | ||
dpred = model.default_predicate; | ||
}); | ||
it('graph construction', function(){ | ||
// // Check simple modelling. | ||
// (function(){ | ||
assert.isDefined(g, 'at least this would be nice (graph)'); | ||
assert.equal(8, g.all_nodes().length, '7 nodes'); | ||
assert.equal(7, g.all_edges().length, '7 edges'); | ||
assert.equal(7, g.all_edges().length, '7 edges'); | ||
assert.equal(1, g.get_singleton_nodes().length, 'just one single'); | ||
assert.equal('z', g.get_singleton_nodes()[0].id(), 'z alone'); | ||
assert.equal(1, g.all_dangling().length, 'just one dangle'); | ||
assert.equal(false, g.is_complete(), 'nope'); | ||
}); | ||
it('leaf correctness', function(){ | ||
// // Create graph described below. | ||
// // | ||
// // a n x z | ||
// // / \ | | | ||
// // b c | y? <-- y is not extant, just referenced | ||
// // || / \| | ||
// // || e d | ||
// // \\___// <-- non-default relationship (d is_a b) | ||
// // \---/ | ||
// // | ||
// var g = new bbop.model.graph(); | ||
// g.add_node(new bbop.model.node('a')); | ||
// g.add_node(new bbop.model.node('b')); | ||
// g.add_node(new bbop.model.node('c')); | ||
// g.add_node(new bbop.model.node('d')); | ||
// g.add_node(new bbop.model.node('e')); | ||
// g.add_node(new bbop.model.node('n')); | ||
// g.add_node(new bbop.model.node('x')); | ||
// g.add_node(new bbop.model.node('z')); | ||
// g.add_edge(new bbop.model.edge('b', 'a')); | ||
// g.add_edge(new bbop.model.edge('c', 'a')); | ||
// g.add_edge(new bbop.model.edge('d', 'c')); | ||
// g.add_edge(new bbop.model.edge('e', 'c')); | ||
// g.add_edge(new bbop.model.edge('d', 'n')); | ||
// g.add_edge(new bbop.model.edge('d', 'b', 'is_a')); | ||
// g.add_edge(new bbop.model.edge('y', 'x')); | ||
assert.equal(false, g.is_leaf_node('a'), '! leaf a'); | ||
assert.equal(false, g.is_leaf_node('b'), '! leaf b'); | ||
assert.equal(false, g.is_leaf_node('c'), '! leaf c'); | ||
assert.equal(true, g.is_leaf_node('d'), 'leaf d'); | ||
assert.equal(true, g.is_leaf_node('e'), 'leaf e'); | ||
assert.equal(false, g.is_leaf_node('n'), '! leaf n'); | ||
assert.equal(false, g.is_leaf_node('x'), '! leaf z'); | ||
assert.equal(false, g.is_leaf_node('y'), '! leaf y'); | ||
assert.equal(true, g.is_leaf_node('z'), 'leaf z'); | ||
assert.equal(3, g.get_leaf_nodes().length, '3 leaves'); | ||
}); | ||
it('root correctness', function(){ | ||
// var dpred = bbop.model.default_predicate; | ||
assert.equal(true, g.is_root_node('a'), 'root a'); | ||
assert.equal(false, g.is_root_node('b'), '! root b'); | ||
assert.equal(false, g.is_root_node('c'), '! root c'); | ||
assert.equal(false, g.is_root_node('d'), '! root d'); | ||
assert.equal(false, g.is_root_node('e'), '! root e'); | ||
assert.equal(true, g.is_root_node('n'), 'root n'); | ||
assert.equal(true, g.is_root_node('x'), 'root z'); | ||
assert.equal(false, g.is_root_node('y'), '! root y'); | ||
assert.equal(true, g.is_root_node('z'), 'root z'); | ||
assert.equal(4, g.get_root_nodes().length, '4 roots'); | ||
}); | ||
it('graph structure up', function(){ | ||
// // Test graph construction. | ||
// mr_t.is_defined(g, 'at least this would be nice (graph)'); | ||
// mr_t.is_same_atom(8, g.all_nodes().length, '7 nodes'); | ||
// mr_t.is_same_atom(7, g.all_edges().length, '7 edges'); | ||
// mr_t.is_same_atom(7, g.all_edges().length, '7 edges'); | ||
// mr_t.is_same_atom(1, g.get_singleton_nodes().length, 'just one single'); | ||
// mr_t.is_same_atom('z', g.get_singleton_nodes()[0].id(), 'z alone'); | ||
// mr_t.is_same_atom(1, g.all_dangling().length, 'just one dangle'); | ||
// mr_t.is_same_atom(false, g.is_complete(), 'nope'); | ||
assert.equal(0, g.get_parent_nodes('a').length, 'a is root'); | ||
assert.equal(1, g.get_parent_nodes('b').length, 'b under a (1)'); | ||
assert.equal('a', g.get_parent_nodes('b')[0].id(), 'b under a (2)'); | ||
assert.equal(3, g.get_parent_nodes('d').length, 'd: b c n'); | ||
assert.equal(2, g.get_parent_nodes('d', dpred).length, 'd: c n'); | ||
assert.equal(1, g.get_parent_nodes('d', 'is_a').length, 'd: b'); | ||
}); | ||
it('graph structure down', function(){ | ||
// // Test leaf correctness. | ||
// mr_t.is_same_atom(false, g.is_leaf_node('a'), '! leaf a'); | ||
// mr_t.is_same_atom(false, g.is_leaf_node('b'), '! leaf b'); | ||
// mr_t.is_same_atom(false, g.is_leaf_node('c'), '! leaf c'); | ||
// mr_t.is_same_atom(true, g.is_leaf_node('d'), 'leaf d'); | ||
// mr_t.is_same_atom(true, g.is_leaf_node('e'), 'leaf e'); | ||
// mr_t.is_same_atom(false, g.is_leaf_node('n'), '! leaf n'); | ||
// mr_t.is_same_atom(false, g.is_leaf_node('x'), '! leaf z'); | ||
// mr_t.is_same_atom(false, g.is_leaf_node('y'), '! leaf y'); | ||
// mr_t.is_same_atom(true, g.is_leaf_node('z'), 'leaf z'); | ||
// mr_t.is_same_atom(3, g.get_leaf_nodes().length, '3 leaves'); | ||
assert.equal(2, g.get_child_nodes('a').length, 'a has 2'); | ||
assert.equal(1, g.get_child_nodes('b').length, 'b has 1'); | ||
assert.equal('d', g.get_child_nodes('b')[0].id(), 'b: d 1'); | ||
assert.equal(0, g.get_child_nodes('b', dpred).length, 'b: d 2'); | ||
assert.equal('d', g.get_child_nodes('b', 'is_a')[0].id(), 'b: d 3'); | ||
assert.equal(0, g.get_child_nodes('d').length, 'd: -'); | ||
assert.equal(0, g.get_child_nodes('z').length, 'z: -'); | ||
assert.equal(0, g.get_child_nodes('x').length, 'x: -'); | ||
}); | ||
it('edges and predicates', function(){ | ||
// // Test roots. | ||
// mr_t.is_same_atom(true, g.is_root_node('a'), 'root a'); | ||
// mr_t.is_same_atom(false, g.is_root_node('b'), '! root b'); | ||
// mr_t.is_same_atom(false, g.is_root_node('c'), '! root c'); | ||
// mr_t.is_same_atom(false, g.is_root_node('d'), '! root d'); | ||
// mr_t.is_same_atom(false, g.is_root_node('e'), '! root e'); | ||
// mr_t.is_same_atom(true, g.is_root_node('n'), 'root n'); | ||
// mr_t.is_same_atom(true, g.is_root_node('x'), 'root z'); | ||
// mr_t.is_same_atom(false, g.is_root_node('y'), '! root y'); | ||
// mr_t.is_same_atom(true, g.is_root_node('z'), 'root z'); | ||
// mr_t.is_same_atom(4, g.get_root_nodes().length, '4 roots'); | ||
//g.add_edge(new model.edge('d', 'b', 'is_a')); | ||
var med = g.get_edges('d', 'b'); | ||
assert.equal(med.length, 1, 'one edge'); | ||
assert.equal(med[0].predicate_id(), 'is_a', 'one edge is_a'); | ||
var mrel = g.get_predicates('d', 'b'); | ||
assert.equal(mrel.length, 1, 'one pred'); | ||
assert.equal(mrel[0], 'is_a', 'one pred is_a'); | ||
}); | ||
it('subgraph test 1', function(){ | ||
// // Test graph structure up. | ||
// mr_t.is_same_atom(0, g.get_parent_nodes('a').length, 'a is root'); | ||
// mr_t.is_same_atom(1, g.get_parent_nodes('b').length, 'b under a (1)'); | ||
// mr_t.is_same_atom('a', g.get_parent_nodes('b')[0].id(), 'b under a (2)'); | ||
// mr_t.is_same_atom(3, g.get_parent_nodes('d').length, 'd: b c n'); | ||
// mr_t.is_same_atom(2, g.get_parent_nodes('d', dpred).length, 'd: c n'); | ||
// mr_t.is_same_atom(1, g.get_parent_nodes('d', 'is_a').length, 'd: b'); | ||
var sub1 = g.get_ancestor_subgraph('d'); | ||
// Roots. | ||
assert.equal(true, sub1.is_root_node('a'), 'root a'); | ||
assert.equal(true, sub1.is_root_node('n'), 'root n'); | ||
assert.equal(false, sub1.is_root_node('x'), '! root x'); | ||
assert.equal(2, sub1.get_root_nodes().length, '2 roots'); | ||
// Leaves. | ||
assert.equal(1, sub1.get_leaf_nodes().length, '1 leaf'); | ||
assert.equal('d', sub1.get_leaf_nodes()[0].id(), 'd leaf'); | ||
// Graph structure up. | ||
assert.equal(0, sub1.get_parent_nodes('a').length, 'a is root'); | ||
assert.equal(1, sub1.get_parent_nodes('b').length, 'b under a (1)'); | ||
assert.equal('a', sub1.get_parent_nodes('b')[0].id(), 'b under a (2)'); | ||
assert.equal(3, sub1.get_parent_nodes('d').length, 'd: b c n'); | ||
assert.equal(2, sub1.get_parent_nodes('d', dpred).length, 'd: c n'); | ||
assert.equal(1, sub1.get_parent_nodes('d', 'is_a').length, 'd: b'); | ||
// Graph structure down. | ||
assert.equal(2, sub1.get_child_nodes('a').length, 'a has 2'); | ||
assert.equal(1, sub1.get_child_nodes('b').length, 'b has 1'); | ||
assert.equal('d', sub1.get_child_nodes('b')[0].id(), 'b: d 1'); | ||
assert.equal(0, sub1.get_child_nodes('b', dpred).length, 'b: d 2'); | ||
assert.equal('d', sub1.get_child_nodes('b', 'is_a')[0].id(), 'b: d 3'); | ||
assert.equal(0, sub1.get_child_nodes('d').length, 'd: -'); | ||
}); | ||
it('subgraph test 2', function(){ | ||
// // Test graph structure down. | ||
// mr_t.is_same_atom(2, g.get_child_nodes('a').length, 'a has 2'); | ||
// mr_t.is_same_atom(1, g.get_child_nodes('b').length, 'b has 1'); | ||
// mr_t.is_same_atom('d', g.get_child_nodes('b')[0].id(), 'b: d 1'); | ||
// mr_t.is_same_atom(0, g.get_child_nodes('b', dpred).length, 'b: d 2'); | ||
// mr_t.is_same_atom('d', g.get_child_nodes('b', 'is_a')[0].id(), 'b: d 3'); | ||
// mr_t.is_same_atom(0, g.get_child_nodes('d').length, 'd: -'); | ||
// mr_t.is_same_atom(0, g.get_child_nodes('z').length, 'z: -'); | ||
// mr_t.is_same_atom(0, g.get_child_nodes('x').length, 'x: -'); | ||
var sub2 = g.get_ancestor_subgraph('d', 'is_a'); | ||
// Roots. | ||
assert.equal(false, sub2.is_root_node('a'), '! root a'); | ||
assert.equal(false, sub2.is_root_node('d'), '! root d'); | ||
assert.equal(true, sub2.is_root_node('b'), 'root b'); | ||
// Leaves. | ||
assert.equal(1, sub2.get_leaf_nodes().length, '1 leaf'); | ||
assert.equal('d', sub2.get_leaf_nodes()[0].id(), 'd leaf'); | ||
// Graph structure up. | ||
assert.equal(0, sub2.get_parent_nodes('b').length, 'b root'); | ||
assert.equal(1, sub2.get_parent_nodes('d').length, 'd: b'); | ||
assert.equal(0, sub2.get_parent_nodes('d', dpred).length, 'd: -'); | ||
assert.equal(1, sub2.get_parent_nodes('d', 'is_a').length, 'd: b'); | ||
// Graph structure down. | ||
assert.equal('d', sub2.get_child_nodes('b')[0].id(), 'b: d 1'); | ||
assert.equal(0, sub2.get_child_nodes('b', dpred).length, 'b: d 2'); | ||
assert.equal('d', sub2.get_child_nodes('b', 'is_a')[0].id(), 'b:d 3'); | ||
assert.equal(0, sub2.get_child_nodes('d').length, 'd: -'); | ||
}); | ||
// // Test edges and predicates. | ||
// //g.add_edge(new bbop.model.edge('d', 'b', 'is_a')); | ||
// var med = g.get_edges('d', 'b'); | ||
// mr_t.is_same_atom(med.length, 1, 'one edge'); | ||
// mr_t.is_same_atom(med[0].predicate_id(), 'is_a', 'one edge is_a'); | ||
// var mrel = g.get_predicates('d', 'b'); | ||
// mr_t.is_same_atom(mrel.length, 1, 'one pred'); | ||
// mr_t.is_same_atom(mrel[0], 'is_a', 'one pred is_a'); | ||
}); | ||
// /// | ||
// /// Test subgraphs. | ||
// /// | ||
// Test cases from owltools.graph.shunt junit test cases. | ||
describe('loading from JSON (good with Solr/GOlr)', function(){ | ||
// var sub1 = g.get_ancestor_subgraph('d'); | ||
// // Roots. | ||
// mr_t.is_same_atom(true, sub1.is_root_node('a'), 'root a'); | ||
// mr_t.is_same_atom(true, sub1.is_root_node('n'), 'root n'); | ||
// mr_t.is_same_atom(false, sub1.is_root_node('x'), '! root x'); | ||
// mr_t.is_same_atom(2, sub1.get_root_nodes().length, '2 roots'); | ||
// // Leaves. | ||
// mr_t.is_same_atom(1, sub1.get_leaf_nodes().length, '1 leaf'); | ||
// mr_t.is_same_atom('d', sub1.get_leaf_nodes()[0].id(), 'd leaf'); | ||
// // Graph structure up. | ||
// mr_t.is_same_atom(0, sub1.get_parent_nodes('a').length, 'a is root'); | ||
// mr_t.is_same_atom(1, sub1.get_parent_nodes('b').length, 'b under a (1)'); | ||
// mr_t.is_same_atom('a', sub1.get_parent_nodes('b')[0].id(), 'b under a (2)'); | ||
// mr_t.is_same_atom(3, sub1.get_parent_nodes('d').length, 'd: b c n'); | ||
// mr_t.is_same_atom(2, sub1.get_parent_nodes('d', dpred).length, 'd: c n'); | ||
// mr_t.is_same_atom(1, sub1.get_parent_nodes('d', 'is_a').length, 'd: b'); | ||
// // Graph structure down. | ||
// mr_t.is_same_atom(2, sub1.get_child_nodes('a').length, 'a has 2'); | ||
// mr_t.is_same_atom(1, sub1.get_child_nodes('b').length, 'b has 1'); | ||
// mr_t.is_same_atom('d', sub1.get_child_nodes('b')[0].id(), 'b: d 1'); | ||
// mr_t.is_same_atom(0, sub1.get_child_nodes('b', dpred).length, 'b: d 2'); | ||
// mr_t.is_same_atom('d', sub1.get_child_nodes('b', 'is_a')[0].id(), 'b: d 3'); | ||
// mr_t.is_same_atom(0, sub1.get_child_nodes('d').length, 'd: -'); | ||
var g1 = null; | ||
var g2 = null; | ||
// var sub2 = g.get_ancestor_subgraph('d', 'is_a'); | ||
// // Roots. | ||
// mr_t.is_same_atom(false, sub2.is_root_node('a'), '! root a'); | ||
// mr_t.is_same_atom(false, sub2.is_root_node('d'), '! root d'); | ||
// mr_t.is_same_atom(true, sub2.is_root_node('b'), 'root b'); | ||
// // Leaves. | ||
// mr_t.is_same_atom(1, sub2.get_leaf_nodes().length, '1 leaf'); | ||
// mr_t.is_same_atom('d', sub2.get_leaf_nodes()[0].id(), 'd leaf'); | ||
// // Graph structure up. | ||
// mr_t.is_same_atom(0, sub2.get_parent_nodes('b').length, 'b root'); | ||
// mr_t.is_same_atom(1, sub2.get_parent_nodes('d').length, 'd: b'); | ||
// mr_t.is_same_atom(0, sub2.get_parent_nodes('d', dpred).length, 'd: -'); | ||
// mr_t.is_same_atom(1, sub2.get_parent_nodes('d', 'is_a').length, 'd: b'); | ||
// // Graph structure down. | ||
// mr_t.is_same_atom('d', sub2.get_child_nodes('b')[0].id(), 'b: d 1'); | ||
// mr_t.is_same_atom(0, sub2.get_child_nodes('b', dpred).length, 'b: d 2'); | ||
// mr_t.is_same_atom('d', sub2.get_child_nodes('b', 'is_a')[0].id(), 'b:d 3'); | ||
// mr_t.is_same_atom(0, sub2.get_child_nodes('d').length, 'd: -'); | ||
// Pre-run. | ||
before(function() { | ||
// })(); | ||
var jo = {"nodes":[{"id":"a","lbl":"A"},{"id":"b","lbl":"B"}],"edges":[{"sub":"a","obj":"b","pred":"is_a"}]}; | ||
g1 = new model.graph(); | ||
g1.load_json(jo); | ||
// // Check loading from JSON (good with Solr/GOlr). | ||
// // Test cases from owltools.graph.shunt junit test cases. | ||
// (function(){ | ||
// A bit of GO. | ||
// Generate from: | ||
// cd ~/local/src/svn/owltools/OWLTools-Runner | ||
// ./bin/owltools --solr-shunt-test | ||
var go = {"nodes":[{"id":"GO:0009987","lbl":"cellular process"},{"id":"GO:0048869","lbl":"cellular developmental process"},{"id":"GO:0048731","lbl":"system development"},{"id":"GO:0007275","lbl":"multicellular organismal development"},{"id":"GO:0030154","lbl":"cell differentiation"},{"id":"GO:0007399","lbl":"nervous system development"},{"id":"GO:0048856","lbl":"anatomical structure development"},{"id":"GO:0008150","lbl":"biological_process"},{"id":"GO:0022008","lbl":"neurogenesis"},{"id":"GO:0042063","lbl":"gliogenesis"},{"id":"GO:0032502","lbl":"developmental process"},{"id":"GO:0032501","lbl":"multicellular organismal process"},{"id":"GO:0048699","lbl":"generation of neurons"}],"edges":[{"sub":"GO:0022008","obj":"GO:0007399","pred":"part_of"},{"sub":"GO:0042063","obj":"GO:0022008","pred":"is_a"},{"sub":"GO:0022008","obj":"GO:0030154","pred":"is_a"},{"sub":"GO:0032501","obj":"GO:0008150","pred":"is_a"},{"sub":"GO:0032502","obj":"GO:0008150","pred":"is_a"},{"sub":"GO:0048731","obj":"GO:0048856","pred":"is_a"},{"sub":"GO:0007399","obj":"GO:0048731","pred":"is_a"},{"sub":"GO:0007275","obj":"GO:0032501","pred":"is_a"},{"sub":"GO:0007275","obj":"GO:0032502","pred":"is_a"},{"sub":"GO:0048856","obj":"GO:0032502","pred":"is_a"},{"sub":"GO:0048869","obj":"GO:0009987","pred":"is_a"},{"sub":"GO:0048699","obj":"GO:0022008","pred":"is_a"},{"sub":"GO:0048869","obj":"GO:0032502","pred":"is_a"},{"sub":"GO:0009987","obj":"GO:0008150","pred":"is_a"},{"sub":"GO:0030154","obj":"GO:0048869","pred":"is_a"},{"sub":"GO:0048731","obj":"GO:0007275","pred":"part_of"}]}; | ||
g2 = new model.graph(); | ||
g2.load_json(go); | ||
}); | ||
// /// | ||
// /// Trivial. | ||
// /// | ||
it('graph one okay', function(){ | ||
// var jo = {"nodes":[{"id":"a","lbl":"A"},{"id":"b","lbl":"B"}],"edges":[{"sub":"a","obj":"b","pred":"is_a"}]}; | ||
// var g1 = new bbop.model.graph(); | ||
// var result1 = g1.load_json(jo); | ||
assert.isTrue(g1.is_root_node('b'), 'root b'); | ||
assert.isFalse(g1.is_root_node('a'), '! root a'); | ||
assert.equal('b', g1.get_parent_nodes('a')[0].id(), 'b under a'); | ||
}); | ||
// mr_t.is_same_atom(true, g1.is_root_node('b'), 'root b'); | ||
// mr_t.is_same_atom(false, g1.is_root_node('a'), '! root a'); | ||
// mr_t.is_same_atom('b', g1.get_parent_nodes('a')[0].id(), 'b under a'); | ||
// /// | ||
// /// A bit of GO. | ||
// /// Generate from: | ||
// /// cd ~/local/src/svn/owltools/OWLTools-Runner | ||
// /// ./bin/owltools --solr-shunt-test | ||
// /// | ||
it('graph two okay', function(){ | ||
var leaves = g2.get_child_nodes('GO:0022008'); | ||
assert.equal(leaves.length, 2, 'two children for GO:0022008'); | ||
var leaf1 = leaves[0]; | ||
var leaf2 = leaves[1]; | ||
assert.includeMembers(['GO:0042063', 'GO:0048699'], [leaf1.id()], | ||
'either of the two kids (1)'); | ||
assert.includeMembers(['GO:0042063', 'GO:0048699'], [leaf2.id()], | ||
'either of the two kids (2)'); | ||
assert.notEqual(leaf1.id(), leaf2.id(), | ||
'the children are different'); | ||
assert.equal(g2.get_child_nodes('GO:0022008', 'part_of').length, 0, | ||
'no part_of kids'); | ||
assert.equal(g2.get_child_nodes('GO:0022008', 'is_a').length, 2, | ||
'two is_a kids'); | ||
}); | ||
}); | ||
// var go = {"nodes":[{"id":"GO:0009987","lbl":"cellular process"},{"id":"GO:0048869","lbl":"cellular developmental process"},{"id":"GO:0048731","lbl":"system development"},{"id":"GO:0007275","lbl":"multicellular organismal development"},{"id":"GO:0030154","lbl":"cell differentiation"},{"id":"GO:0007399","lbl":"nervous system development"},{"id":"GO:0048856","lbl":"anatomical structure development"},{"id":"GO:0008150","lbl":"biological_process"},{"id":"GO:0022008","lbl":"neurogenesis"},{"id":"GO:0042063","lbl":"gliogenesis"},{"id":"GO:0032502","lbl":"developmental process"},{"id":"GO:0032501","lbl":"multicellular organismal process"},{"id":"GO:0048699","lbl":"generation of neurons"}],"edges":[{"sub":"GO:0022008","obj":"GO:0007399","pred":"part_of"},{"sub":"GO:0042063","obj":"GO:0022008","pred":"is_a"},{"sub":"GO:0022008","obj":"GO:0030154","pred":"is_a"},{"sub":"GO:0032501","obj":"GO:0008150","pred":"is_a"},{"sub":"GO:0032502","obj":"GO:0008150","pred":"is_a"},{"sub":"GO:0048731","obj":"GO:0048856","pred":"is_a"},{"sub":"GO:0007399","obj":"GO:0048731","pred":"is_a"},{"sub":"GO:0007275","obj":"GO:0032501","pred":"is_a"},{"sub":"GO:0007275","obj":"GO:0032502","pred":"is_a"},{"sub":"GO:0048856","obj":"GO:0032502","pred":"is_a"},{"sub":"GO:0048869","obj":"GO:0009987","pred":"is_a"},{"sub":"GO:0048699","obj":"GO:0022008","pred":"is_a"},{"sub":"GO:0048869","obj":"GO:0032502","pred":"is_a"},{"sub":"GO:0009987","obj":"GO:0008150","pred":"is_a"},{"sub":"GO:0030154","obj":"GO:0048869","pred":"is_a"},{"sub":"GO:0048731","obj":"GO:0007275","pred":"part_of"}]}; | ||
describe('failing case from the taxslim', function(){ | ||
// var g2 = new bbop.model.graph(); | ||
// var result2 = g2.load_json(go); | ||
// Pre-run. | ||
before(function() { | ||
}); | ||
// var leaves = g2.get_child_nodes('GO:0022008'); | ||
// mr_t.is_same_atom(2, leaves.length, 'two children for GO:0022008'); | ||
it('check', function(){ | ||
// var leaf1 = leaves[0]; | ||
// var leaf2 = leaves[1]; | ||
// mr_t.is_in_list(leaf1.id(), ['GO:0042063', 'GO:0048699'], | ||
// 'either of the two kids (1)'); | ||
// mr_t.is_in_list(leaf2.id(), ['GO:0042063', 'GO:0048699'], | ||
// 'either of the two kids (2)'); | ||
// mr_t.is_different_atom(leaf1.id(), leaf2.id(), | ||
// 'the children are different'); | ||
// mr_t.is_same_atom(g2.get_child_nodes('GO:0022008', 'part_of').length, | ||
// 0, 'no part_of kids'); | ||
// mr_t.is_same_atom(g2.get_child_nodes('GO:0022008', 'is_a').length, | ||
// 2, 'two is_a kids'); | ||
// })(); | ||
var tax = | ||
{"nodes": [ | ||
{"id":"NCBITaxon:33316","lbl":"Coelomata"}, | ||
{"id":"NCBITaxon:2759","lbl":"Eukaryota"}, | ||
{"id":"NCBITaxon:117565","lbl":"Hyperotreti"}, | ||
{"id":"NCBITaxon:33154","lbl":"Fungi/Metazoa group"}, | ||
{"id":"NCBITaxon:1","lbl":"root"}, | ||
{"id":"NCBITaxon:7742","lbl":"Vertebrata"}, | ||
{"id":"NCBITaxon:7711","lbl":"Chordata"}, | ||
{"id":"NCBITaxon:89593","lbl":"Craniata"}, | ||
{"id":"NCBITaxon:6072","lbl":"Eumetazoa"}, | ||
{"id":"NCBITaxon:131567","lbl":"cellular organisms"}, | ||
{"id":"NCBITaxon:33511","lbl":"Deuterostomia"}, | ||
{"id":"NCBITaxon:33213","lbl":"Bilateria"}, | ||
{"id":"NCBITaxon:33208","lbl":"Metazoa"} | ||
], | ||
"edges": [ | ||
{"sub":"NCBITaxon:33208","obj":"NCBITaxon:33154","pred":"is_a"}, | ||
{"sub":"NCBITaxon:33154","obj":"NCBITaxon:2759","pred":"is_a"}, | ||
{"sub":"NCBITaxon:6072","obj":"NCBITaxon:33208","pred":"is_a"}, | ||
{"sub":"NCBITaxon:33316","obj":"NCBITaxon:33213","pred":"is_a"}, | ||
{"sub":"NCBITaxon:2759","obj":"NCBITaxon:131567","pred":"is_a"}, | ||
{"sub":"NCBITaxon:89593","obj":"NCBITaxon:7711","pred":"is_a"}, | ||
{"sub":"NCBITaxon:33511","obj":"NCBITaxon:33316","pred":"is_a"}, | ||
{"sub":"NCBITaxon:7711","obj":"NCBITaxon:33511","pred":"is_a"}, | ||
{"sub":"NCBITaxon:33213","obj":"NCBITaxon:6072","pred":"is_a"}, | ||
{"sub":"NCBITaxon:7742","obj":"NCBITaxon:89593","pred":"is_a"}, | ||
{"sub":"NCBITaxon:131567","obj":"NCBITaxon:1","pred":"is_a"}, | ||
{"sub":"NCBITaxon:117565","obj":"NCBITaxon:89593","pred":"is_a"} | ||
] | ||
}; | ||
var g = new model.graph(); | ||
var result2 = g.load_json(tax); | ||
assert.isTrue(g.is_complete(), 'tax is complete'); | ||
var leaves = g.get_child_nodes('NCBITaxon:89593'); | ||
assert.equal(2, leaves.length, 'two children for NCBITaxon:89593'); | ||
var root_kids = g.get_child_nodes('NCBITaxon:1'); | ||
assert.equal(1, root_kids.length, 'one kid for root'); | ||
assert.equal('NCBITaxon:131567', root_kids[0].id(), | ||
'and the one root kid is NCBITaxon:131567'); | ||
}); | ||
}); | ||
describe('roundtrip', function(){ | ||
// // Here is a failing case from the taxslim | ||
// (function(){ | ||
// Pre-run. | ||
before(function() { | ||
}); | ||
// var tax = | ||
// {"nodes": | ||
// [ | ||
// {"id":"NCBITaxon:33316","lbl":"Coelomata"}, | ||
// {"id":"NCBITaxon:2759","lbl":"Eukaryota"}, | ||
// {"id":"NCBITaxon:117565","lbl":"Hyperotreti"}, | ||
// {"id":"NCBITaxon:33154","lbl":"Fungi/Metazoa group"}, | ||
// {"id":"NCBITaxon:1","lbl":"root"}, | ||
// {"id":"NCBITaxon:7742","lbl":"Vertebrata"}, | ||
// {"id":"NCBITaxon:7711","lbl":"Chordata"}, | ||
// {"id":"NCBITaxon:89593","lbl":"Craniata"}, | ||
// {"id":"NCBITaxon:6072","lbl":"Eumetazoa"}, | ||
// {"id":"NCBITaxon:131567","lbl":"cellular organisms"}, | ||
// {"id":"NCBITaxon:33511","lbl":"Deuterostomia"}, | ||
// {"id":"NCBITaxon:33213","lbl":"Bilateria"}, | ||
// {"id":"NCBITaxon:33208","lbl":"Metazoa"} | ||
// ], | ||
// "edges": | ||
// [ | ||
// {"sub":"NCBITaxon:33208","obj":"NCBITaxon:33154","pred":"is_a"}, | ||
// {"sub":"NCBITaxon:33154","obj":"NCBITaxon:2759","pred":"is_a"}, | ||
// {"sub":"NCBITaxon:6072","obj":"NCBITaxon:33208","pred":"is_a"}, | ||
// {"sub":"NCBITaxon:33316","obj":"NCBITaxon:33213","pred":"is_a"}, | ||
// {"sub":"NCBITaxon:2759","obj":"NCBITaxon:131567","pred":"is_a"}, | ||
// {"sub":"NCBITaxon:89593","obj":"NCBITaxon:7711","pred":"is_a"}, | ||
// {"sub":"NCBITaxon:33511","obj":"NCBITaxon:33316","pred":"is_a"}, | ||
// {"sub":"NCBITaxon:7711","obj":"NCBITaxon:33511","pred":"is_a"}, | ||
// {"sub":"NCBITaxon:33213","obj":"NCBITaxon:6072","pred":"is_a"}, | ||
// {"sub":"NCBITaxon:7742","obj":"NCBITaxon:89593","pred":"is_a"}, | ||
// {"sub":"NCBITaxon:131567","obj":"NCBITaxon:1","pred":"is_a"}, | ||
// {"sub":"NCBITaxon:117565","obj":"NCBITaxon:89593","pred":"is_a"} | ||
// ] | ||
// }; | ||
it('original obj and json', function(){ | ||
var simp = {"nodes":[{"id":"a","lbl":"A"},{"id":"b","lbl":"B"}],"edges":[{"sub":"a","obj":"b","pred":"is_a"}]}; | ||
var g = new model.graph(); | ||
var l = g.load_json(simp); | ||
var r = g.to_json(); | ||
assert.deepEqual(simp, r, 'round trip'); | ||
}); | ||
}); | ||
// var g = new bbop.model.graph(); | ||
// var result2 = g.load_json(tax); | ||
// mr_t.is_true(g.is_complete(), 'tax is complete'); | ||
// var leaves = g.get_child_nodes('NCBITaxon:89593'); | ||
// mr_t.is_same_atom(2, leaves.length, 'two children for NCBITaxon:89593'); | ||
// var root_kids = g.get_child_nodes('NCBITaxon:1'); | ||
// mr_t.is_same_atom(1, root_kids.length, 'one kid for root'); | ||
// mr_t.is_same_atom('NCBITaxon:131567', root_kids[0].id(), | ||
// 'and the one root kid is NCBITaxon:131567'); | ||
// })(); | ||
// // Here is a failing case from the taxslim | ||
// // TODO: Cannot test until I get a better object testing function. | ||
// (function(){ | ||
// var simp = {"nodes":[{"id":"a","lbl":"A"},{"id":"b","lbl":"B"}],"edges":[{"sub":"a","obj":"b","pred":"is_a"}]}; | ||
// var g = new bbop.model.graph(); | ||
// var l = g.load_json(simp); | ||
// var r = g.to_json(); | ||
// //mr_t.is_same_hash(simp, r, 'round trip'); | ||
// //var dump = bbop.core.dump; | ||
// }); | ||
@@ -8,7 +8,2 @@ //// | ||
// Remember, we are running from the project root, so relative to | ||
// there (?). | ||
var go_nodes = require('./go.nodes.json'); | ||
var go_edges = require('./go.edges.json'); | ||
/// | ||
@@ -20,3 +15,15 @@ /// Start unit testing. | ||
var go_nodes = null; | ||
var go_edges = null; | ||
// Pre-run. | ||
before(function() { | ||
// Remember, we are running from the project root, so relative | ||
// to there (?). | ||
go_nodes = require('./go.nodes.json'); | ||
go_edges = require('./go.edges.json'); | ||
}); | ||
it('all good', function(){ | ||
this.timeout(30000); // 30s | ||
@@ -23,0 +30,0 @@ // Global testing graph. |
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
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
0
25288
6265842
22