1/* Part of SWI-Prolog 2 3 Author: Jan Wielemaker 4 E-mail: J.Wielemaker@vu.nl 5 WWW: http://www.swi-prolog.org 6 Copyright (c) 2011-2018, University of Amsterdam 7 VU University Amsterdam 8 All rights reserved. 9 10 Redistribution and use in source and binary forms, with or without 11 modification, are permitted provided that the following conditions 12 are met: 13 14 1. Redistributions of source code must retain the above copyright 15 notice, this list of conditions and the following disclaimer. 16 17 2. Redistributions in binary form must reproduce the above copyright 18 notice, this list of conditions and the following disclaimer in 19 the documentation and/or other materials provided with the 20 distribution. 21 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 POSSIBILITY OF SUCH DAMAGE. 34*/ 35 36:- module(rdf_turtle_io, 37 [ 38 ]). 39:- use_module(library(semweb/rdf_turtle_write)). 40 41:- multifile 42 rdf_io:write_graph/4. 43 44/** <module> Write query-result graphs as Turtle 45 46This module writes a SPARQL graph results using the Turtle format. It 47acts as a hook into rdf_io.pl. 48*/ 49 50 /******************************* 51 * GRAPH OUTPUT * 52 *******************************/ 53 54%! rdf_io:write_graph(+Format, +Serialization, +Triples, +Options) 55% 56% Write an RDF result-graph as an HTML table, where resources are 57% links to the ClioPatria local view. 58% 59% @param Format is one of =turtle= or =canonical_turtle= 60% @param Serialization is ignored 61% @param Triples is a list of rdf(S,P,O) triples 62 63rdf_iowrite_graph(turtle, _Serialization, Triples, Options) :- 64 option(mimetype(Type), Options, 'text/turtle'), 65 format('Transfer-encoding: chunked~n'), 66 format('Content-type: ~w~n~n', [Type]), 67 ( Triples == [] 68 -> format('# Graph contains no data~n', []) 69 ; rdf_save_turtle(stream(current_output), 70 [ expand(triple_in(Triples)) 71 ]) 72 ). 73rdf_iowrite_graph(canonical_turtle, _Serialization, Triples, Options) :- 74 option(mimetype(Type), Options, 'text/turtle'), 75 format('Transfer-encoding: chunked~n'), 76 format('Content-type: ~w~n~n', [Type]), 77 ( Triples == [] 78 -> format('# Graph contains no data~n', []) 79 ; rdf_save_canonical_turtle(stream(current_output), 80 [ expand(triple_in(Triples)) 81 ]) 82 ). 83 84:- public 85 triple_in/5. 86 87triple_in(RDF, S,P,O,_G) :- 88 member(rdf(S,P,O), RDF)