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);
// Evento: click sul bottone di copia dei risultati testuali
$("#copiaTesto").on("click", function(){
$("#risultatitesto").copy2clipboard();
});
@ -107,84 +108,31 @@ $(document).ready(function() {
var addClaN = $(this).attr('id');
switch (addClaN) {
case "Grammaticale":
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>'));
addGramCla();
$('#cla' + tabID + '-tab').tab('show');
break;
case "Sintattico":
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>'));
addSyntCla();
$('#cla' + tabID + '-tab').tab('show');
break;
case "Metafore":
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>'));
addMetaCla();
$('#cla' + tabID + '-tab').tab('show');
break;
case "Dialoghi":
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>'));
addDialCla();
$('#cla' + tabID + '-tab').tab('show');
break;
case "Struttura":
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>'));
addStruCla();
$('#cla' + tabID + '-tab').tab('show');
break;
case "andCond":
condListLen++;
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();}
});
addLogicCond("AND")
refreshConnectWith();
break;
case "orCond":
condListLen++;
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();}
});
addLogicCond("OR")
refreshConnectWith();
break;
default:
@ -239,12 +187,11 @@ $(document).ready(function() {
$("#apriFile").on('change', function() {
var file = $(this).prop('files')[0];
//console.log(file);
var reader = new FileReader();
reader.onload = function(data){
queryJson = JSON.parse(data.target.result)
console.log(queryJson);
$("#sparqlquery").val(data.target.result);
makeUpGui(queryJson);
};
if (file) {reader.readAsText(file);}
});
@ -574,7 +521,7 @@ $(document).ready(function() {
var logicExprString = ``;
var execQuery = ``;
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":""}');
queryJson.LiDaVersion = "1.0";
queryJson.Clausola0 = c0;
@ -587,8 +534,6 @@ $(document).ready(function() {
async function executeQuery(){
//execQuery = sparqlQuery3;
//queryFields = queryFields3;
$("#loader").show();
bindingsStream = await myEngine.queryBindings(execQuery, { sources: [ { type: 'sparql', value: sparqlEndpoint }, ], });
$("#sparqlquery").val(execQuery);
@ -600,6 +545,7 @@ $(document).ready(function() {
var resultTablePart4 = '';
var resultTablePart5 = '</tbody></table>';
var resultTable = '';
var latestVerso = '';
var latestResult = '';
var rowNum = 1;
for (var i = 0; i < queryFields.length; i++) {
@ -609,11 +555,10 @@ $(document).ready(function() {
$('#resultsId1').empty();
$('#resultsId1').addClass("small pb-2")
$("#risultatitesto").empty();
//$("#risultatitesto").append("[\n");
bindingsStream.on('data', (binding) => {
//console.log(binding.toString()); // Quick way to print bindings for testing
//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';
$("#risultatitesto").append(latestResult);
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>";
};
resultTable = resultTable + resultTablePart4 + '</tr>';
//$("#risultatitesto").append(binding.toString() + ",\n");
$("#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', () => {
$("#loader").hide();
resultTable = resultTable + resultTablePart5;
$("#resultsId1").append(resultTable);
//$("#risultatitesto").append("]");
$("#copiaTesto").prop("disabled", false);
$('#resultTable').DataTable( {
colReorder: true,
@ -650,6 +589,79 @@ $(document).ready(function() {
});
};
// 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
function refreshTabList(){
var tabs=$("#tab-list li:not(:first)");
@ -694,7 +706,7 @@ $(document).ready(function() {
var tabsC=$("#cla-TabContent").find(".tab-pane:not(:first)");
var clausoleText = "";
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) {
$(tabsC).each(function(){
if ($("#H-cla0")[0]) {
@ -710,12 +722,12 @@ $(document).ready(function() {
if (claActive > 0) {
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) {
case "Grammaticale":
var graSelect = $(this).find(".catgram");
claText = len + ". Categoria grammaticale: " + graSelect[0].options[graSelect[0].selectedIndex].text + '<br><span class="small ml-3">';
jsonTextToParse = jsonTextToParse + ', "' + graSelect.attr('name') + '": "' + graSelect[0].options[graSelect[0].selectedIndex].value + '"';
var gramSelect = $(this).find(".catgram");
claText = len + ". Categoria grammaticale: " + gramSelect[0].options[gramSelect[0].selectedIndex].text + '<br><span class="small ml-3">';
jsonTextToParse = jsonTextToParse + ', "' + gramSelect.attr('name') + '": "' + gramSelect[0].options[gramSelect[0].selectedIndex].value + '"';
var claSubParList = $(this).children(".dettaglifiltri").find("select, fieldset");
claSubParList.each(function(){
var claSubParType = $(this)[0].type;
@ -836,7 +848,6 @@ $(document).ready(function() {
logicExprString = parseCond("#sortable0", "AND");
$("#sparqlquery").val(logicExprString);
queryJson.EsprLogica = logicExprString.split(' ');
//console.log(queryJson);
};
// 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>');
};
function cambio(event) {
var file = event.target.files[0];
var reader = new FileReader();
reader.onload = function(e) {
// The file's text will be printed here
console.log(e.target.result)
function makeUpGui(queryJson) {
// 1. verifica json legit
// 2. pulire interfaccia
// 3. contare clausole, ricrearle in ordine e popolarle
// 4. ricreare condizioni logiche
// 5. ricreare albero logico
// 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);
}
});