PageRenderTime 1154ms CodeModel.GetById 244ms app.highlight 624ms RepoModel.GetById 143ms app.codeStats 0ms

/visualization/widgets/protoviz/utility.infinit.e.protovis.visualizations/arc.js

https://github.com/IKANOW/Infinit.e
JavaScript | 978 lines | 780 code | 86 blank | 112 comment | 185 complexity | 5143f0ab12be17b99f03dd2aca939625 MD5 | raw file
  1// This file contains the weighted network of coappearances of characters in
  2// Victor Hugo's novel "Les Miserables". Nodes represent characters as indicated
  3// by the labels, and edges connect any pair of characters that appear in the
  4// same chapter of the book. The values on the edges are the number of such
  5// coappearances. The data on coappearances were taken from D. E. Knuth, The
  6// Stanford GraphBase: A Platform for Combinatorial Computing, Addison-Wesley,
  7// Reading, MA (1993).
  8//
  9// The group labels were transcribed from "Finding and evaluating community
 10// structure in networks" by M. E. J. Newman and M. Girvan.
 11
 12var mydata ;
 13var mynodes;
 14var mylinks;
 15
 16
 17var infinite = {
 18  nodes:[
 19         {nodeName:"news", group:1},
 20         {nodeName:"imagery", group:1},
 21         {nodeName:"social", group:1},
 22         {nodeName:"video", group:1},
 23         {nodeName:"discussion", group:1},
 24         {nodeName:"taylor swift", group:2},
 25         {nodeName:"selena gomez", group:2},
 26         {nodeName:"israel", group:2},
 27         {nodeName:"president", group:2},
 28         {nodeName:"palin", group:2},
 29         {nodeName:"the washington post company", group:2},
 30         {nodeName:"piper", group:2},
 31         {nodeName:"the washington post", group:2},
 32         {nodeName:"lady liberty", group:2},
 33         {nodeName:"iman al-obeidi", group:2},
 34         {nodeName:"united states", group:2},
 35         {nodeName:"she was assaulted by gaddafi troops, is reportedly on her way to us", group:2},
 36         {nodeName:"her way", group:2},
 37         {nodeName:"rachel nicholas", group:2},
 38         {nodeName:"cleveland", group:2},
 39         {nodeName:"person travel", group:3},
 40         {nodeName:"generic relations", group:3},
 41         {nodeName:"family relation", group:3},
 42         {nodeName:"quotation", group:3},
 43         {nodeName:"taylor swift", group:4},
 44         {nodeName:"selena gomez", group:4},
 45         {nodeName:"israel", group:4},
 46         {nodeName:"president", group:4},
 47         {nodeName:"palin", group:4},
 48         {nodeName:"the washington post company", group:4},
 49         {nodeName:"piper", group:4},
 50         {nodeName:"the washington post", group:4},
 51         {nodeName:"lady liberty", group:4},
 52         {nodeName:"iman al-obeidi", group:4},
 53         {nodeName:"united states", group:4},
 54         {nodeName:"she was assaulted by gaddafi troops, is reportedly on her way to us", group:4},
 55         {nodeName:"her way", group:4},
 56         {nodeName:"rachel nicholas", group:4},
 57         {nodeName:"cleveland", group:4}
 58         ],
 59    links:[
 60           {source:1, target:0, value:1},
 61           {source:2, target:0, value:8},
 62           {source:3, target:0, value:10},
 63           {source:3, target:2, value:6},
 64           {source:4, target:0, value:1},
 65           {source:5, target:0, value:1},
 66           {source:6, target:0, value:1},
 67           {source:7, target:0, value:1},
 68           {source:8, target:0, value:2},
 69           {source:9, target:0, value:1},
 70           {source:11, target:10, value:1}
 71           ]
 72    }
 73
 74var miserables = {
 75  nodes:[
 76    {nodeName:"Myriel", group:1},
 77    {nodeName:"Napoleon", group:1},
 78    {nodeName:"Mlle. Baptistine", group:1},
 79    {nodeName:"Mme. Magloire", group:1},
 80    {nodeName:"Countess de Lo", group:1},
 81    {nodeName:"Geborand", group:1},
 82    {nodeName:"Champtercier", group:1},
 83    {nodeName:"Cravatte", group:1},
 84    {nodeName:"Count", group:1},
 85    {nodeName:"Old Man", group:1},
 86    {nodeName:"Labarre", group:2},
 87    {nodeName:"Valjean", group:2},
 88    {nodeName:"Marguerite", group:3},
 89    {nodeName:"Mme. de R", group:2},
 90    {nodeName:"Isabeau", group:2},
 91    {nodeName:"Gervais", group:2},
 92    {nodeName:"Tholomyes", group:3},
 93    {nodeName:"Listolier", group:3},
 94    {nodeName:"Fameuil", group:3},
 95    {nodeName:"Blacheville", group:3},
 96    {nodeName:"Favourite", group:3},
 97    {nodeName:"Dahlia", group:3},
 98    {nodeName:"Zephine", group:3},
 99    {nodeName:"Fantine", group:3},
100    {nodeName:"Mme. Thenardier", group:4},
101    {nodeName:"Thenardier", group:4},
102    {nodeName:"Cosette", group:5},
103    {nodeName:"Javert", group:4},
104    {nodeName:"Fauchelevent", group:0},
105    {nodeName:"Bamatabois", group:2},
106    {nodeName:"Perpetue", group:3},
107    {nodeName:"Simplice", group:2},
108    {nodeName:"Scaufflaire", group:2},
109    {nodeName:"Woman 1", group:2},
110    {nodeName:"Judge", group:2},
111    {nodeName:"Champmathieu", group:2},
112    {nodeName:"Brevet", group:2},
113    {nodeName:"Chenildieu", group:2},
114    {nodeName:"Cochepaille", group:2},
115    {nodeName:"Pontmercy", group:4},
116    {nodeName:"Boulatruelle", group:6},
117    {nodeName:"Eponine", group:4},
118    {nodeName:"Anzelma", group:4},
119    {nodeName:"Woman 2", group:5},
120    {nodeName:"Mother Innocent", group:0},
121    {nodeName:"Gribier", group:0},
122    {nodeName:"Jondrette", group:7},
123    {nodeName:"Mme. Burgon", group:7},
124    {nodeName:"Gavroche", group:8},
125    {nodeName:"Gillenormand", group:5},
126    {nodeName:"Magnon", group:5},
127    {nodeName:"Mlle. Gillenormand", group:5},
128    {nodeName:"Mme. Pontmercy", group:5},
129    {nodeName:"Mlle. Vaubois", group:5},
130    {nodeName:"Lt. Gillenormand", group:5},
131    {nodeName:"Marius", group:8},
132    {nodeName:"Baroness T", group:5},
133    {nodeName:"Mabeuf", group:8},
134    {nodeName:"Enjolras", group:8},
135    {nodeName:"Combeferre", group:8},
136    {nodeName:"Prouvaire", group:8},
137    {nodeName:"Feuilly", group:8},
138    {nodeName:"Courfeyrac", group:8},
139    {nodeName:"Bahorel", group:8},
140    {nodeName:"Bossuet", group:8},
141    {nodeName:"Joly", group:8},
142    {nodeName:"Grantaire", group:8},
143    {nodeName:"Mother Plutarch", group:9},
144    {nodeName:"Gueulemer", group:4},
145    {nodeName:"Babet", group:4},
146    {nodeName:"Claquesous", group:4},
147    {nodeName:"Montparnasse", group:4},
148    {nodeName:"Toussaint", group:5},
149    {nodeName:"Child 1", group:10},
150    {nodeName:"Child 2", group:10},
151    {nodeName:"Brujon", group:4},
152    {nodeName:"Mme. Hucheloup", group:8}
153  ],
154  links:[
155    {source:1, target:0, value:1},
156    {source:2, target:0, value:8},
157    {source:3, target:0, value:10},
158    {source:3, target:2, value:6},
159    {source:4, target:0, value:1},
160    {source:5, target:0, value:1},
161    {source:6, target:0, value:1},
162    {source:7, target:0, value:1},
163    {source:8, target:0, value:2},
164    {source:9, target:0, value:1},
165    {source:11, target:10, value:1},
166    {source:11, target:3, value:3},
167    {source:11, target:2, value:3},
168    {source:11, target:0, value:5},
169    {source:12, target:11, value:1},
170    {source:13, target:11, value:1},
171    {source:14, target:11, value:1},
172    {source:15, target:11, value:1},
173    {source:17, target:16, value:4},
174    {source:18, target:16, value:4},
175    {source:18, target:17, value:4},
176    {source:19, target:16, value:4},
177    {source:19, target:17, value:4},
178    {source:19, target:18, value:4},
179    {source:20, target:16, value:3},
180    {source:20, target:17, value:3},
181    {source:20, target:18, value:3},
182    {source:20, target:19, value:4},
183    {source:21, target:16, value:3},
184    {source:21, target:17, value:3},
185    {source:21, target:18, value:3},
186    {source:21, target:19, value:3},
187    {source:21, target:20, value:5},
188    {source:22, target:16, value:3},
189    {source:22, target:17, value:3},
190    {source:22, target:18, value:3},
191    {source:22, target:19, value:3},
192    {source:22, target:20, value:4},
193    {source:22, target:21, value:4},
194    {source:23, target:16, value:3},
195    {source:23, target:17, value:3},
196    {source:23, target:18, value:3},
197    {source:23, target:19, value:3},
198    {source:23, target:20, value:4},
199    {source:23, target:21, value:4},
200    {source:23, target:22, value:4},
201    {source:23, target:12, value:2},
202    {source:23, target:11, value:9},
203    {source:24, target:23, value:2},
204    {source:24, target:11, value:7},
205    {source:25, target:24, value:13},
206    {source:25, target:23, value:1},
207    {source:25, target:11, value:12},
208    {source:26, target:24, value:4},
209    {source:26, target:11, value:31},
210    {source:26, target:16, value:1},
211    {source:26, target:25, value:1},
212    {source:27, target:11, value:17},
213    {source:27, target:23, value:5},
214    {source:27, target:25, value:5},
215    {source:27, target:24, value:1},
216    {source:27, target:26, value:1},
217    {source:28, target:11, value:8},
218    {source:28, target:27, value:1},
219    {source:29, target:23, value:1},
220    {source:29, target:27, value:1},
221    {source:29, target:11, value:2},
222    {source:30, target:23, value:1},
223    {source:31, target:30, value:2},
224    {source:31, target:11, value:3},
225    {source:31, target:23, value:2},
226    {source:31, target:27, value:1},
227    {source:32, target:11, value:1},
228    {source:33, target:11, value:2},
229    {source:33, target:27, value:1},
230    {source:34, target:11, value:3},
231    {source:34, target:29, value:2},
232    {source:35, target:11, value:3},
233    {source:35, target:34, value:3},
234    {source:35, target:29, value:2},
235    {source:36, target:34, value:2},
236    {source:36, target:35, value:2},
237    {source:36, target:11, value:2},
238    {source:36, target:29, value:1},
239    {source:37, target:34, value:2},
240    {source:37, target:35, value:2},
241    {source:37, target:36, value:2},
242    {source:37, target:11, value:2},
243    {source:37, target:29, value:1},
244    {source:38, target:34, value:2},
245    {source:38, target:35, value:2},
246    {source:38, target:36, value:2},
247    {source:38, target:37, value:2},
248    {source:38, target:11, value:2},
249    {source:38, target:29, value:1},
250    {source:39, target:25, value:1},
251    {source:40, target:25, value:1},
252    {source:41, target:24, value:2},
253    {source:41, target:25, value:3},
254    {source:42, target:41, value:2},
255    {source:42, target:25, value:2},
256    {source:42, target:24, value:1},
257    {source:43, target:11, value:3},
258    {source:43, target:26, value:1},
259    {source:43, target:27, value:1},
260    {source:44, target:28, value:3},
261    {source:44, target:11, value:1},
262    {source:45, target:28, value:2},
263    {source:47, target:46, value:1},
264    {source:48, target:47, value:2},
265    {source:48, target:25, value:1},
266    {source:48, target:27, value:1},
267    {source:48, target:11, value:1},
268    {source:49, target:26, value:3},
269    {source:49, target:11, value:2},
270    {source:50, target:49, value:1},
271    {source:50, target:24, value:1},
272    {source:51, target:49, value:9},
273    {source:51, target:26, value:2},
274    {source:51, target:11, value:2},
275    {source:52, target:51, value:1},
276    {source:52, target:39, value:1},
277    {source:53, target:51, value:1},
278    {source:54, target:51, value:2},
279    {source:54, target:49, value:1},
280    {source:54, target:26, value:1},
281    {source:55, target:51, value:6},
282    {source:55, target:49, value:12},
283    {source:55, target:39, value:1},
284    {source:55, target:54, value:1},
285    {source:55, target:26, value:21},
286    {source:55, target:11, value:19},
287    {source:55, target:16, value:1},
288    {source:55, target:25, value:2},
289    {source:55, target:41, value:5},
290    {source:55, target:48, value:4},
291    {source:56, target:49, value:1},
292    {source:56, target:55, value:1},
293    {source:57, target:55, value:1},
294    {source:57, target:41, value:1},
295    {source:57, target:48, value:1},
296    {source:58, target:55, value:7},
297    {source:58, target:48, value:7},
298    {source:58, target:27, value:6},
299    {source:58, target:57, value:1},
300    {source:58, target:11, value:4},
301    {source:59, target:58, value:15},
302    {source:59, target:55, value:5},
303    {source:59, target:48, value:6},
304    {source:59, target:57, value:2},
305    {source:60, target:48, value:1},
306    {source:60, target:58, value:4},
307    {source:60, target:59, value:2},
308    {source:61, target:48, value:2},
309    {source:61, target:58, value:6},
310    {source:61, target:60, value:2},
311    {source:61, target:59, value:5},
312    {source:61, target:57, value:1},
313    {source:61, target:55, value:1},
314    {source:62, target:55, value:9},
315    {source:62, target:58, value:17},
316    {source:62, target:59, value:13},
317    {source:62, target:48, value:7},
318    {source:62, target:57, value:2},
319    {source:62, target:41, value:1},
320    {source:62, target:61, value:6},
321    {source:62, target:60, value:3},
322    {source:63, target:59, value:5},
323    {source:63, target:48, value:5},
324    {source:63, target:62, value:6},
325    {source:63, target:57, value:2},
326    {source:63, target:58, value:4},
327    {source:63, target:61, value:3},
328    {source:63, target:60, value:2},
329    {source:63, target:55, value:1},
330    {source:64, target:55, value:5},
331    {source:64, target:62, value:12},
332    {source:64, target:48, value:5},
333    {source:64, target:63, value:4},
334    {source:64, target:58, value:10},
335    {source:64, target:61, value:6},
336    {source:64, target:60, value:2},
337    {source:64, target:59, value:9},
338    {source:64, target:57, value:1},
339    {source:64, target:11, value:1},
340    {source:65, target:63, value:5},
341    {source:65, target:64, value:7},
342    {source:65, target:48, value:3},
343    {source:65, target:62, value:5},
344    {source:65, target:58, value:5},
345    {source:65, target:61, value:5},
346    {source:65, target:60, value:2},
347    {source:65, target:59, value:5},
348    {source:65, target:57, value:1},
349    {source:65, target:55, value:2},
350    {source:66, target:64, value:3},
351    {source:66, target:58, value:3},
352    {source:66, target:59, value:1},
353    {source:66, target:62, value:2},
354    {source:66, target:65, value:2},
355    {source:66, target:48, value:1},
356    {source:66, target:63, value:1},
357    {source:66, target:61, value:1},
358    {source:66, target:60, value:1},
359    {source:67, target:57, value:3},
360    {source:68, target:25, value:5},
361    {source:68, target:11, value:1},
362    {source:68, target:24, value:1},
363    {source:68, target:27, value:1},
364    {source:68, target:48, value:1},
365    {source:68, target:41, value:1},
366    {source:69, target:25, value:6},
367    {source:69, target:68, value:6},
368    {source:69, target:11, value:1},
369    {source:69, target:24, value:1},
370    {source:69, target:27, value:2},
371    {source:69, target:48, value:1},
372    {source:69, target:41, value:1},
373    {source:70, target:25, value:4},
374    {source:70, target:69, value:4},
375    {source:70, target:68, value:4},
376    {source:70, target:11, value:1},
377    {source:70, target:24, value:1},
378    {source:70, target:27, value:1},
379    {source:70, target:41, value:1},
380    {source:70, target:58, value:1},
381    {source:71, target:27, value:1},
382    {source:71, target:69, value:2},
383    {source:71, target:68, value:2},
384    {source:71, target:70, value:2},
385    {source:71, target:11, value:1},
386    {source:71, target:48, value:1},
387    {source:71, target:41, value:1},
388    {source:71, target:25, value:1},
389    {source:72, target:26, value:2},
390    {source:72, target:27, value:1},
391    {source:72, target:11, value:1},
392    {source:73, target:48, value:2},
393    {source:74, target:48, value:2},
394    {source:74, target:73, value:3},
395    {source:75, target:69, value:3},
396    {source:75, target:68, value:3},
397    {source:75, target:25, value:3},
398    {source:75, target:48, value:1},
399    {source:75, target:41, value:1},
400    {source:75, target:70, value:1},
401    {source:75, target:71, value:1},
402    {source:76, target:64, value:1},
403    {source:76, target:65, value:1},
404    {source:76, target:66, value:1},
405    {source:76, target:63, value:1},
406    {source:76, target:62, value:1},
407    {source:76, target:48, value:1},
408    {source:76, target:58, value:1}
409  ]
410};
411
412var arrayNodes = new Array();
413var jsonNodes = [];
414var jsonLinks = [];
415var max = 25;
416
417function getThings(response, group) {
418  var array = new Array();
419  var count = 1;
420  // Loop through the items
421  for(var i=0, l=response.data.length; i < l;   i)
422  {
423    if ( count == max)
424      break;
425    
426    for(var e=0, el=response.data[i].entities.length; e < el; e) {
427      if (existsInArray(array, response.data[i].entities[e].disambiguous_name.toLowerCase()) == false ) {
428        var thing = response.data[i].entities[e].type.toLowerCase();
429        if ( thing == "facility" || thing == "organization" || thing == "printmedia" || thing == "technology" || thing == "company" ) {
430          count++;
431          array.push(response.data[i].entities[e].disambiguous_name.toLowerCase());
432        }
433      }
434      e++;
435    }
436   
437    i++;
438  }  
439    array.sort();
440    toNodes(array, group);   
441}
442
443
444function getPlaces(response, group) {
445  var array = new Array();
446  var count = 1;
447  // Loop through the items
448  for(var i=0, l=response.data.length; i < l;   i)
449  {
450    if ( count >= max)
451      break;
452    
453    for(var e=0, el=response.data[i].entities.length; e < el; e) {
454      if ( count >= max)
455        break;
456    
457      if (existsInArray(array, response.data[i].entities[e].disambiguous_name.toLowerCase()) == false ) {
458        var place = response.data[i].entities[e].type.toLowerCase();
459        if ( place == "city" || place == "continent" || place == "country" || place == "stateorcountry" ) {
460          count++;
461          array.push(response.data[i].entities[e].disambiguous_name.toLowerCase());
462        }
463      }
464      e++;
465    }
466   
467    for(var e=0, el=response.data[i].events.length; e < el; e) {
468      
469      if ( count >= max)
470        break;
471    
472      if (response.data[i].events[e].entity1 != null && response.data[i].events[e].entity1_index !=null) {
473        if (existsInArray(array, response.data[i].events[e].entity1.toLowerCase()) == false ) {
474          var place = response.data[i].events[e].entity1_index.toLowerCase();
475          if (place.indexOf("country") > 0 || place.indexOf("city") > 0 || place.indexOf("continent") > 0) {
476            count++;
477            array.push(response.data[i].events[e].entity1.toLowerCase());
478          }
479        }
480      }
481      e++;
482    }
483    
484    
485    for(var e=0, el=response.data[i].events.length; e < el; e) {
486      
487      if ( count >= max)
488        break;
489      
490      if (response.data[i].events[e].entity2 != null && response.data[i].events[e].entity2_index !=null) {
491        if (existsInArray(array, response.data[i].events[e].entity2.toLowerCase()) == false )
492          var place = response.data[i].events[e].entity2_index.toLowerCase();
493          if (place.indexOf("country") > 0 || place.indexOf("city") > 0 || place.indexOf("continent") > 0) {
494            count++;
495            array.push(response.data[i].events[e].entity2.toLowerCase());
496        }
497      }
498      e++;
499    }
500    
501  
502    i++;
503  }  
504    array.sort();
505    toNodes(array, group);
506    
507}
508
509function getLocation(value) {
510  var location = -1;
511  for(var i=0, l=arrayNodes.length; i < l;   i) {
512    if (value.toLowerCase() == arrayNodes[i].toLowerCase()) {
513      return i;
514    }
515    i++;
516  }
517  return location;
518}
519function existsInJsonNodes(source, target) {
520  var exists = false;
521  for(var i=0, l=jsonNodes.length; i < l; i) {
522    if (jsonNodes[i].source == source && jsonNodes[i].target == target) { 
523      return true;
524    }
525    i++;
526  }
527  return exists;
528  
529}
530// SOMETHING FUNKY GOING HERE
531function existsInJsonLinks(sourceLocation, targetLocation) {
532  var exists = false;
533  if ( jsonLinks.length > 0 ) {
534    for(var i=0, l=jsonLinks.length; i < l; i) {
535      
536      if (jsonLinks[i].source == sourceLocation && jsonLinks[i].target == targetLocation) {
537        if (jsonLinks[i].value <= 50 ) {
538          jsonLinks[i].value = jsonLinks[i].value + 1;
539        }
540        return true;
541      }
542      /*else {
543        jsonLinks.push({source: sourceLocation, target: targetLocation, value: 1});
544      }*/
545      i++;
546    }
547    jsonLinks.push({source: sourceLocation, target: targetLocation, value: 1});
548  } else {
549    jsonLinks.push({source: sourceLocation, target: targetLocation, value: 1});
550  }
551
552  return exists;
553  
554}
555
556function getMediaLinks(response) {
557  var sourceLocation = 10;
558  var targetLocation = 10;
559  
560  for(var i=0, l=response.data.length; i < l;   i)
561    {
562      var mediaType = response.data[i].mediaType.toLowerCase();
563      sourceLocation = getLocation(mediaType);
564      
565      for(var e=0, el=response.data[i].entities.length; e < el; e) {
566        targetLocation = getLocation(response.data[i].entities[e].disambiguous_name.toLowerCase());
567        if (sourceLocation > 0 && targetLocation > 0) {
568          existsInJsonLinks(sourceLocation, targetLocation);
569        }
570        e++;
571      }
572      
573      
574      for(var e=0, el=response.data[i].events.length; e < el; e) {
575        targetLocation = getLocation(response.data[i].events[e].verb_category.toLowerCase());
576        if (sourceLocation > 0 && targetLocation > 0) {
577          existsInJsonLinks(sourceLocation, targetLocation);
578        }
579        e++;
580      }
581      
582      i++;
583    }
584}
585
586function whenEventOccured(publishedDate) {
587  var today = new Date()
588  
589  if (today.getFullYear() == publishedDate.getFullYear()) {
590    if ((today.getDay() == publishedDate.getDay()) && ( today.getMonth() == publishedDate.getMonth())) {
591      return "In the last day";
592    } else if ((today.getDay != publishedDate.getDay()) && (today.getMonth() == publishedDate.getMonth())) {
593      if (today.getDay() - publishedDate.getDay() <= 7 ) {
594        return "In the last week";
595      } else {
596        return "In the last month";
597      }
598    } else {
599      if ((today.getMonth() >=1) && (today.getMonth() <=3 ) && ((publishedDate.getMonth() >=1) && (publishedDate.getMonth() <=3))) {
600        return "In the last quarter";
601      } else if ((today.getMonth() >=4) && (today.getMonth() <=6) && ((publishedDate.getMonth() >=4) && (publishedDate.getMonth() <=6))) {
602        return "In the last quarter";
603      } else if ((today.getMonth() >=7) && (today.getMonth() <=9) && ((publishedDate.getMonth() >=7) && (publishedDate.getMonth() <=9))) {
604        return "In the last quarter";
605      } else if ((today.getMonth() >=10) && (today.getMonth() <=12) && ((publishedDate.getMonth() >=10) && (publishedDate.getMonth() <=12))) {
606        return "In the last quarter";
607      } else {
608        return "In the last year";
609      }
610    }
611    
612  } else if (today.getFullYear() - publishedDate.getFullYear() <= 10 ) {
613    return "In the last decade";
614  }
615}
616
617function getTimeLinks(response) {
618  var sourceLocation;
619  var targetLocation;
620  
621  for(var i=0, l=response.data.length; i < l;   i)
622      {
623        var publishedDate = new Date(response.data[i].publishedDate);
624        var when = whenEventOccured(publishedDate);
625        sourceLocation = getLocation(when);
626        for(var e=0, el=response.data[i].events.length; e < el; e) {
627          if (response.data[i].events[e].entity1 != null && response.data[i].events[e].entity1_index !=null) {
628              if (response.data[i].events[e].entity1_index.toLowerCase().indexOf("person") > 0) {
629                targetLocation = getLocation(response.data[i].events[e].entity1.toLowerCase());
630                              
631                if (sourceLocation > 0 && targetLocation > 0 ) {
632                  existsInJsonLinks(sourceLocation, targetLocation)
633                }
634              }
635          }
636          e++;
637        }
638      i++;  
639      }  
640}
641
642function getPeopleLinks(response) {
643  var sourceLocation;
644  var targetLocation;
645    
646  for(var i=0, l=response.data.length; i < l;   i)
647    {
648    for(var e=0, el=response.data[i].events.length; e < el; e) {
649        if (response.data[i].events[e].entity1 != null && response.data[i].events[e].entity1_index !=null) {
650            if (response.data[i].events[e].entity1_index.toLowerCase().indexOf("person") > 0) {
651              sourceLocation = getLocation(response.data[i].events[e].entity1.toLowerCase());
652              targetLocation = getLocation(response.data[i].events[e].verb_category.toLowerCase());
653                            
654              if (sourceLocation > 0 && targetLocation > 0 ) {
655                existsInJsonLinks(sourceLocation, targetLocation)
656              }
657            }
658        }
659        e++;
660    }
661    i++;
662  }
663  
664  for(var i=0, l=response.data.length; i < l;   i)
665    {
666    for(var e=0, el=response.data[i].events.length; e < el; e) {
667        if (response.data[i].events[e].entity1 != null && response.data[i].events[e].entity1_index !=null && response.data[i].events[e].entity2 !=null) {
668            if (response.data[i].events[e].entity1_index.toLowerCase().indexOf("person") > 0) {
669              sourceLocation = getLocation(response.data[i].events[e].entity1.toLowerCase());
670              targetLocation = getLocation(response.data[i].events[e].entity2.toLowerCase());
671                            
672              if (sourceLocation > 0 && targetLocation > 0 ) {
673                existsInJsonLinks(sourceLocation, targetLocation)
674              }
675            }
676        }
677        e++;
678    }
679    i++;
680  }
681}
682
683function getEventLinks(response) {
684  var sourceLocation;
685  var targetLocation;
686    
687  for(var i=0, l=response.data.length; i < l;   i)
688    {
689      for(var e=0, el=response.data[i].events.length; e < el; e) {
690        if (response.data[i].events[e].entity1 != null && response.data[i].events[e].entity1_index !=null && response.data[i].events[e].entity2 !=null) {
691            if (response.data[i].events[e].entity1_index.toLowerCase().indexOf("person") > 0) {
692              sourceLocation = getLocation(response.data[i].events[e].verb_category.toLowerCase());
693              targetLocation = getLocation(response.data[i].events[e].entity2.toLowerCase());
694                            
695              if (sourceLocation > 0 && targetLocation > 0 ) {
696                existsInJsonLinks(sourceLocation, targetLocation)
697              }
698            }
699        }
700        e++;
701    }
702      i++;
703    }
704}
705
706function getPeople(response, group) {
707  var array = new Array();
708  var count = 0;
709  // Loop through the items
710  for(var i=0, l=response.data.length; i < l;   i)
711  {
712    
713    if ( count >= max )
714      break;
715    
716    for(var e=0, el=response.data[i].entities.length; e < el; e) {
717      if ( count >= max)
718        break;
719      
720      if (existsInArray(array, response.data[i].entities[e].disambiguous_name.toLowerCase()) == false ) {
721        if (response.data[i].entities[e].type.toLowerCase() == "person" ) {
722          count++;
723          array.push(response.data[i].entities[e].disambiguous_name.toLowerCase());
724        }
725      }
726      e++;
727    }
728   
729    for(var e=0, el=response.data[i].events.length; e < el; e) {
730      if ( count >= max)
731        break;
732      
733      if (response.data[i].events[e].entity1 != null && response.data[i].events[e].entity1_index !=null) {
734        if (existsInArray(array, response.data[i].events[e].entity1.toLowerCase()) == false ) {
735          if (response.data[i].events[e].entity1_index.toLowerCase().indexOf("person") > 0) {
736            count++;
737            array.push(response.data[i].events[e].entity1.toLowerCase());
738          }
739        }
740      }
741      e++;
742    }
743    
744    
745    for(var e=0, el=response.data[i].events.length; e < el; e) {
746      if ( count >= max)
747        break;
748      
749      if (response.data[i].events[e].entity2 != null && response.data[i].events[e].entity2_index !=null) {
750        if (existsInArray(array, response.data[i].events[e].entity2.toLowerCase()) == false )
751          if (response.data[i].events[e].entity2_index.toLowerCase().indexOf("person") > 0){
752          count++;
753          array.push(response.data[i].events[e].entity2.toLowerCase());
754        }
755      }
756      e++;
757    }
758    
759  
760    i++;
761  }  
762    array.sort();
763    toNodes(array, group);
764    return array;
765}
766/*
767function getEntities(response, group, list, includeOrIngore) {
768  var array = new Array();
769  // Loop through the items
770  for(var i=0, l=response.data.length; i < l;   i)
771  {
772    
773    for(var e=0, el=response.data[i].entities.length; e < el; e) {
774      if (existsInArray(array, response.data[i].entities[e].disambiguous_name.toLowerCase()) == false ) {
775        if (list == null ) {
776          array.push(response.data[i].entities[e].disambiguous_name.toLowerCase());
777        }
778        else {
779          if (list != null && includeOrIgnore == true) {
780            if (existsInArray(list, response.data[i].entities[e].type.toLowerCase()) {
781              array.push(response.data[i].entities[e].disambiguous_name.toLowerCase());
782            }
783          }
784        }
785      }
786    
787      e++;
788    }
789    
790    for(var e=0, el=response.data[i].events.length; e < el; e) {
791      
792      if (response.data[i].events[e].entity1 != null) {
793        
794        if (existsInArray(array, response.data[i].events[e].entity1.toLowerCase()) == false ) {
795          if (list == null) {
796            array.push(response.data[i].events[e].entity1.toLowerCase());
797          }
798          else {
799            if (list != null && includeOrIgnore == true) {
800              if (existsInArray(list, response.data[i].events[e].entity1.toLowerCase())) {
801                array.push(response.data[i].events[e].entity1.toLowerCase());
802              }
803            }
804          }
805        }
806        
807      }
808      e++;
809    }
810    
811    for(var e=0, el=response.data[i].events.length; e < el; e) {
812      if (response.data[i].events[e].entity2 != null) {
813        
814        if (existsInArray(array, response.data[i].events[e].entity2.toLowerCase()) == false )
815          array.push(response.data[i].events[e].entity2.toLowerCase());
816          
817      }
818      e++;
819    }
820             
821    i++;
822  }
823  array.sort();
824  toNodes(array, group); 
825}
826*/
827
828function getEvents(response, group) {
829  // build up array
830  var array = new Array();
831  var count = 1;
832  // Loop through the items
833  for(var i=0, l=response.data.length; i < l;   i)
834  {
835    if ( count >= max)
836      break;
837    
838    for(var e=0, el=response.data[i].events.length; e < el; e) {
839   
840      if (existsInArray(array, response.data[i].events[e].verb_category.toLowerCase()) == false ) {
841        count++;
842        array.push(response.data[i].events[e].verb_category.toLowerCase());
843      }
844      e++;
845    }
846                
847    i++;
848  }
849  array.sort();
850  toNodes(array, group); 
851}
852
853function getVerbs(response, group) {
854  // build up array
855  var array = new Array();
856  // Loop through the items
857  for(var i=0, l=response.data.length; i < l;   i)
858  {
859    
860    for(var e=0, el=response.data[i].events.length; e < el; e) {
861   
862      if (response.data[i].events[e].verb != null) {
863        if (existsInArray(array, response.data[i].events[e].verb.toLowerCase()) == false )
864          array.push(response.data[i].events[e].verb.toLowerCase());
865      }
866      e++;
867    }
868                
869    i++;
870  }
871  array.sort();
872  toNodes(array, group); 
873}
874
875function getTime(group) {
876  var array = new Array();
877  
878  array.push("In the last day");
879  array.push("In the last week");
880  array.push("In the last month");
881  array.push("In the last quarter");
882  array.push("In the last year");
883  array.push("In the last decade");
884  
885  toNodes(array,group);
886  
887}
888
889function getSourceMetaTypes(response, group) {
890  var array = new Array();
891  // Loop through the items
892  for(var i=0, l=response.data.length; i < l;   i)
893  {
894      if (existsInArray(array, response.data[i].mediaType.toLowerCase()) == false )
895        array.push(response.data[i].mediaType.toLowerCase());
896      
897      i++;
898  }
899
900  array.sort();
901  toNodes(array, group); 
902}
903
904function getNodes(response) {
905  
906  //getVerbs(response, 3);
907  
908  getPlaces(response, 1);
909  getThings(response, 2);
910  getEvents(response, 3);
911  getSourceMetaTypes(response, 4);
912  getPeople(response, 5);
913  getTime(6);
914  
915
916  console.log(jsonNodes);
917  return jsonNodes;
918}
919
920function getLinks(response) {
921  getTimeLinks(response);
922  getPeopleLinks(response);
923  getEventLinks(response);
924  getMediaLinks(response);
925  console.log(jsonLinks);
926  return jsonLinks;
927}
928
929function toNodes(array, group) {
930  for (var i=0, l=array.length; i < l; i) {
931   arrayNodes.push(array[i].toLowerCase());
932   jsonNodes.push({nodeName: array[i].toLowerCase(), group: group});
933   i++ 
934  }
935}
936
937function existsInArray(array, value) {
938  var exists = false;
939  for (var i=0, l=array.length; i < l; i) {
940    if (array[i].toLowerCase() == value.toLowerCase())
941      exists = true; 
942    i++;
943  }
944  return exists;
945}
946
947
948/*
949function getSourceMetaTypesLinks(response, nodes) {
950  // build up the json
951  var map = new Map;
952  // Loop through the metatypes
953  for(var i=0, l=response.data.length; i < l;   i)
954  {
955      var mediaType = response.data[i].mediaType.toLowerCase();
956      var source = getTarget(response, mediaType);
957      
958      map.put(response.sourceMetaTypes[i].term.toLowerCase() , group);
959
960      // Process each image
961      console.log(response.sourceMetaTypes[i].term.toLowerCase()  + " " + response.sourceMetaTypes[i].count );
962      
963      i++;
964  }
965}
966
967function getTarget(nodes, value) {
968  for(var i=0, l=nodes.length; i < l;   i) {
969    if ( nodes[i].nodeName.toLowerCase() == value.toLowerCase() ) {
970      return i;
971    }
972    i++;
973  }
974}
975*/
976
977
978