accurator/commit

Basing ranked random strategy on number of annotations.

authorChris Dijkshoorn
Sat Apr 2 11:27:02 2016 +0200
committerChris Dijkshoorn
Sat Apr 2 11:27:02 2016 +0200
commita35b648a5f59179656d4543556633471f3aaeb76
tree1055e2762f0f17a739fa97f9dad5d68ed89e3e52
parenta8e959df349cb1640e8f4607860a698ca6e07a7f
Diff style: patch stat
diff --git a/lib/accurator/annotation.pl b/lib/accurator/annotation.pl
index a66f639..a774f91 100644
--- a/lib/accurator/annotation.pl
+++ b/lib/accurator/annotation.pl
@@ -1,7 +1,8 @@
 :- module(annotation, [
 			  annotation_fields/2,
 			  annotations/3,
-			  annotations/4
+			  annotations/4,
+			  number_of_annotations/2
 		  ]).
 
 :- use_module(library(accurator/ui_elements)).
@@ -165,3 +166,13 @@ get_annotation(Uri, AnnotationBody, AnnotationHash) :-
 process_annotation(literal(Annotation), Annotation) :- !.
 process_annotation(Annotation, Label) :-
 	rdf_display_label(Annotation, _, Label).
+
+%%	number_of_annotations(+Uri, -NumberOfAnnotations)
+%
+%	Get the number of annotations for a given uri
+number_of_annotations(Uri, NumberOfAnnotations) :-
+	setof(Annotation,
+		  rdf(Annotation, oa:hasTarget, Uri),
+		  Annotations), !,
+	length(Annotations, NumberOfAnnotations).
+number_of_annotations(_Uri, 0) :- !.
diff --git a/lib/accurator/recommendation/strategy_random.pl b/lib/accurator/recommendation/strategy_random.pl
index 73684cc..3dcecee 100644
--- a/lib/accurator/recommendation/strategy_random.pl
+++ b/lib/accurator/recommendation/strategy_random.pl
@@ -3,6 +3,7 @@
 							random_from_bin/3]).
 
 :- use_module(library(accurator/accurator_user)).
+:- use_module(library(accurator/annotation)).
 :- use_module(library(semweb/rdf_db)).
 :- use_module(library(random)).
 :- use_module(library(pairs)).
@@ -51,15 +52,15 @@ strategy_ranked_random(Result, Options) :-
 	% get list of all targets
     findall(Uri, rdf(Uri, rdf:type, Target), SourceList),
 	filter(Filter, SourceList, FilteredList, Options),
-	maplist(number_of_annotations, FilteredList, PairList),
+	maplist(number_of_annotations_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_annotations_pair(Uri, Number-Uri) :-
+	number_of_annotations(Uri, Number).
 
-number_of_annotations(Uri, Annotations-Uri) :-
-	random_between(0, 10, Annotations).
 
 %%	results_from_bins(+Bins, +Counter, +MaxN, -Agenda)
 %