yaz/commit

FIX shot annotation workflow

authorMichiel Hildebrand
Wed Nov 2 13:29:17 2011 +0100
committerMichiel Hildebrand
Wed Nov 2 13:29:17 2011 +0100
commit17cfa18cdd2baf14e6d8249862628bd45a079035
treef4cebf92db0b927f9394b172c6ad210d84c63c9c
parent6d49989d15520153fb21187059b8ab6c35c628f8
Diff style: patch stat
diff --git a/api/edm_export.pl b/api/edm_export.pl
index cfa5974..84f5245 100644
--- a/api/edm_export.pl
+++ b/api/edm_export.pl
@@ -13,6 +13,8 @@
 :- use_module(library(semweb/rdf_db)).
 :- use_module(library(semweb/rdf_label)).
 
+:- use_module(applications(yaz_shot_annotation)). %FIX this! We should not import from applications
+
 :- http_handler(yaz(api/edmexport), http_api_edm_export, []).
 
 %%	http_api_annotations(+Request)
@@ -20,31 +22,19 @@
 %	Handler for the annotation API.
 
 http_api_edm_export(Request) :-
-		http_parameters(Request,
+	http_parameters(Request,
 			[ video(Video,
 				[description('Current video')]),
-			  process(Process,
-			       [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')]),
+			  shotLevel(ShotLevel,
+				    [boolean, default(true),
+				     description('When set to true only annotations at shot level are returned')
+				    ]),
 			  interval(Interval,
 				   [default(10), number,
 				    description('When set one entry per tag is returned in interval (in milliseconds)')]),
 			  confirmed(Confirmed,
 				    [boolean, default(false),
 				     description('When true only tags that are entered by >1 user are shown')]),
-			  query(Query,
-				[default(''),
-				 description('search string to filter the tags by')]),
-			  type(Type,
-			       [default(false),
-				description('filter tags by type')]),
-			  role(Role,
-			       [default(false),
-				oneof([depicted,associated,false]),
-				description('filter tags by role')]),
 			  limit(Limit,
 				[default(10000), number,
 				 description('limit number of tags shown')]),
@@ -56,17 +46,14 @@ http_api_edm_export(Request) :-
 				  description('Format of the output')
 				 ])
 			]),
-	Options = [process(Process),
-		   user(User),
-		   interval(Interval),
-		   confirmed(Confirmed),
-		   query(Query),
-		   type(Type),
-		   role(Role)
-		  ],
-	% annotations
-	video_annotations(Video, Annotations0, Options),
-	sort_by_arg(Annotations0, 2, Annotations1),
+	(   ShotLevel
+	->  video_shot_annotations(Video, Annotations)
+	;   video_annotations(Video, Annotations0,
+			      [interval(Interval),
+			       confirmed(Confirmed)
+			      ]),
+	    sort_by_arg(Annotations0, 2, Annotations1)
+	),
 	length(Annotations1, Total),
 	list_offset(Annotations1, Offset, Annotations2),
 	list_limit(Annotations2, Limit, Annotations, _),
@@ -102,6 +89,7 @@ edm_wrap(Aggregation, Source, Proxy, Triples) :-
 annotations_to_edm([], _, _, _, []).
 annotations_to_edm([A|As], Video, Source, Proxy, Triples) :-
 	A = annotation(Tag, Start, End, _Entries, _Score),
+	!,
 	StartTime is round(Start/1000),
 	EndTime is round(End/1000),
 	fragment_url(Video, StartTime, EndTime, Fragment),
@@ -123,6 +111,34 @@ annotations_to_edm([A|As], Video, Source, Proxy, Triples) :-
 	append(Ts, Rest, Triples),
 	annotation_value(Tag, TagObject, _Label),
 	annotations_to_edm(As, Video, Source, Proxy, Rest).
+annotations_to_edm([A|As], Video, Source, Proxy, Triples) :-
+	A = shot_annotation(Shot, Start, Duration, Values),
+	!,
+	StartTime is round(Start/1000),
+	fragment_url(Source, StartTime, Duration, ShotSource),
+	prefix_url(Shot, 'proxy/', ShotProxy),
+	shot_annotations_to_edm(Values, ShotProxy, Annotations),
+	rdf_global_term([ rdf(Proxy, ma:hasFragment, ShotProxy),
+			  rdf(Shot, rdf:type, ore:'Aggregation'),
+			  rdf(Shot, ens:hasView, ShotSource),
+			  rdf(ShotProxy, rdf:type, ore:'Proxy'),
+			  rdf(ShotProxy, rdf:type, ma:'MediaFragment'),
+			  rdf(ShotProxy, ore:proxyIn, Shot),
+			  rdf(ShotProxy, ma:duration, literal(Duration)),
+			  rdf(ShotProxy, ebucore:start, literal(StartTime))
+			  |Annotations
+			], Ts),
+	append(Ts, Rest, Triples),
+	annotations_to_edm(As, Video, Source, Proxy, Rest).
+
+shot_annotations_to_edm([], _, []).
+shot_annotations_to_edm([concept(URI,Label,_Type)|Vs], Proxy,
+			[rdf(Proxy,dc:subject,URI),
+			 %rdf(URI,rdf:type,Type),
+			 rdf(URI,rdfs:label,Label)
+			 |Rest
+			]) :-
+	shot_annotations_to_edm(Vs, Proxy, Rest).
 
 
 fragment_url(Video, Start, End, Fragment) :-
diff --git a/api/ugm_ingest.pl b/api/ugm_ingest.pl
index 2ef4b24..678dfa7 100644
--- a/api/ugm_ingest.pl
+++ b/api/ugm_ingest.pl
@@ -53,23 +53,21 @@ http_api_ugm_ingest(Request) :-
 					      [json_tag_entries,
 					       description('JSON object with the annotations')])
 				]),
+		length(Entries, EntryCount),
 		pprime_url(VideoId, video, VideoURL),
 		(   rdf(VideoURL, rdf:type, pprime:'Video')
-		->  reply_json(json([error='video already ingested']))
-		;   length(Entries, EntryCount),
-		    local_video_file(StreamURL, File),
-		    save_video_stream(StreamURL, File),
-		    rdf_transaction((
+		->  rdf_transaction(rdf_retractall(_,_,_,VideoURL))
+		;   true
+		    % for the test bed we have the local copies already
+		    %local_video_file(StreamURL, File),
+		    %save_video_stream(StreamURL, File)
+		),
+		rdf_transaction((
 				    import_video(VideoURL, VideoId, StreamURL, Title, Desc, Duration),
 				    debug(ugm_ingest, 'added video ~w', [VideoURL, StreamURL]),
 				    import_entries(Entries, VideoURL),
 				    debug(ugm_ingest, 'added ~w tag entries', [EntryCount])
-				    )),
-
-		    reply_json(json([success=true,
-				     videoURL=VideoURL
-				    ]))
-		).
+				    )).
 
 http:convert_parameter(json_tag_entries, Atom, Term) :-
 	atom_json_term(Atom, JSON, []),
diff --git a/applications/yaz_game.pl b/applications/yaz_game.pl
index 92a37b9..b601e0f 100644
--- a/applications/yaz_game.pl
+++ b/applications/yaz_game.pl
@@ -705,7 +705,7 @@ cond_object_assert(S,P,O,G) :-
 cond_object_assert(_,_,_,_).
 
 
-:- assert_channel_info.
+%:- assert_channel_info.
 
 
 game_player_score(Game, User, Score) :-
diff --git a/applications/yaz_shot_annotation.pl b/applications/yaz_shot_annotation.pl
index b397fcb..599e5d4 100644
--- a/applications/yaz_shot_annotation.pl
+++ b/applications/yaz_shot_annotation.pl
@@ -1,6 +1,8 @@
 :- module(yaz_shot_annotation,
 	  [assert_shot_data/0,
-	   load_shot_data/0]).
+	   load_shot_data/0,
+	   video_shot_annotations/2
+	  ]).
 
 :- use_module(library(http/http_dispatch)).
 :- use_module(library(http/http_parameters)).
@@ -348,7 +350,10 @@ assert_shot_data :-
 	rdf_transaction(forall(video(Video, Shots),
 			       assert_shots(Shots, Video))).
 load_shot_data :-
-	['videos/shots.pl'].
+	['videos/shots.pl'],
+	unload_shots,
+	assert_shot_data.
+
 unload_shots :-
 	rdf_transaction(rdf_retractall(_,_,_,shots)).
 
@@ -371,7 +376,7 @@ rdfc_assert(S,P,O,F) :-
 
 shot_url(Video, Start, Duration, Shot) :-
 	End is Start+Duration,
-	concat_atom([Video, '#t=', Start, '%2C', End], Shot).
+	concat_atom([Video, '#t=', Start, ',', End], Shot).
 
 video_shot(Video, Shot, Start, Duration) :-
 	rdf(Video, ma:hasFragment, Shot),
@@ -385,3 +390,18 @@ video_shot(Video, Shot, Start, Duration) :-
 
 to_number(A,N) :- atom(A), !, atom_number(A,N),!.
 to_number(N,N).
+
+
+
+
+video_shot_annotations(Video, Annotations) :-
+	A = shot_annotation(Shot, StartTime, Duration, Values),
+	findall(A,
+		(   video_shot(Video, Shot, StartTime, Duration),
+		    findall(concept(URI,Label,Type),
+			    shot_annotation(Shot, URI, Label, Type, _),
+			    Values)
+		),
+		Annotations).
+
+