src/p4l/views.py
author cavaliet
Thu, 05 Sep 2013 13:09:57 +0200
changeset 38 c4e5bb735ec1
parent 35 544bc92e6fe7
child 40 cc7149ca6863
permissions -rw-r--r--
jquery autocomplete with angular for subjects
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
d184767fdd52 first list view
cavaliet
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
d184767fdd52 first list view
cavaliet
parents:
diff changeset
     2
'''
d184767fdd52 first list view
cavaliet
parents:
diff changeset
     3
Created on Aug 27, 2013
d184767fdd52 first list view
cavaliet
parents:
diff changeset
     4
d184767fdd52 first list view
cavaliet
parents:
diff changeset
     5
@author: tc
d184767fdd52 first list view
cavaliet
parents:
diff changeset
     6
'''
d184767fdd52 first list view
cavaliet
parents:
diff changeset
     7
d184767fdd52 first list view
cavaliet
parents:
diff changeset
     8
from django.conf import settings
24
3b1b0a9309d6 login logout
cavaliet
parents: 20
diff changeset
     9
from django.contrib.auth.decorators import login_required
3b1b0a9309d6 login logout
cavaliet
parents: 20
diff changeset
    10
from django.utils.decorators import method_decorator
34
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
    11
from django.views.generic import ListView, DetailView
26
a0e152dd1fad first version of angular intégration
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    12
from p4l.forms import RecordFilterForm
a0e152dd1fad first version of angular intégration
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    13
from p4l.models import Record
a0e152dd1fad first version of angular intégration
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
    14
from p4l.utils import get_labels_for_uris
34
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
    15
import json
1
d184767fdd52 first list view
cavaliet
parents:
diff changeset
    16
import logging
38
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
    17
from p4l.semantictree.forms.forms import SubjectForm
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
    18
from django.utils.safestring import mark_safe
1
d184767fdd52 first list view
cavaliet
parents:
diff changeset
    19
7
02008d61c3c8 record view + correct import
cavaliet
parents: 5
diff changeset
    20
1
d184767fdd52 first list view
cavaliet
parents:
diff changeset
    21
logger = logging.getLogger(__name__)
d184767fdd52 first list view
cavaliet
parents:
diff changeset
    22
d184767fdd52 first list view
cavaliet
parents:
diff changeset
    23
class RecordListView(ListView):
d184767fdd52 first list view
cavaliet
parents:
diff changeset
    24
    
5
62e97cd13730 debug query and enhance display
cavaliet
parents: 4
diff changeset
    25
    queryset = Record.objects.select_related("language").prefetch_related('titles').distinct()  # @UndefinedVariable
1
d184767fdd52 first list view
cavaliet
parents:
diff changeset
    26
    paginate_by = settings.NB_RECORDS_BY_PAGE
d184767fdd52 first list view
cavaliet
parents:
diff changeset
    27
    template_name = "p4l/p4l_home.html"
4
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    28
    form_class = RecordFilterForm
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    29
    
24
3b1b0a9309d6 login logout
cavaliet
parents: 20
diff changeset
    30
    @method_decorator(login_required)
3b1b0a9309d6 login logout
cavaliet
parents: 20
diff changeset
    31
    def dispatch(self, *args, **kwargs):
3b1b0a9309d6 login logout
cavaliet
parents: 20
diff changeset
    32
        return super(RecordListView, self).dispatch(*args, **kwargs)
1
d184767fdd52 first list view
cavaliet
parents:
diff changeset
    33
    
4
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    34
    def get_context_data(self, **kwargs):
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    35
        context = ListView.get_context_data(self, **kwargs)
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    36
        context['filter_form'] = self.form_class()
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    37
        # Add filter params from GET params
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    38
        filter_params = {}
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    39
        if 'title' in self.request.GET:
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    40
            filter_params['title'] = self.request.GET['title']
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    41
        context['filter_params'] = filter_params
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    42
        return context
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    43
    
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    44
    def get_queryset(self):
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    45
        qs = super(RecordListView, self).get_queryset()
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    46
        filter_form = self.form_class(self.request.GET)
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    47
        if filter_form.is_valid():
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    48
            return filter_form.get_filter_qs(qs)
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    49
        else:
047675624f45 first step of title search in list of records
cavaliet
parents: 1
diff changeset
    50
            return qs
7
02008d61c3c8 record view + correct import
cavaliet
parents: 5
diff changeset
    51
02008d61c3c8 record view + correct import
cavaliet
parents: 5
diff changeset
    52
02008d61c3c8 record view + correct import
cavaliet
parents: 5
diff changeset
    53
class RecordDetailView(DetailView):
02008d61c3c8 record view + correct import
cavaliet
parents: 5
diff changeset
    54
    
02008d61c3c8 record view + correct import
cavaliet
parents: 5
diff changeset
    55
    model = Record
02008d61c3c8 record view + correct import
cavaliet
parents: 5
diff changeset
    56
    template_name = "p4l/p4l_record_view.html"
30
a84e31f1f223 update record view with slug
cavaliet
parents: 29
diff changeset
    57
    slug_field = "identifier"
7
02008d61c3c8 record view + correct import
cavaliet
parents: 5
diff changeset
    58
    
24
3b1b0a9309d6 login logout
cavaliet
parents: 20
diff changeset
    59
    @method_decorator(login_required)
3b1b0a9309d6 login logout
cavaliet
parents: 20
diff changeset
    60
    def dispatch(self, *args, **kwargs):
3b1b0a9309d6 login logout
cavaliet
parents: 20
diff changeset
    61
        return super(RecordDetailView, self).dispatch(*args, **kwargs)
3b1b0a9309d6 login logout
cavaliet
parents: 20
diff changeset
    62
    
17
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    63
    def get_context_data(self, **kwargs):
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    64
        context = DetailView.get_context_data(self, **kwargs)
20
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    65
        # We get the language, "fr" by default
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    66
        lang = "fr"
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    67
        if "lang" in self.request.GET:
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    68
            lang = self.request.GET["lang"]
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    69
        elif hasattr(self.request, "LANGUAGE_CODE") and self.request.LANGUAGE_CODE in ["fr","en","es"]:
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    70
            lang = self.request.LANGUAGE_CODE
17
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    71
        # self.object is the record entry
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    72
        # We get the subjects'labels with the Thesaurus repository
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    73
        uri_list = [s.uri for s in self.object.subjects.all()]
20
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    74
        uris_labels = get_labels_for_uris(uri_list, "http://skos.um.es/unescothes/CS000", lang, False)
17
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    75
        context['subjects_labels'] = uris_labels
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    76
        # We get the themes'labels with the Themes repository
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    77
        uri_list = [s.uri for s in self.object.themes.all()]
20
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    78
        uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Themes", lang, False)
17
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    79
        context['themes_labels'] = uris_labels
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    80
        # We get the countries'labels with the Thesaurus repository
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    81
        uri_list = [s.uri for s in self.object.countries.all()]
20
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    82
        uris_labels = get_labels_for_uris(uri_list, "http://skos.um.es/unescothes/CS000/Countries", lang, False)
17
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    83
        context['countries_labels'] = uris_labels
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    84
        # We get the languages'labels with the Languages repository
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    85
        if self.object.language:
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    86
            uri_list = [self.object.language.uri]
20
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    87
            uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Languages", lang, False)
17
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    88
            context['language_label'] = uris_labels[self.object.language.uri]
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    89
        # We get the other languages'labels with the Languages repository
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    90
        uri_list = [s.uri for s in self.object.otherLanguages.all()]
20
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
    91
        uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Languages", lang, False)
17
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    92
        context['otherLanguages_labels'] = uris_labels
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    93
        # We get the project'labels with the Projects repository
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    94
        uri_list = [s.uri for s in self.object.projectNames.all()]
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    95
        uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Projects", None, True)
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    96
        context['projects_labels'] = uris_labels
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    97
        # We get the subjectCorporateBodies'labels with the Organizations repository
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    98
        uri_list = [s.uri for s in self.object.subjectCorporateBodies.all()]
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
    99
        uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Organizations", None, True)
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
   100
        context['subjectCorporateBodies_labels'] = uris_labels
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
   101
        # We get the corporateAuthors'labels with the Organizations repository
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
   102
        uri_list = [s.uri for s in self.object.corporateAuthors.all()]
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
   103
        uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/Organizations", None, True)
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
   104
        context['corporateAuthors_labels'] = uris_labels
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
   105
        # We get the recordType'labels with the DocumentType repository
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
   106
        if self.object.recordType:
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
   107
            uri_list = [self.object.recordType]
20
fa466993084a get language for sparql request
cavaliet
parents: 17
diff changeset
   108
            uris_labels = get_labels_for_uris(uri_list, "http://www.iiep.unesco.org/plan4learning/scheme/DocumentType", lang, False)
17
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
   109
            context['recordType_label'] = uris_labels[self.object.recordType]
7
02008d61c3c8 record view + correct import
cavaliet
parents: 5
diff changeset
   110
        
17
b31a67614f76 fill labels with sparql request on the go
cavaliet
parents: 8
diff changeset
   111
        return context
7
02008d61c3c8 record view + correct import
cavaliet
parents: 5
diff changeset
   112
34
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   113
class RecordEditView(DetailView):
29
3a3b90b1abb2 Correction after rebase/merge
ymh <ymh.work@gmail.com>
parents: 27
diff changeset
   114
    http_method_names = ['get']
3a3b90b1abb2 Correction after rebase/merge
ymh <ymh.work@gmail.com>
parents: 27
diff changeset
   115
    template_name = 'p4l/record_update_form.html'
34
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   116
    model = Record
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   117
    slug_field = "identifier"
26
a0e152dd1fad first version of angular intégration
ymh <ymh.work@gmail.com>
parents: 20
diff changeset
   118
34
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   119
    def get_context_data(self, **kwargs):
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   120
        context = DetailView.get_context_data(self, **kwargs)
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   121
        # We get the language, "fr" by default
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   122
        lang = "fr"
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   123
        if "lang" in self.request.GET:
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   124
            lang = self.request.GET["lang"]
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   125
        elif hasattr(self.request, "LANGUAGE_CODE") and self.request.LANGUAGE_CODE in ["fr","en","es"]:
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   126
            lang = self.request.LANGUAGE_CODE
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   127
        
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   128
        uri_labels = get_labels_for_uris([s.uri for s in self.object.subjects.all()], "http://skos.um.es/unescothes/CS000", lang, False)
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   129
        uri_labels.update(get_labels_for_uris([s.uri for s in self.object.themes.all()], "http://www.iiep.unesco.org/plan4learning/scheme/Themes", lang, False))
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   130
        uri_labels.update(get_labels_for_uris([s.uri for s in self.object.countries.all()], "http://skos.um.es/unescothes/CS000/Countries", lang, False))
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   131
        uri_labels.update(get_labels_for_uris([self.object.language.uri] if self.object.language else [], "http://www.iiep.unesco.org/plan4learning/scheme/Languages", lang, False))
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   132
        uri_labels.update(get_labels_for_uris([s.uri for s in self.object.otherLanguages.all()], "http://www.iiep.unesco.org/plan4learning/scheme/Languages", lang, False))
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   133
        uri_labels.update(get_labels_for_uris([s.uri for s in self.object.projectNames.all()], "http://www.iiep.unesco.org/plan4learning/scheme/Projects", None, True))
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   134
        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))
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   135
        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))
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   136
        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))
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   137
        context['uri_labels'] = json.dumps(uri_labels)
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   138
        
38
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   139
        context['subjects_query_dict'] = json.dumps({
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   140
                            'data-url': settings.SPARQL_QUERY_ENDPOINT,
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   141
                            'data-query':  
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   142
"""
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   143
PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   144
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   145
PREFIX owl:<http://www.w3.org/2002/07/owl#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   146
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   147
SELECT DISTINCT ?uri ?label
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   148
WHERE {
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   149
    ?uri a skos:Concept.
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   150
    ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   151
    ?uri skos:prefLabel ?label.
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   152
    FILTER (lang(?label) = ?language).
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   153
    ?uri skos:prefLabel ?lab.
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   154
    FILTER regex (str(?lab), ?reg, 'i').
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   155
    FILTER (lang (?lab) = ?language).
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   156
    BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place).
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   157
    BIND (STRLEN(STR(?lab)) AS ?len)
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   158
}
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   159
ORDER BY ?place ?len ?lab
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   160
""",
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   161
                            'data-root-query':
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   162
"""
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   163
PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   164
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   165
PREFIX owl:<http://www.w3.org/2002/07/owl#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   166
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   167
SELECT DISTINCT ?uri ?label
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   168
WHERE {
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   169
    ?uri a skos:Collection ;
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   170
    skos:inScheme <http://skos.um.es/unescothes/CS000> ;    
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   171
    rdfs:label ?label .
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   172
    FILTER (lang(?label) = ?language). 
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   173
    FILTER NOT EXISTS { [skos:member ?uri] }
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   174
}
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   175
""",
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   176
                            'data-childs-query':
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   177
"""
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   178
PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   179
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   180
PREFIX owl:<http://www.w3.org/2002/07/owl#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   181
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   182
SELECT DISTINCT ?uri ?label
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   183
WHERE {
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   184
  ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   185
  { ?uri a ?type
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   186
    FILTER (?type = skos:Collection || ?type = skos:Concept) }.
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   187
  ?root skos:narrower|skos:member ?uri.
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   188
  ?uri skos:prefLabel|rdfs:label ?label.
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   189
  FILTER (lang(?label) = ?language).
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   190
}
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   191
""",
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   192
                            'data-child-count-query':
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   193
"""
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   194
PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   195
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   196
PREFIX owl:<http://www.w3.org/2002/07/owl#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   197
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   198
SELECT (COUNT(?uri) as ?nb)
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   199
WHERE {
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   200
    ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   201
    ?root skos:narrower|skos:member ?uri.
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   202
}
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   203
"""
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   204
                            })
c4e5bb735ec1 jquery autocomplete with angular for subjects
cavaliet
parents: 35
diff changeset
   205
        
34
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   206
        return context
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   207
        
cfc090f440d0 add uri labels + dict
ymh <ymh.work@gmail.com>
parents: 33
diff changeset
   208