src/p4l/views.py
changeset 38 c4e5bb735ec1
parent 35 544bc92e6fe7
child 40 cc7149ca6863
--- a/src/p4l/views.py	Wed Sep 04 17:45:18 2013 +0200
+++ b/src/p4l/views.py	Thu Sep 05 13:09:57 2013 +0200
@@ -14,6 +14,8 @@
 from p4l.utils import get_labels_for_uris
 import json
 import logging
+from p4l.semantictree.forms.forms import SubjectForm
+from django.utils.safestring import mark_safe
 
 
 logger = logging.getLogger(__name__)
@@ -132,9 +134,75 @@
         uri_labels.update(get_labels_for_uris([s.uri for s in self.object.subjectCorporateBodies.all()], "http://www.iiep.unesco.org/plan4learning/scheme/Organizations", None, True))
         uri_labels.update(get_labels_for_uris([s.uri for s in self.object.corporateAuthors.all()], "http://www.iiep.unesco.org/plan4learning/scheme/Organizations", None, True))
         uri_labels.update(get_labels_for_uris([self.object.recordType] if self.object.recordType else [], "http://www.iiep.unesco.org/plan4learning/scheme/DocumentType", lang, False))
-
         context['uri_labels'] = json.dumps(uri_labels)
         
+        context['subjects_query_dict'] = json.dumps({
+                            'data-url': settings.SPARQL_QUERY_ENDPOINT,
+                            'data-query':  
+"""
+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> .
+    ?uri skos:prefLabel ?label.
+    FILTER (lang(?label) = ?language).
+    ?uri skos:prefLabel ?lab.
+    FILTER regex (str(?lab), ?reg, 'i').
+    FILTER (lang (?lab) = ?language).
+    BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place).
+    BIND (STRLEN(STR(?lab)) AS ?len)
+}
+ORDER BY ?place ?len ?lab
+""",
+                            'data-root-query':
+"""
+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:Collection ;
+    skos:inScheme <http://skos.um.es/unescothes/CS000> ;    
+    rdfs:label ?label .
+    FILTER (lang(?label) = ?language). 
+    FILTER NOT EXISTS { [skos:member ?uri] }
+}
+""",
+                            'data-childs-query':
+"""
+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> .
+  { ?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) = ?language).
+}
+""",
+                            'data-child-count-query':
+"""
+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> .
+    ?root skos:narrower|skos:member ?uri.
+}
+"""
+                            })
+        
         return context
         
         
\ No newline at end of file