bbop-graph-noctua
Advanced tools
Comparing version 0.0.21 to 0.0.23
148
lib/edit.js
@@ -1363,3 +1363,3 @@ /** | ||
* | ||
* BUG/WARNING: The clique actually needs to use the walked rather | ||
* BUG/WARNING: The clique actually needs to use the walker rather | ||
* than the anc/desc functions it uses now. | ||
@@ -1631,5 +1631,9 @@ * | ||
anchor.get_child_nodes(node.id()).length === 1 ){ | ||
//console.log("foldable: " + node.id()); | ||
//console.log("is foldable: " + node.id()); | ||
ret = true; | ||
}else{ | ||
//console.log("not foldable: " + node.id()); | ||
} | ||
// console.log(" root_p: " + anchor.is_root_node(node.id()) + | ||
// "; kids: " + anchor.get_child_nodes(node.id()).length); | ||
return ret; | ||
@@ -1639,4 +1643,6 @@ } | ||
// Okay, first scan all nodes for our pattern. | ||
each(anchor.all_nodes(), function(ind){ | ||
each(anchor.all_nodes(), function(pattern_seed_indv){ | ||
var pattern_seed_id = pattern_seed_indv.id(); | ||
// The possible base subgraph (seeding with current node--note | ||
@@ -1646,3 +1652,3 @@ // the clone so we don't have infinite recursion) we might | ||
var subgraph = anchor.create_graph(); | ||
subgraph.add_node(ind.clone()); | ||
subgraph.add_node(pattern_seed_indv.clone()); | ||
@@ -1652,17 +1658,21 @@ // Check a set of relations for completeness: enabled_by and | ||
//var collapsable_relations = ['RO:0002333', 'BFO:0000066']; | ||
var fold_occurred_p = false; | ||
var collapsable_relations = relation_list || []; | ||
each(collapsable_relations, function(relation){ | ||
var kids = anchor.get_parent_nodes(ind.id(), relation); | ||
each(kids, function(kid){ | ||
if( _foldable_p(kid) ){ | ||
var parents = anchor.get_parent_nodes(pattern_seed_id, relation); | ||
each(parents, function(parent){ | ||
if( _foldable_p(parent) ){ | ||
fold_occurred_p = true; | ||
// Preserve it and its edge in the new subgraph. | ||
subgraph.add_node(kid.clone()); | ||
subgraph.add_edge( | ||
anchor.get_parent_edges(ind.id(), relation)[0].clone()); | ||
subgraph.add_node(parent.clone()); | ||
subgraph.add_edge( // we know it's just one from above | ||
anchor.get_parent_edges(pattern_seed_id, | ||
relation)[0].clone()); | ||
// Remove same from the original graph, edge will be | ||
// destroyed in the halo. | ||
anchor.remove_node(kid.id(), true); | ||
anchor.remove_node(parent.id(), true); | ||
} | ||
@@ -1676,5 +1686,6 @@ }); | ||
// graph. | ||
if( subgraph.all_nodes().length > 1 ){ | ||
//console.log('slurpable subgraph for: ' + ind.id()); | ||
ind.subgraph(subgraph); | ||
if( fold_occurred_p ){ | ||
// console.log('slurpable subgraph ('+ subgraph.all_nodes().length + | ||
// ') for: ' + pattern_seed_id); | ||
pattern_seed_indv.subgraph(subgraph); | ||
} | ||
@@ -1707,2 +1718,4 @@ | ||
// Restore to graph. | ||
// console.log(' unfold # (' + sub.all_nodes().length + ', ' + | ||
// sub.all_edges().length + ')'); | ||
each(sub.all_nodes(), function(node){ | ||
@@ -1730,4 +1743,4 @@ anchor.add_node(node); | ||
// Now that they've been removed, try and recur (to help | ||
// prevent loops). | ||
// Now that they've been removed (to help prevent loops) try | ||
// and recur. | ||
each(ref_graphs, function(sub){ | ||
@@ -1774,2 +1787,105 @@ anchor.unfold(sub); | ||
/** | ||
* Provide a verbose report of the current state of the graph and | ||
* subgraphs. Writes using console.log; only to be used for debugging. | ||
* | ||
* @returns {null} just the facts | ||
*/ | ||
noctua_graph.prototype.report_state = function(incoming_graph, indentation){ | ||
var anchor = this; | ||
// If not a recursive, we will operate on ourselves. | ||
if( ! incoming_graph ){ | ||
incoming_graph = anchor; | ||
} | ||
// Start with no indentation. | ||
if( typeof(indentation) === 'undefined' ){ | ||
indentation = 0; | ||
} | ||
// Collect spacing for this indentation level of logging. | ||
var spacing = ''; | ||
for( var i = 0; i < indentation; i++ ){ | ||
spacing += ' '; | ||
} | ||
function ll(str){ | ||
console.log(spacing + str); | ||
} | ||
function short(str){ | ||
return str.substr(str.length - 16); | ||
} | ||
// Restore to graph. | ||
var gid = incoming_graph.id() || '(anonymous graph)'; | ||
ll(gid); | ||
ll(' entities # (' + incoming_graph.all_nodes().length + | ||
', ' + incoming_graph.all_edges().length + ')'); | ||
// Show node information, arbitrary, but fixed, order. | ||
each(incoming_graph.all_nodes().sort(function(a,b){ | ||
if( a.id() > b.id() ){ | ||
return 1; | ||
}else if( a.id() < b.id() ){ | ||
return -1; | ||
} | ||
return 0; | ||
}), function(node){ | ||
ll(' node: ' + short(node.id())); | ||
// Subgraph. | ||
var subgraph = node.subgraph(); | ||
if( subgraph ){ | ||
ll(' subgraph: '); | ||
anchor.report_state(subgraph, indentation +1); | ||
} | ||
// Refs. | ||
var ref_graphs = node.referenced_subgraphs(); | ||
if( ref_graphs.length > 0 ){ | ||
ll(' references: '); | ||
each(ref_graphs, function(sub){ | ||
anchor.report_state(sub, (indentation +1)); | ||
}); | ||
} | ||
}); | ||
// Show edge information, arbitrary, but fixed, order. | ||
each(incoming_graph.all_edges().sort(function(a,b){ | ||
if( a.id() > b.id() ){ | ||
return 1; | ||
}else if( a.id() < b.id() ){ | ||
return -1; | ||
} | ||
return 0; | ||
}), function(edge){ | ||
var s = short(edge.subject_id()); | ||
var o = short(edge.object_id()); | ||
var p = edge.predicate_id(); | ||
//ll(' edge: ' + edge.id()); | ||
ll(' edge: ' + s + ', ' + o + ': ' + p); | ||
// Refs. | ||
var ref_graphs = edge.referenced_subgraphs(); | ||
if( ref_graphs.length > 0 ){ | ||
ll(' references: '); | ||
each(ref_graphs, function(sub){ | ||
anchor.report_state(sub, (indentation +1)); | ||
}); | ||
} | ||
}); | ||
if( ! us.isEmpty(incoming_graph._os_table) ){ | ||
console.log(spacing + 'OS:', incoming_graph._os_table); | ||
} | ||
if( ! us.isEmpty(incoming_graph._so_table) ){ | ||
console.log(spacing + 'SO:', incoming_graph._so_table); | ||
} | ||
if( ! us.isEmpty(incoming_graph._predicates) ){ | ||
console.log(spacing + 'PRED:', incoming_graph._predicates); | ||
} | ||
return null; | ||
}; | ||
/// | ||
@@ -1776,0 +1892,0 @@ /// Node subclass and overrides. |
{ | ||
"name": "bbop-graph-noctua", | ||
"version": "0.0.21", | ||
"version": "0.0.23", | ||
"license": "BSD-3-Clause", | ||
@@ -32,5 +32,5 @@ "description": "A subclass of bbop-graph that layers on a complete annotation and graph editing model for the Noctua set of tools.", | ||
"dependencies": { | ||
"bbop-core": "0.0.4", | ||
"bbop-graph": "0.0.14", | ||
"class-expression": "0.0.8", | ||
"bbop-core": "0.0.5", | ||
"bbop-graph": "0.0.16", | ||
"class-expression": "0.0.9", | ||
"underscore": "1.8.3" | ||
@@ -37,0 +37,0 @@ }, |
@@ -726,2 +726,74 @@ //// | ||
describe("new issues in recent data", function(){ | ||
it('model is folded and subgraphs should be absorbed, direct', function(){ | ||
var raw_resp = require('./minerva-05.json'); | ||
var g = new model.graph(); | ||
g.load_data_basic(raw_resp['data']); | ||
// 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 simple evidence fold is fine. | ||
g.fold_evidence(); | ||
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 repeat--it's not refolding | ||
g.fold_evidence(); | ||
assert.equal(g.all_nodes().length, 7, "less nodes in evidence fold x2"); | ||
assert.equal(g.all_edges().length, 5, "less edges in evidence fold x2"); | ||
// ...and this fold compacts most out of existance. | ||
var rellist = ['RO:0002333', 'BFO:0000066', 'RO:0002233', 'RO:0002488']; | ||
//g.report_state(); console.log(''); | ||
g.fold_go_noctua(rellist); | ||
//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"); | ||
}); | ||
it('model is folded 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']; | ||
g.fold_go_noctua(rellist); | ||
//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; | ||
@@ -728,0 +800,0 @@ // var model = new require('..'); |
6446378
20
30312
+ Addedbbop-core@0.0.5(transitive)
+ Addedbbop-graph@0.0.16(transitive)
+ Addedclass-expression@0.0.9(transitive)
- Removedbbop-graph@0.0.14(transitive)
- Removedclass-expression@0.0.8(transitive)
Updatedbbop-core@0.0.5
Updatedbbop-graph@0.0.16
Updatedclass-expression@0.0.9