Tipo --> TipoClausola

This commit is contained in:
Luca Trupiano 2022-10-05 15:07:11 +02:00
parent bae9bb95c2
commit 2732749b6b
1 changed files with 158 additions and 93 deletions

View File

@ -12,6 +12,7 @@ $(document).ready(function() {
$("#copiaTesto").prop("disabled", true); $("#copiaTesto").prop("disabled", true);
// Evento: click sul bottone di copia dei risultati testuali
$("#copiaTesto").on("click", function(){ $("#copiaTesto").on("click", function(){
$("#risultatitesto").copy2clipboard(); $("#risultatitesto").copy2clipboard();
}); });
@ -107,84 +108,31 @@ $(document).ready(function() {
var addClaN = $(this).attr('id'); var addClaN = $(this).attr('id');
switch (addClaN) { switch (addClaN) {
case "Grammaticale": case "Grammaticale":
tabID++; addGramCla();
var clone = document.getElementById("tipogrammaticaleN").cloneNode(true);
clone.setAttribute("id","cla" + tabID);
clone.setAttribute("aria-labelledby","cla" + tabID + "-tab");
clone.removeAttribute("style");
$('#cla-TabContent').append(clone);
// se non cambio l'id della select react non rileva l'evento onchange:
$('#cla' + tabID + " #grammtypes").attr("id","grammtypes" + tabID);
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="Grammaticale"><span class="small font-weight-bold text-lida8">' + iconFilter + '&nbsp;&nbsp;' + claListLen + '. Grammaticale</span></a></li>'));
$('#cla' + tabID + '-tab').tab('show'); $('#cla' + tabID + '-tab').tab('show');
break; break;
case "Sintattico": case "Sintattico":
tabID++; addSyntCla();
var clone = document.getElementById("tiposintatticoN").cloneNode(true);
clone.setAttribute("id","cla" + tabID);
clone.setAttribute("aria-labelledby","cla" + tabID + "-tab");
clone.removeAttribute("style");
$('#cla-TabContent').append(clone);
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="Sintattico"><span class="small font-weight-bold text-lida9">' + iconFilter + '&nbsp;&nbsp;' + claListLen + '. Sintattico</span></a></li>'));
$('#cla' + tabID + '-tab').tab('show'); $('#cla' + tabID + '-tab').tab('show');
break; break;
case "Metafore": case "Metafore":
tabID++; addMetaCla();
$('#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>'));
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>'));
$('#cla' + tabID + '-tab').tab('show'); $('#cla' + tabID + '-tab').tab('show');
break; break;
case "Dialoghi": case "Dialoghi":
tabID++; addDialCla();
$('#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>'));
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>'));
$('#cla' + tabID + '-tab').tab('show'); $('#cla' + tabID + '-tab').tab('show');
break; break;
case "Struttura": case "Struttura":
tabID++; addStruCla();
$('#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>'));
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>'));
$('#cla' + tabID + '-tab').tab('show'); $('#cla' + tabID + '-tab').tab('show');
break; break;
case "andCond": case "andCond":
condListLen++; addLogicCond("AND")
var LItext = condLIpart1 + condListLen + condLIpart2and + condListLen + condLIpart3and + condListLen + condLIpart4;
if ($("#H-cla0")[0]) {
$("#H-cla0")[0].remove();
};
$("#sortable0").append(LItext);
$("#sortable" + condListLen).sortable();
$("#sortable" + condListLen).sortable( "option", "appendTo", document.body );
$("#sortable" + condListLen).sortable({
items: "> li",
handle: ".handle",
opacity: 0.6,
cursor: 'move',
update: function() {refreshSortables();}
});
refreshConnectWith(); refreshConnectWith();
break; break;
case "orCond": case "orCond":
condListLen++; addLogicCond("OR")
var LItext = condLIpart1 + condListLen + condLIpart2or + condListLen + condLIpart3or + condListLen + condLIpart4;
if ($("#H-cla0")[0]) {
$("#H-cla0")[0].remove();
};
$("#sortable0").append(LItext);
$("#sortable" + condListLen).sortable();
$("#sortable" + condListLen).sortable( "option", "appendTo", document.body );
$("#sortable" + condListLen).sortable({
items: "> li",
handle: ".handle",
opacity: 0.6,
cursor: 'move',
update: function() {refreshSortables();}
});
refreshConnectWith(); refreshConnectWith();
break; break;
default: default:
@ -239,12 +187,11 @@ $(document).ready(function() {
$("#apriFile").on('change', function() { $("#apriFile").on('change', function() {
var file = $(this).prop('files')[0]; var file = $(this).prop('files')[0];
//console.log(file);
var reader = new FileReader(); var reader = new FileReader();
reader.onload = function(data){ reader.onload = function(data){
queryJson = JSON.parse(data.target.result) queryJson = JSON.parse(data.target.result)
console.log(queryJson);
$("#sparqlquery").val(data.target.result); $("#sparqlquery").val(data.target.result);
makeUpGui(queryJson);
}; };
if (file) {reader.readAsText(file);} if (file) {reader.readAsText(file);}
}); });
@ -574,7 +521,7 @@ $(document).ready(function() {
var logicExprString = ``; var logicExprString = ``;
var execQuery = ``; var execQuery = ``;
var queryFields = []; // Contiene le intestazioni di colonna della tabella dei risultati var queryFields = []; // Contiene le intestazioni di colonna della tabella dei risultati
var c0 = JSON.parse('{"queryText": "", "lemma_forma": "lemma", "Tipo": "0", "Attiva": "0"}'); var c0 = JSON.parse('{"queryText": "", "lemma_forma": "lemma", "TipoClausola": "0", "Attiva": "0"}');
var queryJson = JSON.parse('{"EsprLogica":""}'); var queryJson = JSON.parse('{"EsprLogica":""}');
queryJson.LiDaVersion = "1.0"; queryJson.LiDaVersion = "1.0";
queryJson.Clausola0 = c0; queryJson.Clausola0 = c0;
@ -587,8 +534,6 @@ $(document).ready(function() {
async function executeQuery(){ async function executeQuery(){
//execQuery = sparqlQuery3;
//queryFields = queryFields3;
$("#loader").show(); $("#loader").show();
bindingsStream = await myEngine.queryBindings(execQuery, { sources: [ { type: 'sparql', value: sparqlEndpoint }, ], }); bindingsStream = await myEngine.queryBindings(execQuery, { sources: [ { type: 'sparql', value: sparqlEndpoint }, ], });
$("#sparqlquery").val(execQuery); $("#sparqlquery").val(execQuery);
@ -600,6 +545,7 @@ $(document).ready(function() {
var resultTablePart4 = ''; var resultTablePart4 = '';
var resultTablePart5 = '</tbody></table>'; var resultTablePart5 = '</tbody></table>';
var resultTable = ''; var resultTable = '';
var latestVerso = '';
var latestResult = ''; var latestResult = '';
var rowNum = 1; var rowNum = 1;
for (var i = 0; i < queryFields.length; i++) { for (var i = 0; i < queryFields.length; i++) {
@ -609,11 +555,10 @@ $(document).ready(function() {
$('#resultsId1').empty(); $('#resultsId1').empty();
$('#resultsId1').addClass("small pb-2") $('#resultsId1').addClass("small pb-2")
$("#risultatitesto").empty(); $("#risultatitesto").empty();
//$("#risultatitesto").append("[\n");
bindingsStream.on('data', (binding) => { bindingsStream.on('data', (binding) => {
//console.log(binding.toString()); // Quick way to print bindings for testing //console.log(binding.toString()); // Quick way to print bindings for testing
//console.log(binding.has('sub')); // Will be true //console.log(binding.has('sub')); // Will be true
var latestVerso = binding.get('Verso').value latestVerso = binding.get('Verso').value
latestResult = rowNum + '. "' + latestVerso.replace(binding.get('Forma').value, '*' + binding.get('Forma').value + '*') + '" (' + binding.get('Cantica').value + ', ' + binding.get('Canto').value + ', Verso ' + binding.get('NumeroVerso').value + ')\n'; latestResult = rowNum + '. "' + latestVerso.replace(binding.get('Forma').value, '*' + binding.get('Forma').value + '*') + '" (' + binding.get('Cantica').value + ', ' + binding.get('Canto').value + ', Verso ' + binding.get('NumeroVerso').value + ')\n';
$("#risultatitesto").append(latestResult); $("#risultatitesto").append(latestResult);
resultTablePart4 = '<tr><th scope="row" class="text-muted">' + rowNum++ + '</th>'; resultTablePart4 = '<tr><th scope="row" class="text-muted">' + rowNum++ + '</th>';
@ -621,18 +566,12 @@ $(document).ready(function() {
resultTablePart4 = resultTablePart4 + '<td class="text-muted">' + binding.get(queryFields[i]).value + "</td>"; resultTablePart4 = resultTablePart4 + '<td class="text-muted">' + binding.get(queryFields[i]).value + "</td>";
}; };
resultTable = resultTable + resultTablePart4 + '</tr>'; resultTable = resultTable + resultTablePart4 + '</tr>';
//$("#risultatitesto").append(binding.toString() + ",\n");
$("#loader").hide(); $("#loader").hide();
//console.log(binding.get('Verso').value);
//console.log(binding.get('form').termType);
//console.log(binding.get('pred').value);
//console.log(binding.get('obj').value);
}); });
bindingsStream.on('end', () => { bindingsStream.on('end', () => {
$("#loader").hide(); $("#loader").hide();
resultTable = resultTable + resultTablePart5; resultTable = resultTable + resultTablePart5;
$("#resultsId1").append(resultTable); $("#resultsId1").append(resultTable);
//$("#risultatitesto").append("]");
$("#copiaTesto").prop("disabled", false); $("#copiaTesto").prop("disabled", false);
$('#resultTable').DataTable( { $('#resultTable').DataTable( {
colReorder: true, colReorder: true,
@ -649,7 +588,80 @@ $(document).ready(function() {
},300); },300);
}); });
}; };
// Funzione di creazione del tab delle clausole grammaticali
function addGramCla(){
tabID++;
var clone = document.getElementById("tipogrammaticaleN").cloneNode(true);
clone.setAttribute("id","cla" + tabID);
clone.setAttribute("aria-labelledby","cla" + tabID + "-tab");
clone.removeAttribute("style");
$('#cla-TabContent').append(clone);
// se non cambio l'id della select react non rileva l'evento onchange:
$('#cla' + tabID + " #grammtypes").attr("id","grammtypes" + tabID);
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="Grammaticale"><span class="small font-weight-bold text-lida8">' + iconFilter + '&nbsp;&nbsp;' + claListLen + '. Grammaticale</span></a></li>'));
}
// Funzione di creazione del tab delle clausole sintattiche
function addSyntCla(){
tabID++;
var clone = document.getElementById("tiposintatticoN").cloneNode(true);
clone.setAttribute("id","cla" + tabID);
clone.setAttribute("aria-labelledby","cla" + tabID + "-tab");
clone.removeAttribute("style");
$('#cla-TabContent').append(clone);
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="Sintattico"><span class="small font-weight-bold text-lida9">' + iconFilter + '&nbsp;&nbsp;' + claListLen + '. Sintattico</span></a></li>'));
}
// Funzione di creazione del tab delle clausole metafore
function addMetaCla(){
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>'));
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(){
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>'));
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(){
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>'));
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>'));
}
// Funzione di creazione del LI delle condizioni logiche
function addLogicCond(condtype){
condListLen++;
if (condtype == "AND") {
var LItext = condLIpart1 + condListLen + condLIpart2and + condListLen + condLIpart3and + condListLen + condLIpart4;
} else {
var LItext = condLIpart1 + condListLen + condLIpart2or + condListLen + condLIpart3or + condListLen + condLIpart4;
}
if ($("#H-cla0")[0]) {
$("#H-cla0")[0].remove();
};
$("#sortable0").append(LItext);
$("#sortable" + condListLen).sortable();
$("#sortable" + condListLen).sortable( "option", "appendTo", document.body );
$("#sortable" + condListLen).sortable({
items: "> li",
handle: ".handle",
opacity: 0.6,
cursor: 'move',
update: function() {refreshSortables();}
});
}
// Funzione di refresh della lista delle tab delle clausole // Funzione di refresh della lista delle tab delle clausole
function refreshTabList(){ function refreshTabList(){
var tabs=$("#tab-list li:not(:first)"); var tabs=$("#tab-list li:not(:first)");
@ -694,7 +706,7 @@ $(document).ready(function() {
var tabsC=$("#cla-TabContent").find(".tab-pane:not(:first)"); var tabsC=$("#cla-TabContent").find(".tab-pane:not(:first)");
var clausoleText = ""; var clausoleText = "";
var len=0; var len=0;
queryJson.Clausola0 = JSON.parse('{"queryText": "' + qText + '", "lemma_forma": "' + l_f + '", "Tipo": "0", "Attiva": "' + claActive + '"}'); queryJson.Clausola0 = JSON.parse('{"queryText": "' + qText + '", "lemma_forma": "' + l_f + '", "TipoClausola": "0", "Attiva": "' + claActive + '"}');
if ($(tabsC).length) { if ($(tabsC).length) {
$(tabsC).each(function(){ $(tabsC).each(function(){
if ($("#H-cla0")[0]) { if ($("#H-cla0")[0]) {
@ -710,12 +722,12 @@ $(document).ready(function() {
if (claActive > 0) { if (claActive > 0) {
checkInsert = '" checked="checked"'; checkInsert = '" checked="checked"';
}; };
var jsonTextToParse = '{"queryText": "' + qText + '", "lemma_forma": "' + l_f + '", "Tipo": "' + claType + '", "Attiva": "' + claActive + '"'; var jsonTextToParse = '{"queryText": "' + qText + '", "lemma_forma": "' + l_f + '", "TipoClausola": "' + claType + '", "Attiva": "' + claActive + '"';
switch (claType) { switch (claType) {
case "Grammaticale": case "Grammaticale":
var graSelect = $(this).find(".catgram"); var gramSelect = $(this).find(".catgram");
claText = len + ". Categoria grammaticale: " + graSelect[0].options[graSelect[0].selectedIndex].text + '<br><span class="small ml-3">'; claText = len + ". Categoria grammaticale: " + gramSelect[0].options[gramSelect[0].selectedIndex].text + '<br><span class="small ml-3">';
jsonTextToParse = jsonTextToParse + ', "' + graSelect.attr('name') + '": "' + graSelect[0].options[graSelect[0].selectedIndex].value + '"'; jsonTextToParse = jsonTextToParse + ', "' + gramSelect.attr('name') + '": "' + gramSelect[0].options[gramSelect[0].selectedIndex].value + '"';
var claSubParList = $(this).children(".dettaglifiltri").find("select, fieldset"); var claSubParList = $(this).children(".dettaglifiltri").find("select, fieldset");
claSubParList.each(function(){ claSubParList.each(function(){
var claSubParType = $(this)[0].type; var claSubParType = $(this)[0].type;
@ -836,7 +848,6 @@ $(document).ready(function() {
logicExprString = parseCond("#sortable0", "AND"); logicExprString = parseCond("#sortable0", "AND");
$("#sparqlquery").val(logicExprString); $("#sparqlquery").val(logicExprString);
queryJson.EsprLogica = logicExprString.split(' '); queryJson.EsprLogica = logicExprString.split(' ');
//console.log(queryJson);
}; };
// Funzione di refresh dei collegamenti tra elementi sortable // Funzione di refresh dei collegamenti tra elementi sortable
@ -906,22 +917,76 @@ $(document).ready(function() {
$(this).after('<div class="mt-2 text-lida3" id="msgCopiati">Copiati nella clipboard</div>'); $(this).after('<div class="mt-2 text-lida3" id="msgCopiati">Copiati nella clipboard</div>');
}; };
function makeUpGui(queryJson) {
function cambio(event) { // 1. verifica json legit
var file = event.target.files[0]; // 2. pulire interfaccia
var reader = new FileReader(); // 3. contare clausole, ricrearle in ordine e popolarle
reader.onload = function(e) { // 4. ricreare condizioni logiche
// The file's text will be printed here // 5. ricreare albero logico
console.log(e.target.result) // 6. ???
var logicExpr = queryJson.EsprLogica;
var clauCount = 0;
var clau2Make = "";
console.log(logicExpr);
for (var i=0; i < logicExpr.length; i++) {
//console.log("- " + logicExpr[i]);
switch (logicExpr[i]) {
case "(":
console.log("(");
break;
case ")":
console.log(")");
break;
case "OR":
console.log("OR");
break;
case "AND":
console.log("AND");
break;
default:
clauCount++
};
}; };
reader.readAsText(file); console.log(clauCount + " clausole:");
for (var i=1; i <= clauCount; i++) {
clau2Make = queryJson["Clausola" + i].TipoClausola;
console.log(clau2Make);
switch (clau2Make) {
case "Grammaticale":
addGramCla();
//$('#cla' + tabID + '-tab').tab('show');
break;
case "Sintattico":
addSyntCla();
//$('#cla' + tabID + '-tab').tab('show');
break;
case "Metafore":
addMetaCla();
//$('#cla' + tabID + '-tab').tab('show');
break;
case "Dialoghi":
addDialCla();
//$('#cla' + tabID + '-tab').tab('show');
break;
case "Struttura":
addStruCla();
//$('#cla' + tabID + '-tab').tab('show');
break;
case "andCond":
addLogicCond("AND")
refreshConnectWith();
break;
case "orCond":
addLogicCond("OR")
refreshConnectWith();
break;
default:
};
};
refreshTabList();
refreshClaList();
}; };
function cloneClaSint(clone,tabID){
var original = document.getElementById("tiposintatticoX");
clone = original.cloneNode(true);
clone.setAttribute("id","tiposintattico" + tabID);
}
}); });