LiDa_Search/js/sparqltemplates.js

474 lines
18 KiB
JavaScript
Raw Normal View History

2024-05-23 08:26:42 +02:00
/**
*
*/
//query per le simple search con condizioni sulla clausola grammaticale
var 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/>
PREFIX lemon: <http://lemon-model.net/lemon#>
PREFIX orl: <https://dantenetwork.it/ontology/orl/current/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX ontolex: <http://www.w3.org/ns/lemon/ontolex#>
PREFIX olires:<https://dantenetwork.it/ontology/olires/current/>
PREFIX comm: <http://dantenetwork.it/data/commedia/>
PREFIX syntit: <https://dantenetwork.it/ontology/syntit/current/>
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: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ecrm: <http://erlangen-crm.org/current/>
PREFIX hdn: <http://dantenetwork.it/data/commedia/>
PREFIX lemon: <http://lemon-model.net/lemon#>
PREFIX orl: <https://dantenetwork.it/ontology/orl/current/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX ontolex: <http://www.w3.org/ns/lemon/ontolex#>
PREFIX olires:<https://dantenetwork.it/ontology/olires/current/>
PREFIX comm: <http://dantenetwork.it/data/commedia/>
PREFIX syntit: <https://dantenetwork.it/ontology/syntit/current/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
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)
}`
2025-02-19 17:50:55 +01:00
//Query per advanced search con obiettivo = 'Frase'
const clausetargetquery = `
2025-02-18 14:54:07 +01:00
PREFIX ecrm: <http://erlangen-crm.org/current/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX olires: <https://dantenetwork.it/ontology/olires/current/>
PREFIX syntit: <https://dantenetwork.it/ontology/syntit/current/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX lemon: <http://lemon-model.net/lemon#>
PREFIX orl: <https://dantenetwork.it/ontology/orl/current/>
PREFIX ontolex: <http://www.w3.org/ns/lemon/ontolex#>
SELECT distinct (?t_canto AS ?Canto) (?t_cantica AS ?Cantica) ?sentence ?clfr ?clto ?clafunction ?clt ?pos WHERE {
{
?sentence rdf:type syntit:Sentence;
syntit:hasSyntacticalComponent ?cl;
ecrm:P148i_is_component_of ?canto.
?cl syntit:hasClauseType ?clatype;
syntit:hasClauseFunction ?clafun.
2025-02-19 17:50:55 +01:00
#?seocc olires:occurrenceOf ?sentence;
# olires:occursInRegion ?frag.
2025-02-18 14:54:07 +01:00
?claocc olires:occurrenceOf ?cl;
olires:occursInRegion ?fragcl.
?fragcl olires:fragmentRegionFrom ?clfr;
olires:fragmentRegionTo ?clto.
}
?canto ecrm:P102_has_title ?t_canto;
olires:hasNumber ?num.
?cantica ecrm:P102_has_title ?t_cantica;
2025-02-19 17:50:55 +01:00
olires:hasStructuralComponent ?canto.
BIND(CONCAT(STR(?clafun), ';') AS ?clafunction)
BIND(STR(?clatype) AS ?clt)
#FILTER (?clto > ?pos && ?clfr<?pos) .
2025-02-18 14:54:07 +01:00
}`
2025-02-19 17:50:55 +01:00
//bindConcatStatement
const clausetarget_functionbind =
`{
2025-02-18 14:54:07 +01:00
"type": "bind",
"variable": {
"termType": "Variable",
"value": "clafun"
},
"expression": {
"type": "operation",
"operator": "concat",
"args": []
}
}`
2025-02-19 17:50:55 +01:00
//clauseTypeBindStatement
const clausetarget_typebind =
`{
2025-02-18 14:54:07 +01:00
"type": "bind",
"variable": {
"termType": "Variable",
"value": "clatype"
},
"expression": {
"type": "operation",
2025-02-19 17:50:55 +01:00
"operator": "",
2025-02-18 14:54:07 +01:00
"args": []
}
2025-02-19 17:50:55 +01:00
}`
2025-02-18 14:54:07 +01:00
/*
*/
//clausePosCoalesceStatement
2025-02-19 17:50:55 +01:00
const clausetarget_coalesce =
`{
2025-02-18 14:54:07 +01:00
"type": "bind",
"variable": {
"termType": "Variable",
"value": "pos"
},
"expression": {
"type": "operation",
"operator": "coalesce",
"args": []
}
}`
2024-05-23 08:26:42 +02:00
2025-02-19 17:50:55 +01:00
const clausepos_filter=`
{
"type": "filter",
"expression": {
"type": "operation",
"operator": "&&",
"args": [
{
"type": "operation",
"operator": ">",
"args": [
{
"termType": "Variable",
"value": "clto"
},
{
"termType": "Variable",
"value": "pos_"
}
]
},
{
"type": "operation",
"operator": "<",
"args": [
{
"termType": "Variable",
"value": "clfr"
},
{
"termType": "Variable",
"value": "pos_"
}
]
}
]
}
}
`
2024-05-23 08:26:42 +02:00
//Query per advanced search con obiettivo = 'Periodo'
const sentencetargetquery = `
PREFIX ecrm: <http://erlangen-crm.org/current/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX olires: <https://dantenetwork.it/ontology/olires/current/>
PREFIX syntit: <https://dantenetwork.it/ontology/syntit/current/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX lemon: <http://lemon-model.net/lemon#>
PREFIX orl: <https://dantenetwork.it/ontology/orl/current/>
PREFIX ontolex: <http://www.w3.org/ns/lemon/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.
2025-02-19 17:50:55 +01:00
#BIND((str(?clatype1),";", str(?clatype2)) AS ?clatype)
2024-05-23 08:26:42 +02:00
#BIND(COALESCE(?posgen,-1) AS ?pos)
}
`
2025-02-19 17:50:55 +01:00
const sentencetargetstatement_posCoalesce = JSON.parse(`{
2024-05-23 08:26:42 +02:00
"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"
}
}
]
}
}`)
2025-02-18 14:54:07 +01:00
2025-02-19 17:50:55 +01:00
const sentencetarget_functionbind =
`
2024-05-23 08:26:42 +02:00
{
"type": "bind",
"variable": {
"termType": "Variable",
"value": "clafunction"
},
"expression": {
"type": "operation",
"operator": "concat",
"args": []
}
}
`
2025-02-19 17:50:55 +01:00
const sentencetarget_occbind =
`
2024-05-23 08:26:42 +02:00
{
"type": "bind",
"variable": {
"termType": "Variable",
"value": "clocc"
},
"expression": {
"type": "operation",
"operator": "concat",
"args": []
}
}
`
2025-02-19 17:50:55 +01:00
const sentencetarget_posbind =
`
2024-05-23 08:26:42 +02:00
{
"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"}}
]
}
]
}
`
2025-02-19 17:50:55 +01:00
const sentencetarget_morphgroup_short = `{"type": "group",
2024-05-23 08:26:42 +02:00
"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"}},
2025-02-20 14:02:54 +01:00
{"subject": {"termType": "Variable","value": "cloccte"},
"predicate": {"termType": "NamedNode","value": "http://erlangen-crm.org/current/P148_has_component"},
"object": {"termType": "Variable","value": "fa"}},
2024-05-23 08:26:42 +02:00
{"subject": {"termType": "Variable","value": "cloccte"},
"predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/occurrenceOf"},
"object": {"termType": "Variable","value": "clg"}},
2024-05-24 17:03:19 +02:00
{"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"}}
2024-05-23 08:26:42 +02:00
]
}
]
}
`
2025-02-19 17:50:55 +01:00
const sentencetarget_posVariable = `{
2024-05-23 08:26:42 +02:00
"termType": "Variable",
"value": "pos"
}`
2025-02-19 17:50:55 +01:00
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"},
2024-05-24 17:03:19 +02:00
"object": {"termType": "Variable", "value": "form"}}`
2024-05-23 08:26:42 +02:00
2025-02-19 17:50:55 +01:00
const occurrenceof_form = `{"subject": {"termType": "Variable","value": "fa"},
2024-05-24 17:03:19 +02:00
"predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/occurrenceOf"},
"object": {"termType": "Variable","value": "form"}}`
2025-02-19 17:50:55 +01:00
const clauseocc_hascomponent_formocc = `{"subject": {"termType": "Variable","value": "cloccu"},
2024-05-24 17:03:19 +02:00
"predicate": {"termType": "NamedNode","value": "http://erlangen-crm.org/current/P148_has_component"},
2025-02-19 17:50:55 +01:00
"object": {"termType": "Variable","value": "fa"}}`
const occurrenceof_clause = `{"subject": {"termType": "Variable","value": "cloccu"},
2024-05-24 17:03:19 +02:00
"predicate": {"termType": "NamedNode","value": "https://dantenetwork.it/ontology/olires/current/occurrenceOf"},
"object": {"termType": "Variable","value": "cl"}}`
2025-02-19 17:50:55 +01:00
2024-05-28 16:06:27 +02:00
//DEFAULT QUERY PER SPARQL EDITOR
2025-02-19 17:50:55 +01:00
const defaultEditorQuery = `# ESEMPIO: i periodi della Commedia con una frase con tipo sintattico 'Subordinata Causale'
2024-05-28 16:06:27 +02:00
PREFIX ecrm: <http://erlangen-crm.org/current/>
PREFIX syntit: <https://dantenetwork.it/ontology/syntit/current/>
PREFIX olires: <https://dantenetwork.it/ontology/olires/current/>
SELECT ?Cantica ?Canto ?Periodo ?FraseSubordinata
WHERE {
?cl syntit:hasClauseType syntit:Causale ;
ecrm:P190_has_symbolic_content ?FraseSubordinata .
?sentence a syntit:Sentence ;
syntit:hasSyntacticalComponent ?cl;
ecrm:P190_has_symbolic_content ?Periodo ;
ecrm:P148i_is_component_of ?q_canto.
?q_canto ecrm:P102_has_title ?Canto .
?cantica ecrm:P102_has_title ?Cantica;
olires:hasStructuralComponent ?q_canto.
} order by ?Cantica ?Canto`
2024-05-28 16:06:27 +02:00
2025-02-19 17:50:55 +01:00