From 9ad7e9a818f5f7d2a7ca501e4cf4de7d0d19b08c Mon Sep 17 00:00:00 2001 From: cesare Date: Thu, 23 May 2024 08:26:42 +0200 Subject: [PATCH] refactoring del codice --- js/sparqltemplates.js | 318 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 318 insertions(+) create mode 100644 js/sparqltemplates.js diff --git a/js/sparqltemplates.js b/js/sparqltemplates.js new file mode 100644 index 0000000..5548899 --- /dev/null +++ b/js/sparqltemplates.js @@ -0,0 +1,318 @@ +/** + * + */ + +//query per le simple search con condizioni sulla clausola grammaticale + +var ontoSparqlQuery = `PREFIX rdfs: +PREFIX ecrm: +PREFIX hdn: +PREFIX lemon: +PREFIX orl: +PREFIX xsd: +PREFIX ontolex: +PREFIX olires: +PREFIX comm: +PREFIX syntit: + +SELECT (?t_canto as ?Canto) (?t_cantica as ?Cantica) ?clatype ?clafunction ?clfr ?clto ?cl ?sentence ?cltext ?pos ?clocc +WHERE { + FILTER(REGEX(?Rappresentazione, "^buon$", "i")) . + FILTER(LANGMATCHES(LANG(?Rappresentazione), "it")) + ###condizioni grammaticali + { + + ?form ontolex:writtenRep ?Rappresentazione. + ?lent ontolex:lexicalForm ?form; + ontolex:canonicalForm ?cf. + ?cf ontolex:writtenRep ?lm. + ?fa olires:occurrenceOf ?form; + olires:OccursInRegion ?reg . + ?reg olires:fragmentRegionFrom ?pos . + } + ###end + ###condizioni sintattiche + { + ?clocc olires:occurrenceOf ?cl ; + ecrm:P148_has_component ?fa ; #condizione join grammaticale sintattica + olires:occursInRegion ?frag . + + ?sentence a syntit:Sentence ; + ecrm:P148i_is_component_of ?canto; + syntit:hasSyntacticalComponent ?cl. + + ?cl syntit:hasClauseType ?clatype ; + ecrm:P190_has_symbolic_content ?cltext ; + syntit:hasClauseFunction ?clafunction. + + ?frag olires:fragmentRegionFrom ?clfr ; + olires:fragmentRegionTo ?clto . + } + ### end + ### condizioni comuni + + ?canto ecrm:P102_has_title ?t_canto; + olires:hasNumber ?num . + ?cantica ecrm:P102_has_title ?t_cantica; + olires:hasStructuralComponent ?canto. + # FILTER (?t_cantica in ("Inferno", "Purgatorio")) + # FILTER (?num IN ("12"^^xsd:short, "4"^^xsd:short ) ) + ### end + }` + + +//Query generica per advanced search con piu condizioni + +var ontoSparqlQueryMultCond = `PREFIX rdfs: +PREFIX ecrm: +PREFIX hdn: +PREFIX lemon: +PREFIX orl: +PREFIX xsd: +PREFIX ontolex: +PREFIX olires: +PREFIX comm: +PREFIX syntit: +PREFIX rdf: + +SELECT (?t_canto as ?Canto) (?t_cantica as ?Cantica) ?clatype ?clafunction ?clfr ?clto ?cl ?sentence ?pos ?clocc +WHERE { + FILTER(REGEX(?Rappresentazione, "^buon$", "i")) . + FILTER(LANGMATCHES(LANG(?Rappresentazione), "it")) + + ### condizioni + ?canto ecrm:P102_has_title ?t_canto; + olires:hasNumber ?num . + ?cantica ecrm:P102_has_title ?t_cantica; + olires:hasStructuralComponent ?canto. + ###condizioni end + ###condizioni sintattiche + { + ?clocc olires:occurrenceOf ?cl ; + ecrm:P148_has_component ?fa ; # join grammaticale sintattica + olires:occursInRegion ?frag . + + ?sentence a syntit:Sentence ; + ecrm:P148i_is_component_of ?canto; + syntit:hasSyntacticalComponent ?cl. + + ?cl syntit:hasClauseType ?clatype ; + ecrm:P190_has_symbolic_content ?cltext ; + syntit:hasClauseFunction ?clafunction. + + ?frag olires:fragmentRegionFrom ?clfr ; + olires:fragmentRegionTo ?clto . + #?frag olires:fragmentRegionFrom ?pos. + } + ###condizioni sintattiche end + BIND(COALESCE(?pos1,-1) AS ?pos) + }` + + + +//Query per advanced search con obiettivo = 'Periodo' +const sentencetargetquery = ` +PREFIX ecrm: +PREFIX xsd: +PREFIX olires: +PREFIX syntit: +PREFIX rdf: +PREFIX lemon: +PREFIX orl: +PREFIX ontolex: + +SELECT (?t_canto as ?Canto) (?t_cantica as ?Cantica) ?sentence ?clfr ?clto ?clafunction ?clocc WHERE { + { + ?sentence rdf:type syntit:Sentence; + ecrm:P148i_is_component_of ?canto. + ?seocc olires:occurrenceOf ?sentence; + olires:occursInRegion ?frag. + ?frag olires:fragmentRegionFrom ?clfr; + olires:fragmentRegionTo ?clto. + + ####aggiungere condizioni sulle clausole + } + + ?canto ecrm:P102_has_title ?t_canto; + olires:hasNumber ?num. + ?cantica ecrm:P102_has_title ?t_cantica; + olires:hasStructuralComponent ?canto. + #BIND(concat(str(?clatype1),";", str(?clatype2)) AS ?clatype) + #BIND(COALESCE(?posgen,-1) AS ?pos) +} + +` + +const sentencetargetstatement_posCoalesce=JSON.parse(`{ + "type": "bind", + "variable": { + "termType": "Variable", + "value": "pos" + }, + "expression": { + "type": "operation", + "operator": "coalesce", + "args": [ + { + "termType": "Variable", + "value": "posgen" + }, + { + "termType": "Literal", + "value": "-1", + "language": "", + "datatype": { + "termType": "NamedNode", + "value": "http://www.w3.org/2001/XMLSchema#integer" + } + } + ] + } +}`) + +const sentencetarget_functionbind= +` + { + "type": "bind", + "variable": { + "termType": "Variable", + "value": "clafunction" + }, + "expression": { + "type": "operation", + "operator": "concat", + "args": [] + } + } +` + +const sentencetarget_occbind= +` + { + "type": "bind", + "variable": { + "termType": "Variable", + "value": "clocc" + }, + "expression": { + "type": "operation", + "operator": "concat", + "args": [] + } + } +` + +const sentencetarget_posbind= +` + { + "type": "bind", + "variable": { + "termType": "Variable", + "value": "pos" + }, + "expression": { + "type": "operation", + "operator": "concat", + "args": [] + } + } +` + +const sentencetarget_syntgroup = `{ + "type": "group", + "patterns": [ + { + "type": "bgp", + "triples": [ + {"subject": {"termType": "Variable","value": "sentence"}, + "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/syntit/current/hasSyntacticalComponent"}, + "object": {"termType": "Variable","value": "cl"}}, + {"subject": {"termType": "Variable","value": "cl"}, + "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/syntit/current/hasClauseType"}, + "object": {"termType": "Variable","value": "clatype"}}, + {"subject": {"termType": "Variable","value": "cl"}, + "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/syntit/current/hasClauseFunction"}, + "object": {"termType": "Variable","value": "clafunction"}} + ] + } + ] + } + +` + +const sentencetarget_morphgroup = `{"type": "group", + "patterns": [{"type": "bgp", + "triples": [ + {"subject": {"termType": "Variable","value": "form"}, + "predicate": {"termType": "NamedNode", "value": "http://www.w3.org/ns/lemon/ontolex#writtenRep"}, + "object": {"termType": "Variable","value": "Rappresentazione"}}, + {"subject": {"termType": "Variable","value": "lent"}, + "predicate": {"termType": "NamedNode","value": "http://www.w3.org/ns/lemon/ontolex#lexicalForm"}, + "object": {"termType": "Variable", "value": "form"}}, + {"subject": {"termType": "Variable","value": "lent"}, + "predicate": {"termType": "NamedNode","value": "http://www.w3.org/ns/lemon/ontolex#canonicalForm"}, + "object": {"termType": "Variable","value": "cf"}}, + {"subject": {"termType": "Variable","value": "cf"}, + "predicate": {"termType": "NamedNode","value": "http://www.w3.org/ns/lemon/ontolex#writtenRep"}, + "object": {"termType": "Variable","value": "lm"}}, + {"subject": {"termType": "Variable","value": "fa"}, + "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/occurrenceOf"}, + "object": {"termType": "Variable","value": "form"}}, + {"subject": {"termType": "Variable","value": "fa"}, + "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/OccursInRegion"}, + "object": {"termType": "Variable", "value": "reg"}}, + {"subject": {"termType": "Variable","value": "reg"}, + "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/fragmentRegionFrom"}, + "object": {"termType": "Variable","value": "pos"}}, + {"subject": {"termType": "Variable","value": "sentence"}, + "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/syntit/current/hasSyntacticalComponent"}, + "object": {"termType": "Variable","value": "clg"}}, + {"subject": {"termType": "Variable","value": "cloccte"}, + "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/occurrenceOf"}, + "object": {"termType": "Variable","value": "clg"}}, + {"subject": {"termType": "Variable","value": "cloccte"}, + "predicate": {"termType": "NamedNode","value": "http://erlangen-crm.org/current/P148_has_component"}, + "object": {"termType": "Variable","value": "fa"}} + ] + } + ] + } + ` + + const sentencetarget_morphgroup_short = `{"type": "group", + "patterns": [{"type": "bgp", + "triples": [ + {"subject": {"termType": "Variable","value": "fa"}, + "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/occurrenceOf"}, + "object": {"termType": "Variable","value": "form"}}, + {"subject": {"termType": "Variable","value": "fa"}, + "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/OccursInRegion"}, + "object": {"termType": "Variable", "value": "reg"}}, + {"subject": {"termType": "Variable","value": "reg"}, + "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/fragmentRegionFrom"}, + "object": {"termType": "Variable","value": "pos"}}, + {"subject": {"termType": "Variable","value": "sentence"}, + "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/syntit/current/hasSyntacticalComponent"}, + "object": {"termType": "Variable","value": "clg"}}, + {"subject": {"termType": "Variable","value": "cloccte"}, + "predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/occurrenceOf"}, + "object": {"termType": "Variable","value": "clg"}}, + {"subject": {"termType": "Variable","value": "cloccte"}, + "predicate": {"termType": "NamedNode","value": "http://erlangen-crm.org/current/P148_has_component"}, + "object": {"termType": "Variable","value": "fa"}} + ] + } + ] + } + ` + + const sentencetarget_posVariable=`{ + "termType": "Variable", + "value": "pos" + }` + +const lemma_writtenrepresentation = `{"subject": {"termType": "Variable", "value":"cf"}, "predicate": {"termType":"NamedNode", "value": "http://www.w3.org/ns/lemon/ontolex#writtenRep"}, "object": {"termType": "Variable", "value": "lm"}}` +const lemma_canonicalform = `{"subject": {"termType": "Variable", "value":"lent"}, "predicate": {"termType":"NamedNode", "value": "http://www.w3.org/ns/lemon/ontolex#canonicalForm"}, "object": {"termType": "Variable", "value": "cf"}}` +const lemma_lexicalform = `{"subject": {"termType": "Variable", "value":"lent"}, "predicate": {"termType":"NamedNode", "value": "http://www.w3.org/ns/lemon/ontolex#lexicalForm"}, "object": {"termType": "Variable", "value": "form"}}` + + \ No newline at end of file