bbop-graph-noctua
Advanced tools
Comparing version 0.0.23 to 0.0.24
@@ -1614,6 +1614,8 @@ /** | ||
* | ||
* @param {Array} list of relations (as strings) to scan for for collapsing | ||
* @param {Array} relation_list of relations (as strings) to scan for for collapsing | ||
* @param {Array} relation_reverse_list of relations (as strings) to scan for for collapsing in the opposite direction. | ||
* @returns {Boolean} if data was loaded | ||
*/ | ||
noctua_graph.prototype.fold_go_noctua = function(relation_list){ | ||
noctua_graph.prototype.fold_go_noctua = function(relation_list, | ||
relation_reverse_list){ | ||
var anchor = this; | ||
@@ -1641,2 +1643,19 @@ | ||
// It is reverse foldable if it is a leaf node (re: opposite of | ||
// root--only source) and if it only has the one child (no way | ||
// out--re: collapsible ). | ||
function _reverse_foldable_p(node){ | ||
var ret = false; | ||
if( anchor.is_leaf_node(node.id()) && | ||
anchor.get_parent_nodes(node.id()).length === 1 ){ | ||
//console.log("is foldable: " + node.id()); | ||
ret = true; | ||
}else{ | ||
//console.log("not foldable: " + node.id()); | ||
} | ||
// console.log(" leaf_p: " + anchor.is_leaf_node(node.id()) + | ||
// "; parents: " + anchor.get_parent_nodes(node.id()).length); | ||
return ret; | ||
} | ||
// Okay, first scan all nodes for our pattern. | ||
@@ -1653,6 +1672,7 @@ each(anchor.all_nodes(), function(pattern_seed_indv){ | ||
// Check a set of relations for completeness: enabled_by and | ||
// occurs_in (location). | ||
//var collapsable_relations = ['RO:0002333', 'BFO:0000066']; | ||
// Fold checking is independent of reverse or not. | ||
var fold_occurred_p = false; | ||
// Check a set of relations for completeness. | ||
var collapsable_relations = relation_list || []; | ||
@@ -1680,2 +1700,25 @@ each(collapsable_relations, function(relation){ | ||
// ...and now the other way. | ||
var collapsable_reverse_relations = relation_reverse_list || []; | ||
each(collapsable_reverse_relations, function(relation){ | ||
var children = anchor.get_child_nodes(pattern_seed_id, relation); | ||
each(children, function(child){ | ||
if( _reverse_foldable_p(child) ){ | ||
fold_occurred_p = true; | ||
// Preserve it and its edge in the new subgraph. | ||
subgraph.add_node(child.clone()); | ||
subgraph.add_edge( // we know it's just one from above | ||
anchor.get_child_edges(pattern_seed_id, | ||
relation)[0].clone()); | ||
// Remove same from the original graph, edge will | ||
// be destroyed in the halo. | ||
anchor.remove_node(child.id(), true); | ||
} | ||
}); | ||
}); | ||
// A usable folding subgraph only occurred when the are more | ||
@@ -1682,0 +1725,0 @@ // than 1 node in it; i.e. we actually actually added things |
{ | ||
"name": "bbop-graph-noctua", | ||
"version": "0.0.23", | ||
"version": "0.0.24", | ||
"license": "BSD-3-Clause", | ||
@@ -5,0 +5,0 @@ "description": "A subclass of bbop-graph that layers on a complete annotation and graph editing model for the Noctua set of tools.", |
@@ -798,2 +798,45 @@ //// | ||
describe("looking at how (un)folding would work in reverse world", function(){ | ||
it('model is folded, including reverses, and subgraphs should be absorbed, unfolding', function(){ | ||
var raw_resp = require('./minerva-05.json'); | ||
var g = new model.graph(); | ||
g.load_data_basic(raw_resp['data']); | ||
//g.report_state(); console.log(''); | ||
// Make sure we're starting at a sane point... | ||
assert.equal(g.all_nodes().length, 12, "all nodes accounted for (1)"); | ||
assert.equal(g.all_edges().length, 5, "all edges accounted for (1)"); | ||
// And check. | ||
g.unfold(); | ||
//g.report_state(); console.log(''); | ||
assert.equal(g.all_nodes().length, 12, "all nodes accounted for (2)"); | ||
assert.equal(g.all_edges().length, 5, "all edges accounted for (2)"); | ||
// And simple evidence fold is fine. | ||
g.fold_evidence(); | ||
//g.report_state(); console.log(''); | ||
assert.equal(g.all_nodes().length, 7, "less nodes in evidence fold"); | ||
assert.equal(g.all_edges().length, 5, "less edges in evidence fold"); | ||
// And check. | ||
g.unfold(); | ||
//g.report_state(); console.log(''); | ||
assert.equal(g.all_nodes().length, 12, "all nodes accounted for (3)"); | ||
assert.equal(g.all_edges().length, 5, "all edges accounted for (3)"); | ||
// ...and this fold compacts most out of existance. | ||
var rellist = ['RO:0002333', 'BFO:0000066', 'RO:0002233', 'RO:0002488']; | ||
var revrellist = ['BFO:0000051']; | ||
g.fold_go_noctua(rellist, revrellist); | ||
//g.report_state(); console.log(''); | ||
assert.equal(g.all_nodes().length, 3, "few nodes in noctua fold"); | ||
assert.equal(g.all_edges().length, 1, "few edges in noctua fold"); | ||
}); | ||
}); | ||
// var assert = require('chai').assert; | ||
@@ -800,0 +843,0 @@ // var model = new require('..'); |
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
6449513
30380