people.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. // Raccatto i parametri dall'URL -- mi aspetto un parametro di nome 'link'!
  2. thisUrlParams = {};
  3. window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
  4. thisUrlParams[key] = value;
  5. });
  6. console.log('URL get params: ', thisUrlParams);
  7. // Funzioni per eseguire le queries
  8. function prepareQueryURL(query){
  9. sparqlEndpoint = 'http://dev.restore.ovi.cnr.it:8890/sparql/';
  10. sparqlUrlParams = '?default-graph-uri=&query=' + encodeURIComponent(query) + '&output=json&callback=?';
  11. return sparqlEndpoint + sparqlUrlParams;
  12. }
  13. function doJsonQuery(query){
  14. queryURL = prepareQueryURL(query);
  15. response = $.ajax({//OGGETTO
  16. url: queryURL,
  17. dataType: "json",
  18. success: function (data){},
  19. error: function (e) {}
  20. });
  21. return response;
  22. }
  23. // Funzioni per raccattare + stringhificare l'output
  24. queryStringOutput = "";
  25. function stringifyResponse(val){
  26. resultArray = val['results']['bindings'];
  27. out = "";
  28. for(i = 0; i < resultArray.length; i++){
  29. out = out + JSON.stringify(resultArray[i])
  30. }
  31. queryStringOutput = (queryStringOutput + out).replace("}{",",");
  32. }
  33. prefixes = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \
  34. PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \
  35. PREFIX crm: <http://www.cidoc-crm.org/cidoc-crm/> \
  36. PREFIX owl: <http://www.w3.org/2002/07/owl#> \
  37. PREFIX schema: <http://schema.org/> \
  38. PREFIX foaf: <http://xmlns.com/foaf/0.1/> \
  39. PREFIX person: <http://www.w3.org/ns/person#>"
  40. query = prefixes + " SELECT DISTINCT ?place ?label ?coordinates \
  41. WHERE { \
  42. {?pc crm:P02_has_range <" + thisUrlParams.link + "> . \
  43. ?event_from crm:P01_has_domain ?pc ; \
  44. rdf:type crm:EL3_Receive_Letter; \
  45. crm:P26_moved_to ?place_from . \
  46. ?place_from rdf:type crm:E53_Place ; \
  47. owl:sameAs ?place . \
  48. ?place rdfs:label ?label ; \
  49. crm:P168_place_is_defined_by ?coordinates . \
  50. } UNION { \
  51. ?pc crm:P02_has_range <" + thisUrlParams.link + "> . \
  52. ?event_from crm:P01_has_domain ?pc ; \
  53. rdf:type crm:EL2_Send_Letter; \
  54. crm:P27_moved_from ?place_from . \
  55. ?place_from rdf:type crm:E53_Place ; \
  56. owl:sameAs ?place . \
  57. ?place rdfs:label ?label ; \
  58. crm:P168_place_is_defined_by ?coordinates . \
  59. } \
  60. }"
  61. queryInfo = prefixes + " SELECT DISTINCT ?graph ?label ?identifier ?name ?givenName ?familyName ?gender ?Birth_Date ?Birth_Place ?Death_Date ?Death_Place ?patronymic ?occupation (group_concat(distinct ?relative1 ;separator=', ') as ?relatives) ?qualification ?group \
  62. WHERE { \
  63. VALUES ?uri {<" + thisUrlParams.link + ">} \
  64. GRAPH ?graph {?uri rdfs:label ?label} \
  65. ?uri foaf:name ?name . \
  66. OPTIONAL {?uri crm:P1_is_identified_by ?id . \
  67. ?id rdfs:label ?identifier } \
  68. OPTIONAL {?uri foaf:givenName ?givenName} \
  69. OPTIONAL {?uri foaf:familyName ?familyName} \
  70. OPTIONAL {?uri foaf:gender ?gender} \
  71. OPTIONAL {?uri person:patronymicName ?patronymic } \
  72. OPTIONAL {?uri schema:hasOccupation ?uriOccupation . \
  73. ?uriOccupation rdf:type schema:Occupation; \
  74. rdfs:label ?occupation } \
  75. OPTIONAL {?uri schema:honorificPrefix ?qualification} \
  76. OPTIONAL {?uri schema:relatedTo ?uriRel1 . \
  77. ?uriRel1 rdfs:label ?relative1} \
  78. OPTIONAL {?uri crm:P100i_died_in ?Death . \
  79. ?Death crm:P4_has_time-span ?Death_TS; \
  80. crm:P7_took_place_at ?Place_D .\
  81. ?Death_TS rdfs:label ?Death_Date . \
  82. ?Place_D rdfs:label ?Death_Place } \
  83. OPTIONAL {?uri crm:P98i_was_born ?Birth . \
  84. ?Birth crm:P4_has_time-span ?Birth_TS; \
  85. crm:P7_took_place_at ?Place_B . \
  86. ?Birth_TS rdfs:label ?Birth_Date . \
  87. ?Place_B rdfs:label ?Birth_Place } \
  88. OPTIONAL {?uri crm:P107i_is_current_or_former_member_of ?uriGroup . \
  89. ?uriGroup rdfs:label ?group } \
  90. } \
  91. GROUP BY ?graph ?label ?identifier ?name ?givenName ?familyName ?gender ?Birth_Date ?Birth_Place ?Death_Date ?Death_Place ?patronymic ?occupation ?qualification ?group "
  92. queryLetters = prefixes + " SELECT DISTINCT ?type ?document_uri ?document_name \
  93. WHERE {?pc crm:P02_has_range <" + thisUrlParams.link + "> . \
  94. ?ev_send crm:P01_has_domain ?pc ; \
  95. rdfs:label ?type ; \
  96. rdfs:subClassOf ?event . \
  97. ?document_uri crm:P25i_moved_by ?event ; \
  98. rdfs:label ?document_name . \
  99. }"
  100. queryNetwork = prefixes + " SELECT DISTINCT COUNT(?event) AS ?count ?uri2 SAMPLE(?label2) AS ?text \
  101. WHERE { \
  102. {?event rdf:type crm:EL1_Exchange_Letters . \
  103. ?event_to rdfs:subClassOf ?event; \
  104. rdf:type crm:EL2_Send_Letter ; \
  105. crm:P01_has_domain ?pc_to . \
  106. ?pc_to crm:P02_has_range ?uri . \
  107. ?uri rdfs:label ?label . \
  108. ?event_from rdfs:subClassOf ?event; \
  109. rdf:type crm:EL3_Receive_Letter; \
  110. crm:P01_has_domain ?pc_from . \
  111. ?pc_from crm:P02_has_range ?uri2 . \
  112. ?uri2 rdfs:label ?label2 . \
  113. FILTER (?uri = <" + thisUrlParams.link + ">) \
  114. } UNION { \
  115. ?event rdf:type crm:EL1_Exchange_Letters . \
  116. ?event_to rdfs:subClassOf ?event; \
  117. rdf:type crm:EL3_Receive_Letter ; \
  118. crm:P01_has_domain ?pc_from . \
  119. ?pc_from crm:P02_has_range ?uri . \
  120. ?uri rdfs:label ?label . \
  121. ?event_from rdfs:subClassOf ?event; \
  122. rdf:type crm:EL2_Send_Letter; \
  123. crm:P01_has_domain ?pc_to . \
  124. ?pc_to crm:P02_has_range ?uri2 . \
  125. ?uri2 rdfs:label ?label2 . \
  126. FILTER (?uri = <" + thisUrlParams.link + ">) \
  127. } \
  128. } ORDER BY DESC (?count)"
  129. queryURL = prepareQueryURL(query);
  130. queryNet = prepareQueryURL(queryNetwork);
  131. query = prepareQueryURL(queryInfo);
  132. queryEx = prepareQueryURL(queryLetters);
  133. response = $.ajax({
  134. url: query,
  135. dataType: "json",
  136. success: function (data){
  137. handle_data(data);
  138. },
  139. error: function (e) {}
  140. });
  141. response = $.ajax({
  142. url: queryURL,
  143. dataType: "json",
  144. success: function (data){
  145. handle_map(data);
  146. },
  147. error: function (e) {}
  148. });
  149. responseNet = $.ajax({
  150. url: queryNet,
  151. dataType: "json",
  152. success: function (data){
  153. handle_network(data);
  154. },
  155. error: function (e) {}
  156. });
  157. responseLet = $.ajax({
  158. url: queryEx,
  159. dataType: "json",
  160. success: function (data){
  161. handle_Letters(data);
  162. },
  163. error: function (e) {}
  164. });
  165. function handle_data(json) {
  166. console.log(json['results']['bindings']);
  167. var graph = "";
  168. var label = "";
  169. if ("givenName" in json.results.bindings) {
  170. givenName = value['givenName']['value'];
  171. alert(givenName);
  172. }
  173. $.each(
  174. json['results']['bindings'],
  175. function (index, value) {
  176. var graph = value['graph']['value'];
  177. var label = value['label']['value'];
  178. var name = value['name']['value'];
  179. var givenName = "";
  180. var familyName = "";
  181. var gender = "";
  182. var patronymic = "";
  183. var occupation = "";
  184. var relative = "";
  185. var identifier = "";
  186. var birth_date = "";
  187. var birth_place = "";
  188. var death_date = "";
  189. var death_place = "";
  190. var qualification = "";
  191. var group = "";
  192. if (value.hasOwnProperty('givenName')) {
  193. $("#givenName").css("display", "flex");
  194. givenName = value['givenName']['value'];
  195. }
  196. if (value.hasOwnProperty('familyName')) {
  197. $("#familyName").css("display", "flex");
  198. familyName = value['familyName']['value'];
  199. }
  200. if (value.hasOwnProperty('gender')) {
  201. $("#gender").css("display", "flex");
  202. gender = value['gender']['value'];
  203. }
  204. if (value.hasOwnProperty('patronymic')) {
  205. $("#patronymic").css("display", "flex");
  206. patronymic = value['patronymic']['value'];
  207. }
  208. if (value.hasOwnProperty('occupation')) {
  209. $("#occupation").css("display", "flex");
  210. occupation = value['occupation']['value'];
  211. }
  212. if (value.hasOwnProperty('relatives')) {
  213. if (value['relatives']['value'] != "") {
  214. $("#relatives").css("display", "flex");
  215. relative = value['relatives']['value'];
  216. }
  217. }
  218. if (value.hasOwnProperty('qualification')) {
  219. $("#honorific").css("display", "flex");
  220. qualification = value['qualification']['value'];
  221. }
  222. if (value.hasOwnProperty('Birth_Date')) {
  223. $("#BirthDate").css("display", "flex");
  224. birth_date = value['Birth_Date']['value'];
  225. }
  226. if (value.hasOwnProperty('Birth_Place')) {
  227. $("#BirthPlace").css("display", "flex");
  228. birth_place = value['Birth_Place']['value'];
  229. }
  230. if (value.hasOwnProperty('Death_Date')) {
  231. $("#DeathDate").css("display", "flex");
  232. death_date = value['Death_Date']['value'];
  233. }
  234. if (value.hasOwnProperty('Death_Place')) {
  235. $("#DeathPlace").css("display", "flex");
  236. death_place = value['Death_Place']['value'];
  237. }
  238. if (value.hasOwnProperty('group')) {
  239. $("#groups").css("display", "flex");
  240. group = value['group']['value'];
  241. }
  242. document.getElementById("grafo").innerHTML = graph;
  243. document.getElementById("nome_persona").innerHTML = label;
  244. document.getElementById("nome").innerHTML = name;
  245. document.getElementById("genere").innerHTML = gender;
  246. document.getElementById("nome_proprio").innerHTML = givenName;
  247. document.getElementById("nome_famiglia").innerHTML = familyName;
  248. document.getElementById("patronimico").innerHTML = patronymic;
  249. document.getElementById("avi").innerHTML = relative;
  250. document.getElementById("qualifica").innerHTML = qualification;
  251. document.getElementById("occupazione").innerHTML = occupation;
  252. document.getElementById("data_nascita").innerHTML = birth_date;
  253. document.getElementById("data_morte").innerHTML = death_date;
  254. document.getElementById("luogo_nascita").innerHTML = birth_place;
  255. document.getElementById("luogo_morte").innerHTML = death_place;
  256. document.getElementById("gruppi_appartenenza").innerHTML = group;
  257. document.getElementById("nome1").innerHTML = label;
  258. document.getElementById("nome2").innerHTML = label;
  259. document.getElementById("nome_au").innerHTML = label;
  260. document.getElementById("nome_ap").innerHTML = label;
  261. document.getElementById("nome_al").innerHTML = label;
  262. });
  263. }
  264. function handle_Letters(json) {
  265. console.log(json);
  266. const send = {};
  267. const receive = {};
  268. var i=0;
  269. var j=0;
  270. $.each(
  271. json['results']['bindings'],
  272. function (index, value) {
  273. type = value['type']['value'];
  274. uri = value['document_uri']['value'];
  275. title = value['document_name']['value'];
  276. if (type == "Invio") {
  277. send[uri] = title;
  278. i++;
  279. } else {
  280. receive[uri] = title;
  281. j++;
  282. }
  283. });
  284. var Send_Letters = "";
  285. var Receive_Letters = "";
  286. for (var key in send) {
  287. Send_Letters += "<div class='row res'><div class='col-10'>" + send[key] + "</div><div class='col d-flex align-items-start justify-content-end'><a href='" + key + "'><i class='fas fa-external-link-alt' aria-hidden='true'></i></a></div></div>";
  288. }
  289. for (var key in receive) {
  290. Receive_Letters += "<div class='row'><div class='col-10'>" + receive[key] + "</div><div class='col'><a href='" + key + "'><i class='fas fa-external-link-alt' aria-hidden='true'></i></a></div></div>";
  291. }
  292. document.getElementById("l_send").innerHTML = i;
  293. document.getElementById("l_receive").innerHTML = j;
  294. document.getElementById("letters_send").innerHTML = Send_Letters;
  295. document.getElementById("letters_receive").innerHTML = Receive_Letters;
  296. if (i==0) {
  297. var messaggio = "<p>Nessun risultato trovato</p>";
  298. document.getElementById("letters_send").innerHTML = messaggio;
  299. }
  300. if (j==0) {
  301. var messaggio = "<p>Nessun risultato trovato</p>";
  302. document.getElementById("letters_receive").innerHTML = messaggio;
  303. }
  304. }
  305. function handle_map(json) {
  306. console.log(json);
  307. const locations = [];
  308. const place_names = [];
  309. var lat = 0;
  310. var long = 0;
  311. var i=0;
  312. var myPlaces = "";
  313. $.each(
  314. json['results']['bindings'],
  315. function (index, value) {
  316. const loc = []
  317. var uri = value['place']['value'];
  318. var label = value['label']['value'];
  319. var coord = value['coordinates']['value'];
  320. const coordinates = coord.split(", ");
  321. loc.push(label);
  322. myPlaces += "<div class='item-place-person'><div class='clickPlace item-place-person-label' data-point='"+ coordinates + "'>" + label + "</div><div class='item-place-person-action'><div class='luogo' id='" +
  323. uri + "'><i class='far fa-map' style='cursor:pointer'></i></div></div></div>";
  324. loc.push(coordinates[0]);
  325. lat += parseInt(coordinates[0]);
  326. loc.push(coordinates[1]);
  327. long += parseInt(coordinates[1].replace(/^(\.)/,"0.").replace("-.", "-0."));
  328. locations.push(loc);
  329. i++;
  330. });
  331. var latitude = lat/i;
  332. var longitude = long/i;
  333. document.getElementById("list_places_person").innerHTML = myPlaces;
  334. var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png',
  335. cloudmadeAttribution = 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 CloudMade, Points &copy 2012 LINZ',
  336. cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 17, attribution: cloudmadeAttribution}),
  337. latlng = new L.LatLng(latitude, longitude);
  338. var map = new L.Map('map', {center: latlng, zoom: 5, layers: [cloudmade]});
  339. mapLink = '<a href="https://openstreetmap.org">OpenStreetMap</a>';
  340. var markers = new L.MarkerClusterGroup();
  341. var markerList = [];
  342. var geo = new L.tileLayer(
  343. 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  344. attribution: '&copy; ' + mapLink + ' Contributors',
  345. maxZoom: 18,
  346. }).addTo(map);
  347. function populate() {
  348. for (var i = 0; i < locations.length; i++) {
  349. var a = locations[i];
  350. var title = a[0];
  351. var marker = new L.Marker(new L.LatLng(a[1], a[2]), { title: title });
  352. marker.bindPopup(title);
  353. markers.addLayer(marker);
  354. markerList.push(marker);
  355. }
  356. }
  357. populate();
  358. map.addLayer(markers);
  359. $('.clickPlace').on('click', function(){
  360. // parse lat and lng from the divs data attribute
  361. var latlng = $(this).data().point.split(',');
  362. var lat = latlng[0];
  363. var lng = latlng[1];
  364. var zoom = 10;
  365. // set the view
  366. map.setView([lat, lng], zoom);
  367. });
  368. }
  369. function handle_network(json) {
  370. console.log(json);
  371. const words = [];
  372. const tempArray = [];
  373. var listwords = "";
  374. var ArrayNames = "";
  375. var temp = 0;
  376. var sum = 0;
  377. var i=0;
  378. var j=0;
  379. $.each(
  380. json['results']['bindings'],
  381. function (index, value) {
  382. text = value['text']['value'];
  383. link = value['uri2']['value'];
  384. num = parseInt(value['count']['value']);
  385. /*count = 0;
  386. if ((num - temp) > 50) {
  387. count = temp + 12;
  388. } else {
  389. count = num;
  390. }
  391. words.push([text, count]);
  392. temp = count;
  393. sum += temp;*/
  394. tempArray.push([text, num]);
  395. ArrayNames += "<div class='item-place-person'><div class='item-place-person-label'>" +
  396. text + "<br /><span class='num_occ'>[Co-occorrenze: " + num + "]</span></div><div class='item-place-person-action'><div><a target='_blank' href='" +
  397. link + "'><i class='fas fa-external-link-alt' aria-hidden='true'></i></a></div><div class='persona' id='" +
  398. link + "'><i class='fa fa-user' style='cursor:pointer'></i></div></div></div></div>";
  399. });
  400. if (tempArray.length < 8) {
  401. for (var k=0; k<tempArray.length; k++) {
  402. text = tempArray[k][0];
  403. count = tempArray[k][1] + 36;
  404. words.push([text, count]);
  405. }
  406. } else {
  407. for (var k=tempArray.length-1; k>=0; k--) {
  408. text = tempArray[k][0];
  409. num = tempArray[k][1];
  410. count = 0;
  411. if ((num - temp) > 50) {
  412. count = temp + 12;
  413. } else {
  414. count = num;
  415. }
  416. words.push([text, count]);
  417. temp = count;
  418. sum += temp;
  419. }
  420. }
  421. document.getElementById("list_person_network").innerHTML = ArrayNames;
  422. /*var tot = parseInt(words[0][1]);*/
  423. for (var i in words) {
  424. var text = words[i][0]
  425. var count = words[i][1];
  426. listwords += '{ "word": \"' + text + '\", "size": \"' + count + '\"},';
  427. }
  428. let listL = ('[' + listwords + ']').replace(',]', ']');
  429. const links = JSON.parse(listL);
  430. console.log(links);
  431. // List of words
  432. var myWords = links;
  433. // set the dimensions and margins of the graph
  434. var margin = {top: 10, right: 10, bottom: 10, left: 10},
  435. width = 850 - margin.left - margin.right,
  436. height = 500 - margin.top - margin.bottom;
  437. // append the svg object to the body of the page
  438. var svg = d3.select("#myWordCloud").append("svg")
  439. .attr("width", width + margin.left + margin.right)
  440. .attr("height", height + margin.top + margin.bottom)
  441. .append("g")
  442. .attr("transform",
  443. "translate(" + (width/2-50) + "," + (height/2+20) + ")");
  444. // Constructs a new cloud layout instance. It run an algorithm to find the position of words that suits your requirements
  445. // Wordcloud features that are different from one word to the other must be here
  446. var layout = d3.layout.cloud()
  447. .size([width, height])
  448. .words(myWords.map(function(d) { return {text: d.word, size:d.size/2}; }))
  449. .padding(5) //space between words
  450. .rotate(function() { return ~~(Math.random() * 2);})
  451. .fontSize(function(d) { return d.size + 6; }) // font size of words
  452. .on("end", draw);
  453. layout.start();
  454. // This function takes the output of 'layout' above and draw the words
  455. // Wordcloud features that are THE SAME from one word to the other can be here
  456. function draw(words) {
  457. var cloud = svg.selectAll("g text")
  458. .data(words, function(d) { return d.text; })
  459. //Entering words
  460. cloud.enter()
  461. .append("text")
  462. .style("font-family", "Impact")
  463. .attr("text-anchor", "middle")
  464. .attr('font-size', 1)
  465. .text(function(d) { return d.text; });
  466. //Entering and existing words
  467. cloud
  468. .transition()
  469. .duration(600)
  470. .style("font-size", function(d) { return d.size + "px"; })
  471. .attr("transform", function(d) {
  472. return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
  473. })
  474. .style("fill-opacity", 1);
  475. //Exiting words
  476. cloud.exit()
  477. .transition()
  478. .duration(200)
  479. .style('fill-opacity', 1e-6)
  480. .attr('font-size', 1)
  481. .remove();
  482. }
  483. }
  484. $(document).on("click", ".luogo", function (ev) {
  485. var link = this.id;
  486. //alert(nome_autore);
  487. //$('#myModal').text("");
  488. window.open("Luogo.html?link="+this.id);
  489. });
  490. $(document).on("click", ".persona", function (ev) {
  491. var link = this.id;
  492. //alert(nome_autore);
  493. //$('#myModal').text("");
  494. window.open("Persona.html?link="+this.id);
  495. });