accurator/commit

Ranked random algorithm completed except for number of annotations retrieval.

authorChris Dijkshoorn
Sat Apr 2 10:28:18 2016 +0200
committerChris Dijkshoorn
Sat Apr 2 10:28:18 2016 +0200
commita74ffc88e7f57854aff6a461c336b986201eea4b
tree9659927736136ded88169889d7c90cb714b44708
parentb9f76396cd4d54c2539c7ac343d704fac182e73e
Diff style: patch stat
diff --git a/lib/accurator/recommendation/strategy_expertise.pl b/lib/accurator/recommendation/strategy_expertise.pl
index a2d159a..993363e 100644
--- a/lib/accurator/recommendation/strategy_expertise.pl
+++ b/lib/accurator/recommendation/strategy_expertise.pl
@@ -2,6 +2,7 @@
 
 :- use_module(library(accurator/accurator_user)).
 :- use_module(library(accurator/expertise)).
+:- use_module(library(accurator/recommendation/strategy_random)).
 :- use_module(library(cluster_search/cs_filter)).
 :- use_module(library(cluster_search/rdf_search)).
 :- use_module(library(cluster_search/owl_ultra_lite)).
@@ -108,7 +109,7 @@ set_expertise_agenda(MaxNumber, Agenda, [max_agenda(_)|Options0], Options) :-
 	reverse(ReverseGroupedValues, GroupedValues),
 	expertise_from_bins(GroupedValues, 0, NumberItems, Agenda).
 
-%%	expertise_from_bins(+Bins, +Counter,+ MaxN, -Agenda)
+%%	expertise_from_bins(+Bins, +Counter, +MaxN, -Agenda)
 %
 %	Determine the agenda by picking expertise values from bins. When a
 %	bin has multiple expertise areas, pick one at random from that bin.
@@ -118,22 +119,6 @@ expertise_from_bins(Bins, N0, MaxN, [Expertise|List]) :-
 	random_from_bin(Bins, NewBins, Expertise),
 	expertise_from_bins(NewBins, N, MaxN, List).
 
-%%	random_from_bin(+Bins, +NewBins, -Expertise)
-%
-%	Get a random value from the bin. If the bin is empty aftwerwards,
-%	remove from bins, otherwise only remove the value from the bin.
-random_from_bin([Value-Bin|Bins], NewBins, Expertise) :-
-	%EXPERIMENT: not so random for now..
-	%length(Bin, Number0),
-	%Number is Number0-1,
-	%random_between(0, Number, Index),
-	Index = 0,
-	nth0(Index, Bin, Expertise, Rest),
-	(  Rest == []
-	-> NewBins = Bins
-	;  NewBins = [Value-Rest|Bins]
-	).
-
 %%	number_of_items(+NumberExpertise, +Number0, -NumberExpertise)
 %
 %	Determine the maximum number of agenda items.
diff --git a/lib/accurator/recommendation/strategy_random.pl b/lib/accurator/recommendation/strategy_random.pl
index 0fff06f..32704ad 100644
--- a/lib/accurator/recommendation/strategy_random.pl
+++ b/lib/accurator/recommendation/strategy_random.pl
@@ -1,5 +1,6 @@
 :- module(strategy_random, [strategy_random/2,
-							strategy_ranked_random/2]).
+							strategy_ranked_random/2,
+							random_from_bin/3]).
 
 :- use_module(library(accurator/accurator_user)).
 :- use_module(library(semweb/rdf_db)).
@@ -42,7 +43,40 @@ strategy_ranked_random(Result, Options) :-
 	option(target(Target), Options),
 	option(number(Number), Options),
 	option(filter(Filter), Options),
-	% Get list of all targets
+	% get list of all targets
     findall(Uri, rdf(Uri, rdf:type, Target), SourceList),
 	filter(Filter, SourceList, FilteredList, Options),
-    assign_random(Number, FilteredList, Result).
+	maplist(number_of_annotations, FilteredList, PairList),
+	% sort to create proper bins
+	keysort(PairList, SortedList),
+	group_pairs_by_key(SortedList, Bins),
+	results_from_bins(Bins, 0, Number, Result).
+
+
+number_of_annotations(Uri, Annotations-Uri) :-
+	random_between(0, 10, Annotations).
+
+%%	results_from_bins(+Bins, +Counter, +MaxN, -Agenda)
+%
+%	Get results by picking uris from bins sorted by the number of
+%	annotatoins (inverse would be interesting for reviewing!). When a
+%	bin has multiple uris, pick one at random from that bin.
+results_from_bins(_Bins, MaxN, MaxN, []).
+results_from_bins(Bins, N0, MaxN, [Expertise|List]) :-
+	N is N0 + 1,
+	random_from_bin(Bins, NewBins, Expertise),
+	results_from_bins(NewBins, N, MaxN, List).
+
+%%	random_from_bin(+Bins, +NewBins, -Expertise)
+%
+%	Get a random value from the bin. If the bin is empty aftwerwards,
+%	remove from bins, otherwise only remove the value from the bin.
+random_from_bin([Value-Bin|Bins], NewBins, Expertise) :-
+	length(Bin, Number0),
+	Number is Number0-1,
+	random_between(0, Number, Index),
+	nth0(Index, Bin, Expertise, Rest),
+	(  Rest == []
+	-> NewBins = Bins
+	;  NewBins = [Value-Rest|Bins]
+	).