cambiata notazione espressione logica nel json + WIP carica query

This commit is contained in:
Luca Trupiano 2022-10-06 13:26:18 +02:00
parent ab27b68ad7
commit e147920973
1 changed files with 189 additions and 160 deletions

View File

@ -108,23 +108,23 @@ $(document).ready(function() {
var addClaN = $(this).attr('id');
switch (addClaN) {
case "Grammaticale":
addGramCla();
addGramCla(1);
$('#cla' + tabID + '-tab').tab('show');
break;
case "Sintattico":
addSyntCla();
addSyntCla(1);
$('#cla' + tabID + '-tab').tab('show');
break;
case "Metafore":
addMetaCla();
addMetaCla(0);
$('#cla' + tabID + '-tab').tab('show');
break;
case "Dialoghi":
addDialCla();
addDialCla(0);
$('#cla' + tabID + '-tab').tab('show');
break;
case "Struttura":
addStruCla();
addStruCla(0);
$('#cla' + tabID + '-tab').tab('show');
break;
case "andCond":
@ -163,7 +163,7 @@ $(document).ready(function() {
});
// Evento: click sull'icona di refresh dei radio button
$('#cla-TabContent').on('click', '.radioRefresh', function() {
$('#cla-TabContent').on('click', '.radioReset', function() {
fSet = $(this).siblings('fieldset');
if (fSet.find(":checked").length) {
radioChecked = fSet.find(":checked")[0];
@ -199,112 +199,9 @@ $(document).ready(function() {
// Evento: SCELTA CATEGORIA GRAMMATICALE
$('#cla-TabContent').on('change', 'select.catgram', function(e) {
e.preventDefault();
var tabPaneId = ($(this).closest('.tab-pane').attr("id"));
var dettagliBox = $(this).parent().parent().siblings(".dettaglifiltri");
dettagliBox.html("");
var containerid = 'dettaglio_' + $(this).parent().parent().parent().attr("id")
if (Object.keys(categorie).includes($(this).val())) {
var filtro = categorie[$(this).val()]
var keys = Object.keys(categorieJson[filtro])
for (var key in keys) {
var vals = categorieJson[filtro][keys[key]]
switch (vals.length) {
case 2:
var element = $('<div />');
element.attr('class', ' d-flex flex-nowrap pr-2 mb-1 col-8 form-group form-control justify-content-between');
var rbfieldset = $('<fieldset />');
var flexdiv1 = $('<div />');
var flexdiv2 = $('<div />');
var input1 = $('<input />');
var input2 = $('<input />');
var label1 = $('<label />');
var label2 = $('<label />');
rbfieldset.attr('id', tabPaneId + keys[key]);
rbfieldset.attr('class', 'bn');
flexdiv1.attr('class', 'custom-control custom-radio custom-control-inline');
flexdiv2.attr('class', 'custom-control custom-radio custom-control-inline');
input1.attr('class', 'custom-control-input');
input2.attr('class', 'custom-control-input');
input1.attr('type', 'radio');
input2.attr('type', 'radio');
input1.attr('id', tabPaneId + vals[0]);
input2.attr('id', tabPaneId + vals[1]);
input1.attr('value', vals[0]);
input2.attr('value', vals[1]);
input1.attr('name', tabPaneId + keys[key]);
input2.attr('name', tabPaneId + keys[key]);
label1.attr('class', 'custom-control-label');
label2.attr('class', 'custom-control-label');
label1.attr('for', tabPaneId + vals[0]);
label2.attr('for', tabPaneId + vals[1]);
label1.append(vals[0]);
label2.append(vals[1]);
input1.appendTo(flexdiv1);
input2.appendTo(flexdiv2);
label1.appendTo(flexdiv1);
label2.appendTo(flexdiv2);
flexdiv1.appendTo(rbfieldset);
flexdiv2.appendTo(rbfieldset);
rbfieldset.appendTo(element);
var iconR = $(iconReset);
iconR.appendTo(element);
element.attr('style', 'display:block');
element.appendTo(dettagliBox);
break;
case 1:
var element = $('<div />');
element.attr('class', ' d-flex flex-nowrap mb-1 col-4 form-group form-control');
var rbfieldset = $('<fieldset />');
flexdiv1 = $('<div />');
input1 = $('<input />');
label1 = $('<label />');
rbfieldset.attr('id', tabPaneId + keys[key]);
rbfieldset.attr('class', 'bn');
flexdiv1.attr('class', 'custom-control custom-checkbox custom-control-inline');
input1.attr('class', 'custom-control-input');
input1.attr('type', 'checkbox');
input1.attr('id', tabPaneId + vals[0].replace(/\s/g, ''));
input1.attr('value', vals[0]);
input1.attr('name', keys[key]);
label1.attr('class', 'custom-control-label');
label1.attr('for', tabPaneId + vals[0].replace(/\s/g, ''));
label1.append(vals[0]);
input1.appendTo(flexdiv1);
label1.appendTo(flexdiv1);
flexdiv1.appendTo(rbfieldset);
rbfieldset.appendTo(element);
element.attr('style', 'display:block');
element.appendTo(dettagliBox);
break;
default:
var element = $('<div />');
element.attr('class', ' col-8 form-group px-0 pb-1 m-0');
var select = $('<select class="form-control custom-select"/>');
select.attr('id', tabPaneId + keys[key]);
select.attr('title', keys[key]);
select.attr('name', keys[key]);
for (var val in vals) {
var seloption = $('<option />');
seloption.attr('value', vals[val]);
seloption.append(vals[val]);
seloption.appendTo(select);
}
select.appendTo(element);
element.attr('style', 'display:block');
element.appendTo(dettagliBox);
}
}
}
if (element) {
element.attr('style', "display: block;");
element.appendTo(dettagliBox);
};
var selectedValue = $(this).val();
addCatgramSubcla(tabPaneId,selectedValue);
});
// Evento: Submit form
@ -319,11 +216,7 @@ $(document).ready(function() {
jsonQuery = buildSQ(queryJson);
queryFields = [];
for (var i in jsonQuery.variables) {
//if (jsonQuery.variables[i].value) {
//queryFields.push(jsonQuery.variables[i].value);
//} else {
queryFields.push(jsonQuery.variables[i].variable.value);
//}
}
execQuery = new sparqlGenerator().stringify(jsonQuery);
executeQuery();
@ -485,7 +378,7 @@ $(document).ready(function() {
var iconClose = '<ion-icon name="close-circle"></ion-icon>';
var iconCheck = '<ion-icon name="checkmark-circle"></ion-icon>';
var iconFilter = '<ion-icon name="filter-circle"></ion-icon>';
var iconReset = '<div class="text-right text-primary radioRefresh"><ion-icon name="refresh-circle"></ion-icon></div>';
var iconReset = '<div class="text-right text-primary radioReset"><ion-icon name="refresh-circle"></ion-icon></div>';
var iconCloseCond = '<div class="p-0 mr-1 text-right text-primary"><span class="iconClClass removeCond">' + iconClose + '</span></div>';
var iconCheckAndClose = '<div class="p-0 m-1 text-right text-primary"><span class="return2Query">' + iconCheck + '</span>&nbsp;&nbsp;<span class="removeClaInTab">' + iconClose + '</span></div>';
var emptyClaList = '<li id="H-cla0" class="list-group-item align-items-center ui-state-default ui-state-disabled border text-muted bg-white ui-state-disabled-opacity-06">Nessuna clausola aggiunta.</li>';
@ -528,7 +421,6 @@ $(document).ready(function() {
const myEngine = new Comunica.QueryEngine();
const sparqlEndpoint = "https://hdnlab1.isti.cnr.it/fuseki/commediaontosintgra/query";
const sparqlEndpoint2 = "https://hdnlab1.isti.cnr.it/fuseki/commedia-wip/query";
// Fine variabili
@ -538,7 +430,6 @@ $(document).ready(function() {
bindingsStream = await myEngine.queryBindings(execQuery, { sources: [ { type: 'sparql', value: sparqlEndpoint }, ], });
$("#sparqlquery").val(execQuery);
$("#copiaQuery").prop("disabled", false);
var resultTablePart1a = '<table id="resultTable" class="table table-striped table-bordered responsive nowrap"><thead><tr>';
var resultTablePart1 = '<table id="resultTable" class="table table-striped table-bordered"><thead><tr>';
var resultTablePart2 = '<th scope="col">#</th>';
var resultTablePart3 = '</tr></thead><tbody>';
@ -590,10 +481,11 @@ $(document).ready(function() {
};
// Funzione di creazione del tab delle clausole grammaticali
function addGramCla(){
function addGramCla(active){
tabID++;
var clone = document.getElementById("tipogrammaticaleN").cloneNode(true);
clone.setAttribute("id","cla" + tabID);
clone.setAttribute("data-claActive",active);
clone.setAttribute("aria-labelledby","cla" + tabID + "-tab");
clone.removeAttribute("style");
$('#cla-TabContent').append(clone);
@ -603,11 +495,118 @@ $(document).ready(function() {
$('#tab-list').append($('<li class="nav-item" role="presentation"><a class="nav-link" id="cla' + tabID + '-tab" data-toggle="tab" href="#cla' + tabID + '" role="tab" aria-controls="cla' + tabID + '" aria-selected="false" data-claType="Grammaticale"><span class="small font-weight-bold text-lida8">' + iconFilter + '&nbsp;&nbsp;' + claListLen + '. Grammaticale</span></a></li>'));
}
// Funzione di creazione delle subclausole grammaticali basate sul valore scelto
function addCatgramSubcla(tabPaneId,selectedValue){
var dettagliBox = $("#" + tabPaneId + " .dettaglifiltri");
//var dettagliBox = $(this).parent().parent().siblings(".dettaglifiltri");
dettagliBox.html("");
if (Object.keys(categorie).includes(selectedValue)) {
var filtro = categorie[selectedValue]
var keys = Object.keys(categorieJson[filtro])
for (var key in keys) {
var vals = categorieJson[filtro][keys[key]]
switch (vals.length) {
case 2:
var element = $('<div />');
element.attr('class', ' d-flex flex-nowrap pr-2 mb-1 col-8 form-group form-control justify-content-between');
var rbfieldset = $('<fieldset />');
var flexdiv1 = $('<div />');
var flexdiv2 = $('<div />');
var input1 = $('<input />');
var input2 = $('<input />');
var label1 = $('<label />');
var label2 = $('<label />');
rbfieldset.attr('id', tabPaneId + keys[key]);
rbfieldset.attr('class', 'bn');
flexdiv1.attr('class', 'custom-control custom-radio custom-control-inline');
flexdiv2.attr('class', 'custom-control custom-radio custom-control-inline');
input1.attr('class', 'custom-control-input');
input2.attr('class', 'custom-control-input');
input1.attr('type', 'radio');
input2.attr('type', 'radio');
input1.attr('id', tabPaneId + vals[0]);
input2.attr('id', tabPaneId + vals[1]);
input1.attr('value', vals[0]);
input2.attr('value', vals[1]);
input1.attr('name', tabPaneId + keys[key]);
input2.attr('name', tabPaneId + keys[key]);
label1.attr('class', 'custom-control-label');
label2.attr('class', 'custom-control-label');
label1.attr('for', tabPaneId + vals[0]);
label2.attr('for', tabPaneId + vals[1]);
label1.append(vals[0]);
label2.append(vals[1]);
input1.appendTo(flexdiv1);
input2.appendTo(flexdiv2);
label1.appendTo(flexdiv1);
label2.appendTo(flexdiv2);
flexdiv1.appendTo(rbfieldset);
flexdiv2.appendTo(rbfieldset);
rbfieldset.appendTo(element);
var iconR = $(iconReset);
iconR.appendTo(element);
element.attr('style', 'display:block');
element.appendTo(dettagliBox);
break;
case 1:
var element = $('<div />');
element.attr('class', ' d-flex flex-nowrap mb-1 col-4 form-group form-control');
var rbfieldset = $('<fieldset />');
flexdiv1 = $('<div />');
input1 = $('<input />');
label1 = $('<label />');
rbfieldset.attr('id', tabPaneId + keys[key]);
rbfieldset.attr('class', 'bn');
flexdiv1.attr('class', 'custom-control custom-checkbox custom-control-inline');
input1.attr('class', 'custom-control-input');
input1.attr('type', 'checkbox');
input1.attr('id', tabPaneId + vals[0].replace(/\s/g, ''));
input1.attr('value', vals[0]);
input1.attr('name', keys[key]);
label1.attr('class', 'custom-control-label');
label1.attr('for', tabPaneId + vals[0].replace(/\s/g, ''));
label1.append(vals[0]);
input1.appendTo(flexdiv1);
label1.appendTo(flexdiv1);
flexdiv1.appendTo(rbfieldset);
rbfieldset.appendTo(element);
element.attr('style', 'display:block');
element.appendTo(dettagliBox);
break;
default:
var element = $('<div />');
element.attr('class', ' col-8 form-group px-0 pb-1 m-0');
var select = $('<select class="form-control custom-select"/>');
select.attr('id', tabPaneId + keys[key]);
select.attr('title', keys[key]);
select.attr('name', keys[key]);
for (var val in vals) {
var seloption = $('<option />');
seloption.attr('value', vals[val]);
seloption.append(vals[val]);
seloption.appendTo(select);
}
select.appendTo(element);
element.attr('style', 'display:block');
element.appendTo(dettagliBox);
}
}
}
if (element) {
element.attr('style', "display: block;");
element.appendTo(dettagliBox);
};
}
// Funzione di creazione del tab delle clausole sintattiche
function addSyntCla(){
function addSyntCla(active){
tabID++;
var clone = document.getElementById("tiposintatticoN").cloneNode(true);
clone.setAttribute("id","cla" + tabID);
clone.setAttribute("data-claActive",active);
clone.setAttribute("aria-labelledby","cla" + tabID + "-tab");
clone.removeAttribute("style");
$('#cla-TabContent').append(clone);
@ -616,25 +615,25 @@ $(document).ready(function() {
}
// Funzione di creazione del tab delle clausole metafore
function addMetaCla(){
function addMetaCla(active){
tabID++;
$('#cla-TabContent').append($('<div class="tab-pane fade p-2 bg-white" data-claActive="0" id="cla' + tabID + '" role="tabpanel" aria-labelledby="cla' + tabID + '-tab" data-claType="Metafore">' + iconCheckAndClose + '<div class="text-muted form-group px-1 pb-1">Clausola <span class="text-lida3">Metafore</span> - non ancora implementata</div></div>'));
$('#cla-TabContent').append($('<div class="tab-pane fade p-2 bg-white" data-claActive="' + active + '" id="cla' + tabID + '" role="tabpanel" aria-labelledby="cla' + tabID + '-tab" data-claType="Metafore">' + iconCheckAndClose + '<div class="text-muted form-group px-1 pb-1">Clausola <span class="text-lida3">Metafore</span> - non ancora implementata</div></div>'));
claListLen++;
$('#tab-list').append($('<li class="nav-item" role="presentation"><a class="nav-link" id="cla' + tabID + '-tab" data-toggle="tab" href="#cla' + tabID + '" role="tab" aria-controls="cla' + tabID + '" aria-selected="false" data-claType="Metafore"><span class="small font-weight-bold text-lida3">' + iconFilter + '&nbsp;&nbsp;' + claListLen + '. Metafore</span></a></li>'));
}
// Funzione di creazione del tab delle clausole dialoghi
function addDialCla(){
function addDialCla(active){
tabID++;
$('#cla-TabContent').append($('<div class="tab-pane fade p-2 bg-white" data-claActive="0" id="cla' + tabID + '" role="tabpanel" aria-labelledby="cla' + tabID + '-tab" data-claType="Dialoghi">' + iconCheckAndClose + '<div class="text-muted form-group px-1 pb-1">Clausola <span class="text-lida4">Dialoghi</span> - non ancora implementata</div></div>'));
$('#cla-TabContent').append($('<div class="tab-pane fade p-2 bg-white" data-claActive="' + active + '" id="cla' + tabID + '" role="tabpanel" aria-labelledby="cla' + tabID + '-tab" data-claType="Dialoghi">' + iconCheckAndClose + '<div class="text-muted form-group px-1 pb-1">Clausola <span class="text-lida4">Dialoghi</span> - non ancora implementata</div></div>'));
claListLen++;
$('#tab-list').append($('<li class="nav-item" role="presentation"><a class="nav-link" id="cla' + tabID + '-tab" data-toggle="tab" href="#cla' + tabID + '" role="tab" aria-controls="cla' + tabID + '" aria-selected="false" data-claType="Dialoghi"><span class="small font-weight-bold text-lida4">' + iconFilter + '&nbsp;&nbsp;' + claListLen + '. Dialoghi</span></a></li>'));
}
// Funzione di creazione del tab delle clausole struttura
function addStruCla(){
function addStruCla(active){
tabID++;
$('#cla-TabContent').append($('<div class="tab-pane fade p-2 bg-white" data-claActive="0" id="cla' + tabID + '" role="tabpanel" aria-labelledby="cla' + tabID + '-tab" data-claType="Struttura">' + iconCheckAndClose + '<div class="text-muted form-group px-1 pb-1">Clausola <span class="text-lida5">Struttura testo</span> - non ancora implementata</div></div>'));
$('#cla-TabContent').append($('<div class="tab-pane fade p-2 bg-white" data-claActive="' + active + '" id="cla' + tabID + '" role="tabpanel" aria-labelledby="cla' + tabID + '-tab" data-claType="Struttura">' + iconCheckAndClose + '<div class="text-muted form-group px-1 pb-1">Clausola <span class="text-lida5">Struttura testo</span> - non ancora implementata</div></div>'));
claListLen++;
$('#tab-list').append($('<li class="nav-item" role="presentation"><a class="nav-link" id="cla' + tabID + '-tab" data-toggle="tab" href="#cla' + tabID + '" role="tab" aria-controls="cla' + tabID + '" aria-selected="false" data-claType="Struttura"><span class="small font-weight-bold text-lida5">' + iconFilter + '&nbsp;&nbsp;' + claListLen + '. Struttura</span></a></li>'));
}
@ -703,12 +702,11 @@ $(document).ready(function() {
var claActive = 1
};
var l_f = $("form #lemma_forma")[0].options[$("form #lemma_forma")[0].selectedIndex].value;
var tabsC=$("#cla-TabContent").find(".tab-pane:not(:first)");
var clausoleText = "";
var tabsContent=$("#cla-TabContent").find(".tab-pane:not(:first)");
var len=0;
queryJson.Clausola0 = JSON.parse('{"queryText": "' + qText + '", "lemma_forma": "' + l_f + '", "TipoClausola": "0", "Attiva": "' + claActive + '"}');
if ($(tabsC).length) {
$(tabsC).each(function(){
if ($(tabsContent).length) {
$(tabsContent).each(function(){
if ($("#H-cla0")[0]) {
$("#H-cla0")[0].remove();
};
@ -776,6 +774,14 @@ $(document).ready(function() {
// Funzione di refresh dei placeholders e attivazione/disattivazione bottoni nelle liste sortable
function refreshSortables(){
$("#sortable0").children(".claLI").each(function() {
if ($(this).find("input")[0].checked){
$(this).find('.clatext').css({ opacity: 1 });
};
if ($(this).find("input")[0].checked == false){
$(this).find('.clatext').css({ opacity: 0.6 });
};
});
$(".ui-sortable:not(:first)").each(function() {
var sortableID = $(this)[0].id;
var placeholderID = "#placeholderSort" + sortableID.slice(-1);
@ -866,7 +872,7 @@ $(document).ready(function() {
// Funzione di parsing delle clausole e delle condizioni logiche
function parseCond(sortableList, condType){
var condText = "";
var items = $(sortableList).children("li")
var items = $(sortableList).children("li");
var itemsText = [];
$(items).each(function() {
if ($(this).hasClass("condLIand")) {
@ -899,11 +905,11 @@ $(document).ready(function() {
condText += itemsText[0];
break;
default:
condText = "( ";
for (let i = 0; i < (len - 1); i++) {
condText += itemsText[i] + " " + condType + " ";
condText = "( " + condType + " ";
for (let i = 0; i < len; i++) {
condText += itemsText[i] + " ";
}
condText += itemsText[len - 1] + " )"
condText += ")";
};
return condText;
};
@ -918,12 +924,28 @@ $(document).ready(function() {
};
function makeUpGui(queryJson) {
// 1. verifica json legit
// 2. pulire interfaccia
// 1. verifica json legit --> TO DO
// 2. pulire interfaccia --> OK
// 3. contare clausole, ricrearle in ordine e popolarle
// 4. ricreare condizioni logiche
// 4. ricreare condizioni logiche --> OK
// 5. ricreare albero logico
// 6. ???
// -------------------
// 2:
var tabsContent=$("#cla-TabContent").find(".tab-pane:not(:first)");
var tabs=$("#tab-list li:not(:first)");
if ($(tabsContent).length) {
$(tabsContent).each(function(){
$(this).remove();
});
$(tabs).each(function(){
$(this).remove();
});
};
claListLen = 0;
condListLen = 0;
$('#sortable0').html(emptyClaList);
// 3:
var logicExpr = queryJson.EsprLogica;
var clauCount = 0;
var clau2Make = "";
@ -932,59 +954,66 @@ $(document).ready(function() {
//console.log("- " + logicExpr[i]);
switch (logicExpr[i]) {
case "(":
console.log("(");
//console.log("(");
break;
case ")":
console.log(")");
//console.log(")");
break;
case "OR":
console.log("OR");
//console.log("OR");
addLogicCond("OR");
refreshConnectWith();
break;
case "AND":
console.log("AND");
//console.log("AND");
addLogicCond("AND");
refreshConnectWith();
break;
default:
clauCount++
};
};
console.log(clauCount + " clausole:");
for (var i=1; i <= clauCount; i++) {
clau2Make = queryJson["Clausola" + i].TipoClausola;
console.log(clau2Make);
clau2Make = queryJson["Clausola" + i].TipoClausola;
active = queryJson["Clausola" + i].Attiva
switch (clau2Make) {
case "Grammaticale":
addGramCla();
//$('#cla' + tabID + '-tab').tab('show');
break;
selectedValue = queryJson["Clausola" + i].typeGramm0;
addGramCla(active);
if (selectedValue != "all") {
console.log(tabID + " " + selectedValue);
console.log($("#cla" + tabID + " .catgram"));
$("#cla" + tabID + " .catgram").val(selectedValue);
addCatgramSubcla("cla" + tabID,selectedValue)
// aggiungere altri valori
}
break;
case "Sintattico":
addSyntCla();
//$('#cla' + tabID + '-tab').tab('show');
addSyntCla(active);
break;
case "Metafore":
addMetaCla();
//$('#cla' + tabID + '-tab').tab('show');
addMetaCla(active);
break;
case "Dialoghi":
addDialCla();
//$('#cla' + tabID + '-tab').tab('show');
addDialCla(active);
break;
case "Struttura":
addStruCla();
//$('#cla' + tabID + '-tab').tab('show');
addStruCla(active);
break;
case "andCond":
addLogicCond("AND")
/* case "andCond":
addLogicCond("AND");
refreshConnectWith();
break;
case "orCond":
addLogicCond("OR")
addLogicCond("OR");
refreshConnectWith();
break;
break; */
default:
};
};
refreshTabList();
refreshClaList();
refreshSortables();
};
});