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