accurator/commit
Added random strategy, ranking based on number of users that annotated.
author | Chris Dijkshoorn |
---|---|
Thu Apr 28 16:14:53 2016 +0200 | |
committer | Chris Dijkshoorn |
Thu Apr 28 16:14:53 2016 +0200 | |
commit | 815416a87e99fb2bc4cd9e8cc5518175bf286a96 |
tree | 72faaed213a9927ec09430c1158b1b43f7708d64 |
parent | b4af6c367d1075d867a992f59e02d7b8341108d7 |
Diff style: patch stat
diff --git a/api/accurator.pl b/api/accurator.pl index a6ea752..2c7c23b 100644 --- a/api/accurator.pl +++ b/api/accurator.pl @@ -334,7 +334,7 @@ strategy(random, Options) :- reply_json_dict(Result). strategy(ranked_random, Options) :- - strategy_ranked_random(Result, Options), + strategy_user_ranked_random(Result, Options), reply_json_dict(Result). strategy(expertise, Options) :- diff --git a/lib/accurator/annotation.pl b/lib/accurator/annotation.pl index a774f91..a07c507 100644 --- a/lib/accurator/annotation.pl +++ b/lib/accurator/annotation.pl @@ -2,7 +2,8 @@ annotation_fields/2, annotations/3, annotations/4, - number_of_annotations/2 + number_of_annotations/2, + number_of_users/2 ]). :- use_module(library(accurator/ui_elements)). @@ -176,3 +177,14 @@ number_of_annotations(Uri, NumberOfAnnotations) :- Annotations), !, length(Annotations, NumberOfAnnotations). number_of_annotations(_Uri, 0) :- !. + +%% number_of_users(+Uri, -NumberOfUsers) +% +% Get the number of users who annotated the object of the given uri. +number_of_users(Uri, NumberOfUsers) :- + setof(User, + ( rdf(Annotation, oa:hasTarget, Uri), + rdf(Annotation, oa:annotatedBy, User)), + Users), !, + length(Users, NumberOfUsers). +number_of_users(_Uri, 0) :- !. diff --git a/lib/accurator/recommendation/strategy_random.pl b/lib/accurator/recommendation/strategy_random.pl index 65de9fc..3c7e33e 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_user_ranked_random/2, random_from_bin/3]). :- use_module(library(accurator/accurator_user)). @@ -41,6 +42,28 @@ assign_random(Number, SourceList, [Uri|List]) :- NewNumber is Number-1, assign_random(NewNumber, NewSourceList, List). + +%% strategy_user_ranked_random(-Result, +Options) +% +% Assign a number of objects in a random fassion, prioritysing +% items with low numbers of users that annotated them. +strategy_user_ranked_random(Result, Options) :- + option(target(Target), Options), + option(number(Number), Options), + option(filter(Filter), Options), + % get list of all targets + findall(Uri, rdf(Uri, rdf:type, Target), SourceList), + filter(Filter, SourceList, FilteredList, Options), + maplist(number_of_users_pair, 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_users_pair(Uri, Number-Uri) :- + number_of_users(Uri, Number). + + %% strategy_ranked_random(-Result, +Options) % % Assign a number of objects in a random fassion, prioritysing