yaz/commit

support gardening for waisda data

authorMichiel Hildebrand
Sat Feb 12 16:45:05 2011 +0100
committerMichiel Hildebrand
Sat Feb 12 16:45:05 2011 +0100
commit016186120ac11bc40e29acb6098377d2ad78f62b
tree208f46032a9ac7e44e073979c55ace326f35fb96
parente8cff415dee20f0dd808f5352e7dd27b70e3934c
Diff style: patch stat
diff --git a/applications/yaz_mgarden.pl b/applications/yaz_mgarden.pl
index 3612d99..94ee0d7 100644
--- a/applications/yaz_mgarden.pl
+++ b/applications/yaz_mgarden.pl
@@ -51,12 +51,12 @@ http_yaz_mgarden(Request) :-
 				[optional(true),
 				 description('Current video')]),
 			  process(Process,
-			       [optional(true), desription('When set only annotations within this process are shown')]),
+			       [desription('When set only annotations within this process are shown')]),
 			  user(User,
 				[default(CurrentUser),
 				 description('When set only annotations created by this user are shown')])
-  			]),
-	process_video(Process, Video),
+   			]),
+	rdf(Process,opmv:used,Video),
 	Options = [process(Process),
 		   user(User)
   		  ],
@@ -67,36 +67,19 @@ http_yaz_mgarden(Request) :-
 	set_player_score(User, Process),
 	video_annotations(Video, As0, Options),
 	sort_by_arg(As0, 2, As),
- 	tag_matches(As, User, Process, 10000, Annotations),
+	setting(game:match_interval, Interval),
+ 	tag_matches(As, User, Process, Interval, Annotations),
 	active_players(Process, Players),
  	html_video_page(Process, Video, CurrentUser, Players, Annotations, 0, Options).
 
-process_video(Process, Video) :-
-	(   var(Video),
-	    var(Process)
-	->  fail % proper error
-	;   var(Video)
-	->  rdf(Process,opmv:used,Video)
-	;   true
-	).
-
-
 tag_matches([], _, _, _, []).
 tag_matches([A0|As], User, Process, Interval, [A|Rest]) :-
-	A0 = annotation(Value,Start,End,Entries),
+	A0 = annotation(Value,Start,End,Entries,Score),
 	A =  annotation(Value,Start,End,Entries,Score,Matches),
-	tag_score(Entries, Score),
-	findall(M,tag_match(Value, Start, User, Process, Interval, M),Ms),
+ 	findall(M,tag_match(Value, Start, User, Process, Interval, M),Ms),
 	sort(Ms, Matches),
  	tag_matches(As, User, Process, Interval, Rest).
 
-tag_score(Entries, Score) :-
-	findall(S, (member(i(E,_), Entries),
-		    rdf(E, pprime:score, literal(S))
-		   ),
-		Ss),
-	sumlist(Ss, Score).
-
 tag_match(literal(Tag), Time, User, Game, Interval, Match) :-
 	Match = match(Type, 0, E, literal(Tag1)),
 	snowball(dutch, Tag, Stem0),
diff --git a/applications/yaz_player.pl b/applications/yaz_player.pl
index 9cb89af..b2429b8 100644
--- a/applications/yaz_player.pl
+++ b/applications/yaz_player.pl
@@ -36,9 +36,11 @@ http_yaz_player(Request) :-
 			[ video(Video,
 				[description('Current video')]),
 			  process(Process,
-			       [optional(true), desription('When set only annotations within this process are shown')]),
+			       [optional(true),
+				desription('When set only annotations within this process are shown')]),
 			  user(User,
-				[optional(true), description('When set only annotations from this user are shown')]),
+				[optional(true),
+				 description('When set only annotations from this user are shown')]),
 			  interval(Interval,
 				   [default(10000), number,
 				    description('When set one entry per tag is returned in interval (in milliseconds)')]),
@@ -55,11 +57,12 @@ http_yaz_player(Request) :-
 		   user(User),
 		   interval(Interval),
 		   confirmed(Confirmed)
-		  ],
-	video_annotations(Video, Annotations0, Options),
+ 		  ],
+ 	video_annotations(Video, Annotations0, Options),
 	sort_by_arg(Annotations0, 2, Annotations1),
 	list_limit(Annotations1, Limit, Annotations, _),
-	html_video_page(Video, Annotations, StartTime, Options).
+ 	html_video_page(Video, Annotations, StartTime, Options).
+
 
 
 %%	html_video_page(+Video, +Annotations, +StartTime, +Options)
@@ -79,13 +82,15 @@ html_video_page(Video, Annotations, StartTime, Options) :-
 
 html_video_page_containers(Video, _Options) -->
 	{ display_label(Video, Title),
-	  http_link_to_id(http_yaz_tag_garden, [video(Video)], Link)
+	   video_desc(Video, Desc)
+	  %http_link_to_id(http_yaz_tag_garden, [video(Video)], Link)
  	},
 	html([ h2(Title),
-	       a(href(Link), 'Garden this video'),
+	       div(class(desc), Desc),
+	       %a(href(Link), 'Garden this video'),
 	       div([id(video)],
-		   [ div(id(videoplayer), []),
-		     div(id(tagplayer), [])
+		   [ div(id(tagplayer), []),
+		     div(id(videoplayer), [])
 		   ])
 	     ]).
 
diff --git a/config-available/yaz.pl b/config-available/yaz.pl
index 77351d3..fc98f9f 100644
--- a/config-available/yaz.pl
+++ b/config-available/yaz.pl
@@ -8,7 +8,7 @@
 % rdf stuff
 :- rdf_register_ns(sem, 'http://semanticweb.cs.vu.nl/2009/04/event/').
 :- rdf_register_ns(pprime, 'http://semanticweb.cs.vu.nl/prestoprime/').
-:- rdf_register_ns(opmv, 'http://purl.org/net/opmv/ns#').
+:- Rdf_Register_Ns(opmv, 'http://purl.org/net/opmv/ns#').
 
 % yaz applications (or actually the different pages)
 :- use_module(applications(yaz_admin)).
diff --git a/lib/video_annotation.pl b/lib/video_annotation.pl
index acdcd77..dd10a8b 100644
--- a/lib/video_annotation.pl
+++ b/lib/video_annotation.pl
@@ -2,8 +2,8 @@
 	  [ annotation_process/4,         % ?User, ?Video, ?Process
 	    value_annotation/4,           % +Value, ?Process, +User, -Time
 	    video_annotations/3,          % +Video, -Annotations, +Options
-	    video_annotation/4,	          % +Video, -AnnotationId, -Value, -Time
-	    video_annotation/5,	          % +Video, -AnnotationId, -Value, -Time, +Options
+	    video_annotation/5,	          % +Video, -AnnotationId, -Value, -Time, -Score
+	    video_annotation/6,	          % +Video, -AnnotationId, -Value, -Time, -Score, +Options
 	    video_tag/2,                  % +Video, -Tag
  	    video_provenance/2,           % +Video, -Provenance
 	    video_transaction/2,          % +Video, -Transaction
@@ -113,32 +113,38 @@ value_annotation(Value, Process, User, Time) :-
 %	 * interval(Interval)
 %	 group all annotations with a similar value and within interval
 %	 together.
+%
+%	 * confirmed(Confirmed)
+%	 When set to true only annotations with score>0 are included.
 
 video_annotations(Video, Annotations, Options) :-
-	A = [Value,Time]-Id,
-	findall(A, video_annotation(Video, Id, Value, Time, Options), As0),
-	keysort(As0, As),
+	A = a(Value,Time,Id,Score),
+	findall(A, video_annotation(Video, Id, Value, Time, Score, Options), As0),
+	sort(As0, As),
 	(   option(interval(Interval), Options),
 	    Interval > 0
 	->  annotations_per_interval(As, Interval, Annotations)
 	;   maplist(annotation_term, As, Annotations)
 	).
 
-annotation_term([Value,Time]-Id, annotation(Value,Time,Time,[i(Id,Time)])).
+annotation_term(a(Value,Time,Id,Score),
+		annotation(Value,Time,Time,[i(Id,Time)],Score)).
 
 %%	annotations_per_interval(+Terms, +Interval, -GroupedAnnotations)
 %
 %	A group contains all annotations with a similar value and within
 %	time Interval. Similarity of the annotation value is defined by
 %	matching_annotation_value/2.
+%
+%	@TBD only the first Score is used
 
 annotations_per_interval([], _, []).
-annotations_per_interval([[Value,Start]-Id|T], Interval, [A|As]) :-
-	A = annotation(Value, Start, End, [i(Id,Start)|Is]),
+annotations_per_interval([a(Value, Start, Id, Score)|T], Interval, [A|As]) :-
+ 	A = annotation(Value, Start, End, [i(Id,Start)|Is], Score),
 	matching_value_in_interval(T, Value, Start, Start, Interval, Is, End, Rest),
  	annotations_per_interval(Rest, Interval, As).
 
-matching_value_in_interval([[V0,T0]-Id|As], V, Time, _, Interval, [i(Id,T0)|Is], End, Rest) :-
+matching_value_in_interval([a(V0,T0,Id,_)|As], V, Time, _, Interval, [i(Id,T0)|Is], End, Rest) :-
 	matching_annotation_value(V0, V),
  	T0 < Time+Interval,
 	!,
@@ -148,26 +154,47 @@ matching_value_in_interval(Rest, _V, _Time, End, _Interval, [], End, Rest).
 matching_annotation_value(V, V).
 
 
-%%	video_annotation(+Video, -AnnotationId, -Value, -Time).
-%	video_annotation(+Video, -AnnotationId, -Value, -Time,
+%%	video_annotation(+Video, -AnnotationId, -Value, -Time, -Score).
+%	video_annotation(+Video, -AnnotationId, -Value, -Time, -Score
 %	+Options).
 %
 %	True if Video is annotated with AnnotationId and has properties
 %	Value and Time.
 
-video_annotation(Video, AnnotationId, Value, Time) :-
-	video_annotation(Video, AnnotationId, Value, Time, []).
+video_annotation(Video, AnnotationId, Value, Time, Score) :-
+	video_annotation(Video, AnnotationId, Value, Time, Score, []).
 
-video_annotation(Video, AnnotationId, Value, Time, Options) :-
+video_annotation(Video, AnnotationId, Value, Time, Score, Options) :-
 	option(process(Process), Options, _),
 	option(user(User), Options, _),
- 	rdf(Video, pprime:hasAnnotation, AnnotationId, Process),
-	%rdf(Video, pprime:hasAnnotation, AnnotationId),
-	once(rdf(AnnotationId, pprime:creator, User)),
+	option(confirmed(Confirmed), Options, false),
+	annotation_in_process(Process, Video, AnnotationId),
+	rdf(AnnotationId, pprime:creator, User),
  	rdf(AnnotationId, rdf:value, V),
 	annotation_obj(V, Value),
 	rdf(AnnotationId, pprime:videoPlayhead, Time0),
-	literal_to_number(Time0, Time).
+	literal_to_number(Time0, Time),
+	(   rdf(AnnotationId, pprime:score, Score0)
+	->  literal_to_number(Score0, Score)
+	;   Score = 0
+	),
+	(   Confirmed
+	->  Score > 0
+	;   true
+	).
+
+
+annotation_in_process(Process, Video, AnnotationId) :-
+	var(Process),
+	!,
+ 	rdf(Video, pprime:hasAnnotation, AnnotationId).
+annotation_in_process(Process, Video, AnnotationId) :-
+ 	rdf(Video, pprime:hasAnnotation, AnnotationId, F),
+	(   F == Process  % provenance is stored in the transaction
+	->  true
+	;   rdf(AnnotationId, opmv:used, Process) % provenance is stored explicit
+	).
+
 
 annotation_obj(V, Term) :-
 	(   V = literal(_)
diff --git a/lib/yaz_util.pl b/lib/yaz_util.pl
index 090f30f..5fa274b 100644
--- a/lib/yaz_util.pl
+++ b/lib/yaz_util.pl
@@ -16,7 +16,7 @@
 	    tag_entry_time/2,
 	    iri_to_url/2,
 	    delete_nonground/2,
-	    video_source/2,
+ 	    video_source/2,
 	    video_source/3,
 	    annotation_to_json/2,
 	    video_desc/2
@@ -335,6 +335,7 @@ http:convert_parameter(jsonresource, Atom, Term) :-
     annotation(tag:_, count:number),
     annotation(tag:_, tags:list, count:number),
     annotation(tag:_, startTime:number, endTime:number, annotations:list),
+    annotation(tag:_, startTime:number, endTime:number, annotations:list, score:number),
     annotation(tag:_, startTime:number, endTime:number, annotations:list, score:number, match:_),
     match(type:atom, score:_),
     match(type:atom, score:_, uri:_, value:_),
diff --git a/web/css/player.css b/web/css/player.css
index caa7d16..6c2057e 100644
--- a/web/css/player.css
+++ b/web/css/player.css
@@ -2,6 +2,17 @@
 	margin: 0 auto;
 }
 
+.video-results h2 {
+	margin-bottom: 0;
+}
+.video-results .desc {
+	margin-bottom: 15px;
+	max-height: 2em;
+	color: #888;
+	font-size: 95%;
+	clear: both;
+}
+
 /* element style */
 
 /* controls */
@@ -22,6 +33,7 @@
 /* tag player */
 #videoplayer {
 	float: left;
+	margin-left: 20px;
 }
 #tagplayer {
 	float: left;