src/p4l/settings.py
changeset 61 305f9fcd409b
parent 60 da37c87abbfb
child 62 8433e12362e0
--- a/src/p4l/settings.py	Tue Sep 10 12:14:52 2013 +0200
+++ b/src/p4l/settings.py	Tue Sep 10 16:54:29 2013 +0200
@@ -295,7 +295,165 @@
     ?root skos:narrower|skos:member ?uri.
 }
 """
-                            }
+}
+SPARQL_COUNTRY_QUERIES = {
+'filter' : """
+PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
+PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX owl:<http://www.w3.org/2002/07/owl#>
+PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
+SELECT DISTINCT ?uri ?label
+WHERE {
+    ?uri a skos:Concept.
+    ?uri skos:inScheme <http://skos.um.es/unescothes/CS000/Countries> .
+    ?uri skos:prefLabel ?label.
+    FILTER (lang(?label) = %s).
+    ?uri skos:prefLabel ?lab.
+    FILTER regex (str(?lab), ?reg, 'i').
+    FILTER (lang (?lab) = %s).
+    BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place).
+    BIND (STRLEN(STR(?lab)) AS ?len)
+}
+ORDER BY ?place ?len ?lab
+""",
+'root' : """
+PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
+PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX owl:<http://www.w3.org/2002/07/owl#>
+PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
+SELECT DISTINCT ?uri ?label
+WHERE {
+    ?uri a skos:Concept ;
+    skos:inScheme <http://skos.um.es/unescothes/CS000/Countries> ;    
+    skos:prefLabel ?label .
+    FILTER (lang(?label) = %s). 
+    FILTER NOT EXISTS { [skos:narrower ?uri] }
+}
+""",
+'childs' : """
+PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
+PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX owl:<http://www.w3.org/2002/07/owl#>
+PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
+SELECT DISTINCT ?uri ?label
+WHERE {
+  ?uri skos:inScheme <http://skos.um.es/unescothes/CS000/Countries> .
+  { ?uri a ?type
+    FILTER (?type = skos:Collection || ?type = skos:Concept) }.
+  ?root skos:narrower|skos:member ?uri.
+  ?uri skos:prefLabel|rdfs:label ?label.
+  FILTER (lang(?label) = %s).
+}
+""",
+'child-count' : """
+PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
+PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX owl:<http://www.w3.org/2002/07/owl#>
+PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
+SELECT (COUNT(?uri) as ?nb)
+WHERE {
+    ?uri skos:inScheme <http://skos.um.es/unescothes/CS000/Countries> .
+    ?root skos:narrower|skos:member ?uri.
+}
+"""
+}
+SPARQL_LANGUAGE_QUERIES = {
+'filter' : """
+PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
+PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX owl:<http://www.w3.org/2002/07/owl#>
+PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
+SELECT DISTINCT ?uri ?label
+WHERE {
+    ?uri a skos:Concept.
+    ?uri skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Languages> .
+    ?uri skos:prefLabel ?label.
+    FILTER (lang(?label) = %s).
+    ?uri skos:prefLabel ?lab.
+    FILTER regex (str(?lab), ?reg, 'i').
+    FILTER (lang (?lab) = %s).
+    BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place).
+    BIND (STRLEN(STR(?lab)) AS ?len)
+}
+ORDER BY ?place ?len ?lab
+""",
+'root' : """
+PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
+PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX owl:<http://www.w3.org/2002/07/owl#>
+PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
+SELECT DISTINCT ?uri ?label
+WHERE {
+    ?uri a skos:Concept ;
+    skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Languages> ;    
+    skos:prefLabel ?label .
+    FILTER (lang(?label) = %s). 
+    FILTER NOT EXISTS { [skos:narrower ?uri] }
+}
+"""
+}
+SPARQL_PROJECT_QUERIES = {
+'filter' : """
+PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
+PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX owl:<http://www.w3.org/2002/07/owl#>
+PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
+SELECT DISTINCT ?uri ?label
+WHERE {
+    ?uri a skos:Concept.
+    ?uri skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Projects> .
+    ?uri skos:prefLabel ?label.
+    ?uri skos:prefLabel ?lab.
+    FILTER regex (str(?lab), ?reg, 'i').
+    BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place).
+    BIND (STRLEN(STR(?lab)) AS ?len)
+}
+ORDER BY ?place ?len ?lab
+""",
+'root' : """
+PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
+PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX owl:<http://www.w3.org/2002/07/owl#>
+PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
+SELECT DISTINCT ?uri ?label
+WHERE {
+    ?uri a skos:Concept ;
+    skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Projects> ;    
+    skos:prefLabel ?label .
+}
+"""
+}
+SPARQL_ORGANIZATION_QUERIES = {
+'filter' : """
+PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
+PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX owl:<http://www.w3.org/2002/07/owl#>
+PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
+SELECT DISTINCT ?uri ?label
+WHERE {
+    ?uri a skos:Concept.
+    ?uri skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Organizations> .
+    ?uri skos:prefLabel ?label.
+    ?uri skos:prefLabel ?lab.
+    FILTER regex (str(?lab), ?reg, 'i').
+    BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place).
+    BIND (STRLEN(STR(?lab)) AS ?len)
+}
+ORDER BY ?place ?len ?lab
+""",
+'root' : """
+PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
+PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
+PREFIX owl:<http://www.w3.org/2002/07/owl#>
+PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
+SELECT DISTINCT ?uri ?label
+WHERE {
+    ?uri a skos:Concept ;
+    skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Organizations> ;    
+    skos:prefLabel ?label .
+}
+"""
+}
 
 
 REST_FRAMEWORK = {