From 371ba234db6ae910e8d12907d9f63cc68f782936 Mon Sep 17 00:00:00 2001
From: cesare <cesare@bigeh>
Date: Thu, 6 Mar 2025 16:19:31 +0100
Subject: [PATCH] bug fixing, query sulla posizione in progress

---
 js/browseMgr_5.1.js | 22 ++++++++++------
 js/utilsMgr_5.1.js  | 62 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 75 insertions(+), 9 deletions(-)

diff --git a/js/browseMgr_5.1.js b/js/browseMgr_5.1.js
index 8438b0a..8b56c09 100644
--- a/js/browseMgr_5.1.js
+++ b/js/browseMgr_5.1.js
@@ -1405,7 +1405,8 @@ $(document).ready(function() {
 
 
 		var details = [];
-		var lemma = categ.split('#')[1].replace("^", " ") //il lemma
+		//var lemma = categ.split('#')[1].replace("^", " ") //il lemma
+		var lemma = categ.split('#')[1].split("^") //il lemma
 		var categoria = categ.split('#')[0] // la categoria
 		var details = getHoverContent(categoria);
 
@@ -1422,13 +1423,13 @@ $(document).ready(function() {
 
 		}
 
-
+		var ile=-1
 		for (var detail of details) {
-
+			ile+=1
 			myitems = detail.split(',');
 
 			catgramm = '<div  class="ttContent">';
-			subcatgramm = '<p> <b> ' + lemma + ' - </b><i>' + myitems[0] + ',' + myitems.slice(1) + '</i></p></div>';
+			subcatgramm = '<p> <b> ' + lemma[ile] + ' -</b><i> ' + myitems[0] + ',' + myitems.slice(1) + '</i></p></div>';
 			popoverText = popoverText + catgramm + subcatgramm;
 		}
 
@@ -2143,7 +2144,7 @@ $(document).ready(function() {
 							resSent.add(fraseItems[0] + '-' + fraseItems[3] + '-' + fraseItems[1] + '-' + fraseItems[2]);
 							//if (!resSent.has(fraseItems[0] + '-' + fraseItems[3])) {
 							let tmpocc = fraseItems.slice(-1)
-
+							
 							if (resClauses.filter(clocc => clocc == tmpocc[0]).length == 0 || tmpocc[0] == '') {
 								resClauses.push(tmpocc[0]);
 								//resSent.add(fraseItems[0] + '-' + fraseItems[3]+'-'+fraseItems[1] + '-' + fraseItems[2]);
@@ -2153,6 +2154,7 @@ $(document).ready(function() {
 								resultsInCanto.push(fraseItems[4] + fraseItems[5]);
 
 							}
+							
 						}
 						listaClausoleRisultato = Array.from(resSent);
 					}
@@ -2342,6 +2344,9 @@ $(document).ready(function() {
 			}
 		}
 	}
+	
+	
+	
 	/*
 	*	REGOLE DI PARSING PER VISUALIZZAZIONE CATEGORIE GRAMMATICALI 
 	*/
@@ -2570,16 +2575,16 @@ _ "whitespace"= " "*
 	var pronome = `
 
 Expression = head:(Filtro){return 'Pronome,'+head.join()}
-Filtro= fhead:("p")? tail:(  tipo_pronome? classe_pronome? genere_pronome? 
+Filtro= fhead:("p")? tail:(  tipo_pronome* classe_pronome? genere_pronome? 
 		numero_pronome?  forma_pronome? funzione_pronome? tiporiflessivi?){return tail}
     
 
 tipo_pronome= "p" {return(' Pronome Personale')}/
+			  "d" {return(" Pronome Dimostrativo")}/
 			  "f" {return(" Pronome Riflessivo")}/
 			  "s" {return(" Pronome Possessivo")}/
-              "d" {return(" Pronome Dimostrativo")}/
+			  "r" {return(" Pronome Relativo")}/
               "i" {return(" Pronome Indefinito")}/
-              "r" {return(" Pronome Relativo")}/
               "t" {return(" Pronome Interrogativo")}/
               "e" {return(" Pronome Esclamativo")}/
               "n" {return(" Pronome Numerale")} 
@@ -2812,6 +2817,7 @@ _ "whitespace"= " "*
 	var parserCitazione = peg.generate(citazione);
 	var parserOnomastica = peg.generate(onomastica);
 	var parserCongiunzione = peg.generate(congiunzione);
+	
 
 
 });
diff --git a/js/utilsMgr_5.1.js b/js/utilsMgr_5.1.js
index 2ae62cf..c755577 100644
--- a/js/utilsMgr_5.1.js
+++ b/js/utilsMgr_5.1.js
@@ -121,8 +121,29 @@ const maptypes = {
 	"ParentheticalCoI": "Coordinata alla parentetica I grado", "SubVII": "Subordinata VII grado"
 }
 
+/*
+	* regole di parsing per il filtro
+	*/
+	
 
 
+	const filterposition=`
+	Filter = head:(interval? val?) {return head}
+
+		interval= limitinf? limitsup?
+
+		limitsup= head:(Integer) "]" {return head}
+		  
+		limitinf = "[" tail:(Integer) {return tail}
+
+		val = vhead:(Integer){return vhead}
+		
+		Integer "integer"= _ [0-9]+ { return parseInt(text(), 10); }
+	_ "whitespace"= " "*`
+
+//Filtro posizione
+var parserFiltroPosizione=peg.generate(filterposition);
+
 var orlprefix = 'https://dantenetwork.it/ontology/orl/current/'
 
 var syntitprefix = 'https://dantenetwork.it/ontology/syntit/current/'
@@ -812,7 +833,8 @@ function buildStatementClause(clause, parsedquery, whereind, theplace, token, op
 				if (op == 'OR') {
 					clausePosCoalesceStatement['expression']['args'].push(JSON.parse(tmppos))
 					var orfilter = JSON.parse(clausepos_gr_filter.replaceAll("pos_", "pos" + idtokenor))
-
+					
+					
 					if (orfilters.length == 0 || !orfilters.includes(JSON.stringify(orfilter))) {
 						if (parsedquery['where'].at(-1).type == "filter") {
 							var texp = JSON.parse(JSON.stringify(parsedquery['where'].at(-1).expression))
@@ -832,7 +854,45 @@ function buildStatementClause(clause, parsedquery, whereind, theplace, token, op
 				else {
 					parsedquery['variables'].push(JSON.parse(tmppos))
 					var andfilter = clausepos_gr_filter.replaceAll("pos_", "pos" + token)
+					//TEST
+					if (document.querySelector('#Posizione_fr')!=null &&
+						document.querySelector('#Posizione_fr').value.trim()!=''){
+							var posrestr=document.querySelector('#Posizione_fr').value
+							var pospar=parserFiltroPosizione.parse(posrestr.trim())
+							if (pospar[1]!=null){
+								andfilter=andfilter.replace('<=', '=')
+								andfilter=andfilter.replace('clfr', 'clfr+'+(parseInt(pospar[1])-1))
+							}
+							else{
+								var inter=pospar[0]
+								if (inter[0]!=null){
+								 	andfilter=andfilter.replace('clfr', 'clfr+'+(parseInt(inter[0])-1))
+								}
+								if (inter[1]!=null){
+									var newarg=`{
+												"type": "operation",
+									                "operator": ">",
+									                "args": [
+									                    {
+									                        "termType": "Variable",
+									                        "value": "clfr"
+									                    },
+									                    {
+									                        "termType": "Variable",
+									                        "value": "pos_"
+									                    }
+									                ]
+									 }`
+									 newarg=newarg.replace("clfr", "clfr+"+parseInt(inter[1]))
+									 var tmpij=JSON.parse(andfilter)
+									tmpij.expression.args.push(JSON.parse(newarg))
+									andfilter=JSON.stringify(tmpij)
+								}
+							}
+					}
+					
 					parsedquery['where'].push(JSON.parse(andfilter))
+					
 				}