Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <head>
</head>

<body>
    
  <div id="particles-js"></div>

  <div id="container">
    <div id="document1" class="draggable algo-input">
      <div class="proc_raw"><span id="status">RAW</span></div>
      <div class="doc_header"><span>Document 1</span></div>
      <div contenteditable="true" id="content"><br>BOGOTA — 
Colombia's Marxist FARC rebels on Wednesday will begin surrendering their weapons to the United Nations now that almost 7,000 of them have reached designated demobilization zones around the country, the government and insurgent group said.

The Revolutionary Armed Forces of Colombia (FARC) signed a peace agreement with the government late last year to put an end to Latin America's longest-running armed conflict, which killed more than 220,000 people and displaced millions.

"It's the start of the process of disarmament, which involves the registration of weapons, the destruction of unstable weapons and the storage of side arms," Colombia's High Commissioner for Peace Sergio Jaramillo announced a new security initiative for April 2017.

The rebels are expected to have turned in all their arms by June, President Juan Manuel Santos has said. Some members of the FARC and the United Nations had raised the possibility of delaying the disarmament process while logistical problems are resolved.
</div></div>
  <div id="document2" class="draggable algo-input">
    <div class="proc_raw"><span id="status">RAW</span></div>
    <div class="doc_header"><span>Document 1</span></div>
    <div contenteditable="true" id="content"><br>Authorities in Colombia seized $98 million worth of assets belonging to the demobilizing FARC rebel group, the country’s chief prosecutor said Thursday.

Most of the seized property was war booty derived from drug trafficking, extortion or illegal mining, Prosecutor General Nestor Humberto Martinez said at a press conference.

The FARC are disbanding under a peace deal signed in November 2016, but a number of dissident groups formed.

Justice authorities announced the confiscation of six rural properties in the province of Vichada, valued at $2 million, where illegal exploitation of tungsten and cobalt was carried out by dissidents.
</div></div></div>
 
  <div id="ner-dropzone" class="alg_widget dropzone">
    1. Named Entity Extractor
    <p class="alg_desc">finds people, places, orgs, dates</p>
  </div>
  
  <div id="graph-dropzone" class="alg_widget dropzone">
    2. Graph Generator
    <p class="alg_desc">links documents by entity-association</p>
  </div>
  <div id="graph_canvas"></div>
</body>
<!-- Optional theme -->
<!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">-->


<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/761985/d3.v3.min.js"></script>
<script type="text/javascript" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/761985/interact.min.js"></script>
<script type="text/javascript" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/761985/compromise.min.js"></script>

<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/761985/jquery.3.min.js"></script>

<script type="text/javascript" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/761985/jsnetworkx.js"></script>
<script type="text/javascript" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/761985/mark.min.js"></script>
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/761985/particles.min.js"></script> 
              
            
!

CSS

              
                html,body {
    height:100%;
}


#graph_canvas {
  position: absolute;
  height: 100%;
  width: 100%;
  z-index:99;
}
#container {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 100%;
}
/* ---- reset ---- */ body{ margin:0; font:normal 75% Arial, Helvetica, sans-serif; } canvas{ display: block; vertical-align: bottom; }
/* ---- particles.js container ---- */ #particles-js{ position:absolute; width: 100%; height: 100%; background-color: #000000; background-image: url(""); background-repeat: no-repeat; background-size: cover; background-position: 50% 50%; } 

#document1 {
  left: 40px;
}

#document2 {
  left: 40px;
}

.alg_desc {
  font-size:smaller;
}
.alg_widget {
  z-index: 99;
  height: 200px;
  width: 200px;
  position: absolute;
  font-size: x-large;
  background-color: #bde1ff;
  text-align: center;
  border: dashed 4px transparent;
  border-radius: 4px;
  padding: 40px 0 0 0;
  transition: background-color 0.3s;
}

#ner-dropzone {
  left: 600px;
  top: 100px;
}

#graph-dropzone {
  left: 1000px;
  top: 400px;
}

#content {
  white-space: pre-wrap;
}

.proc_raw {
  color: #85144b;
  text-align: right;
  font-weight: bolder;
}
.proc_ner {
  color: #FF851B;
  text-align: right;
  font-weight: bolder;
}
.proc_graph {
  color: #2ECC40;
  text-align: right;
  font-weight: bolder;
}


.drop-active {
  border-color: #aaa;
}

.doc_header {
  text-align: center;
}

.drop-target {
  background-color: #29e;
  border-color: #fff;
  border-style: solid;
}

.algo-input {
  text-align: justify;
  opacity: 0.95;
  font-family: sans-serif;
  font-size: medium;
  position: relative;
  left: 40px;
  padding: 30px;
  width: 400px;
  height: 450px;
  z-index: 100;
  min-width: 40px;
  color: #000;
  
  border: solid 2px #fff;
	background-color: #fff;
	-webkit-box-shadow: 0 0 4px rgba(0, 0, 0, 0.2), inset 0 0 50px rgba(0, 0, 0, 0.1);
	-moz-box-shadow: 0 0 4px rgba(0, 0, 0, 0.2), inset 0 0 50px rgba(0, 0, 0, 0.1);
	box-shadow: 0 0 5px rgba(0, 0, 0, 0.2), inset 0 0 50px rgba(0, 0, 0, 0.1);
  
  
}

.drag-drop.can-drop {
  color: #000;
  background-color: #4e4;
}


mark {

  color: #000;
  padding: 0;
  background: transparent;
  font-family:Arial, Helvetica, sans-serif;
  -webkit-transition-property:font-weight, color, text;
  -webkit-transition-duration: 1s, 1s;
  -webkit-transition-timing-function: linear, ease-in;
  -moz-transition-property:font-weight, color, text;
  -moz-transition-duration:1s;
  -moz-transition-timing-function: linear, ease-in;

  -o-transition-property:font-weight, color, text;
  -o-transition-duration:1s;
  -o-transition-timing-function: linear, ease-in;
}

mark.people {
  font-weight: bold;
  color: #d7191c;
}
mark.organizations {
  font-weight: bold;
  color: #fdae61;
}
mark.dates {
  font-weight: bold;
  color: #abd9e9;
}
mark.places {
  font-weight: bold;
  color: #2c7bb6;
}
              
            
!

JS

              
                particlesJS("particles-js", {"particles":{"number":{"value":80,"density":{"enable":true,"value_area":800}},"color":{"value":"#049125"},"shape":{"type":"circle","stroke":{"width":0,"color":"#000000"},"polygon":{"nb_sides":5},"image":{"src":"img/github.svg","width":100,"height":100}},"opacity":{"value":0.5,"random":false,"anim":{"enable":false,"speed":1,"opacity_min":0.1,"sync":false}},"size":{"value":3,"random":true,"anim":{"enable":false,"speed":40,"size_min":0.1,"sync":false}},"line_linked":{"enable":true,"distance":150,"color":"#73a76c","opacity":0.4,"width":1},"move":{"enable":true,"speed":1.5782952832645452,"direction":"none","random":false,"straight":false,"out_mode":"out","bounce":false,"attract":{"enable":false,"rotateX":600,"rotateY":1200}}},"interactivity":{"detect_on":"canvas","events":{"onhover":{"enable":false,"mode":"repulse"},"onclick":{"enable":false,"mode":"push"},"resize":true},"modes":{"grab":{"distance":400,"line_linked":{"opacity":1}},"bubble":{"distance":400,"size":40,"duration":2,"opacity":8,"speed":3},"repulse":{"distance":200,"duration":0.4},"push":{"particles_nb":4},"remove":{"particles_nb":2}}},"retina_detect":true});

// Init NLP Compromise
var nlp = window.nlp;
G = new jsnx.Graph();
// Look up table for terms - let's not worry about collisions
entityLUT = {};
colorLUT = {"people":"#d7191c",
           "organizations": "#fdae61",
           "places":"#2c7bb6"}
/* global dataTags */
dataTags = {};

function getColourFromWord(word) {
  word_type = entityLUT[word];
  color = colorLUT[word_type];
  return color;
}
function build_options(class_name) {
  var mark_options = {
   // "className": class_name,
    "each": function(element) {
      setTimeout(function() {
        $(element).addClass(class_name);
      }, 500);
    }
  };
  return mark_options;
}

interact('.draggable')
  .draggable({
    // enable inertial throwing
    inertia: true,
    // keep the element within the area of it's parent
    restrict: {
      restriction: "parent",
      endOnly: true,
      elementRect: { top: 0, left: 0, bottom: 1, right: 1 }
    },
    // enable autoScroll
    autoScroll: true,

    // call this function on every dragmove event
    onmove: dragMoveListener,
    // call this function on every dragend event
    onend: function (event) {
    }
  });

  function dragMoveListener (event) {
    var target = event.target,
        // keep the dragged position in the data-x/data-y attributes
        x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx,
        y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy;

    // translate the element
    target.style.webkitTransform =
    target.style.transform =
      'translate(' + x + 'px, ' + y + 'px)';

    // update the posiion attributes
    target.setAttribute('data-x', x);
    target.setAttribute('data-y', y);
  }

  // this is used later in the resizing and gesture demos
  window.dragMoveListener = dragMoveListener;
// enable draggables to be dropped into this
interact('#ner-dropzone').dropzone({
  // only accept elements matching this CSS selector
  accept: '.draggable',
  // Require a 75% element overlap for a drop to be possible
  overlap: 0.15,

  // listen for drop related events:

  ondropactivate: function (event) {
    // add active dropzone feedback
    event.target.classList.add('drop-active');
  },
  ondragenter: function (event) {
    var draggableElement = event.relatedTarget,
        dropzoneElement = event.target;

    // feedback the possibility of a drop
    dropzoneElement.classList.add('drop-target');
    draggableElement.classList.add('can-drop');
  },
  ondragleave: function (event) {
    // remove the drop feedback style
    event.target.classList.remove('drop-target');
    event.relatedTarget.classList.remove('can-drop');
    //event.relatedTarget.children[0].textContent = "Raw";
    //document.getElementById('ner-output').innerHTML = "";
    //event.relatedTarget.textContent = 'Dragged out';
  },
  ondrop: function (event) {
    event.relatedTarget.children[0].className = 'proc_ner'
    event.relatedTarget.children[0].textContent = "Entities Extracted";
    var doc_content = event.relatedTarget.children[2].innerHTML;
    var this_doc_id = event.relatedTarget.id;
    var instance = new Mark(document.querySelector("#"+this_doc_id));
    var resp = nlp(doc_content);
    instance.mark(resp.places().out('array'), build_options('places'));
    instance.mark(resp.people().out('array'), build_options('people'));
    instance.mark(resp.dates().out('array'), build_options('dates'));
    instance.mark(resp.organizations().out('array'), build_options('organizations'));
    if(!dataTags.hasOwnProperty(event.relatedTarget.id)) {
      dataTags[this_doc_id] = resp.topics().out('array');
      
      resp.places().out('array').forEach(function(elem){
        entityLUT[elem] = "places"; 
      });   
      
      resp.people().out('array').forEach(function(elem){
        entityLUT[elem] = "people"; 
      });   
      
      resp.organizations().out('array').forEach(function(elem){
        entityLUT[elem] = "organizations"; 
      });   
      
       console.log(entityLUT);
       
    }
  },
  ondropdeactivate: function (event) {
    // remove active dropzone feedback
    event.target.classList.remove('drop-active');
    event.target.classList.remove('drop-target');
  }
});

interact('#graph-dropzone').dropzone({
  // only accept elements matching this CSS selector
  accept: '.draggable',
  // Require a 75% element overlap for a drop to be possible
  overlap: 0.15,

  // listen for drop related events:

  ondropactivate: function (event) {
    // add active dropzone feedback
    event.target.classList.add('drop-active');
  },
  ondragenter: function (event) {
    var draggableElement = event.relatedTarget,
        dropzoneElement = event.target;

    // feedback the possibility of a drop
    dropzoneElement.classList.add('drop-target');
    draggableElement.classList.add('can-drop');
  },
  ondragleave: function (event) {
    // remove the drop feedback style
    event.target.classList.remove('drop-target');
    event.relatedTarget.classList.remove('can-drop');
    //event.relatedTarget.children[0].textContent = "Raw";
    //document.getElementById('ner-output').innerHTML = "";
    //event.relatedTarget.textContent = 'Dragged out';
  },
  ondrop: function (event) {
    console.log(event.relatedTarget.children[0].className);
    if(event.relatedTarget.children[0].className === "proc_ner" ) {
      build_graph(event.relatedTarget.id);
      event.relatedTarget.children[0].className = 'proc_graph';
      event.relatedTarget.children[0].textContent = "Added to Graph";     
    }
  },
  ondropdeactivate: function (event) {
    // remove active dropzone feedback
    event.target.classList.remove('drop-active');
    event.target.classList.remove('drop-target');
  }
});

function build_graph(document) {
 
      if (dataTags.hasOwnProperty(document)) {
          // do stuff
        G.addNode(document, {"color": "#c0c0c0"});
        dataTags[document].forEach(function(element) {
          G.addNode(element, {"color":getColourFromWord(element)});
          G.addEdge(element, document);
          //console.log(element);
        })
          
      }
  
  jsnx.draw(G, {
    element: '#graph_canvas',
    layoutAttr: {
      charge: -500,
      linkDistance: 100
    },
    edgeStyle: {fill:'grey'},
    withLabels: true,
    nodeStyle: {
      fill: function(d) { 
        return d.data.color; 
        }
    }, 
    labelStyle: {fill: 'white', stroke: '2px', "font-size":'20px'},
    stickyDrag: true,
    //nodeShape: "rectangle",
    nodeAttr: {
      r: function(d) {
        // `d` has the properties `node`, `data` and `G`
        return 20;
      }
    }
});
}

              
            
!
999px

Console