cluster_search/commit

Simplified things (a bit to much maybe).

authorChris Dijkshoorn
Fri Nov 29 22:01:02 2013 +0100
committerChris Dijkshoorn
Fri Nov 29 22:01:02 2013 +0100
commit0118c21b2656123b01fa30e0b388f734e66a9cf5
tree0dff3886afc72f3775b61258e4ea8441ab86b4e6
parente0b1a4d6139092c9cadf20fff90d317c1ea6252e
Diff style: patch stat
diff --git a/api/cluster_search.pl b/api/cluster_search.pl
index b26f84d..05a70c9 100644
--- a/api/cluster_search.pl
+++ b/api/cluster_search.pl
@@ -19,7 +19,7 @@
 :- use_module(library(cluster_search/rdf_search)).
 :- use_module(library(cluster_search/iface_util)).
 :- use_module(library(cluster_search/settings)).
-:- use_module(library(cluster_search/search_statistics)).
+%:- use_module(library(cluster_search/search_statistics)).
 
 % search modules
 :- use_module(library(cluster_search/graph_search)).
@@ -57,6 +57,15 @@ search_api(Request) :-
     enrich(Clusters, EnrichedClusters, Options),
     write_data(EnrichedClusters).
 
+%%	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(false)])
+	]),
+    Options = [query(Query)].
+
 %%	cluster_search(-Clusters, +Options)
 %
 %	Executes a graph search algorithm according to given options.
@@ -71,15 +80,6 @@ cluster_search(Clusters, Options) :-
     OrganizeOptions = [groupBy(path)],
     organize_resources(SearchResults, State, Clusters, OrganizeOptions).
 
-%%	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(false)])
-	]),
-    Options = [query(Query)].
-
 %%	write_data(+Data, +Options)
 %
 %	Write data in JSON format to output stream.
diff --git a/lib/cluster_search/filter.pl b/lib/cluster_search/filter.pl
index aa2687d..ac100f7 100644
--- a/lib/cluster_search/filter.pl
+++ b/lib/cluster_search/filter.pl
@@ -25,7 +25,6 @@
 	  [ target_goal/3,            % +Goal, +R, +Options
 	    filter_to_goal/4,		% +FilterList, +R, -Goal, +Options
 	    search_filter/2,		%
-
 	    filter_from_parameters/2,   % +Options, -Filter
 	    filter_from_parameters/3,   % +Options, -Filter, -Rest
 	    filter_to_parameter/2,	% +FilterList, -JSON
diff --git a/lib/cluster_search/graph_search.pl b/lib/cluster_search/graph_search.pl
index c80a7cb..9201d1d 100644
--- a/lib/cluster_search/graph_search.pl
+++ b/lib/cluster_search/graph_search.pl
@@ -1,26 +1,3 @@
-/*  This file is part of ClioPatria.
-
-    Author:
-    HTTP:	http://e-culture.multimedian.nl/
-    GITWEB:	http://gollem.science.uva.nl/git/ClioPatria.git
-    GIT:	git://gollem.science.uva.nl/home/git/ClioPatria.git
-    GIT:	http://gollem.science.uva.nl/home/git/ClioPatria.git
-    Copyright:  2007, E-Culture/MultimediaN
-
-    ClioPatria 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.
-
-    ClioPatria 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 ClioPatria.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
 :- module(graph_search,
 	  [ graph_search/3,		% +Query, -RDFState, +Options
 	    flush_graph_search_cache/0
@@ -28,28 +5,13 @@
 
 :- use_module(library(semweb/rdf_db)).
 :- use_module(library(debug)).
-:- use_module(library(option)).
 :- use_module(library(settings)).
 
 % util modules
 :- use_module(rdf_search).
-:- use_module(rdf_direct_search).
 :- use_module(rdf_backward_search).
 :- use_module(filter).
-
-
-/***************************************************
-* Settings
-***************************************************/
-
-:- setting(search:graphSearchCache, boolean, false,
-	   'Cache graph search results').
-:- setting(search:graphSearchCacheSize, nonneg, 50,
-	   'Maximum searches kept in cache (0 is unbound)').
-
-/***************************************************
-* graph search
-***************************************************/
+:- use_module(library(cluster_search/settings)).
 
 %%	graph_search(+Keyword, -RDFState, +Options) is det.
 %
@@ -65,28 +27,45 @@
 %	  * threshold(+Threshold)
 %	  Search cut-off threshold
 %
-%	@tbd	Merge with find/3 from biggraphs.pl
+%	@tbd restore different types of search and pruning in
+%	do_graph_search
+:- dynamic
+    graph_search_cache/4, % +Hash, +Kwd, +Options, -State
+    cache_generation/1.
 
 :- rdf_meta
-	graph_search(+, -, t).
-:- dynamic
-        graph_search_cache/4,		% +Hash, +Kwd, +Options, -State
-	cache_generation/1.
-
-graph_search(Kwd, State, Options) :-
-	setting(search:graphSearchCache, false), !,
-	debug(graph_search, 'graph_search Keyword: ~p, no caching', [Kwd]),
-	do_graph_search(Kwd, State, Options).
-graph_search(Kwd, State, Options) :-
-	check_cache_validity,
-	term_hash(Kwd+Options, Key),
-	(   graph_search_cache(Key, Kwd, Options, State),
-	    debug(graph_search, 'graph_search Keyword: ~p, in cache', [Kwd])
-	->  true
-	;   debug(graph_search, 'graph_search Keyword: ~p, caching', [Kwd]),
-	    do_graph_search(Kwd, State, Options),
-	    push_graph_search_cache(Key, Kwd, Options, State)
-	).
+    graph_search(+, -, t).
+
+graph_search(Keyword, State, Options) :-
+    setting(search:graphSearchCache, false), !,
+    do_graph_search(Keyword, State, Options).
+
+graph_search(Keyword, State, Options) :-
+    check_cache_validity,
+    term_hash(Keyword+Options, Key),
+    (   graph_search_cache(Key, Keyword, Options, State),
+	debug(graph_search, 'graph_search Keyword: ~p, in cache', [Keyword])
+    ->  true
+    ;   debug(graph_search, 'graph_search Keyword: ~p, caching', [Keyword]),
+	do_graph_search(Keyword, State, Options),
+	push_graph_search_cache(Key, Keyword, Options, State)
+    ).
+
+do_graph_search(Keyword, State, Options) :-
+    setting(search:basic_search_target, SearchTarget),
+    filter_to_goal([type(SearchTarget)], R, Goal, Options),
+    TargetCond = target_goal(Goal, R),
+    rdf_backward_search(Keyword, TargetCond, State, Options),
+    prune(State, []).
+
+prune(State, Options) :-
+    rdf_prune_search(State, Options),
+    rdf_search_property(State, graph_size(Nodes)),
+    debug(rdf_search, 'After prune: ~D nodes in graph', [Nodes]).
+
+/***************************************************
+* caching
+***************************************************/
 
 %%	check_cache_validity is det.
 %
@@ -96,13 +75,13 @@ graph_search(Kwd, State, Options) :-
 %	the search, but that is not easy to define.
 
 check_cache_validity :-
-	cache_generation(CacheGen),
-	rdf_generation(CacheGen), !.
+    cache_generation(CacheGen),
+    rdf_generation(CacheGen), !.
 check_cache_validity :-
-	rdf_generation(CacheGen),
-	retractall(cache_generation(_)),
-	assert(cache_generation(CacheGen)),
-	flush_graph_search_cache.
+    rdf_generation(CacheGen),
+    retractall(cache_generation(_)),
+    assert(cache_generation(CacheGen)),
+    flush_graph_search_cache.
 
 
 %%	flush_graph_search_cache is det.
@@ -110,7 +89,7 @@ check_cache_validity :-
 %	Flushes the cache for graph_search/3.
 
 flush_graph_search_cache :-
-	retractall(graph_search_cache(_,_,_,_)).
+    retractall(graph_search_cache(_,_,_,_)).
 
 %%	push_graph_search_cache(+Key, +Keyword, +Options, -State) is det.
 %
@@ -132,46 +111,3 @@ push_graph_search_cache(Key, Kwd, Options, State) :-
 	;   true
 	),
 	assertz(graph_search_cache(Key, Kwd, Options, State)).
-
-
-do_graph_search(Kwd, State, Options) :-
-    % Get the type of search from option list of set default from settings, either literal,concept,backward.
-    setting(search:search_type, Default),
-    option(search_type(Type), Options, Default),
-
-    option(filter(Filter0), Options, []),
-    search_filter(Filter0, Filter),
-
-	filter_to_goal(Filter, R, Goal, Options),
-	debug(graph_search, 'graph_search Used search_type: ~p Options in do_graph_search: ~p ', [Type, Options]),
-	TargetCond = target_goal(Goal, R),
-	(   Type == concept
-	->  rdf_concept_search(Kwd, TargetCond, State, Options)
-	;   Type == literal
-	->  rdf_literal_search(Kwd, TargetCond, State, Options)
-	;   rdf_backward_search(Kwd, TargetCond, State, Options)
-	),
-	(   option(prune(true), Options)
-	->  prune(State, [])
-	;   option(prune(full), Options)
-	->  prune(State, [recursive])
-	;   true
-	)/*,
-	(   search_graph_filter_option(Options)
-	->  rdf_search_property(State, graph(Graph0)),
-	    search_graph_rdf_graph(Graph0, RDF0),
-	    big_graphs:filter_rdf(RDF0, RDF, Options)
-	    %search_graph_rdf_graph(Graph, RDF),
-	    %rdf_search:set_graph_of_state(Graph, State)
-	;   true
-	)*/.
-
-
-%%	prune(!State) is det.
-%
-%	Prune paths from the graph that do not end in a target.
-
-prune(State, Options) :-
-	rdf_prune_search(State, Options),
-	rdf_search_property(State, graph_size(Nodes)),
-	debug(rdf_search, 'After prune: ~D nodes in graph', [Nodes]).
diff --git a/lib/cluster_search/rdf_backward_search.pl b/lib/cluster_search/rdf_backward_search.pl
index a009028..3437213 100644
--- a/lib/cluster_search/rdf_backward_search.pl
+++ b/lib/cluster_search/rdf_backward_search.pl
@@ -1,26 +1,3 @@
-/*  This file is part of ClioPatria.
-
-    Author:
-    HTTP:	http://e-culture.multimedian.nl/
-    GITWEB:	http://gollem.science.uva.nl/git/ClioPatria.git
-    GIT:	git://gollem.science.uva.nl/home/git/ClioPatria.git
-    GIT:	http://gollem.science.uva.nl/home/git/ClioPatria.git
-    Copyright:  2007, E-Culture/MultimediaN
-
-    ClioPatria 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.
-
-    ClioPatria 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 ClioPatria.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
 :- module(rdf_backward_search,
 	  [ rdf_backward_search/4,	% +KeyWord, +TargetCond, -State, +Options
 	    predicate_weight/2
diff --git a/lib/cluster_search/settings.pl b/lib/cluster_search/settings.pl
index ab8adf9..b073842 100644
--- a/lib/cluster_search/settings.pl
+++ b/lib/cluster_search/settings.pl
@@ -38,3 +38,8 @@
 	   'Setting indicating the level of enrichment of results.').
 :- setting(search:ui, uri, rui:rijksmuseumUI,
 	   'Default URI defining the UI for search').
+:- setting(search:graphSearchCache, boolean, false,
+	   'Cache graph search results').
+:- setting(search:graphSearchCacheSize, nonneg, 50,
+	   'Maximum searches kept in cache (0 is unbound)').
+
diff --git a/lib/cluster_search/web_ui.pl b/lib/cluster_search/web_ui.pl
index fad343f..b1c4d39 100644
--- a/lib/cluster_search/web_ui.pl
+++ b/lib/cluster_search/web_ui.pl
@@ -86,7 +86,7 @@ reply_page(Page, Options) :-
     html_resource(css('search.css'), [requires([css('bootstrap.min.css')])]),
     reply_html_page(
 	[
-	\title(Page),
+	\title(Page, Options),
 	link([href(Icon),rel('shortcut icon')]),
 	meta([name('viewport'),content('width=device-width, initial-scale=1.0')])
     ],
@@ -205,16 +205,20 @@ ssl_verify(_SSL, _ProblemCertificate, _AllCertificates, _FirstCertificate, _Erro
 %%	title(+Page)
 %
 %	Replies the title for the given page.
-title(front) -->
+title(front, _) -->
     {rdf(rui:rijksmuseumUI, dcterms:title, literal(lang(en, Title)))},
     html(title(Title)).
-title(about) -->
+title(about, _) -->
     {rdf(rui:rijksmuseumUI, dcterms:title, literal(lang(en, Title))),
     concat('About ', Title, TitleAbout)
     },
     html(title(TitleAbout)).
-title(results) --> html(title('Results')).
-title(result) --> html(title('Item')).
+title(results, _) --> html(title('Results')).
+title(result, Options) -->
+    {option(uri(Uri), Options),
+     rdf(Uri, dcterms:title, literal(Title))
+    },
+    html(title(Title)).
 
 %%	scripts(+Page)
 %