src/p4l/semantictree/forms/forms.py
changeset 36 08cffedf6e60
child 126 a345f1a67bf1
equal deleted inserted replaced
35:544bc92e6fe7 36:08cffedf6e60
       
     1 from django import forms
       
     2 from .widgets import SemanticTreeWidget, SemanticTagItWidget
       
     3 
       
     4 
       
     5 class SubjectForm(forms.Form):
       
     6     # __reg__ is updated with the real regexp by the js
       
     7     subject = forms.CharField(required=True, label="Subjects", 
       
     8                           widget=SemanticTreeWidget(attrs={
       
     9                             'size':  25, 
       
    10                             'class': "form-control",
       
    11                             'data-url': "http://localhost:8080/openrdf-sesame/repositories/plan4learning",
       
    12                             'data-query':  
       
    13 """
       
    14 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
    15 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
    16 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
    17 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
    18 SELECT DISTINCT ?uri ?label
       
    19 WHERE {
       
    20     ?uri a skos:Concept.
       
    21     ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
       
    22     ?uri skos:prefLabel ?label.
       
    23     FILTER (lang(?label) = ?language).
       
    24     ?uri skos:prefLabel ?lab.
       
    25     FILTER regex (str(?lab), ?reg, 'i').
       
    26     FILTER (lang (?lab) = ?language).
       
    27     BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place).
       
    28     BIND (STRLEN(STR(?lab)) AS ?len)
       
    29 }
       
    30 ORDER BY ?place ?len ?lab
       
    31 """,
       
    32                             'data-root-query':
       
    33 """
       
    34 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
    35 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
    36 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
    37 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
    38 SELECT DISTINCT ?uri ?label
       
    39 WHERE {
       
    40     ?uri a skos:Collection ;
       
    41     skos:inScheme <http://skos.um.es/unescothes/CS000> ;    
       
    42     rdfs:label ?label .
       
    43     FILTER (lang(?label) = ?language). 
       
    44     FILTER NOT EXISTS { [skos:member ?uri] }
       
    45 }
       
    46 """,
       
    47                             'data-childs-query':
       
    48 """
       
    49 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
    50 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
    51 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
    52 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
    53 SELECT DISTINCT ?uri ?label
       
    54 WHERE {
       
    55   ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
       
    56   { ?uri a ?type
       
    57     FILTER (?type = skos:Collection || ?type = skos:Concept) }.
       
    58   ?root skos:narrower|skos:member ?uri.
       
    59   ?uri skos:prefLabel|rdfs:label ?label.
       
    60   FILTER (lang(?label) = ?language).
       
    61 }
       
    62 """,
       
    63                             'data-child-count-query':
       
    64 """
       
    65 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
    66 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
    67 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
    68 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
    69 SELECT (COUNT(?uri) as ?nb)
       
    70 WHERE {
       
    71     ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
       
    72     ?root skos:narrower|skos:member ?uri.
       
    73 }
       
    74 """
       
    75                             }))
       
    76 
       
    77 
       
    78 
       
    79 
       
    80 class SemForm(forms.Form):
       
    81     # __reg__ is updated with the real regexp by the js
       
    82     sem = forms.CharField(required=True, label="Dude, sem", 
       
    83                           widget=SemanticTreeWidget(attrs={
       
    84                             'size':  25, 
       
    85                             'class': "dude",
       
    86                             'data-url': "http://localhost:8080/openrdf-sesame/repositories/plan4learning",
       
    87                             'data-query':  
       
    88 """
       
    89 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
    90 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
    91 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
    92 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
    93 SELECT DISTINCT ?uri ?label
       
    94 WHERE {
       
    95     ?uri a skos:Concept.
       
    96     ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
       
    97     ?uri skos:prefLabel ?label.
       
    98     FILTER (lang(?label) = ?language).
       
    99     ?uri skos:prefLabel ?lab.
       
   100     FILTER regex (str(?lab), ?reg, 'i').
       
   101     FILTER (lang (?lab) = ?language).
       
   102     BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place).
       
   103     BIND (STRLEN(STR(?lab)) AS ?len)
       
   104 }
       
   105 ORDER BY ?place ?len ?lab
       
   106 """,
       
   107                             'data-root-query':
       
   108 """
       
   109 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   110 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   111 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   112 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   113 SELECT DISTINCT ?uri ?label
       
   114 WHERE {
       
   115     ?uri a skos:Collection ;
       
   116     skos:inScheme <http://skos.um.es/unescothes/CS000> ;    
       
   117     rdfs:label ?label .
       
   118     FILTER (lang(?label) = ?language). 
       
   119     FILTER NOT EXISTS { [skos:member ?uri] }
       
   120 }
       
   121 """,
       
   122                             'data-childs-query':
       
   123 """
       
   124 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   125 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   126 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   127 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   128 SELECT DISTINCT ?uri ?label
       
   129 WHERE {
       
   130   ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
       
   131   { ?uri a ?type
       
   132     FILTER (?type = skos:Collection || ?type = skos:Concept) }.
       
   133   ?root skos:narrower|skos:member ?uri.
       
   134   ?uri skos:prefLabel|rdfs:label ?label.
       
   135   FILTER (lang(?label) = ?language).
       
   136 }
       
   137 """,
       
   138                             'data-child-count-query':
       
   139 """
       
   140 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   141 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   142 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   143 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   144 SELECT (COUNT(?uri) as ?nb)
       
   145 WHERE {
       
   146     ?uri skos:inScheme <http://skos.um.es/unescothes/CS000> .
       
   147     ?root skos:narrower|skos:member ?uri.
       
   148 }
       
   149 """
       
   150                             }))
       
   151     iam = forms.CharField(required=True, label="Dude, iam", widget=SemanticTreeWidget(attrs={
       
   152                             'size':  25, 
       
   153                             'class': "dude",
       
   154                             'data-url': "http://localhost:8080/openrdf-sesame/repositories/plan4learning",
       
   155                             'data-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 a skos:Concept.
       
   164     ?uri skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Themes> .
       
   165     ?uri skos:prefLabel ?label.
       
   166     FILTER (lang(?label) = ?language).
       
   167     ?uri skos:prefLabel ?lab.
       
   168     FILTER regex (str(?lab), ?reg, 'i').
       
   169     FILTER (lang (?lab) = ?language).
       
   170     BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place).
       
   171     BIND (STRLEN(STR(?lab)) AS ?len)
       
   172 }
       
   173 ORDER BY ?place ?len ?lab
       
   174 """,
       
   175                             'data-root-query':
       
   176 """
       
   177 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   178 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   179 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   180 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   181 SELECT DISTINCT ?uri ?label
       
   182 WHERE {
       
   183     ?uri a skos:Concept ;
       
   184     skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Themes> ;    
       
   185     skos:prefLabel ?label .
       
   186     FILTER (lang(?label) = ?language). 
       
   187     FILTER NOT EXISTS { [skos:narrower ?uri] }
       
   188 }
       
   189 """,
       
   190                             'data-childs-query':
       
   191 """
       
   192 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   193 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   194 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   195 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   196 SELECT DISTINCT ?uri ?label
       
   197 WHERE {
       
   198   ?uri skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Themes> .
       
   199   { ?uri a ?type
       
   200     FILTER (?type = skos:Collection || ?type = skos:Concept) }.
       
   201   ?root skos:narrower|skos:member ?uri.
       
   202   ?uri skos:prefLabel|rdfs:label ?label.
       
   203   FILTER (lang(?label) = ?language).
       
   204 }
       
   205 """,
       
   206                             'data-child-count-query':
       
   207 """
       
   208 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   209 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   210 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   211 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   212 SELECT (COUNT(?uri) as ?nb)
       
   213 WHERE {
       
   214     ?uri skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Themes> .
       
   215     ?root skos:narrower|skos:member ?uri.
       
   216 }
       
   217 """
       
   218                             }))
       
   219     ntm = forms.CharField(required=True, label="Dude, ntm", widget=SemanticTagItWidget(attrs={
       
   220                             'size':  25, 
       
   221                             'class': "dude",
       
   222                             'data-url': "http://localhost:8080/openrdf-sesame/repositories/plan4learning",
       
   223                             'data-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 a skos:Concept.
       
   232     ?uri skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Themes> .
       
   233     ?uri skos:prefLabel ?label.
       
   234     FILTER (lang(?label) = ?language).
       
   235     ?uri skos:prefLabel ?lab.
       
   236     FILTER regex (str(?lab), ?reg, 'i').
       
   237     FILTER (lang (?lab) = ?language).
       
   238     BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place).
       
   239     BIND (STRLEN(STR(?lab)) AS ?len)
       
   240 }
       
   241 ORDER BY ?place ?len ?lab
       
   242 """,
       
   243                             'data-root-query':
       
   244 """
       
   245 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   246 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   247 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   248 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   249 SELECT DISTINCT ?uri ?label
       
   250 WHERE {
       
   251     ?uri a skos:Concept ;
       
   252     skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Themes> ;    
       
   253     skos:prefLabel ?label .
       
   254     FILTER (lang(?label) = ?language). 
       
   255     FILTER NOT EXISTS { [skos:narrower ?uri] }
       
   256 }
       
   257 """,
       
   258                             'data-childs-query':
       
   259 """
       
   260 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   261 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   262 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   263 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   264 SELECT DISTINCT ?uri ?label
       
   265 WHERE {
       
   266   ?uri skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Themes> .
       
   267   { ?uri a ?type
       
   268     FILTER (?type = skos:Collection || ?type = skos:Concept) }.
       
   269   ?root skos:narrower|skos:member ?uri.
       
   270   ?uri skos:prefLabel|rdfs:label ?label.
       
   271   FILTER (lang(?label) = ?language).
       
   272 }
       
   273 """,
       
   274                             'data-child-count-query':
       
   275 """
       
   276 PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
       
   277 PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
       
   278 PREFIX owl:<http://www.w3.org/2002/07/owl#>
       
   279 PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
       
   280 SELECT (COUNT(?uri) as ?nb)
       
   281 WHERE {
       
   282     ?uri skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Themes> .
       
   283     ?root skos:narrower|skos:member ?uri.
       
   284 }
       
   285 """
       
   286                             }))
       
   287 
       
   288 
       
   289