implementazione simple search

This commit is contained in:
cesare 2022-12-12 13:30:59 +01:00
parent 844465c56a
commit e3ff96bb02
3 changed files with 33447 additions and 33616 deletions

View File

@ -43,7 +43,7 @@ $(document).ready(function() {
// prima cantica
$('#cantica1').on('click', function() {
//$("#CantiInferno").attr('style', 'display:block')
$('#cantica1').css({ 'opacity': 1 });
$('#cantica2').css({ 'opacity': 0.40 });
$('#cantica3').css({ 'opacity': 0.40 });
@ -51,8 +51,7 @@ $(document).ready(function() {
// seconda cantica
$('#cantica2').on('click', function() {
//hideMinimap();
//$("#CantiPurgatorio").attr('style', 'display:block')
$('#cantica1').css({ 'opacity': 0.40 });
$('#cantica2').css({ 'opacity': 1 });
$('#cantica3').css({ 'opacity': 0.40 });
@ -61,8 +60,7 @@ $(document).ready(function() {
// terza cantica
$('#cantica3').on('click', function() {
//hideMinimap();
//$("#CantiParadiso").attr('style', 'display:block')
$('#cantica1').css({ 'opacity': 0.40 });
$('#cantica2').css({ 'opacity': 0.40 });
$('#cantica3').css({ 'opacity': 1 });
@ -104,22 +102,12 @@ $(document).ready(function() {
//Query
jQuery(document).delegate('#searchcomm', 'click', function(e) {
cleanSearchResult()
esprlogica = []
esprlogica.push('Clausola1')
condizioni = { "EsprLogica": esprlogica }
clausola = {}
clausola['typeGramm0'] = $('#queryText').val()
clausola['queryText'] = ""
condizioni['Clausola1'] = clausola
jsonQuery = buildSQ(condizioni)
myquery = new sparqlGenerator().stringify(jsonQuery)
executeQuerySearch(myquery)
jQuery(document).delegate('#searchcomm, #searchcomm2', 'click', function(e) {
e.preventDefault();
manageQuery()
});
//Reset
jQuery(document).delegate('#cleanresult', 'click', function(e) {
@ -169,6 +157,20 @@ $(document).ready(function() {
if (currentMinimap != '')
showMinimap(currentMinimap)
}
function manageQuery(){
cleanSearchResult()
esprlogica = []
jsonQuery=getJsonQuery()
console.log("got json query")
jsonQuery = buildSQ(jsonQuery)
myquery = new sparqlGenerator().stringify(jsonQuery)
console.log(myquery)
executeQuerySearch(myquery)
}
//minimap management
@ -213,28 +215,8 @@ $(document).ready(function() {
}
/*
function getDimensions() {
cantoplace = document.getElementById(displayId)
let bodyWidth = cantoplace.clientWidth;
let bodyRatio = bodyWidth / cantoplace.clientHeight
//let winRatio=cantoplace.clientWidth / getInnerHeight(cantoplace)
let winRatio = window.innerHeight / window.innerWidth;
minimap.style.width = '55%';
viewer.style.width = '55%'
realScale = minimap.clientWidth / bodyWidth;
minimapSize.style.paddingTop = `${bodyRatio * 100}%`
viewer.style.paddingTop = `${winRatio * 100}%`;
minimapContent.style.transform = `scale(${realScale})`;
minimapContent.style.width = `${(100 / realScale)}%`;
minimapContent.style.height = `${(100 / realScale)}%`;
}*/
function getInnerHeight(elm) {
var computed = getComputedStyle(elm),
padding = parseInt(computed.paddingTop) + parseInt(computed.paddingBottom);
@ -365,6 +347,7 @@ $(document).ready(function() {
return orderedListaCanti
}
// Search functions
/* async function executeQueryVersi(query) {
bindingsStream = await myEngine.queryBindings(query, { sources: [{ type: 'sparql', value: sparqlEndpoint },], });
@ -523,10 +506,12 @@ $(document).ready(function() {
for (cantica of cantiche) {
i += 1
let count = resultsInCantica.reduce((n, x) => n + (x === cantica), 0);
var spanbadgecantica = $('<span />');
spanbadgecantica.attr('class', 'badge badge-primary badge-pill ml-1');
spanbadgecantica.append(count)
spanbadgecantica.appendTo($('#cantica' + i))
if (count>0){
var spanbadgecantica = $('<span />');
spanbadgecantica.attr('class', 'badge badge-primary badge-pill ml-1');
spanbadgecantica.append(count)
spanbadgecantica.appendTo($('#cantica' + i))
}
}
//aggiunge badge con totale risultati accanto ai canti
@ -535,13 +520,14 @@ $(document).ready(function() {
if (k == 0)
continue
let count = resultsInCanto.reduce((n, x) => n + (x === cantica + 'Canto ' + k), 0);
var spanbadge = $('<span />');
spanbadge.attr('class', cantobadgeclass);
spanbadge.append(count)
//$("[name='nameofobject']")
spanbadge.appendTo($('[name="' + cantica + 'Canto ' + k + '"]'))
//spanbadge.insertAfter($('[name="'+cantica+'Canto '+k+'"]'))
if (count>0){
var spanbadge = $('<span />');
spanbadge.attr('class', cantobadgeclass);
spanbadge.append(count)
//$("[name='nameofobject']")
spanbadge.appendTo($('[name="' + cantica + 'Canto ' + k + '"]'))
//spanbadge.insertAfter($('[name="'+cantica+'Canto '+k+'"]'))
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -76,28 +76,6 @@ LIMIT 20
`
// Per restituire i versi di una cantica
var qVersiCanticaold=`
PREFIX ecrm: <http://erlangen-crm.org/current/>
PREFIX orl: <https://dantenetwork.it/ontology/orl/current/>
PREFIX ontolex: <http://www.w3.org/ns/lemon/ontolex#>
PREFIX olires: <https://dantenetwork.it/ontology/olires/current/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX text: <http://jena.apache.org/text#>
PREFIx hdn: <https://dantenetwork.it/data/commedia/>
SELECT (?textver AS ?Verso) (?NumVerso AS ?NumeroVerso) (?t_canto AS ?Canto) (?t_cantica AS ?Cantica) ?from ?to
WHERE {
?ver ecrm:P190_Has_Symbolic_Content ?textver;
olires:hasNumber ?NumVerso;
olires:OccursInRegion ?reg .
?reg olires:fragmentRegionFrom ?from;
olires:fragmentRegionTo ?to .
?canto ecrm:P102_has_title ?t_canto;
olires:hasStructuralComponent ?ver.
?cantica ecrm:P102_has_title ?t_cantica ;
olires:hasStructuralComponent ?canto.
FILTER regex(?t_cantica,"Inferno","i") .
}`
var qVersiCantica=`
PREFIX ecrm: <http://erlangen-crm.org/current/>
@ -157,31 +135,11 @@ Integer "integer"
_ "whitespace"= " "*
`
var hdnquerygrammartest = `
Expression
= head:((_)?"("(_)?("AND "/"OR ") Filtro+ (_)?(")")?){return '{"'+head[3]+'": ['+head[4]+"]}"}//{ return head}.join("").replaceAll(", ,","").replaceAll("(,","(").replaceAll(",("," (")}
/ resu:Filtro {return resu[1].split().join()+' ';}
Filtro
= (_)"("?head:(("AND "/"OR "))? tail:Clausola+ (_)? closecl:(")")?
{if (head != null) return ' {"'+head+'":['+tail+"]}";
else if (tail!=null & tail.length <2) return ' '+tail+''
else return ""+tail+"";}
/ cl:Clausola
Clausola
= cla:("Clausola"Integer)(_)? {return ' {"TERM": "'+cla[0]+cla[1]+'"}';}
Integer "integer"
= _ [0-9]+ { return parseInt(text(), 10); }
_ "whitespace"= " "*
`
var testmm = 0
//query
ontoSparqlQuery = `PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ecrm: <http://erlangen-crm.org/current/>
PREFIX hdn: <http://dantenetwork.it/data/commedia/>
@ -194,26 +152,24 @@ PREFIX comm: <http://dantenetwork.it/data/commedia/>
SELECT (?form as ?IRIForma) (?Rappresentazione as ?Forma) (?lm as ?Lemma) (?textver as ?Verso) (?NumVerso as ?NumeroVerso)
(?t_canto as ?Canto) (?t_cantica as ?Cantica) ?pos
WHERE {
?fa orl:occurrenceOf ?form.
FILTER(REGEX(?Rappresentazione, "^andare$", "i")) .
FILTER(LANGMATCHES(LANG(?Rappresentazione), "it"))
?form ontolex:writtenRep ?Rappresentazione.
?fa orl:occurrenceOf ?form;
olires:OccursInRegion ?reg .
?ver ecrm:P190_Has_Symbolic_Content ?textver;
olires:hasNumber ?NumVerso;
olires:hasStructuralComponent ?fa.
?fa olires:OccursInRegion ?reg .
?reg olires:fragmentRegionFrom ?pos .
?reg olires:fragmentRegionFrom ?pos .
?canto ecrm:P102_has_title ?t_canto;
olires:hasStructuralComponent ?ver.
?cantica ecrm:P102_has_title ?t_cantica;
olires:hasStructuralComponent ?canto.
?form ontolex:writtenRep ?Rappresentazione.
?lent ontolex:lexicalForm ?form;
ontolex:canonicalForm ?cf.
?cf ontolex:writtenRep ?lm.
FILTER(LANGMATCHES(LANG(?Rappresentazione), "it"))
} `
//Togliere LIMIT in prod
}`
orlprefix = 'https://dantenetwork.it/ontology/orl/current/'
var stringInSparql= false;
@ -355,50 +311,9 @@ function buildSQ(stquery) {
//Prendo la query SPARQL template
const parsedquery = parser.parse(ontoSparqlQuery);
//const parsedquery = parser.parse(tqvpvs);
const lf = document.getElementById("lemma_forma");
//mytestq = parser.parse(tq);
var ftxt = document.getElementById("queryText");
//Nick
if (ftxt == null) {
ftxt = document.getElementById("searchValue");
/*
//definizione struttura della query
var EsprLogica = ""
filters = $("[id^=filtro-]")
term = "";
filters.each(function(index, element) {
var mx = $(this).find('#andor');
if (index == 0) {
EsprLogica += ''
term = $(this).attr('id')
}
else {
EsprLogica = "(" + mx.val() + " " + term + " " + $(this).attr('id') + ") "
term = EsprLogica
}
});
stquery['EsprLogica'] = EsprLogica.split(" ")
// fine definizione struttura
*/
if (stquery['EsprLogica'] != '') {
if (stquery['query'] != null && clause['query'].trim() != "") {
if (clause['query'].trim().slice(-1) !== '*')
strval = "^" + clause['query'].trim() + "$";
else
strval = clause['query'].trim().slice(0, -1)
multipleCondSpQuery.where[1].expression.args[1].value = strval;
if (clause['lemma_forma'] != null && clause['lemma_forma'] == 'lemma')
multipleCondSpQuery.where[1].expression.args[0].value = "lm";
}
buildSPQuery(stquery)
return multipleCondSpQuery;
}
myquery = buildClauseNick(stquery, parsedquery);
return (myquery)
}
if (stquery['EsprLogica'] != null && stquery['EsprLogica'].length > 1) {
buildSPQuery(stquery)
@ -412,76 +327,36 @@ function buildSQ(stquery) {
return (myquery)
}
if (ftxt.value.trim() != "") {
if(stquery['Clausola0']['queryText']!= ""){
searchtext=stquery['Clausola0']['queryText']
strval=searchtext
if(stquery['Clausola0']['opzioni_testo']=='parola'){
strval = "^" + searchtext.trim() + "$";
}
if(stquery['Clausola0']['opzioni_testo']=='sottostringa'){
strval = searchtext.trim();
}
if(stquery['Clausola0']['opzioni_testo']=='suffisso'){
strval = searchtext.trim()+ "$";
}
if(stquery['Clausola0']['opzioni_testo']=='prefisso'){
strval = "^" +searchtext.trim();
}
//COMPLETARE con regexp
if (ftxt.value.trim().slice(-1) !== '*')
strval = "^" + ftxt.value.trim() + "$";
else
strval = ftxt.value.trim().slice(0, -1)
parsedquery.where[1].expression.args[1].value = strval;
if (lf.value == 'lemma')
parsedquery.where[1].expression.args[0].value = "lm";
parsedquery.where[0].expression.args[1].value = strval;
if (stquery['Clausola0']['lemma_forma'] == 'lemma')
parsedquery.where[0].expression.args[0].value = "lm";
}
else {
parsedquery.where.splice(1, 1)
parsedquery.where.splice(0, 1)
}
return (parsedquery)
}
//Nick
function buildClauseNick(nickclause, parsedquery) {
//clause = clause['filtro-1'];//da modificare
sctk = Object.keys(nickclause)
clause={}
for (ck in sctk){
if (sctk[ck].includes("filtro-")){
clause = nickclause [sctk[ck]]
break
}
}
if (clause['query'] != null && clause['query'].trim() != "") {
if (clause['query'].trim().slice(-1) !== '*')
strval = "^" + clause['query'].trim() + "$";
else
strval = clause['query'].trim().slice(0, -1)
parsedquery.where[1].expression.args[1].value = strval;
if (clause['lemma_forma'] != null && clause['lemma_forma'] == 'lemma')
parsedquery.where[1].expression.args[0].value = "lm";
}
else {
parsedquery.where.splice(1, 1)
}
if (clause['categoria'] != null && clause['categoria'] != "all")
parsedquery.where[0].triples.push(JSON.parse(data21)[clause['categoria']]);
if (clause['tipoClausola'] != null && Object.keys(sottoCategorie).includes(clause['categoria'].trim())) {
//sctmp=JSON.parse(sottoCategorieSostantivi)
sctmp = sottoCategorie[clause['categoria'].trim()]
sctk = Object.keys(sctmp)
for (ke in sctk) {
keval = clause[encodeURI(sctk[ke])]
if (keval != null && keval != '') {
keval = decodeURI(keval)
sttmts = sctmp[sctk[ke]]
if (sttmts[keval] != null && (sttmts[keval].split(':')[1]) != null) {
subcatstat = buildsubcategoryClause(sttmts[keval])
parsedquery.where[0].triples.push(subcatstat);
}
}
}
}
return parsedquery
}
function buildJsonClause(clause, parsedquery, whereind, theplace) {
//Nick
@ -611,37 +486,7 @@ function buildsubcategoryClause(sttmnt) {
}
/*
//autocomplete
var categorie = ['aggettivovolgare', 'articolovolgare', 'avverbiovolgare',
'citazionevolgare', 'congiunzionevolgare', 'interiezionevolgare',
'locuzionevolgare', 'onomasticavolgare', 'preposizionevolgare',
'pronomevolgare', 'sostantivovolgare','verbovolgare'];
function autocompleteMatch(input) {
if (input == '') {
return [];
}
var reg = new RegExp(input)
return categorie.filter(function(term) {
if (term.match(reg)) {
return term;
}
});
}
function showResults(val) {
res = document.getElementById("aco");
res.innerHTML = '';
let list = '';
let terms = autocompleteMatch(val);
for (i=0; i<terms.length; i++) {
list += '<li>' + terms[i] + '</li>';
}
res.innerHTML = '<ul>' + list + '</ul>';
}
*/
var sottoCategorie = {
"verbovolgare": {
"Diatesi": { "Attivo": "TipoDiatesiVerboVolgare:VerboVolgareAttivo", "Passivo": "TipoDiatesiVerboVolgare:VerboVolgarePassivo" },