people.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  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 ?alias (GROUP_CONCAT(DISTINCT CONCAT(?variant, '| ', ?otherName) ; SEPARATOR = ';') AS ?variants) ?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. OPTIONAL {?uri schema:alternateName ?alias . } \
  91. OPTIONAL {?uri owl:sameAs ?variant . \
  92. ?variant foaf:name ?otherName . } \
  93. } \
  94. GROUP BY ?graph ?label ?identifier ?name ?givenName ?familyName ?alias ?gender ?Birth_Date ?Birth_Place ?Death_Date ?Death_Place ?patronymic ?occupation ?qualification ?group \
  95. LIMIT 1 "
  96. queryLetters = prefixes + " SELECT DISTINCT ?type ?segnatura ?document_uri ?document_name ?time_span ?InfObj \
  97. WHERE {?pc crm:P02_has_range <" + thisUrlParams.link + "> . \
  98. ?ev_move crm:P01_has_domain ?pc ; \
  99. rdfs:label ?type ; \
  100. rdfs:subClassOf ?event . \
  101. ?document_uri crm:P25i_moved_by ?event ; \
  102. rdfs:label ?document_name . \
  103. ?document_uri crm:P1_is_identified_by ?uriSegnatura . \
  104. ?uriSegnatura crm:P2_has_type 'Segnatura' ; \
  105. rdfs:label ?segnatura . \
  106. OPTIONAL {GRAPH <http://dev.restore.ovi.cnr.it:8890/ovi/datini> {?document_uri crm:P128_carries ?InfObj . \
  107. ?InfObj rdf:type crm:E73_Information_Object} }. \
  108. OPTIONAL {?ev_move crm:P4_has_time-span ?uri_ts . \
  109. ?uri_ts rdfs:label ?time_span . } \
  110. }"
  111. queryOpere = prefixes + " SELECT DISTINCT ?subject ?label ?nct (group_concat(distinct ?time_span ;separator='-') as ?time_span) \
  112. WHERE {?subject rdf:type crm:E22_Man-Made_Object ; \
  113. rdfs:label ?label ; \
  114. crm:P1_is_identified_by ?uri_nct . \
  115. ?uri_nct rdfs:label ?nct . \
  116. ?production crm:P108_has_produced ?subject . \
  117. OPTIONAL {?production crm:P4_has_time-span ?uri_time_span . \
  118. ?uri_time_span rdfs:label ?time_span } \
  119. ?pc crm:P01_has_domain ?production ; \
  120. crm:P02_has_range <" + thisUrlParams.link + "> } \
  121. GROUP BY ?subject ?label ?nct "
  122. queryNetwork = prefixes + " SELECT DISTINCT COUNT(?event) AS ?count ?uri2 SAMPLE(?label2) AS ?text \
  123. WHERE { \
  124. {?event rdf:type crm:EL1_Exchange_Letters . \
  125. ?event_to rdfs:subClassOf ?event; \
  126. rdf:type crm:EL2_Send_Letter ; \
  127. crm:P01_has_domain ?pc_to . \
  128. ?pc_to crm:P02_has_range ?uri . \
  129. ?uri rdfs:label ?label . \
  130. ?event_from rdfs:subClassOf ?event; \
  131. rdf:type crm:EL3_Receive_Letter; \
  132. crm:P01_has_domain ?pc_from . \
  133. ?pc_from crm:P02_has_range ?uri2 . \
  134. ?uri2 rdfs:label ?label2 . \
  135. FILTER (?uri = <" + thisUrlParams.link + ">) \
  136. } UNION { \
  137. ?event rdf:type crm:EL1_Exchange_Letters . \
  138. ?event_to rdfs:subClassOf ?event; \
  139. rdf:type crm:EL3_Receive_Letter ; \
  140. crm:P01_has_domain ?pc_from . \
  141. ?pc_from crm:P02_has_range ?uri . \
  142. ?uri rdfs:label ?label . \
  143. ?event_from rdfs:subClassOf ?event; \
  144. rdf:type crm:EL2_Send_Letter; \
  145. crm:P01_has_domain ?pc_to . \
  146. ?pc_to crm:P02_has_range ?uri2 . \
  147. ?uri2 rdfs:label ?label2 . \
  148. FILTER (?uri = <" + thisUrlParams.link + ">) \
  149. } \
  150. } ORDER BY DESC (?count)"
  151. queryURL = prepareQueryURL(query);
  152. queryNet = prepareQueryURL(queryNetwork);
  153. queryOA = prepareQueryURL(queryOpere);
  154. query = prepareQueryURL(queryInfo);
  155. queryEx = prepareQueryURL(queryLetters);
  156. response = $.ajax({
  157. url: query,
  158. dataType: "json",
  159. success: function (data){
  160. handle_data(data);
  161. },
  162. error: function (e) {}
  163. });
  164. response = $.ajax({
  165. url: queryURL,
  166. dataType: "json",
  167. success: function (data){
  168. handle_map(data);
  169. },
  170. error: function (e) {}
  171. });
  172. responseNet = $.ajax({
  173. url: queryNet,
  174. dataType: "json",
  175. success: function (data){
  176. handle_network(data);
  177. },
  178. error: function (e) {}
  179. });
  180. responseLet = $.ajax({
  181. url: queryEx,
  182. dataType: "json",
  183. success: function (data){
  184. handle_Letters(data);
  185. },
  186. error: function (e) {}
  187. });
  188. responseOA = $.ajax({
  189. url: queryOA,
  190. dataType: "json",
  191. success: function (data){
  192. handle_Artwork(data);
  193. },
  194. error: function (e) {}
  195. });
  196. function handle_data(json) {
  197. console.log(json['results']['bindings']);
  198. var graph = "";
  199. var label = "";
  200. if ("givenName" in json.results.bindings) {
  201. givenName = value['givenName']['value'];
  202. }
  203. $.each(
  204. json['results']['bindings'],
  205. function (index, value) {
  206. var graph = value['graph']['value'];
  207. var label = value['label']['value'];
  208. var name = value['name']['value'];
  209. var givenName = "";
  210. var familyName = "";
  211. var alias = "";
  212. var gender = "";
  213. var patronymic = "";
  214. var occupation = "";
  215. var relative = "";
  216. var identifier = "";
  217. var birth_date = "";
  218. var birth_place = "";
  219. var death_date = "";
  220. var death_place = "";
  221. var qualification = "";
  222. var group = "";
  223. var variants = "";
  224. if (value.hasOwnProperty('givenName')) {
  225. $("#givenName").css("display", "flex");
  226. givenName = value['givenName']['value'];
  227. }
  228. if (value.hasOwnProperty('familyName')) {
  229. $("#familyName").css("display", "flex");
  230. familyName = value['familyName']['value'].toLowerCase();
  231. familyName = familyName.charAt(0).toUpperCase() + familyName.slice(1)
  232. }
  233. if (value.hasOwnProperty('alias')) {
  234. $("#aliasName").css("display", "flex");
  235. alias = value['alias']['value'];
  236. }
  237. if (value.hasOwnProperty('gender')) {
  238. $("#gender").css("display", "flex");
  239. gender = value['gender']['value'];
  240. }
  241. if (value.hasOwnProperty('patronymic')) {
  242. $("#patronymic").css("display", "flex");
  243. patronymic = value['patronymic']['value'];
  244. }
  245. if (value.hasOwnProperty('occupation')) {
  246. $("#occupation").css("display", "flex");
  247. occupation = value['occupation']['value'];
  248. }
  249. if (value.hasOwnProperty('relatives')) {
  250. if (value['relatives']['value'] != "") {
  251. relative = value['relatives']['value'];
  252. }
  253. }
  254. if (value.hasOwnProperty('qualification')) {
  255. $("#honorific").css("display", "flex");
  256. qualification = value['qualification']['value'];
  257. }
  258. if (value.hasOwnProperty('Birth_Date')) {
  259. $("#BirthDate").css("display", "flex");
  260. birth_date = value['Birth_Date']['value'];
  261. }
  262. if (value.hasOwnProperty('Birth_Place')) {
  263. $("#BirthPlace").css("display", "flex");
  264. birth_place = value['Birth_Place']['value'];
  265. }
  266. if (value.hasOwnProperty('Death_Date')) {
  267. $("#DeathDate").css("display", "flex");
  268. death_date = value['Death_Date']['value'];
  269. }
  270. if (value.hasOwnProperty('Death_Place')) {
  271. $("#DeathPlace").css("display", "flex");
  272. death_place = value['Death_Place']['value'];
  273. }
  274. if (value.hasOwnProperty('group')) {
  275. $("#groups").css("display", "flex");
  276. group = value['group']['value'];
  277. }
  278. if (value.hasOwnProperty('variants')) {
  279. if (value['variants']['value'] != "| ") {
  280. alert(value['variants']['value']);
  281. $("#otherNames").css("display", "flex");
  282. let strings = value['variants']['value'];
  283. variants = strings.split(";");
  284. }
  285. }
  286. var dataset = get_dataset_name(graph);
  287. var second_name = patronymic + " " + relative;
  288. var first_name = "";
  289. if ((givenName != "") || (second_name != " ") || (familyName != "")) {
  290. first_name = givenName + " " + second_name + " " + familyName;
  291. } else {
  292. first_name = name;
  293. }
  294. var name_string = "";
  295. if (variants.length>0) {
  296. for (var i=0; i<variants.length; i++) {
  297. let chunk = variants[i].split("| ");
  298. name_string = name_string + "<a href='" + chunk[0] + "'>" + chunk[1] + "</a><br />";
  299. }
  300. }
  301. console.log(variants);
  302. /*for (var i=0; i<l; i++) {
  303. names_string = names_string + "<a href='" + variants[i][0] + "'>" + variants[i][1] + "</a>";
  304. }*/
  305. document.getElementById("grafo").innerHTML = dataset;
  306. document.getElementById("nome_persona").innerHTML = first_name;
  307. document.getElementById("nome").innerHTML = name;
  308. document.getElementById("genere").innerHTML = gender;
  309. document.getElementById("nome_proprio").innerHTML = givenName;
  310. document.getElementById("nome_famiglia").innerHTML = familyName;
  311. document.getElementById("alias").innerHTML = alias;
  312. document.getElementById("variants").innerHTML = name_string;
  313. document.getElementById("patronimico").innerHTML = second_name;
  314. document.getElementById("qualifica").innerHTML = qualification;
  315. document.getElementById("occupazione").innerHTML = occupation;
  316. document.getElementById("data_nascita").innerHTML = birth_date;
  317. document.getElementById("data_morte").innerHTML = death_date;
  318. document.getElementById("luogo_nascita").innerHTML = birth_place;
  319. document.getElementById("luogo_morte").innerHTML = death_place;
  320. document.getElementById("gruppi_appartenenza").innerHTML = group;
  321. const collection = document.getElementsByClassName("PN");
  322. for (var i=0; i<collection.length; i++) {
  323. collection[i].innerHTML = first_name;
  324. }
  325. });
  326. }
  327. function get_dataset_name(graph) {
  328. var string = "Scheda Onomastica";
  329. if (graph == "http://dev.restore.ovi.cnr.it:8890/aspo/onomastica") {
  330. string = string + " / Onomastica Datini";
  331. }
  332. else if (graph == "http://dev.restore.ovi.cnr.it:8890/mpp/authors"){
  333. string = string + " / Artisti";
  334. }
  335. else {
  336. string = string;
  337. }
  338. return (string);
  339. }
  340. function handle_Letters(json) {
  341. console.log(json);
  342. const send = [];
  343. const receive = [];
  344. var i=0;
  345. var j=0;
  346. $.each(
  347. json['results']['bindings'],
  348. function (index, value) {
  349. type = value['type']['value'];
  350. uri = value['document_uri']['value'];
  351. title = value['document_name']['value'];
  352. segnatura = value['segnatura']['value'];
  353. var data = "";
  354. var InfObj = "";
  355. if (value.hasOwnProperty('time_span')) {
  356. data = value['time_span']['value'];
  357. }
  358. if (value.hasOwnProperty('InfObj')) {
  359. InfObj = value['InfObj']['value'];
  360. }
  361. if (type == "Invio") {
  362. send.push([uri, title, segnatura, data, InfObj]);
  363. i++;
  364. } else {
  365. receive.push([uri, title, segnatura, data, InfObj]);
  366. j++;
  367. }
  368. });
  369. var Send_Letters = "";
  370. var Receive_Letters = "";
  371. //POPULATE SEND LETTERS BOX
  372. for (var i=0; i<send.length; i++) {
  373. var letter = '<a href=' + send[i][0] + ' target="_blank">' + send[i][1] + '</a>';
  374. var infObject_button = "";
  375. if (send[i][2] != "") {
  376. letter = letter + "<br />Segnatura: " + send[i][2];
  377. }
  378. if (send[i][3] != "") {
  379. letter = letter + "<br />Data invio: " + send[i][3];
  380. }
  381. if (send[i][4] != "") {
  382. infObject_button += '<button type="button" id="' + send[i][4] +
  383. '" class="lettera btn btn-default" alt="lettera" ><i class="fa fa-envelope"></i><p class="btn-text">Scheda Lettera</p></button>';
  384. } else {
  385. infObject_button += '<button type="button" id="' + send[i][0] +
  386. '" class="object btn btn-default" alt="oggetto" title="' + send[i][1] +
  387. '"><i class="fa fa-book"></i><p class="btn-text">Scheda Oggetto</p></button>';
  388. }
  389. Send_Letters += '<div class="row res"><div class="col-8"><p>'+ letter +'</p></div>' +
  390. '<div class="col d-flex align-items-start justify-content-end">' + infObject_button +
  391. '<button type="button" id="' + send[i][0] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button>' +
  392. '<button type="button" id="' + send[i][0] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button>' +
  393. '<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + send[i][0] + '" target="_blank"><button type="button" class="btn btn-default info" alt="LOD"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></div></div>';
  394. }
  395. //POPULATE RECEIVE LETTERS BOX
  396. for (var i=0; i<receive.length; i++) {
  397. var letter = '<a href=' + receive[i][0] + ' target="_blank">' + receive[i][1] + '</a>';
  398. var infObject_button = "";
  399. if (receive[i][2] != "") {
  400. letter = letter + "<br />Segnatura: " + receive[i][2];
  401. }
  402. if (receive[i][3] != "") {
  403. letter = letter + "<br />Data ricezione: " + receive[i][3];
  404. }
  405. if (receive[i][4] != "") {
  406. infObject_button += '<button type="button" id="' + receive[i][4] +
  407. '" class="lettera btn btn-default" alt="lettera" ><i class="fa fa-envelope"></i><p class="btn-text">Scheda Lettera</p></button>';
  408. } else {
  409. infObject_button += '<button type="button" id="' + receive[i][0] +
  410. '" class="object btn btn-default" alt="oggetto" title="' + receive[i][1] +
  411. '"><i class="fa fa-book"></i><p class="btn-text">Scheda Oggetto</p></button>';
  412. }
  413. Receive_Letters += '<div class="row res"><div class="col-8"><p>'+ letter +'</p></div>' +
  414. '<div class="col d-flex align-items-start justify-content-end">' + infObject_button +
  415. '<button type="button" id="' + receive[i][0] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button>' +
  416. '<button type="button" id="' + receive[i][0] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button>' +
  417. '<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + receive[i][0] + '" target="_blank"><button type="button" class="btn btn-default info" alt="LOD"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></div></div>';
  418. }
  419. document.getElementById("l_send").innerHTML = send.length;
  420. document.getElementById("l_receive").innerHTML = receive.length;
  421. document.getElementById("letters_send").innerHTML = Send_Letters;
  422. document.getElementById("letters_receive").innerHTML = Receive_Letters;
  423. if (i==0) {
  424. var messaggio = "<p class='no-results'>Nessun risultato trovato</p>";
  425. document.getElementById("letters_send").innerHTML = messaggio;
  426. }
  427. if (j==0) {
  428. var messaggio = "<p class='no-results'>Nessun risultato trovato</p>";
  429. document.getElementById("letters_receive").innerHTML = messaggio;
  430. }
  431. }
  432. function handle_Artwork(json) {
  433. console.log(json);
  434. const oa = [];
  435. $.each(
  436. json['results']['bindings'],
  437. function (index, value) {
  438. uri = value['subject']['value'];
  439. label = value['label']['value'];
  440. nct = value['nct']['value'];
  441. var data = "";
  442. if (value.hasOwnProperty('time_span')) {
  443. data = value['time_span']['value'];
  444. }
  445. oa.push([uri, label, nct, data]);
  446. });
  447. var Artworks = "";
  448. for (var i=0; i<oa.length; i++) {
  449. var artwork = '<a href=' + oa[i][0] + ' target="_blank">' + oa[i][1] + '</a><br />NCT: ' + oa[i][2];
  450. if (oa[i][3] != "") {
  451. artwork = artwork + "<br />Data: " + oa[i][3];
  452. }
  453. var object_button = '<button type="button" id="' + oa[i][0] +
  454. '" class="artwork btn btn-default" alt="opera d\'arte" title="' + oa[i][1] +
  455. '"><i class="fas fa-paint-brush"></i><p class="btn-text">Scheda Opera d\'Arte</p></button>';
  456. Artworks += '<div class="row res"><div class="col-8"><p>'+ artwork +'</p></div>' +
  457. '<div class="col d-flex align-items-start justify-content-end">' + object_button +
  458. '<button type="button" id="' + oa[i][0] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button>' +
  459. '<button type="button" id="' + oa[i][0] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button>' +
  460. '<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + oa[i][0] + '" target="_blank"><button type="button" class="btn btn-default info" alt="LOD"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></div></div>';
  461. }
  462. /*if (receive[i][4] != "") {
  463. infObject_button += '<button type="button" id="' + receive[i][4] +
  464. '" class="lettera btn btn-default" alt="lettera" ><i class="fa fa-envelope"></i><p class="btn-text">Scheda Lettera</p></button>';
  465. } else {
  466. infObject_button += '<button type="button" id="' + receive[i][0] +
  467. '" class="object btn btn-default" alt="oggetto" title="' + receive[i][1] +
  468. '"><i class="fa fa-book"></i><p class="btn-text">Scheda Oggetto</p></button>';
  469. }
  470. Receive_Letters += '<div class="row res"><div class="col-8"><p>'+ artwork +'</p></div>' +
  471. '<div class="col d-flex align-items-start justify-content-end">' + infObject_button +
  472. '<button type="button" id="' + receive[i][0] + '" class="cit btn btn-default" alt="scheda" title="Info"><i class="fa fa-quote-right"></i><p class="btn-text">Citazione</p></button>' +
  473. '<button type="button" id="' + receive[i][0] + '" class="hyp btn btn-default" alt="scheda" title="Info"><i class="fa fa-link"></i><p class="btn-text">Hyperlink</p></button>' +
  474. '<a href="http://dev.restore.ovi.cnr.it/lodlive/?' + receive[i][0] + '" target="_blank"><button type="button" class="btn btn-default info" alt="LOD"><i class="fa fa-share-alt"></i><p class="btn-text">Lod</p></button></a></div></div>';
  475. }*/
  476. document.getElementById("n_oa").innerHTML = oa.length;
  477. document.getElementById("object_oa").innerHTML = Artworks;
  478. }
  479. function handle_map(json) {
  480. console.log(json);
  481. const locations = [];
  482. const place_names = [];
  483. var lat = 0;
  484. var long = 0;
  485. var i=0;
  486. var myPlaces = "";
  487. $.each(
  488. json['results']['bindings'],
  489. function (index, value) {
  490. const loc = []
  491. var uri = value['place']['value'];
  492. var label = value['label']['value'];
  493. var coord = value['coordinates']['value'];
  494. const coordinates = coord.split(", ");
  495. loc.push(label);
  496. 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='" +
  497. uri + "'><i class='far fa-map' style='cursor:pointer'></i></div></div></div>";
  498. loc.push(coordinates[0]);
  499. lat += parseInt(coordinates[0]);
  500. loc.push(coordinates[1]);
  501. long += parseInt(coordinates[1].replace(/^(\.)/,"0.").replace("-.", "-0."));
  502. locations.push(loc);
  503. i++;
  504. });
  505. var latitude = lat/i;
  506. var longitude = long/i;
  507. document.getElementById("list_places_person").innerHTML = myPlaces;
  508. var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png',
  509. cloudmadeAttribution = 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 CloudMade, Points &copy 2012 LINZ',
  510. cloudmade = new L.TileLayer(cloudmadeUrl, {maxZoom: 17, attribution: cloudmadeAttribution}),
  511. latlng = new L.LatLng(latitude, longitude);
  512. var map = new L.Map('map', {center: latlng, zoom: 5, layers: [cloudmade]});
  513. mapLink = '<a href="https://openstreetmap.org">OpenStreetMap</a>';
  514. var markers = new L.MarkerClusterGroup();
  515. var markerList = [];
  516. var geo = new L.tileLayer(
  517. 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  518. attribution: '&copy; ' + mapLink + ' Contributors',
  519. maxZoom: 18,
  520. }).addTo(map);
  521. function populate() {
  522. for (var i = 0; i < locations.length; i++) {
  523. var a = locations[i];
  524. var title = a[0];
  525. var marker = new L.Marker(new L.LatLng(a[1], a[2]), { title: title });
  526. marker.bindPopup(title);
  527. markers.addLayer(marker);
  528. markerList.push(marker);
  529. }
  530. }
  531. populate();
  532. map.addLayer(markers);
  533. $('.clickPlace').on('click', function(){
  534. // parse lat and lng from the divs data attribute
  535. var latlng = $(this).data().point.split(',');
  536. var lat = latlng[0];
  537. var lng = latlng[1];
  538. var zoom = 10;
  539. // set the view
  540. map.setView([lat, lng], zoom);
  541. });
  542. }
  543. function handle_network(json) {
  544. console.log(json);
  545. const words = [];
  546. const tempArray = [];
  547. var listwords = "";
  548. var ArrayNames = "";
  549. var temp = 0;
  550. var sum = 0;
  551. var i=0;
  552. var j=0;
  553. $.each(
  554. json['results']['bindings'],
  555. function (index, value) {
  556. text = value['text']['value'];
  557. link = value['uri2']['value'];
  558. num = parseInt(value['count']['value']);
  559. /*count = 0;
  560. if ((num - temp) > 50) {
  561. count = temp + 12;
  562. } else {
  563. count = num;
  564. }
  565. words.push([text, count]);
  566. temp = count;
  567. sum += temp;*/
  568. tempArray.push([text, num]);
  569. ArrayNames += "<div class='item-place-person'><div class='item-place-person-label'>" +
  570. text + "<br /><span class='num_occ'>[Co-occorrenze: " + num + "]</span></div><div class='item-place-person-action'><div class='persona' id='" +
  571. link + "'><i class='fa fa-user' style='cursor:pointer'></i></div></div></div></div>";
  572. });
  573. if (tempArray.length < 8) {
  574. for (var k=0; k<tempArray.length; k++) {
  575. text = tempArray[k][0];
  576. count = tempArray[k][1] + 36;
  577. words.push([text, count]);
  578. }
  579. } else {
  580. for (var k=tempArray.length-1; k>=0; k--) {
  581. text = tempArray[k][0];
  582. num = tempArray[k][1];
  583. count = 0;
  584. if ((num - temp) > 50) {
  585. count = temp + 12;
  586. } else {
  587. count = num;
  588. }
  589. words.push([text, count]);
  590. temp = count;
  591. sum += temp;
  592. }
  593. }
  594. document.getElementById("list_person_network").innerHTML = ArrayNames;
  595. /*var tot = parseInt(words[0][1]);*/
  596. for (var i in words) {
  597. var text = words[i][0]
  598. var count = words[i][1];
  599. listwords += '{ "word": \"' + text + '\", "size": \"' + count + '\"},';
  600. }
  601. let listL = ('[' + listwords + ']').replace(',]', ']');
  602. const links = JSON.parse(listL);
  603. console.log(links);
  604. // List of words
  605. var myWords = links;
  606. // set the dimensions and margins of the graph
  607. var margin = {top: 10, right: 10, bottom: 10, left: 10},
  608. width = 850 - margin.left - margin.right,
  609. height = 500 - margin.top - margin.bottom;
  610. // append the svg object to the body of the page
  611. var svg = d3.select("#myWordCloud").append("svg")
  612. .attr("width", width + margin.left + margin.right)
  613. .attr("height", height + margin.top + margin.bottom)
  614. .append("g")
  615. .attr("transform",
  616. "translate(" + (width/2-50) + "," + (height/2+20) + ")");
  617. // Constructs a new cloud layout instance. It run an algorithm to find the position of words that suits your requirements
  618. // Wordcloud features that are different from one word to the other must be here
  619. var layout = d3.layout.cloud()
  620. .size([width, height])
  621. .words(myWords.map(function(d) { return {text: d.word, size:d.size/2}; }))
  622. .padding(5) //space between words
  623. .rotate(function() { return ~~(Math.random() * 2);})
  624. .fontSize(function(d) { return d.size + 6; }) // font size of words
  625. .on("end", draw);
  626. layout.start();
  627. // This function takes the output of 'layout' above and draw the words
  628. // Wordcloud features that are THE SAME from one word to the other can be here
  629. function draw(words) {
  630. var cloud = svg.selectAll("g text")
  631. .data(words, function(d) { return d.text; })
  632. //Entering words
  633. cloud.enter()
  634. .append("text")
  635. .style("font-family", "Impact")
  636. .attr("text-anchor", "middle")
  637. .attr('font-size', 1)
  638. .text(function(d) { return d.text; });
  639. //Entering and existing words
  640. cloud
  641. .transition()
  642. .duration(600)
  643. .style("font-size", function(d) { return d.size + "px"; })
  644. .attr("transform", function(d) {
  645. return "translate(" + [d.x, d.y] + ")rotate(" + d.rotate + ")";
  646. })
  647. .style("fill-opacity", 1);
  648. //Exiting words
  649. cloud.exit()
  650. .transition()
  651. .duration(200)
  652. .style('fill-opacity', 1e-6)
  653. .attr('font-size', 1)
  654. .remove();
  655. }
  656. }
  657. $(document).on("click", ".luogo", function (ev) {
  658. var link = this.id;
  659. //alert(nome_autore);
  660. //$('#myModal').text("");
  661. window.open("Luogo.html?link="+this.id);
  662. });
  663. $(document).on("click", ".persona", function (ev) {
  664. var link = this.id;
  665. //alert(nome_autore);
  666. //$('#myModal').text("");
  667. window.open("Persona.html?link="+this.id);
  668. });
  669. $(document).on("click", ".lettera", function (ev) {
  670. var link = this.id;
  671. //alert(nome_autore);
  672. //$('#myModal').text("");
  673. window.open("lettera.html?link="+this.id);
  674. });
  675. $(document).on("click", ".object", function (ev) {
  676. var link = this.id;
  677. //alert(nome_autore);
  678. //$('#myModal').text("");
  679. window.open("object.html?link="+this.id);
  680. });
  681. $(document).on("click", ".hyp", function (ev) {
  682. var link = this.id;
  683. $("#myModal").empty();
  684. $("#myModal").css("display", "block");
  685. $('#myModal').append("<div class='modal-content'><div class='modal-close'><span class='close'>&times;</span></div><div id='myInput'>" +
  686. link + "</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  687. });
  688. $(document).on("click", ".artwork", function (ev) {
  689. var link = this.id;
  690. //alert(nome_autore);
  691. //$('#myModal').text("");
  692. window.open("OA.html?link="+this.id);
  693. });
  694. $(document).on("click", ".close", function (ev) {
  695. var link = this.id;
  696. //alert(nome_autore);
  697. //$('#myModal').text("");
  698. $("#myModal").css("display", "none");
  699. });
  700. $(document).on("click", ".back", function (ev) {
  701. $("#myTab").css("display", "none");
  702. });
  703. $(document).on("click", ".cit", function (ev) {
  704. var author ="RESTORE. smart access to digital heritage and memory"
  705. var year = new Date().getFullYear()
  706. var today = new Date();
  707. var dd = String(today.getDate()).padStart(2, '0');
  708. var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
  709. var yyyy = today.getFullYear();
  710. today = dd + '/' + mm + '/' + yyyy;
  711. var link = this.id;
  712. //alert(nome_autore);
  713. //$('#myModal').text("");
  714. $("#myModal").empty();
  715. $("#myModal").css("display", "block");
  716. $('#myModal').append("<div class='modal-content'><div class='modal-close'><span class='close'>&times;</span></div><div id='myInput'>" +
  717. author + " " + year + ", accesso effettuato: " + today + ", &lt;" + link + "&gt;</div><button id='copy_btn' class='btn btn-theme-primary btn-md' onclick='myFunction()'>Copia</button>");
  718. });
  719. function copyToClipboard(text) {
  720. var sampleTextarea = document.createElement("textarea");
  721. document.body.appendChild(sampleTextarea);
  722. sampleTextarea.value = text; //save main text in it
  723. sampleTextarea.select(); //select textarea contenrs
  724. document.execCommand("copy");
  725. document.body.removeChild(sampleTextarea);
  726. }
  727. function myFunction(){
  728. var copy = document.getElementById("myInput");
  729. copyText = copy.textContent;
  730. copyToClipboard(copyText);
  731. //copyToClipboard(copyText.value);
  732. }