accurator/commit

Checking for results per expertise topic #106

authorChris Dijkshoorn
Fri Oct 2 13:07:47 2015 +0200
committerChris Dijkshoorn
Fri Oct 2 13:07:47 2015 +0200
commit687d5b3c76652c4c55fd921817aa2be18cac431a
treef352f30db5631b89e14c2456674e3dee98756dcc
parentf01874298029ce43ea3c8aa1a3c5bfe97dc896c2
Diff style: patch stat
diff --git a/api/accurator.pl b/api/accurator.pl
index dcb0f9a..6b04847 100644
--- a/api/accurator.pl
+++ b/api/accurator.pl
@@ -124,7 +124,11 @@ get_parameters_domain(Request, Options) :-
 %
 %	Retrieves a list of expertise topics.
 expertise_topics_api(Request) :-
-    get_parameters_expertise(Request, Options),
+    get_parameters_expertise(Request, Options0),
+	logged_on(User),
+	Options1 = [user(User) | Options0],
+	get_domain(User, Domain),
+	Options = [domain(Domain) | Options1],
 	get_expertise_topics(Dic, Options),
 	reply_json_dict(Dic).
 
@@ -136,6 +140,8 @@ get_parameters_expertise(Request, Options) :-
         [locale(Locale,
 		    [description('Locale of language elements to retrieve'),
 			 optional(false)]),
+		target(Target,
+			[default('http://www.europeana.eu/schemas/edm/ProvidedCHO')]),
 		taxonomy(Taxonomy,
 			[description('Domain specific taxonomy.'),
 			 optional(false)]),
@@ -151,7 +157,7 @@ get_parameters_expertise(Request, Options) :-
 			 default(3)])]),
     atom_number(NumberOfTopicsString, NumberOfTopics),
 	atom_number(NumberOfChildrenString, NumberOfChildren),
-	Options = [locale(Locale), taxonomy(Taxonomy),
+	Options = [locale(Locale), target(Target), taxonomy(Taxonomy),
 			   topConcept(TopConcept), numberOfTopics(NumberOfTopics),
 			   numberOfChildren(NumberOfChildren)].
 
diff --git a/lib/accurator/expertise.pl b/lib/accurator/expertise.pl
index e0a70cc..85229dc 100644
--- a/lib/accurator/expertise.pl
+++ b/lib/accurator/expertise.pl
@@ -9,6 +9,9 @@
 */
 
 :- use_module(library(semweb/rdf_db)).
+:- use_module(library(accurator/recommendation/strategy_expertise)).
+:- use_module(api(cluster_search)).
+:- use_module(library(accurator/accurator_user)).
 
 :- rdf_register_prefix(as, 'http://accurator.nl/schema#').
 :- rdf_register_prefix(txn, 'http://lod.taxonconcept.org/ontology/txn.owl#').
@@ -16,18 +19,21 @@
 
 %%	get_expertise_topics(-Topics, +Options)
 %
-%	Retrieves a list of expertise topics, starting from the top concept.
+%	Retrieves a list of expertise topics (e.g. bird orders), starting
+%	from the top concept.
 get_expertise_topics(Topics, Options) :-
 	option(locale(Locale), Options),
 	option(topConcept(TopConcept), Options),
 	option(numberOfTopics(Number), Options),
-	get_number_topics([TopConcept], Number, TopicUris),
+	get_number_topics([TopConcept], Number, TopicUris1),
+	filter_topics(TopicUris1, TopicUris, Options),
 	maplist(get_info_topics(Locale, Options), TopicUris, TopicDicts),
 	Topics = expertise_topics{topics:TopicDicts}.
 
 %%	get_domain_topics(+Domain, -Topics)
 %
-%	Retrieves a list of expertise topics, starting from the top concept.
+%	Retrieves a list of domain topics (e.g. bird or bible), starting
+%	from the top concept.
 get_domain_topics(Domain, Topics) :-
 	rdf(DomainUri, rdf:type, as:'Domain'),
 	rdf(DomainUri, rdfs:label, literal(Domain)),
@@ -78,6 +84,27 @@ get_broader_child(Concept, Child) :-
 
 %add subproperty query
 
+%%	filter_topics(+Topics, -FilteredTopics, +Options)
+%
+%	Filter the list of topics.
+filter_topics([], [], _Options) :- !.
+filter_topics([Topic|Topics], [Topic|FilteredTopics], Options) :-
+	check_topic(Topic, Options), !,
+	filter_topics(Topics, FilteredTopics, Options).
+filter_topics([_Topic|Topics], FilteredTopics, Options) :-
+	filter_topics(Topics, FilteredTopics, Options).
+
+%%	check_topic(+Topic)
+%
+%	See if topic has results.
+check_topic(Topic, Options) :-
+	cluster_recommender(Topic, State, Options),
+	get_target_count(State, Targets),
+	Targets > 0.
+
+% get the number of targets found from state
+get_target_count(state(_,_,_,Count,_,_,_,_,_,_,_), Count).
+
 %%	get_info_topics(+Locale, +Options, +Uri, -Dict)
 %
 %	Get label of topics and when specified the children of topics.
diff --git a/lib/accurator/recommendation/strategy_expertise.pl b/lib/accurator/recommendation/strategy_expertise.pl
index 3e6b403..d987a34 100644
--- a/lib/accurator/recommendation/strategy_expertise.pl
+++ b/lib/accurator/recommendation/strategy_expertise.pl
@@ -1,4 +1,4 @@
-:- module(strategy_expertise, [strategy_expertise/2]).
+:- module(strategy_expertise, [strategy_expertise/2, cluster_recommender/3]).
 
 :- use_module(library(accurator/accurator_user)).
 :- use_module(library(accurator/expertise)).
@@ -15,9 +15,9 @@
 
 %strategy_expertise(Result, []).
 
-%%      strategy_expertise(-Result, +Options)
+%%	strategy_expertise(-Result, +Options)
 %
-%       Assign a number of objects in a random fassion.
+%	Recommend items based on user expertise.
 strategy_expertise(Clusters, Options0) :-
 	option(user(User), Options0),
 	get_domain(User, Domain),