/** * QUERY SECTION * * */ // SPARQL Query text -- 'prefixes' and 'thisUrlParams' defined in people.js; let queryNetwork = prefixes + " SELECT DISTINCT COUNT(?event) AS ?count ?uri2 SAMPLE(?label2) AS ?text \ WHERE { \ {?event rdf:type crm:EL1_Exchange_Letters . \ ?event_to rdfs:subClassOf ?event; \ rdf:type crm:EL2_Send_Letter ; \ crm:P01_has_domain ?pc_to . \ ?pc_to crm:P02_has_range ?uri . \ ?uri rdfs:label ?label . \ ?event_from rdfs:subClassOf ?event; \ rdf:type crm:EL3_Receive_Letter; \ crm:P01_has_domain ?pc_from . \ ?pc_from crm:P02_has_range ?uri2 . \ ?uri2 rdfs:label ?label2 . \ FILTER (?uri = <" + thisUrlParams.link + ">) \ } UNION { \ ?event rdf:type crm:EL1_Exchange_Letters . \ ?event_to rdfs:subClassOf ?event; \ rdf:type crm:EL3_Receive_Letter ; \ crm:P01_has_domain ?pc_from . \ ?pc_from crm:P02_has_range ?uri . \ ?uri rdfs:label ?label . \ ?event_from rdfs:subClassOf ?event; \ rdf:type crm:EL2_Send_Letter; \ crm:P01_has_domain ?pc_to . \ ?pc_to crm:P02_has_range ?uri2 . \ ?uri2 rdfs:label ?label2 . \ FILTER (?uri = <" + thisUrlParams.link + ">) \ } \ } ORDER BY DESC (?count)" // 'prepareQueryURL' defined in people.js let queryNet = prepareQueryURL(queryNetwork); // do the query, call data processor on successful output $.ajax({ url: queryNet, dataType: "json", success: (data) => handle_word_network(data) }); /** * COMPONENT CREATION SECTION * * */ // Master function, takes data output from the query and creates the HTML for the Word Cloud component of the page function handle_word_network(json){ // Pre-process data let tempArray = processQuery(json); let words = prepareWords(tempArray); // Create page elements doListPersonNetwork(tempArray); doWordCloud(words); } // Return structured object from raw query data for further processing function processQuery(json) { const tempArray = []; $.each( json['results']['bindings'], function (index, value) { let text = value['text']['value']; let link = value['uri2']['value']; let num = parseInt(value['count']['value']); tempArray.push({'text': text, 'count': num, 'hlink': link}); } ); return tempArray; } // Define font size, according to the number of words and limiting the impact of huge counts -- to refactor?? function prepareWords(tempArray){ const words = []; if (tempArray.length < 8) { // Less than 8 results -- font size is just = count/2 + constant for (let entry in tempArray) { let text = entry['text']; let preSize = entry['count'] + 36; let link = entry['hlink']; words.push( { 'text': text, 'size': preSize/2 + 6, 'hlink': link } ); } } else { // More than 8 results -- font size = count except for especially "big" words let temp = 0; for (let k=tempArray.length-1; k>=0; k--) { let text = tempArray[k]['text']; let count = tempArray[k]['count']; let link = tempArray[k]['hlink']; let preSize = 0; if ((count - temp) > 50) { preSize = temp + 12; } else { preSize = count; } words.push( { 'text': text, 'size': preSize/2 + 6, 'hlink': link } ); temp = preSize; } } console.log('tempArray', tempArray) console.log('words', words) return words; } // Create formatted list of people in the network function doListPersonNetwork(tempArray){ let ArrayNames = ""; tempArray.forEach(element => { ArrayNames += "
Nessuna persona trovata
\