skos_browser/commit

Add concept info

authorMichiel Hildebrand
Fri Nov 9 16:02:24 2012 +0100
committerMichiel Hildebrand
Fri Nov 9 16:02:24 2012 +0100
commitda964ce9f29aa3cd41ab0bafacd396101a34d476
tree9072adbc8ff104ba964188ee798710448c0ce76b
parent5602f9390f3c56fb23bb132496fd5ef73d13df9d
Diff style: patch stat
diff --git a/api/skos_concepts.pl b/api/skos_concepts.pl
index 7202f4a..f241bde 100644
--- a/api/skos_concepts.pl
+++ b/api/skos_concepts.pl
@@ -177,110 +177,7 @@ has_narrower(Concept, true) :-
 has_narrower(_, false).
 
 
-%%	http_concept_info(+Request)
-%
-%       API handler to fetch info about a URI.
-%
-%       @TBD support for language tags
 
-http_concept_info(Request) :-
-	http_parameters(Request,
-			[  concept(C,
-			       [description('Concept to request info about')])
-			]),
-	rdf_display_label(C, Label),
-	skos_description(C, Desc),
-	skos_alt_labels(C, AltLabels0),
-	delete(AltLabels0, Label, AltLabels),
-	skos_related_concepts(C, Related),
-	voc_get_computed_props(C, Amalgame),
-	format('Content-type: text/html~n~n'),
-	phrase(html(\html_info_snippet(C, Label, Desc, AltLabels, Related, Amalgame)), HTML),
-	print_html(HTML).
-
-skos_description(C, Desc) :-
-	(   rdf_has(C, skos:scopeNote, Lit)
-	->  literal_text(Lit, Desc)
-	;   Desc = ''
-	).
-skos_alt_labels(C, AltLabels) :-
-	findall(AL, ( rdf_has(C, skos:altLabel, Lit),
-		      literal_text(Lit, AL)
-		    ),
-		AltLabels0),
-	sort(AltLabels0, AltLabels).
-skos_related_concepts(C, Related) :-
-	Concept = concept(R, Label),
-	findall(Concept, ( skos_related(C, R),
-			   rdf_display_label(R, Label)
-		    ),
-		Related).
-
-skos_related(C, R) :-
-	rdf_has(C, skos:related, R).
-skos_related(C, R) :-
-	rdf_has(R, skos:related, C),
-	\+ rdf_has(C, skos:related, R).
-
-html_info_snippet(URI, Label, Desc, AltLabels, Related, AmalGame) -->
-	{ truncate_atom(Desc, 80, ShortDesc)
-	},
-	html(div(class(infobox),
-		 [ h3([\resource_link(URI, Label),
-		       \html_label_list(AltLabels)
-		      ]),
-		   div(class(uri), URI),
-		   div(style('float:left'),
-		       [ div([class(desc), title(Desc)], ShortDesc),
-			 \html_related_list(Related)
-		       ]),
-		   div(class(amalgame),
-		       \html_amalgame_props(AmalGame))
-		 ])).
-
-html_label_list([]) --> !.
-html_label_list(Ls) -->
-	html(span(class(altlabels),
-		  [ ' (',
-		    \html_label_list_(Ls),
-		    ')'
-		  ])).
-
-html_label_list_([L]) --> !,
-	html(span(class(label), L)).
-html_label_list_([L|Ls]) -->
-	html(span(class(label), [L,', '])),
-	html_label_list_(Ls).
-
-html_related_list([]) --> !.
-html_related_list(Cs) -->
-	html(div(class(related),
-		 [ 'related: ',
-		   \html_concept_list(Cs)
-		 ])).
-
-html_concept_list([concept(URI, Label)]) --> !,
-	resource_link(URI, Label).
-html_concept_list([concept(URI, Label)|Cs]) -->
-	html([\resource_link(URI, Label), ', ']),
-	html_concept_list(Cs).
-
-html_amalgame_props([]) --> !.
-html_amalgame_props(Props) -->
-	html(table(\amalgame_props(Props))).
-
-amalgame_props([]) --> !.
-amalgame_props([Term|Ts]) -->
-	{ Term =.. [Prop, Value],
-	  literal_text(Value, Txt)
-	},
-	html(tr([td(Prop), td(Txt)])),
-	amalgame_props(Ts).
-
-resource_link(URI, Label) -->
-	{ www_form_encode(URI, EncURI)
-	},
-	html(a(href(location_by_id(list_resource)+'?r='+EncURI), Label)).
 
 		 /*******************************
 		 *	     UTILILIES          *
diff --git a/applications/skos_browser.pl b/applications/skos_browser.pl
index 66a1143..2b81705 100644
--- a/applications/skos_browser.pl
+++ b/applications/skos_browser.pl
@@ -1,13 +1,15 @@
 :- module(skos_browser, []).
 
 :- use_module(library(http/http_dispatch)).
+:- use_module(library(http/http_parameters)).
 :- use_module(library(http/html_write)).
 :- use_module(library(http/http_path)).
 :- use_module(library(http/html_head)).
 :- use_module(library(yui3_beta)).
+:- use_module(library(semweb/rdf_label)).
 
 :- http_handler(skosbrowser(.), http_skos_browser, []).
-
+:- http_handler(skosbrowser(concept), http_concept_info, []).
 
 %%	http_skos_browser(+Request)
 %
@@ -19,9 +21,11 @@ http_skos_browser(_Request) :-
 	reply_html_page(cliopatria(default),
 			[ title(['SKOS vocabulary browser'])
 			],
-			[  \html_requires(css('columnbrowser.css')),
+			[  \html_requires(css('skosbrowser.css')),
+			   \html_requires(css('columnbrowser.css')),
 			   h2('SKOS vocabulary browser'),
 			   div([class('yui-skin-sam'), id(browser)], []),
+			   div([id(detail)], []),
 			   script(type('text/javascript'),
 				  [ \yui_script
 				  ])
@@ -38,11 +42,18 @@ yui_script -->
 	  Browser = browser
 	},
 	yui3([json([modules(json(Modules))])],
-	     [datasource|Includes],
+	     [datasource,'node-load'|Includes],
 	     [ \skos_api_datasource(DS),
-	       \skos_browser(DS, Browser)
+	       \skos_browser(DS, Browser),
+	       \yui3_on(Browser, itemSelect, [e], \js_item_select)
 	     ]).
 
+js_item_select -->
+	{ http_location_by_id(http_concept_info, URL)
+	},
+	html(['var url = "',URL,'"+"?concept="+e.id;']),
+	yui3_load(one(id(detail)), symbol(url)).
+
 skos_api_datasource(DS) -->
 	yui3_new(DS,
 		 'Y.DataSource.IO',
@@ -96,3 +107,87 @@ js_module(columnbrowser, json([fullpath(Path),
 			     requires([node,event,widget,resourcelist])
 			    ])) :-
     http_absolute_location(js('columnbrowser.js'), Path, []).
+
+
+
+		 /*******************************
+		 *	    concept view	*
+		 *******************************/
+
+%%	http_concept_info(+Request)
+%
+%       API handler to fetch info about a URI.
+%
+%       @TBD support for language tags
+
+http_concept_info(Request) :-
+	http_parameters(Request,
+			[  concept(C,
+			       [description('Concept to request info about')])
+			]),
+	rdf_display_label(C, Label),
+	skos_description(C, Desc),
+	skos_alt_labels(C, AltLabels0),
+	delete(AltLabels0, Label, AltLabels),
+	skos_related_concepts(C, Related),
+	format('Content-type: text/html~n~n'),
+	phrase(html(\html_info_snippet(C, Label, Desc, AltLabels, Related)), HTML),
+	print_html(HTML).
+
+skos_description(C, Desc) :-
+	(   rdf_has(C, skos:scopeNote, Lit)
+	->  literal_text(Lit, Desc)
+	;   Desc = ''
+	).
+
+skos_alt_labels(C, AltLabels) :-
+	findall(AL, ( rdf_has(C, skos:altLabel, Lit),
+		      literal_text(Lit, AL)
+		    ),
+		AltLabels0),
+	sort(AltLabels0, AltLabels).
+
+skos_related_concepts(C, Related) :-
+	Concept = concept(R, Label),
+	findall(Concept, ( skos_related(C, R),
+			   rdf_display_label(R, Label)
+		    ),
+		Related).
+
+skos_related(C, R) :-
+	rdf_has(C, skos:related, R).
+skos_related(C, R) :-
+	rdf_has(R, skos:related, C),
+	\+ rdf_has(C, skos:related, R).
+
+html_info_snippet(URI, Label, Desc, AltLabels, Related) -->
+	html(div(class(infobox),
+		 [ h3([\resource_link(URI, Label)
+		      ]),
+		   div(class(uri), URI),
+		   div(
+		       [ div(class(labels),
+			     \html_label_list(AltLabels)),
+			 div(class(desc), Desc),
+			 div(class(related),
+			     \html_concept_list(Related))
+		       ])
+		 ])).
+
+html_label_list([]) --> !.
+html_label_list([L]) --> !,
+	html(span(class(label), L)).
+html_label_list([L|Ls]) -->
+	html(span(class(label), [L,', '])),
+	html_label_list(Ls).
+
+html_concept_list([concept(URI, Label)]) --> !,
+	resource_link(URI, Label).
+html_concept_list([concept(URI, Label)|Cs]) -->
+	html([\resource_link(URI, Label), ', ']),
+	html_concept_list(Cs).
+
+resource_link(URI, Label) -->
+	{ www_form_encode(URI, EncURI)
+	},
+	html(a(href(location_by_id(list_resource)+'?r='+EncURI), Label)).
diff --git a/web/css/skosbrowser.css b/web/css/skosbrowser.css
new file mode 100644
index 0000000..e69de29