cluster_search_ui/commit

Added optional well showing annotations added to object.

authorChris Dijkshoorn
Sat Dec 20 21:38:31 2014 +0100
committerChris Dijkshoorn
Sat Dec 20 21:38:31 2014 +0100
commit3ad1aea78dfe57458414e367d0a5b27104ae2dd6
treec6a5c9fbd8d424c1da58ae6cf00d26953a90fc50
parentf65e48d5e932d9cb1c5b988a3bdc348947d710e9
Diff style: patch stat
diff --git a/lib/cluster_search_ui/enrichment.pl b/lib/cluster_search_ui/enrichment.pl
index cee3be6..e031900 100644
--- a/lib/cluster_search_ui/enrichment.pl
+++ b/lib/cluster_search_ui/enrichment.pl
@@ -1,8 +1,9 @@
 :- module(enrichment, [
-	      enrich_item/2,
-	      uri_label/2,
-	      metadata/2
-	  ]).
+			  enrich_item/2,
+			  uri_label/2,
+			  metadata/2,
+			  object_annotations/2
+		  ]).
 
 :- use_module(library(semweb/rdf_label)).
 :- use_module(library(sandbox)).
@@ -12,21 +13,47 @@
 :- use_module(library(http/http_ssl_plugin)).
 :- use_module(library(semweb/rdf_db)).
 
+:- rdf_register_prefix(oa, 'http://www.w3.org/ns/oa#').
+:- rdf_register_prefix(ann_ui, 'http://semanticweb.cs.vu.nl/annotate/ui/').
+
 %%	metadata(+Uri, -Metadata)
 %
 %	Get all properties and subjects attached to a Uri
 metadata(Uri, Metadata) :-
-    findall(metadata{%predicate:Predicate,
+    findall(property_pair{%predicate=Predicate,
 		     predicate_label:PredicateLabel,
-		     %object:Object,
+		     %object=Object,
 		     object_label:ObjectLabel},
 	    (	rdf(Uri, Predicate, Object),
-		rdf_display_label(Predicate, _, PredicateLabel),
-		rdf_display_label(Object, _, ObjectLabel)
+			rdf_display_label(Predicate, _, PredicateLabel),
+			rdf_display_label(Object, _, ObjectLabel)
+	    ),
+	    Properties),
+	get_title(Uri, DisplayTitle),
+	Metadata = metadata{display_title:DisplayTitle, properties:Properties}.
+
+%%	object_annotations(+Uri, -Metadata)
+%
+%	Get all properties and subjects attached to a Uri
+object_annotations(Uri, Annotations) :-
+    findall(annotation{%predicate=Predicate,
+		     field:FieldLabel,
+		     %object=Object,
+		     body:NiceAnnotation},
+	    (	rdf_has(Selector, oa:hasSource, Uri),
+			rdf_has(AnnotationHash, oa:hasTarget, Selector),
+			rdf_has(AnnotationHash, oa:hasBody, Annotation),
+			process_annotation(Annotation, NiceAnnotation),
+			rdf_has(AnnotationHash, ann_ui:annotationField, FieldUri),
+			rdf_display_label(FieldUri, _, FieldLabel)
 	    ),
-	    Metadata).
-    %rdf(Uri, _Predicate, Object),
+	    FoundAnnotations),
+	get_title(Uri, DisplayTitle),
+	Annotations = annotations{display_title:DisplayTitle, annotations:FoundAnnotations}.
 
+process_annotation(literal(Annotation), Annotation) :- !.
+process_annotation(Annotation, Label) :-
+	rdf_display_label(Annotation, _, Label).
 
 %%	uri_label(Uri, Label)
 %
diff --git a/web/js/result.js b/web/js/result.js
index ffcf8ad..1c32536 100644
--- a/web/js/result.js
+++ b/web/js/result.js
@@ -1,8 +1,14 @@
 /* Result
 *  Code for showing the information regarding one of the results
 */
+displayOptions = {
+	showAnnotations: true,
+}
+
 function showResult(uri) {
-	metadata(uri)
+	metadata(uri);
+	var tempUri = 'http://purl.org/collections/nl/rma/collection/r-97182';
+	annotations(tempUri);
 }
 
 function metadata(uri) {
@@ -10,27 +16,53 @@ function metadata(uri) {
 	new Pengine({application: 'enrichment',
 				ask: 'metadata(' + Pengine.stringify(uri, {string:'atom'}) + ', Metadata),!',
 				onsuccess: function () {
-					$("#metadata").append(metadataWell(this.data));
+					$("#metadata").append(metadataWell(this.data, uri));
 				}
 	});
 }
 
-function metadataWell(data) {
+function metadataWell(data, uri) {
 	var metadata = data[0].Metadata;
 	var html = $.el.div({'class':'well well-sm'},
+						$.el.h4('Showing metadata for ' + metadata.display_title),
 						$.el.dl({'class':'dl-horizontal'}));
-	
-	for(var i=0; i<metadata.length; i++) {
+	// First item is title, so start from 1
+	for(var i=1; i<metadata.properties.length; i++) {
 		html.appendChild(
 			$.el.dt(
 				$.el.a({'class':'r_def',
-					    'href':'results?query=' + metadata[i].predicate_label},
-					metadata[i].predicate_label)));
+					    'href':'results?query=' + metadata.properties[i].predicate_label},
+					metadata.properties[i].predicate_label)));
 		html.appendChild(
 			$.el.dd(
 				$.el.a({'class':'r_undef',
-					    'href':'results?query='+metadata[i].object_label},
-					metadata[i].object_label)));
+					    'href':'results?query=' + metadata.properties[i].object_label},
+					metadata.properties[i].object_label)));
+	}
+	return html;
+}
+
+function annotations(uri) {
+	// Get metadata from server
+	new Pengine({application: 'enrichment',
+				ask: 'object_annotations(' + Pengine.stringify(uri, {string:'atom'}) + ', Annotations),!',
+				onsuccess: function () {
+					console.log('The annotations', annotations);
+					//if(this.data[0].Annotations.annotations > 0)
+						$("#metadata").append(annotationWell(this.data));
+				}
+				});
+}
+
+function annotationWell(data) {
+	var annotations = data[0].Annotations.annotations;
+	var html = $.el.div({'class':'well well-sm'},
+						$.el.h4('Annotations added to ' + data[0].Annotations.display_title),
+						$.el.dl({'class':'dl-horizontal'}));
+	// First item is title, so start from 1
+	for(var i=1; i<annotations.length; i++) {
+		html.appendChild($.el.dt(annotations[i].field));
+		html.appendChild($.el.dd(annotations[i].body));
 	}
 	return html;
 }
\ No newline at end of file