annotation_service/commit

OA compliant hasBody for literal tags

authorJacco van Ossenbruggen
Tue May 13 18:55:42 2014 +0200
committerJacco van Ossenbruggen
Tue May 13 18:55:42 2014 +0200
commit26ed6a121b68af7ddd64096d5fd8af0db9043891
tree0f7df9d37cc987e102e69e3d40dccd1baac4d599
parente158bb7338429c2dc31107b939422ba0c5ffca2f
Diff style: patch stat
diff --git a/lib/oa_annotation.pl b/lib/oa_annotation.pl
index e00580a..8d7fc36 100644
--- a/lib/oa_annotation.pl
+++ b/lib/oa_annotation.pl
@@ -46,6 +46,14 @@ normalize_property(Property, NormalizedProperty) :-
 normalize_object(literal(Object), hasBody, ObjectDict) :-
 	ObjectDict = body{'@value':Object},
 	!.
+
+normalize_object(Object, hasBody, ObjectDict) :-
+	rdf_is_resource(Object),
+	rdfs_individual_of(Object, cnt:'ContentAsText'),
+	rdf_has(Object, cnt:chars, literal(Lit)),
+	ObjectDict = body{'@value':Lit},
+	!.
+
 normalize_object(Object, hasBody, ObjectDict) :-
 	rdf_is_resource(Object),
 	ObjectDict = body{'@id':Object},
@@ -140,26 +148,20 @@ rdf_add_annotation(Options, Annotation) :-
 	format_time(atom(DefaultTimeStamp), '%FT%T%:z', Time), % xsd:dateTime
 	option(timestamp(TimeStamp), Options, DefaultTimeStamp),
 	make_target_pairs(TargetDictList, TargetPairs, Graph),
+	make_body_pairs(BodyDict, BodyPairs, Graph),
 
-	(   BodyDict.get('@id') = UriString
-	->  atom_string(Body, UriString)
-	;   atom_string(Literal, BodyDict.get('@value')),
-	    Body=literal(Literal) % FIXME make OA compliant
-	),
-
-	KeyValue0 = [
+	KeyValuePairs = [
 	    po(rdf:type, oa:'Annotation'),
 	    po(rdf:type, QType),
 	    po(oa:annotatedAt, literal(type(xsd:dateTime, TimeStamp))),
 	    po(oa:annotatedBy, User),
 	    po(oa:motivatedBy, Mot),
-	    po(oa:hasBody, Body),
 	    po(dcterms:title, literal(Label)),
 	    po(ann_ui:annotationField, Field),
 	    po(ann_ui:typingTime, literal(type(xsd:integer, TT)))
-	    |
-	    TargetPairs
 	],
+	append([KeyValuePairs, TargetPairs, BodyPairs], KeyValue0),
+
 	sort(KeyValue0, KeyValue),
 	rdf_global_term(KeyValue, Pairs),
 	variant_sha1(Pairs, Hash),
@@ -179,6 +181,17 @@ make_target_pairs([Dict|Tail], [po(oa:hasTarget, TargetNode)|PairTail], Graph) :
 	),
 	make_target_pairs(Tail, PairTail, Graph).
 
+make_body_pairs(BodyDict, Pairs, Graph) :-
+	(   BodyDict.get('@id') = UriString
+	->  atom_string(Body, UriString)
+	;   atom_string(Literal, BodyDict.get('@value')),
+	    rdf_bnode(Body),
+	    rdf_assert(Body, rdf:type, cnt:'ContentAsText', Graph),
+	    rdf_assert(Body, cnt:chars, literal(Literal), Graph),
+	    rdf_assert(Body, dc:format, literal('text/plain'), Graph)
+	),
+	Pairs = [po(oa:hasBody, Body)].
+
 
 make_specific_target(TargetDict, Graph, TargetNode) :-
 	SelectorDict = TargetDict.get(hasSelector),
diff --git a/lib/oa_schema.pl b/lib/oa_schema.pl
index 0640995..2ac5bd6 100644
--- a/lib/oa_schema.pl
+++ b/lib/oa_schema.pl
@@ -20,6 +20,7 @@ Prolog.
 
 % Namespaces for current open annotation model
 :- rdf_register_ns(oa,  'http://www.w3.org/ns/oa#').
+:- rdf_register_ns(cnt, 'http://www.w3.org/2011/content#').
 
 :- rdf_attach_library(annotation_service(rdf)).
 :- rdf_load_library(oa).