<jupyter_start><jupyter_text>Uses https://github.com/ResidentMario/py_d3 for D3 Visualisation<jupyter_code>%load_ext py_d3
%%d3 "3.4.8"
<g></g>

<script>
d3.select("g").text("Hello World");
</script>
from rdflib import Graph
g = Graph()
g.parse("../rdf/lw-eii.ttl", format="ttl")
len(g) # prints 2

import pprint
for stmt in g:
    pprint.pprint(stmt)

%%javascript
require.config({
  paths: {
      d3: '//d3js.org/d3.v4.min'
  }
});
%%javascript
element.append("<div id='chart1'><svg></svg></div>");
%%javascript
require(['d3'], function(d3){
  //a weird idempotency thing
  $("#chart1").remove();
  //create canvas
  element.append("<div id='chart1'></div>");
  $("#chart1").width("960px");
  $("#chart1").height("600px");        
  var margin = {top: 20, right: 20, bottom: 30, left: 40};
  var width = 880 - margin.left - margin.right;
  var height = 500 - margin.top - margin.bottom;
  var svg = d3.select("#chart1").append("svg")
    .style("position", "relative")
    .style("max-width", "960px")
    .attr("width", width + "px")
    .attr("height", (height + 50) + "px")
    .append("g")
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
  
  
var nodes = [
  { id: "mammal", group: 0, label: "Mammals", level: 1 },
  { id: "dog"   , group: 0, label: "Dogs"   , level: 2 },
  { id: "cat"   , group: 0, label: "Cats"   , level: 2 },
  { id: "fox"   , group: 0, label: "Foxes"  , level: 2 },
  { id: "elk"   , group: 0, label: "Elk"    , level: 2 },
  { id: "insect", group: 1, label: "Insects", level: 1 },
  { id: "ant"   , group: 1, label: "Ants"   , level: 2 },
  { id: "bee"   , group: 1, label: "Bees"   , level: 2 },
  { id: "fish"  , group: 2, label: "Fish"   , level: 1 },
  { id: "carp"  , group: 2, label: "Carp"   , level: 2 },
  { id: "pike"  , group: 2, label: "Pikes"  , level: 2 }
]


// simulation setup with all forces
var simulation = d3
  .forceSimulation()
  .force('charge', d3.forceManyBody().strength(-120))
  .force('center', d3.forceCenter(width / 2, height / 2))


function getNodeColor(node) {
  return node.level === 1 ? 'red' : 'gray'
}

var nodeElements = svg.append("g")
  .attr("class", "nodes")
  .selectAll("circle")
  .data(nodes)
  .enter().append("circle")
    .attr("r", 10)
    .attr("fill", getNodeColor)

var textElements = svg.append("g")
  .attr("class", "texts")
  .selectAll("text")
  .data(nodes)
  .enter().append("text")
    .text(function (node) { return  node.label })
	  .attr("font-size", 15)
	  .attr("dx", 15)
    .attr("dy", 4)

  simulation.nodes(nodes).on('tick', () => {
    nodeElements
      .attr('cx', function (node) { return node.x })
      .attr('cy', function (node) { return node.y })
    textElements
      .attr('x', function (node) { return node.x })
      .attr('y', function (node) { return node.y })
  })
});<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2231201686577653, 'fraction_numerical': 0.029866479269149683, 'mean_word_length': 3.2683658170914542, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '239060', 'license': 'Apache-2.0', 'n_tokens_mistral': 1165, 'n_tokens_neox': 1103, 'n_words': 259, 'path': 'notebooks/VisualiseTeamGraph.ipynb', 'repo_name': 'CSIRO-enviro-informatics/team-projects', 'size': '2846'}