EDM/commit

Modularize the code

authorJan Wielemaker
Thu Nov 25 11:34:34 2010 +0100
committerJan Wielemaker
Thu Nov 25 11:34:34 2010 +0100
commit63c8265dc1ec28dc1207fe14c792f786aaf715ab
tree0bc7317f15eb4f374fdbfef331f90c96393995d5
parentff82f22863878c723eade0934399d7396322f0a0
Diff style: patch stat
diff --git a/components/edm_components.pl b/components/edm_components.pl
new file mode 100644
index 0000000..3072615
--- /dev/null
+++ b/components/edm_components.pl
@@ -0,0 +1,71 @@
+/*  Part of ClioPatria SeRQL and SPARQL server
+
+    Author:        Jan Wielemaker
+    E-mail:        J.Wielemaker@cs.vu.nl
+    WWW:           http://www.swi-prolog.org
+    Copyright (C): 2010, University of Amsterdam,
+		   VU University Amsterdam
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    as published by the Free Software Foundation; either version 2
+    of the License, or (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+    As a special exception, if you link this library with other files,
+    compiled with a Free Software compiler, to produce an executable, this
+    library does not by itself cause the resulting executable to be covered
+    by the GNU General Public License. This exception does not however
+    invalidate any other reasons why the executable file might be covered by
+    the GNU General Public License.
+*/
+
+:- module(edm_components,
+	  [ edm_display_link//2		% +URI, +Options
+	  ]).
+:- include(bundle(html_page)).
+:- use_module(cliopatria(hooks)).
+:- use_module(library(http/page_info)).
+:- use_module(library(semweb/rdf_db)).
+:- use_module(library(http/http_path)).
+
+/** <module> Domain-specific components for EDM models
+
+    * When displaying a link to a WebResource, it either uses the
+    referenced image as label or shows both the internal link and
+    a link to the external resource.
+*/
+
+
+%%	edm_display_link(+URI, +Options)// is semidet.
+%
+%	Display EDM WebResources.  If  the   resource  is  a  thumbnail,
+%	display it inline. Else put an icon behind the default link that
+%	links to the external site.
+
+edm_display_link(R, Options) -->
+	{ \+ memberchk(edm(false), Options),
+	  rdf_has(R, rdf:type, ens:'WebResource')
+	},
+	(   { page_content_type(R, Type),
+	      sub_atom(Type, 0, _, _, 'image/')
+	    }
+	->  html(a(href(R), img([class(thumbnail), src(R)])))
+	;   { http_absolute_location(icons('external-link-ltr-icon.png'),
+				     External, [])
+	    },
+	    html(span([ \rdf_link(R, [edm(false)|Options]),
+			html(a([class(img), href(R)], img(src(External))))
+		      ]))
+	).
+
+
+
diff --git a/skin/EDM.pl b/components/edm_graph.pl
similarity index 61%
rename from skin/EDM.pl
rename to components/edm_graph.pl
index 033b0c6..cf9cc0c 100644
--- a/skin/EDM.pl
+++ b/components/edm_graph.pl
@@ -1,92 +1,32 @@
-:- module(edm,
-	  [
+:- module(edm_graph,
+	  [ edm_context_graph/3,	% +URI, -Graph, +Options
+	    edm_node_shape/3		% +URI, -Shape, +Options
 	  ]).
 :- use_module(cliopatria(hooks)).
 :- use_module(library(uri)).
 :- use_module(library(semweb/rdf_db)).
 :- use_module(library(semweb/rdfs)).
 :- use_module(library(semweb/rdf_abstract)).
+:- use_module(library(http/page_info)).
 :- use_module(library(http/html_write)).
-:- use_module(library(http/http_open)).
-:- use_module(library(http/http_path)).
 :- use_module(library(lists)).
 :- use_module(components(label)).
 :- use_module(library(settings)).
 :- use_module(library(count)).
 
-/** <module> Customise ClioPatria for EDM
+/** <module> EDM Context graphs
 
-This module customises ClioPatria  for  use   with  EDM  (Europeana Data
-Model) data. It realises two customizations:
-
-    * When displaying a link to a WebResource, it either uses the
-    referenced image as label or shows both the internal link and
-    a link to the external resource.
-
-    * Context graphs are customised, both in how they are computed and
-    in the rendering of the EDM classes.
+This module customises context graphs, both in how they are computed and
+in the rendering of the EDM classes.
 
 @see cliopatria(hooks) for a description of the hooks.
 */
 
-:- rdf_register_ns(ens, 'http://www.europeana.eu/schemas/edm/').
-:- rdf_register_ns(ore, 'http://www.openarchives.org/ore/terms/').
-
-%%	cliopatria:display_link(+URI, +Options)// is det.
-%
-%	Display EDM WebResources.  If  the   resource  is  a  thumbnail,
-%	display it inline. Else put an icon behind the default link that
-%	links to the external site.
-
-cliopatria:display_link(R, Options) -->
-	{ \+ memberchk(edm(false), Options),
-	  rdf_has(R, rdf:type, ens:'WebResource')
-	},
-	(   { content_type(R, Type),
-	      sub_atom(Type, 0, _, _, 'image/')
-	    }
-	->  html(a(href(R), img([class(thumbnail), src(R)])))
-	;   { http_absolute_location(icons('external-link-ltr-icon.png'),
-				     External, [])
-	    },
-	    html(span([ \rdf_link(R, [edm(false)|Options]),
-			html(a([class(img), href(R)], img(src(External))))
-		      ]))
-	).
-
-
-:- dynamic
-	content_type_cache/2.
-
-content_type(URL, MimeType) :-
-	content_type_cache(URL, Type), !,
-	atom(Type),
-	Type = MimeType.
-content_type(URL, MimeType) :-
-	uri_components(URL, Components),
-	uri_data(scheme, Components, Scheme),
-	Scheme == http,
-	catch(http_open(URL, Stream,
-			[ method(head),
-			  header(content_type, Type)
-			]), _, fail),
-	close(Stream),
-	assertz(content_type_cache(URL, Type)),
-	MimeType = Type.
-content_type(URL, _) :-
-	assertz(content_type_cache(URL, meta(fail))),
-	fail.
-
-
-		 /*******************************
-		 *	       CONTEXT		*
-		 *******************************/
-
 % Use SVG context graphs, so we can include images.
 
 :- set_setting_default(graphviz:format, svg).
 
-%%	cliopatria:context_graph(+URI, -Graph, +Options)
+%%	edm_context_graph(+URI, -Graph, +Options)
 %
 %	Compute the EDM context graph. This is currently defined to do a
 %	two-step breadth-first expansion of the graph from URI using the
@@ -97,7 +37,7 @@ content_type(URL, _) :-
 	edm_relation(r),
 	edm_class(r).
 
-cliopatria:context_graph(R, RDF, Options) :-
+edm_context_graph(R, RDF, Options) :-
 	option(style(edm), Options),
 	bf_graph(R, 2, 100, 20, RDF0),
 	minimise_graph(RDF0, RDF1),		% remove inverse/symmetric/...
@@ -163,12 +103,12 @@ edm_class(ore:'Proxy').
 edm_class(ens:'PhysicalThing').
 
 
-%%	cliopatria:node_shape(+URI, -Shape, +Options)
+%%	edm_node_shape(+URI, -Shape, +Options)
 %
 %	Realise   EDM-specific   vizualisation   of     nodes   in   the
 %	context-graph.
 
-cliopatria:node_shape(URI, Shape, Options) :-
+edm_node_shape(URI, Shape, Options) :-
 	option(style(edm), Options),
 	node_shape(URI, Shape, Options).
 
@@ -177,7 +117,7 @@ node_shape(URI, Shape, Options) :-
 	Shape = [shape(tripleoctagon),style(filled),fillcolor('#ff85fd')].
 node_shape(URI, Shape, _Options) :-
 	rdf_has(URI, rdf:type, ens:'WebResource'),
-	content_type(URI, Type),
+	page_content_type(URI, Type),
 	sub_atom(Type, 0, _, _, 'image/'),
 	Shape = [img([src(URI)])].
 node_shape(URI, Shape, _Options) :-
diff --git a/config-available/EDM.pl b/config-available/EDM.pl
index 0c9a894..2d96715 100644
--- a/config-available/EDM.pl
+++ b/config-available/EDM.pl
@@ -1,4 +1,6 @@
 :- module(conf_EDM, []).
+:- use_module(library(semweb/rdf_db)).
+:- use_module(cliopatria(hooks)).
 
 /** <module> View Europeana Data Model
 
@@ -6,4 +8,17 @@ This config installs hooks into the  system   to  vizualise parts of the
 Europeana Data Model (EDM).
 */
 
-:- use_module(skin('EDM')).
+:- rdf_register_ns(ens, 'http://www.europeana.eu/schemas/edm/').
+:- rdf_register_ns(ore, 'http://www.openarchives.org/ore/terms/').
+
+:- use_module(components(edm_components)).
+:- use_module(components(edm_graph)).
+
+cliopatria:display_link(R, Options) -->
+	edm_display_link(R, Options).
+
+cliopatria:context_graph(R, RDF, Options) -->
+	edm_context_graph(R, RDF, Options).
+
+cliopatria:node_shape(URI, Shape, Options) -->
+	edm_node_shape(URI, Shape, Options).