src/p4l/semantictree/forms/forms.py
changeset 127 63fd69b7ea61
parent 126 a345f1a67bf1
child 128 b1dd506b2493
equal deleted inserted replaced
126:a345f1a67bf1 127:63fd69b7ea61
     1 # -*- coding: utf-8 -*-
       
     2 #
       
     3 # Copyright IRI (2013)
       
     4 #
       
     5 # contact@iri.centrepompidou.fr
       
     6 #
       
     7 # This software is governed by the CeCILL-B license under French law and
       
     8 # abiding by the rules of distribution of free software.  You can  use, 
       
     9 # modify and/ or redistribute the software under the terms of the CeCILL-B
       
    10 # license as circulated by CEA, CNRS and INRIA at the following URL
       
    11 # "http://www.cecill.info". 
       
    12 #
       
    13 # As a counterpart to the access to the source code and  rights to copy,
       
    14 # modify and redistribute granted by the license, users are provided only
       
    15 # with a limited warranty  and the software's author,  the holder of the
       
    16 # economic rights,  and the successive licensors  have only  limited
       
    17 # liability. 
       
    18 #
       
    19 # In this respect, the user's attention is drawn to the risks associated
       
    20 # with loading,  using,  modifying and/or developing or reproducing the
       
    21 # software by the user in light of its specific status of free software,
       
    22 # that may mean  that it is complicated to manipulate,  and  that  also
       
    23 # therefore means  that it is reserved for developers  and  experienced
       
    24 # professionals having in-depth computer knowledge. Users are therefore
       
    25 # encouraged to load and test the software's suitability as regards their
       
    26 # requirements in conditions enabling the security of their systems and/or 
       
    27 # data to be ensured and,  more generally, to use and operate it in the 
       
    28 # same conditions as regards security. 
       
    29 #
       
    30 # The fact that you are presently reading this means that you have had
       
    31 # knowledge of the CeCILL-B license and that you accept its terms.
       
    32 #
       
    33 
       
    34 from django import forms
       
    35 from .widgets import SemanticTreeWidget, SemanticTagItWidget
       
    36 
       
    37 
       
    38 class SubjectForm(forms.Form):
       
    39     # __reg__ is updated with the real regexp by the js
       
    40     subject = forms.CharField(required=True, label="Subjects", 
       
    41                           widget=SemanticTreeWidget(attrs={
       
    42                             'size':  25, 
       
    43                             'class': "form-control",
       
    44                             'data-url': "http://localhost:8080/openrdf-sesame/repositories/plan4learning",
       
    45                             'data-query':  
       
    46 """
       
    47 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
    48 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
    49 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
    50 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
    51 SELECT DISTINCT ?uri ?label
       
    52 WHERE {
       
    53     ?uri a skos:Concept.
       
    54     ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
       
    55     ?uri skos:prefLabel ?label.
       
    56     FILTER (lang(?label) = ?language).
       
    57     ?uri skos:prefLabel ?lab.
       
    58     FILTER regex (str(?lab), ?reg, 'i').
       
    59     FILTER (lang (?lab) = ?language).
       
    60     BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place).
       
    61     BIND (STRLEN(STR(?lab)) AS ?len)
       
    62 }
       
    63 ORDER BY ?place ?len ?lab
       
    64 """,
       
    65                             'data-root-query':
       
    66 """
       
    67 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
    68 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
    69 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
    70 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
    71 SELECT DISTINCT ?uri ?label
       
    72 WHERE {
       
    73     ?uri a skos:Collection ;
       
    74     skos:inScheme <http://skos.um.es/unescothes/CS000> ;    
       
    75     rdfs:label ?label .
       
    76     FILTER (lang(?label) = ?language). 
       
    77     FILTER NOT EXISTS { [skos:member ?uri] }
       
    78 }
       
    79 """,
       
    80                             'data-childs-query':
       
    81 """
       
    82 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
    83 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
    84 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
    85 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
    86 SELECT DISTINCT ?uri ?label
       
    87 WHERE {
       
    88   ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
       
    89   { ?uri a ?type
       
    90     FILTER (?type = skos:Collection || ?type = skos:Concept) }.
       
    91   ?root skos:narrower|skos:member ?uri.
       
    92   ?uri skos:prefLabel|rdfs:label ?label.
       
    93   FILTER (lang(?label) = ?language).
       
    94 }
       
    95 """,
       
    96                             'data-child-count-query':
       
    97 """
       
    98 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
    99 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   100 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   101 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   102 SELECT (COUNT(?uri) as ?nb)
       
   103 WHERE {
       
   104     ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
       
   105     ?root skos:narrower|skos:member ?uri.
       
   106 }
       
   107 """
       
   108                             }))
       
   109 
       
   110 
       
   111 
       
   112 
       
   113 class SemForm(forms.Form):
       
   114     # __reg__ is updated with the real regexp by the js
       
   115     sem = forms.CharField(required=True, label="Dude, sem", 
       
   116                           widget=SemanticTreeWidget(attrs={
       
   117                             'size':  25, 
       
   118                             'class': "dude",
       
   119                             'data-url': "http://localhost:8080/openrdf-sesame/repositories/plan4learning",
       
   120                             'data-query':  
       
   121 """
       
   122 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   123 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   124 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   125 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   126 SELECT DISTINCT ?uri ?label
       
   127 WHERE {
       
   128     ?uri a skos:Concept.
       
   129     ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
       
   130     ?uri skos:prefLabel ?label.
       
   131     FILTER (lang(?label) = ?language).
       
   132     ?uri skos:prefLabel ?lab.
       
   133     FILTER regex (str(?lab), ?reg, 'i').
       
   134     FILTER (lang (?lab) = ?language).
       
   135     BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place).
       
   136     BIND (STRLEN(STR(?lab)) AS ?len)
       
   137 }
       
   138 ORDER BY ?place ?len ?lab
       
   139 """,
       
   140                             'data-root-query':
       
   141 """
       
   142 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   143 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   144 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   145 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   146 SELECT DISTINCT ?uri ?label
       
   147 WHERE {
       
   148     ?uri a skos:Collection ;
       
   149     skos:inScheme <http://skos.um.es/unescothes/CS000> ;    
       
   150     rdfs:label ?label .
       
   151     FILTER (lang(?label) = ?language). 
       
   152     FILTER NOT EXISTS { [skos:member ?uri] }
       
   153 }
       
   154 """,
       
   155                             'data-childs-query':
       
   156 """
       
   157 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   158 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   159 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   160 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   161 SELECT DISTINCT ?uri ?label
       
   162 WHERE {
       
   163   ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
       
   164   { ?uri a ?type
       
   165     FILTER (?type = skos:Collection || ?type = skos:Concept) }.
       
   166   ?root skos:narrower|skos:member ?uri.
       
   167   ?uri skos:prefLabel|rdfs:label ?label.
       
   168   FILTER (lang(?label) = ?language).
       
   169 }
       
   170 """,
       
   171                             'data-child-count-query':
       
   172 """
       
   173 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   174 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   175 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   176 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   177 SELECT (COUNT(?uri) as ?nb)
       
   178 WHERE {
       
   179     ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
       
   180     ?root skos:narrower|skos:member ?uri.
       
   181 }
       
   182 """
       
   183                             }))
       
   184     iam = forms.CharField(required=True, label="Dude, iam", widget=SemanticTreeWidget(attrs={
       
   185                             'size':  25, 
       
   186                             'class': "dude",
       
   187                             'data-url': "http://localhost:8080/openrdf-sesame/repositories/plan4learning",
       
   188                             'data-query':  
       
   189 """
       
   190 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   191 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   192 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   193 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   194 SELECT DISTINCT ?uri ?label
       
   195 WHERE {
       
   196     ?uri a skos:Concept.
       
   197     ?uri skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Themes> .
       
   198     ?uri skos:prefLabel ?label.
       
   199     FILTER (lang(?label) = ?language).
       
   200     ?uri skos:prefLabel ?lab.
       
   201     FILTER regex (str(?lab), ?reg, 'i').
       
   202     FILTER (lang (?lab) = ?language).
       
   203     BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place).
       
   204     BIND (STRLEN(STR(?lab)) AS ?len)
       
   205 }
       
   206 ORDER BY ?place ?len ?lab
       
   207 """,
       
   208                             'data-root-query':
       
   209 """
       
   210 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   211 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   212 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   213 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   214 SELECT DISTINCT ?uri ?label
       
   215 WHERE {
       
   216     ?uri a skos:Concept ;
       
   217     skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Themes> ;    
       
   218     skos:prefLabel ?label .
       
   219     FILTER (lang(?label) = ?language). 
       
   220     FILTER NOT EXISTS { [skos:narrower ?uri] }
       
   221 }
       
   222 """,
       
   223                             'data-childs-query':
       
   224 """
       
   225 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   226 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   227 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   228 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   229 SELECT DISTINCT ?uri ?label
       
   230 WHERE {
       
   231   ?uri skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Themes> .
       
   232   { ?uri a ?type
       
   233     FILTER (?type = skos:Collection || ?type = skos:Concept) }.
       
   234   ?root skos:narrower|skos:member ?uri.
       
   235   ?uri skos:prefLabel|rdfs:label ?label.
       
   236   FILTER (lang(?label) = ?language).
       
   237 }
       
   238 """,
       
   239                             'data-child-count-query':
       
   240 """
       
   241 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   242 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   243 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   244 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   245 SELECT (COUNT(?uri) as ?nb)
       
   246 WHERE {
       
   247     ?uri skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Themes> .
       
   248     ?root skos:narrower|skos:member ?uri.
       
   249 }
       
   250 """
       
   251                             }))
       
   252     ntm = forms.CharField(required=True, label="Dude, ntm", widget=SemanticTagItWidget(attrs={
       
   253                             'size':  25, 
       
   254                             'class': "dude",
       
   255                             'data-url': "http://localhost:8080/openrdf-sesame/repositories/plan4learning",
       
   256                             'data-query':  
       
   257 """
       
   258 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   259 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   260 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   261 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   262 SELECT DISTINCT ?uri ?label
       
   263 WHERE {
       
   264     ?uri a skos:Concept.
       
   265     ?uri skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Themes> .
       
   266     ?uri skos:prefLabel ?label.
       
   267     FILTER (lang(?label) = ?language).
       
   268     ?uri skos:prefLabel ?lab.
       
   269     FILTER regex (str(?lab), ?reg, 'i').
       
   270     FILTER (lang (?lab) = ?language).
       
   271     BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place).
       
   272     BIND (STRLEN(STR(?lab)) AS ?len)
       
   273 }
       
   274 ORDER BY ?place ?len ?lab
       
   275 """,
       
   276                             'data-root-query':
       
   277 """
       
   278 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   279 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   280 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   281 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   282 SELECT DISTINCT ?uri ?label
       
   283 WHERE {
       
   284     ?uri a skos:Concept ;
       
   285     skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Themes> ;    
       
   286     skos:prefLabel ?label .
       
   287     FILTER (lang(?label) = ?language). 
       
   288     FILTER NOT EXISTS { [skos:narrower ?uri] }
       
   289 }
       
   290 """,
       
   291                             'data-childs-query':
       
   292 """
       
   293 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   294 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   295 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   296 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   297 SELECT DISTINCT ?uri ?label
       
   298 WHERE {
       
   299   ?uri skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Themes> .
       
   300   { ?uri a ?type
       
   301     FILTER (?type = skos:Collection || ?type = skos:Concept) }.
       
   302   ?root skos:narrower|skos:member ?uri.
       
   303   ?uri skos:prefLabel|rdfs:label ?label.
       
   304   FILTER (lang(?label) = ?language).
       
   305 }
       
   306 """,
       
   307                             'data-child-count-query':
       
   308 """
       
   309 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   310 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   311 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   312 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   313 SELECT (COUNT(?uri) as ?nb)
       
   314 WHERE {
       
   315     ?uri skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Themes> .
       
   316     ?root skos:narrower|skos:member ?uri.
       
   317 }
       
   318 """
       
   319                             }))
       
   320 
       
   321 
       
   322