acronym better management
authorcavaliet
Tue, 17 Sep 2013 16:11:13 +0200
changeset 95 594f79a5706b
parent 94 fd2ba38ce4ad
child 96 d2c4dbdf3548
acronym better management
src/p4l/settings.py
src/p4l/static/p4l/js/semantictree.js
src/p4l/utils.py
--- a/src/p4l/settings.py	Mon Sep 16 18:00:04 2013 +0200
+++ b/src/p4l/settings.py	Tue Sep 17 16:11:13 2013 +0200
@@ -408,12 +408,13 @@
 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
+SELECT DISTINCT ?uri ?label ?acro
 WHERE {
     ?uri a skos:Concept.
     ?uri skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Projects> .
     ?uri skos:prefLabel ?label.
     ?uri skos:prefLabel ?lab.
+    OPTIONAL { ?uri skos:altLabel ?acro }.
     FILTER regex (str(?lab), ?reg, 'i').
     BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place).
     BIND (STRLEN(STR(?lab)) AS ?len)
@@ -425,11 +426,12 @@
 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
+SELECT DISTINCT ?uri ?label ?acro
 WHERE {
     ?uri a skos:Concept ;
     skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Projects> ;    
     skos:prefLabel ?label .
+    OPTIONAL { ?uri skos:altLabel ?acro }
 }
 ORDER BY ?label
 """
@@ -440,12 +442,13 @@
 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
+SELECT DISTINCT ?uri ?label ?acro
 WHERE {
     ?uri a skos:Concept.
     ?uri skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Organizations> .
     ?uri skos:prefLabel ?label.
     ?uri skos:prefLabel ?lab.
+    OPTIONAL { ?uri skos:altLabel ?acro }.
     FILTER regex (str(?lab), ?reg, 'i').
     BIND (STRLEN(STRBEFORE (str(?lab), ?reg)) AS ?place).
     BIND (STRLEN(STR(?lab)) AS ?len)
@@ -457,11 +460,12 @@
 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
+SELECT DISTINCT ?uri ?label ?acro
 WHERE {
     ?uri a skos:Concept ;
     skos:inScheme <http://www.iiep.unesco.org/plan4learning/scheme/Organizations> ;    
     skos:prefLabel ?label .
+    OPTIONAL { ?uri skos:altLabel ?acro }
 }
 ORDER BY ?label
 """
--- a/src/p4l/static/p4l/js/semantictree.js	Mon Sep 16 18:00:04 2013 +0200
+++ b/src/p4l/static/p4l/js/semantictree.js	Tue Sep 17 16:11:13 2013 +0200
@@ -23,10 +23,11 @@
                 success: function( data ) {
                 	// build response
                 	response( $.map( data["results"]["bindings"], function( item ) {
-                		//console.log(item["uri"]["value"] + " = " + item["label"]["value"]);
+                		// If acronym
+                		var s = (("acro" in item)?(item["acro"]["value"] + ". "):"") + item["label"]["value"];
                 		return {
-                			label: item["label"]["value"],
-                			value: item["label"]["value"] + " (" + item["uri"]["value"] + ")"
+                			label: s,
+                			value: s + " (" + item["uri"]["value"] + ")"
                 		}
                     }));
                 }
@@ -73,8 +74,9 @@
 	            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");
-	            $('#term-tree-'+input_name)
-	                .jstree({
+	            // We load the tree only once
+	            if(!$('#term-tree-'+input_name).hasClass("jstree")){
+	            	$('#term-tree-'+input_name).jstree({
 	                    themes: {
 	                        theme: "apple",
 	                        dots: true,
@@ -131,23 +133,25 @@
 	                            				attr = {'rel':'leaf'};
 	                            			}
 	                            		}
+	                            		// If acronym :
+	                            		var s = (("acro" in b[i])?(b[i]["acro"]["value"] + ". "):"") + b[i]["label"]["value"];
 	                            		// nb of child > 0 : state closed if yes, no state if not.
 	                            		if(nb>0){
 		                            		mytree.push({
 			                            		"data" : { 
-			                            			"title" : b[i]["label"]["value"] + " (" + nb + ") "
+			                            			"title" : s + " (" + nb + ") "
 			                            		},
 			                            		"state" : "closed",
-			                            		"metadata" : {uri: "<"+uri+">", label:b[i]["label"]["value"]},
+			                            		"metadata" : {uri: "<"+uri+">", label:s},
 			                            		"attr": attr
 			                            	});
 	                            		}
 	                            		else{
 	                            			mytree.push({
 			                            		"data" : { 
-			                            			"title" : b[i]["label"]["value"]
+			                            			"title" : s
 			                            		},
-			                            		"metadata" : {uri: "<"+uri+">", label:b[i]["label"]["value"]},
+			                            		"metadata" : {uri: "<"+uri+">", label:s},
 			                            		"attr": attr
 			                            	});
 	                            		}
@@ -171,12 +175,7 @@
 	                    },
 	                    plugins : [ "themes", "json_data", "ui", "types"]
 	                });
-	        },
-	        close: function( event, ui ) {
-	        	//console.log("close");
-	        	// this is the span with class="dialog" and id="dialog-inputname"
-	        	var input_name = this.id.substr(7);
-	            $.jstree._reference($('#term-tree-'+input_name)).destroy();
+	            }
 	        },
 	        buttons: [
 	            {
--- a/src/p4l/utils.py	Mon Sep 16 18:00:04 2013 +0200
+++ b/src/p4l/utils.py	Tue Sep 17 16:11:13 2013 +0200
@@ -107,7 +107,7 @@
                             first_label = b['label']['value']
                 else:
                     if 'acro' in b and 'value' in b['acro']:
-                        first_label = b['acro']['value'] + " : " + b['label']['value']
+                        first_label = b['acro']['value'] + ". " + b['label']['value']
                     else:
                         first_label = b['label']['value']
                 if lang in tmp_dict or first_label: