--- a/src/p4l/settings.py Thu Sep 05 15:05:47 2013 +0200
+++ b/src/p4l/settings.py Thu Sep 05 15:47:30 2013 +0200
@@ -173,6 +173,67 @@
NB_RECORDS_BY_PAGE = 20
SPARQL_QUERY_ENDPOINT = "http://localhost:8080/openrdf-sesame/repositories/plan4learning"
+SPARQL_SUBJECT_QUERIES = {
+"filter" : """
+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
+""",
+"root" : """
+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> ;
+ skos:prefLabel|rdfs:label ?label .
+ FILTER (lang(?label) = ?language).
+ FILTER NOT EXISTS { [skos:member ?uri] }
+}
+""",
+"childs" : """
+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).
+}
+""",
+"child-count" : """
+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.
+}
+"""
+}
REST_FRAMEWORK = {
# Use hyperlinked styles by default.
--- a/src/p4l/static/p4l/css/semantictree.css Thu Sep 05 15:05:47 2013 +0200
+++ b/src/p4l/static/p4l/css/semantictree.css Thu Sep 05 15:47:30 2013 +0200
@@ -1,4 +1,4 @@
-@charset "UTF-8";
+/*@charset "UTF-8";
.large_25 {
width: 25px;
@@ -32,3 +32,4 @@
font-weight: bold;
color: red;
}
+*/
\ No newline at end of file
--- a/src/p4l/static/p4l/js/semantictree.js Thu Sep 05 15:05:47 2013 +0200
+++ b/src/p4l/static/p4l/js/semantictree.js Thu Sep 05 15:47:30 2013 +0200
@@ -54,12 +54,7 @@
$( '#dialog-link-'+input_name ).click(function( event ) {
event.preventDefault();
var input_name = this.id.substr(12);
- console.log("input_name 2 = " + input_name);
- console.log($( '#dialog-'+input_name ));
$( '#dialog-'+input_name ).dialog( "open" );
- //if(! $('#thesaurus_tree').is(":disabled")) {
- // $( ".dialog" ).dialog( "open" );
- //}
});
$( '#dialog-'+input_name ).dialog({
@@ -76,7 +71,6 @@
var root_query = $("#id_"+input_name).attr("data-root-query");
var childs_query = $("#id_"+input_name).attr("data-childs-query");
var child_count_query = $("#id_"+input_name).attr("data-child-count-query");
- console.log("ICI 1");
$('#term-tree-'+input_name)
.jstree({
themes: {
@@ -88,7 +82,6 @@
ajax: {
url : url,
data: function(node){
- console.log("ICI 2");
var res = {};
if(node.data) {
res.query = childs_query;
@@ -98,15 +91,12 @@
res.query = root_query;
}
res.$language = '"fr"';
- console.log("ICI 3");
- console.log(res);
return res;
},
headers: {
Accept: "application/sparql-results+json;charset=UTF-8"
},
success: function(json) {
- console.log("ICI 4");
var b = json["results"]["bindings"];
var mytree = [];
var l = b.length;
@@ -132,7 +122,7 @@
if(nb>0){
mytree.push({
"data" : {
- "title" : b[i]["label"]["value"] + " (" + nb + ") " + uri.substr(uri.lastIndexOf("/")+1),
+ "title" : b[i]["label"]["value"] + " (" + nb + ") "
},
"state" : "closed",
"metadata" : {uri: "<" + uri + ">", label:b[i]["label"]["value"]}
@@ -142,14 +132,12 @@
else{
mytree.push({
"data" : {
- "title" : b[i]["label"]["value"] + " " + uri.substr(uri.lastIndexOf("/")+1),
+ "title" : b[i]["label"]["value"]
},
"metadata" : {uri: "<" + uri + ">", label:b[i]["label"]["value"]}
});
}
}
- console.log("ICI 5");
- console.log(mytree);
return mytree;
},
error: function() {
@@ -183,10 +171,18 @@
selected_node = $(selected[0]);
// Update text input : val() if classical input, add tag to tagit instance if necessary
if($('#id_'+input_name).hasClass("semantic-tree-tagit")){
+ // #TODO : update when we add tag-it for real
$('#id_'+input_name).tagit("createTag", selected_node.data('label'));
}
else{
- $('#id_'+input_name).val(selected_node.data('label'));
+ // First we update the uri/label dict
+ uri = selected_node.data('uri');
+ label = selected_node.data('label');
+ angular.element($('#id_'+input_name)[0]).scope().updateUriLabelDict(uri, label);
+ // Angular does not listen to val() event so we update the model value manually:
+ angular.element($('#id_'+input_name)[0]).controller('ngModel').$setViewValue(uri);
+ // And update the text field val
+ $('#id_'+input_name).val(label + " (" + uri + ")");
}
//$('#thesaurus_tree').data('term_tree_node',selected_node.data('term_tree_node'));
//$('#thesaurus_tree').val(selected_node.data('term_tree_node').id).trigger('change');
@@ -208,7 +204,7 @@
function init_tagit_autocomplete()
{
// Semantic search management with tag-it feature
- $(".semantic-tree-tagit").tagit({
+ /*$(".semantic-tree-tagit").tagit({
tagSource: function(request, response) {
// We use "this" because there can be several autocomplete in the same form.
// this.element[0] is the input.
@@ -235,7 +231,7 @@
});
},
allowSpaces: true
- });
+ });*/
}
--- a/src/p4l/views.py Thu Sep 05 15:05:47 2013 +0200
+++ b/src/p4l/views.py Thu Sep 05 15:47:30 2013 +0200
@@ -127,69 +127,10 @@
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> ;
- skos:prefLabel|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.
-}
-"""
+ 'data-query': settings.SPARQL_SUBJECT_QUERIES["filter"],
+ 'data-root-query': settings.SPARQL_SUBJECT_QUERIES["root"],
+ 'data-childs-query': settings.SPARQL_SUBJECT_QUERIES["childs"],
+ 'data-child-count-query': settings.SPARQL_SUBJECT_QUERIES["child-count"]
})
return context