Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Proper csv export ubvu.

  • Loading branch information...
rasvaan committed Nov 16, 2016
1 parent 871cc19 commit 4a57559f97b8a657717b2423a2f6b46fdb0dcfaf
Showing with 21 additions and 5 deletions.
  1. +21 −5 lib/accurator/review.pl
@@ -167,11 +167,12 @@
%
% Export a list of annotations to a csv file or turtle graph.
export_annotations(csv, FileName, Annotations) :-
Columns = row('object_id', 'annotation_type', 'annotation_text', 'annotation_uri'),
Header = row('object_id', 'annotation_type', 'annotation_text', 'annotation_uri'),
atomic_list_concat([FileName, '.csv'], FilePath),
setup_call_cleanup(
open(FileName, write, Out),
open(FilePath, write, Out),
(
csv_write_stream(Out, [Columns], []),
csv_write_stream(Out, [Header], []),
maplist(write_annotation_csv(Out), Annotations)
),
close(Out)
@@ -182,27 +183,42 @@
rdf_save_turtle(Graph, [graph(Graph)]),
rdf_unload_graph(Graph).

%% write_annotation_csv(+Out, +Annotation)
%
% Write data to csv stream.
write_annotation_csv(Out, Annotation) :-
get_data_annotation(Annotation, Object, Type, Text, Uri),
csv_write_stream(Out, [row(Object, Type, Text, Uri)], []).

get_data_annotation(Annotation, Object, Type, Text, null) :-
%% get_data_annotation(+Annotation, -Object, -Type, -Text, -Concept)
%
% Retrieve the data for exporting the annotation.
get_data_annotation(Annotation, ObjectId, Type, Text, null) :-
rdf(Annotation, oa:hasTarget, Object),
rdf(Object, rdf:type, edm:'ProvidedCHO'),
object_id(Object, ObjectId),
rdf(Annotation, oa:hasBody, TextNode),
rdf_is_bnode(TextNode), !,
rdf(TextNode, cnt:chars, literal(Text)),
rdf(Annotation, 'http://semanticweb.cs.vu.nl/annotate/ui/annotationField', Field),
rdf(Field, rdfs:label, literal(lang(en, Type))).

get_data_annotation(Annotation, Object, Type, Text, Concept) :-
get_data_annotation(Annotation, ObjectId, Type, Text, Concept) :-
rdf(Annotation, oa:hasTarget, Object),
rdf(Object, rdf:type, edm:'ProvidedCHO'),
object_id(Object, ObjectId),
rdf(Annotation, oa:hasBody, Concept),
rdf_display_label(Concept, _, Text), !,
rdf(Annotation, 'http://semanticweb.cs.vu.nl/annotate/ui/annotationField', Field),
rdf(Field, rdfs:label, literal(lang(en, Type))).

%% objectid(+Object, -ObjectId)
%
% Shorten Id ubvu, otherwise return Uri.
object_id(Object, ObjectId) :-
string_concat('http://purl.org/collections/nl/ubvu/print-', ObjectId, Object), !.
object_id(Object, Object).

%% add_annotation(Graph, Annotation)
%
% Assert triples in Graph describing Annotation

0 comments on commit 4a57559

Please sign in to comment.
You can’t perform that action at this time.