cluster_search/commit

Generates the carousel from the info in the UI rdf.

authorChris Dijkshoorn
Wed Sep 18 13:15:15 2013 +0200
committerChris Dijkshoorn
Wed Sep 18 13:15:15 2013 +0200
commite2e75be4f2b0ce92abbf97584f64444a6ec4dadb
tree514f072d5efe3477ee512c6b01cf67091cb1d315
parent1b4d4587c07faac9e4d0274949929add6a3fb568
Diff style: patch stat
diff --git a/api/cluster_search.pl b/api/cluster_search.pl
index ef907e6..dff0b1b 100644
--- a/api/cluster_search.pl
+++ b/api/cluster_search.pl
@@ -25,7 +25,7 @@
 :- use_module(library(cluster_search/graph_search)).
 
 % output modules
-:- use_module(library(cluster_search/web_page_elements)).
+:- use_module(library(cluster_search/web_ui)).
 
 % register namespaces
 :- rdf_register_prefix(rma, 'http://purl.org/collections/nl/rma/schema#').
diff --git a/lib/cluster_search/web_page_elements.pl b/lib/cluster_search/web_ui.pl
similarity index 89%
rename from lib/cluster_search/web_page_elements.pl
rename to lib/cluster_search/web_ui.pl
index d197417..4b6c3ac 100644
--- a/lib/cluster_search/web_page_elements.pl
+++ b/lib/cluster_search/web_ui.pl
@@ -1,7 +1,7 @@
 /* page_elements
 * number of dcg rules which allow easy creation of html pages
 */
-:- module(web_page_elements, [web/1, about/1, result/1]).
+:- module(web_ui, [web/1, about/1, result/1]).
 
 % http library modules
 :- use_module(library(http/html_write)).
@@ -20,10 +20,7 @@
 :- use_module(cliopatria(components/label)).
 
 % load ui config file
-%:- rdf_load(rdf('cluster_search_ui.ttl')).
-
-:- html_resource(css('search.css'),
-		 [requires([css('bootstrap.min.css')])]).
+:- rdf_load(rdf('rijksmuseum_ui.ttl')).
 
 :- set_setting_default(thumbnail:thumbnail_size, size(350,300)).
 :- set_setting_default(thumbnail:medium_size, size(1280,1024)).
@@ -31,9 +28,6 @@
 
 :- rdf_register_prefix(rma, 'http://purl.org/collections/nl/rma/schema#').
 
-% Carousel items
-
-
 web(Request) :-
     get_parameters(Request, Options),
     option(query(Query), Options),
@@ -49,9 +43,8 @@ result(Request) :-
     get_parameters(Request, Options),
     reply_page(result, Options).
 
-/* get_parameters(+Request, -Options)
-*  retrieves an option list of parameters from the url
-*/
+%% get_parameters(+Request, -Options)
+%  Retrieves an option list of parameters from the url.
 get_parameters(Request, Options) :-
     http_parameters(Request,
 	[query(Query, [description('Entered Query'),optional(true)]),
@@ -59,62 +52,12 @@ get_parameters(Request, Options) :-
 	]),
     Options = [query(Query), uri(URI)].
 
-:- multifile cliopatria:image_url/2.
-/* image_url(+Uri, -ImageUrl)
-*
-*  Check if image is present, if so, return request url.
-*  If the image is not present, check if present at RMA site.
-*  If not present, but a imageURL in database, remove imageURL triple
-*  If not present in cache, database and at RMA, send image stub.
-*/
-image_url(Uri, ImageUrl) :-
-	cliopatria:image_url(Uri, ImageUrl).
-image_url(Uri, ImageUrl) :-
-    rdf(Uri, rma:imageURL, Image),
-    url_cached(Image, file(_)),
-    !,
-    concat('cache/original?uri=', Image, RequestUrl),
-    http_absolute_location(root(RequestUrl), ImageUrl, []).
-
-image_url(Uri, ImageUrl) :-
-    rdf(Uri, rma:imageURL, Image),
-    https_header_response(Image, Status),
-    Status == 200,
-    !,
-    concat('cache/original?uri=', Image, RequestUrl),
-    http_absolute_location(root(RequestUrl), ImageUrl, []).
-
-image_url(Uri, Stub) :-
-    rdf(Uri, rma:imageURL, Image),
-    !,
-    rdf_retractall(Uri, rma:imageURL, Image),
-    http_absolute_location(icons('stub.png'), Stub, []).
-
-image_url(_, Stub) :- http_absolute_location(icons('stub.png'), Stub, []).
-
-/* https_header_response(+URL, -Status)
-*  Return the response header of input URL
-*/
-https_header_response(URL, Status) :-
-    http_open(URL, In,
-	  [method(head),
-	   status_code(Status),
-	   cert_verify_hook(ssl_verify)
-	  ]),
-    close(In).
-
-:- public ssl_verify/5.
-/* ssl_verify(+SSL, +ProblemCert, +AllCerts, +FirstCert, +Error)
-*  Currently we accept  all  certificates.
-*/
-ssl_verify(_SSL, _ProblemCertificate, _AllCertificates, _FirstCertificate, _Error).
-
-
-/* reply_page(+Request, +Options)
-*  replies the html page corresponding to the type of page and Request
-*/
+%% reply_page(+Request, +Options)
+%  replies the html page corresponding to the type of page and Request
 reply_page(Page, Options) :-
-    http_absolute_location(icons('signpainter.png'), Icon, []),
+    rdf(csui:clusterSearchDemoUI, csui:icon, literal(IconName)),
+    http_absolute_location(icons(IconName), Icon, []),
+    html_resource(css('search.css'), [requires([css('bootstrap.min.css')])]),
     reply_html_page(
 	[
 	\title(Page),
@@ -122,18 +65,17 @@ reply_page(Page, Options) :-
 	meta([name('viewport'),content('width=device-width, initial-scale=1.0')])
     ],
 	[
-	    \html_requires(css('search.css')),
-	    \navigation_bar(Page),
-	    \scripts(Page),
-	    \generate_content(Page, Options)
+	\html_requires(css('search.css')),
+	\navigation_bar(Page),
+	\scripts(Page),
+	\generate_content(Page, Options)
     ]).
 
 generate_content(front, _) -->
-    {http_absolute_location(icons('carousel/1.jpg'), Carousel1, []),
-     http_absolute_location(icons('carousel/2.jpg'), Carousel2, []),
-     http_absolute_location(icons('carousel/3.jpg'), Carousel3, [])
-    },
-    content(front, [item(Carousel1,'?query=japan','Search for Japan'),item(Carousel2,'?query=het+melkmeisje','Search for het melkmeisje'),item(Carousel3,'?query=rembrandt','Search for Rembrandt')]).
+    {get_carousel_items(CarouselItems),
+     debug(carousel_rdf, 'The found carousel items: ~p', [CarouselItems])
+     },
+    content(front, CarouselItems).
 
 generate_content(results, Options) -->
     content(results, Options).
@@ -149,6 +91,18 @@ generate_content(result, Options) -->
 generate_content(about, _) -->
     content(about).
 
+%% get_carousel_items(-CarouselItems)
+%  retrieve items for the carousel from the database
+get_carousel_items(CarouselItems) :-
+    findall(item(LocationAbsolute, Action, Title),
+	    (	rdf(Item, rdf:type, csui:carouselItem),
+		rdf(Item, csui:imageLocation, literal(LocationRelative)),
+		http_absolute_location(img(LocationRelative), LocationAbsolute, []),
+		rdf(Item, csui:action, literal(Action)),
+		rdf(Item, dcterms:title, literal(lang(en, Title)))
+	    ),
+	    CarouselItems).
+
 /***************************************************
 * web page elements dcg
 ***************************************************/
@@ -156,7 +110,11 @@ generate_content(about, _) -->
 /* title(+Page)
 * replies the title for the given page
 */
-title(front) --> html(title('Cluster Search')).
+title(front) -->
+    {rdf(csui:clusterSearchDemoUI, dcterms:title, literal(lang(en, Title))),
+    debug(rdf_settings, 'The title: ~p', [Title])
+    },
+    html(title('Cluster Search')).
 title(about) --> html(title('About Cluster Search')).
 title(results) --> html(title('Results')).
 title(result) --> html(title('Item')).
@@ -418,3 +376,54 @@ carousel_navigation -->
 	   span(class('icon-next'),''))
 	]
     ).
+
+
+:- multifile cliopatria:image_url/2.
+/* image_url(+Uri, -ImageUrl)
+*
+*  Check if image is present, if so, return request url.
+*  If the image is not present, check if present at RMA site.
+*  If not present, but a imageURL in database, remove imageURL triple
+*  If not present in cache, database and at RMA, send image stub.
+*/
+image_url(Uri, ImageUrl) :-
+	cliopatria:image_url(Uri, ImageUrl).
+image_url(Uri, ImageUrl) :-
+    rdf(Uri, rma:imageURL, Image),
+    url_cached(Image, file(_)),
+    !,
+    concat('cache/original?uri=', Image, RequestUrl),
+    http_absolute_location(root(RequestUrl), ImageUrl, []).
+
+image_url(Uri, ImageUrl) :-
+    rdf(Uri, rma:imageURL, Image),
+    https_header_response(Image, Status),
+    Status == 200,
+    !,
+    concat('cache/original?uri=', Image, RequestUrl),
+    http_absolute_location(root(RequestUrl), ImageUrl, []).
+
+image_url(Uri, Stub) :-
+    rdf(Uri, rma:imageURL, Image),
+    !,
+    rdf_retractall(Uri, rma:imageURL, Image),
+    http_absolute_location(icons('stub.png'), Stub, []).
+
+image_url(_, Stub) :- http_absolute_location(icons('stub.png'), Stub, []).
+
+/* https_header_response(+URL, -Status)
+*  Return the response header of input URL
+*/
+https_header_response(URL, Status) :-
+    http_open(URL, In,
+	  [method(head),
+	   status_code(Status),
+	   cert_verify_hook(ssl_verify)
+	  ]),
+    close(In).
+
+:- public ssl_verify/5.
+/* ssl_verify(+SSL, +ProblemCert, +AllCerts, +FirstCert, +Error)
+*  Currently we accept  all  certificates.
+*/
+ssl_verify(_SSL, _ProblemCertificate, _AllCertificates, _FirstCertificate, _Error).
diff --git a/rdf/cluster_search_ui.ttl b/rdf/cluster_search_ui.ttl
deleted file mode 100644
index b04f3e1..0000000
--- a/rdf/cluster_search_ui.ttl
+++ /dev/null
@@ -1,8 +0,0 @@
-@prefix ui:		<http://semanticweb.cs.vu.nl/annotate/ui/> .
-@prefix rdf:	<http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
-@prefix rdfs:	<http://www.w3.org/2000/01/rdf-schema#> .
-@prefix dc:		<http://purl.org/dc/terms/> .
-@prefix skos:	<http://www.w3.org/2004/02/skos/core#> .
-
-ui:clusterSearchDemoUI a ui:clusterSearchUI ;
-	dc:title "Cluster Search"@en .
\ No newline at end of file
diff --git a/rdf/cluster_search_ui_schema.ttl b/rdf/cluster_search_ui_schema.ttl
index 4fd0330..914a52f 100644
--- a/rdf/cluster_search_ui_schema.ttl
+++ b/rdf/cluster_search_ui_schema.ttl
@@ -1,11 +1,11 @@
-@prefix :       <http://semanticweb.cs.vu.nl/annotate/ui/> .
+@prefix ui:       <http://semanticweb.cs.vu.nl/clustersearch/ui/> .
 @prefix rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
 @prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> .
 @prefix dc:     <http://purl.org/dc/terms/> .
 @prefix skos:   <http://www.w3.org/2004/02/skos/core#> .
 
-:uiLabel a rdf:Property;
+ui:uiLabel a rdf:Property;
 rdfs:label "super-property of all labels"@en .
 
-:filterLabel rdfs:subPropertyOf :uiLabel .
+ui:filterLabel rdfs:subPropertyOf ui:uiLabel .
 
diff --git a/rdf/rijksmuseum_ui.ttl b/rdf/rijksmuseum_ui.ttl
new file mode 100644
index 0000000..d821b8e
--- /dev/null
+++ b/rdf/rijksmuseum_ui.ttl
@@ -0,0 +1,24 @@
+@prefix csui:     <http://semanticweb.cs.vu.nl/clustersearch/ui/> .
+@prefix rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix dcterms:	<http://purl.org/dc/terms/> .
+@prefix skos:   <http://www.w3.org/2004/02/skos/core#> .
+
+csui:rijksmuseumUI a csui:clusterSearchUI ;
+	dcterms:title "Cluster Search"@en ;
+	csui:iconLocation "signpainter.png" .
+	
+csui:carouselJapan a csui:carouselItem ;
+	dcterms:title "Search for Japan"@en ;
+	csui:imageLocation "carousel/japan.jpg" ;
+	csui:action "?query=japan" .
+	
+csui:carouselRembandt a csui:carouselItem ;
+	dcterms:title "Search for Rembrandt"@en ;
+	csui:imageLocation "carousel/rembrandt.jpg" ;
+	csui:action "?query=Rembrandt" .
+	
+csui:carouselMelkmeisje a csui:carouselItem ;
+	dcterms:title "Search for het melkmeisje"@en ;
+	csui:imageLocation "carousel/melkmeid.jpg" ;
+	csui:action "?query=het+melkmeisje" .
\ No newline at end of file
diff --git a/rdf/void.ttl b/rdf/void.ttl
index 10a375f..49ce577 100644
--- a/rdf/void.ttl
+++ b/rdf/void.ttl
@@ -5,7 +5,7 @@
 @prefix   dcterms: <http://purl.org/dc/terms/> .
 
 [ vann:preferredNamespacePrefix "csui" ;
-  vann:preferredNamespaceUri "http://semanticweb.cs.vu.nl/annotate/ui/"
+  vann:preferredNamespaceUri "http://semanticweb.cs.vu.nl/clustersearch/ui/"
 ] .
 
 <cluster-search-ui-schema>
@@ -13,7 +13,7 @@
 	dcterms:title "Cluster Search UI configuration schema";
 	void:dataDump <cluster_search_ui_schema.ttl> .
 
-<clusters-search-ui>
+<rijksmuseum-search-ui>
 	a void:Dataset ;
-	dcterms:title "Cluster Search UI configuration ui instance";
-	void:dataDump <cluster_search_ui.ttl> .
+	dcterms:title "Cluster Search UI configuration ui instance for the Rijksmuseum collection";
+	void:dataDump <rijksmuseum_ui.ttl> .
diff --git a/web/icons/carousel/1.jpg b/web/img/carousel/japan.jpg
similarity index 100%
rename from web/icons/carousel/1.jpg
rename to web/img/carousel/japan.jpg
diff --git a/web/icons/carousel/2.jpg b/web/img/carousel/melkmeid.jpg
similarity index 100%
rename from web/icons/carousel/2.jpg
rename to web/img/carousel/melkmeid.jpg
diff --git a/web/icons/carousel/3.jpg b/web/img/carousel/rembrandt.jpg
similarity index 100%
rename from web/icons/carousel/3.jpg
rename to web/img/carousel/rembrandt.jpg
diff --git a/web/icons/stub.png b/web/img/stub.png
similarity index 100%
rename from web/icons/stub.png
rename to web/img/stub.png