/** * */ $(document).ready(function() { const sparqlGenerator = sparqljs.Generator; const myEngine = new Comunica.QueryEngine(); const sparqlEndpoint = "https://hdnlab1.isti.cnr.it/fuseki/commediaontosintgra/query"; var listaVersi = new Set() $('#cantica1').on('click', function() { alert("test fava") activateMenuItem ('#cantica1') jsonQuery = versiCantica("cantica1"); execQuery = new sparqlGenerator().stringify(jsonQuery); executeQueryVersi(execQuery); }); jQuery(document).delegate('.navig-canto', 'click', function(e) { $('.canto').each(function() { $(this).attr("style", 'display:none'); }); $("#"+$(this).attr('name').replace(" ","_")).attr('style','display:block') }); //Utility functions //activate navigation menu items function activateMenuItem(menuItem){ $('.blog-nav-item').each(function() { $(this).attr("class", $(this).attr("class").replace(' active','')); }); $(menuItem).attr("class", $(menuItem).attr("class")+' active'); } async function executeQueryVersi(query){ bindingsStream = await myEngine.queryBindings(query, { sources: [ { type: 'sparql', value: sparqlEndpoint }, ], }); alert(query) try { var listaCanti = new Set() listaVersi = new Set() bindingsStream.on('data', (binding) => { //console.log(binding.toString()); // Quick way to print bindings for testing //console.log(binding.has('sub')); // Will be true //la lista dei canti listaCanti.add( binding.get('Canto').value) //la lista dei versi var obj = new Object(); obj.numverso = binding.get('NumeroVerso').value; obj.verso = binding.get('Verso').value; obj.canto = binding.get('Canto').value; obj.from = binding.get('from').value; obj.to = binding.get('to').value; listaVersi.add(obj) }); bindingsStream.on('end', () => { var orderedListaCanti = Array.from(listaCanti) orderedListaCanti = orderedListaCanti.sort((a, b) => { if (parseInt(a.split(" ")[1]) < parseInt(b.split(" ")[1])) { return -1; } }); var orderedListaVersi = Array.from(listaVersi) orderedListaVersi = orderedListaVersi.sort((a, b) => { if (parseInt(a.numverso) < parseInt(b.numverso)) { return -1; } }); for (canto of orderedListaCanti){ var licanto = $('
') licanto.attr('name', canto) licanto.attr('href', "#") licanto.append(canto) licanto.appendTo('#listacanti') var divcanto=$('') var titolocanto=$('') titolocanto.append(canto) divcanto.attr('class', 'canto') divcanto.attr('style', 'display:none') divcanto.attr('id', canto.replace(" ","_")) titolocanto.appendTo(divcanto) divcanto.appendTo(' .blog-main') } for (verso of orderedListaVersi){ var elementoverso=$('') elementoverso.append(verso.numverso+". "+verso.verso) elementoverso.attr("style", "line-height: 0.5em") elementoverso.appendTo('#'+verso.canto.replace(" ","_")) } }); } catch(err) { console.log(err.message); $("#loader").hide(); }; }; });