src/p4l/views.py
changeset 43 829d9d4111da
parent 40 cc7149ca6863
child 45 9dd14a51a2bb
equal deleted inserted replaced
42:ad27066048ce 43:829d9d4111da
   125         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))
   125         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))
   126         context['uri_labels'] = json.dumps(uri_labels)
   126         context['uri_labels'] = json.dumps(uri_labels)
   127         
   127         
   128         context['subjects_query_dict'] = json.dumps({
   128         context['subjects_query_dict'] = json.dumps({
   129                             'data-url': settings.SPARQL_QUERY_ENDPOINT,
   129                             'data-url': settings.SPARQL_QUERY_ENDPOINT,
   130                             'data-query':  
   130                             'data-query': settings.SPARQL_SUBJECT_QUERIES["filter"],
   131 """
   131                             'data-root-query': settings.SPARQL_SUBJECT_QUERIES["root"],
   132 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
   132                             'data-childs-query': settings.SPARQL_SUBJECT_QUERIES["childs"],
   133 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
   133                             'data-child-count-query': settings.SPARQL_SUBJECT_QUERIES["child-count"]
   134 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   135 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   136 SELECT DISTINCT ?uri ?label
       
   137 WHERE {
       
   138     ?uri a skos:Concept.
       
   139     ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
       
   140     ?uri skos:prefLabel ?label.
       
   141     FILTER (lang(?label) = ?language).
       
   142     ?uri skos:prefLabel ?lab.
       
   143     FILTER regex (str(?lab), ?reg, 'i').
       
   144     FILTER (lang (?lab) = ?language).
       
   145     BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place).
       
   146     BIND (STRLEN(STR(?lab)) AS ?len)
       
   147 }
       
   148 ORDER BY ?place ?len ?lab
       
   149 """,
       
   150                             'data-root-query':
       
   151 """
       
   152 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   153 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   154 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   155 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   156 SELECT DISTINCT ?uri ?label
       
   157 WHERE {
       
   158     ?uri a skos:Collection ;
       
   159     skos:inScheme <http://skos.um.es/unescothes/CS000> ;    
       
   160     skos:prefLabel|rdfs:label ?label .
       
   161     FILTER (lang(?label) = ?language). 
       
   162     FILTER NOT EXISTS { [skos:member ?uri] }
       
   163 }
       
   164 """,
       
   165                             'data-childs-query':
       
   166 """
       
   167 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   168 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   169 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   170 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   171 SELECT DISTINCT ?uri ?label
       
   172 WHERE {
       
   173   ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
       
   174   { ?uri a ?type
       
   175     FILTER (?type = skos:Collection || ?type = skos:Concept) }.
       
   176   ?root skos:narrower|skos:member ?uri.
       
   177   ?uri skos:prefLabel|rdfs:label ?label.
       
   178   FILTER (lang(?label) = ?language).
       
   179 }
       
   180 """,
       
   181                             'data-child-count-query':
       
   182 """
       
   183 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   184 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   185 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   186 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   187 SELECT (COUNT(?uri) as ?nb)
       
   188 WHERE {
       
   189     ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
       
   190     ?root skos:narrower|skos:member ?uri.
       
   191 }
       
   192 """
       
   193                             })
   134                             })
   194         
   135         
   195         return context
   136         return context
   196         
   137         
   197         
   138