/* read dbpedia-imports data and provide it in form of tree (for the package hierarchy) and links (for the imports) */ /* code adapted from http://bl.ocks.org/mbostock/4341134 */ (function() { window.dbpedia_reader = { // Lazily construct the package hierarchy from class names. tree1: function(classes) { var map = {}; function find(name, data) { var node = map[name], i; if (!node) { node = map[name] = data || {name: name, children: []}; if (name.length) { node.parent = find(name.substring(0, i = name.lastIndexOf("."))); node.parent.children.push(node); node.key = name.substring(i + 1); } } return node; } classes.forEach(function(d) { find(d.name, d); }); var dbpedia = map['dbpedia']; delete dbpedia.parent; // CHANGED root node is not "" return dbpedia; }, tree: function(classes) { function treeVisit(node, parent) { node.key = node.name.replace("http://dbpedia.org/ontology/", ""); for (var i = 0; i < node.size; i++) { newNode = {"name": ""+(i+1)+"", "size": 0}; if (!node.children) node.children = []; node.children.push(newNode); } if (parent != null) { node.parent = parent; node.name = parent.name + "." + node.key; } else node.name = node.key; if (node.children) { node.children.forEach(function(d) { treeVisit(d, node); }); } return node; } return treeVisit(classes, null); }, // Return a list of imports for the given array of nodes. imports: function(nodes) { var map = {}, imports = []; // Compute a map from name to node. nodes.forEach(function(d) { map[d.name] = d; }); // For each import, construct a link from the source to target node. nodes.forEach(function(d) { if (d.imports) d.imports.forEach(function(i) { imports.push({source: map[d.name], target: map[i]}); }); }); return imports; } }; ; }).call(this);