This module implements the Turtle language for representing the RDF triple model as defined by Dave Beckett from the Institute for Learning and Research Technology University of Bristol and later standardized by the W3C RDF working group.
This module acts as a plugin to rdf_load/2,
for processing files with one of the extensions .ttl
or .n3
.
rdf(Subject, Predicate, Object [, Graph])
The representation is consistent with the SWI-Prolog RDF/XML and ntriples parsers. Provided options are:
node(1)
, node(2)
, ...auto
(default), turtle
or trig
.
The auto mode switches to TriG format of there is a
{
before the first triple. Finally, of the format is
explicitly stated as turtle
and the file appears to be a
TriG file, a warning is printed and the data is loaded while ignoring
the graphs.->
IRI mapping because
this rarely causes errors. To force strictly conforming mode, pass iri
.prefixes(Pairs)
. Compatibility to rdf_load/2.[]
if there is no base-uri.warning
(default), print the error and continue parsing
the remainder of the file. If error
, abort with an
exception on the first error encountered.on_error(warning)
is active, this option cane be used to
retrieve the number of generated errors.Input | is one of stream(Stream) , atom(Atom) ,
a http ,
https or file url or a filename specification
as accepted by absolute_file_name/3. |
rdf(S,P,O)
terms for a normal Turtle file or rdf(S,P,O,G)
terms if the GRAPH
keyword is used to associate a set of
triples in the document with a particular graph. The Graph
argument provides the default graph for storing the triples and Line
is the line number where the statement started.
call(OnObject, ListOfTriples, Graph:Line)
This predicate supports the same Options as rdf_load_turtle/3.
Errors encountered are sent to print_message/2, after which the parser tries to recover and parse the remainder of the data.
turtle_write_quoted_string(Out, Value, false)
,
writing a string with only a single "
. Embedded newlines
are escapes as \n
.<...>
true
(default), use a
for the predicate rdf:type
.
Otherwise use the full resource.true
(default false
), emit numeric
datatypes using Prolog's write to achieve canonical output.true
(default), write some informative comments between
the output segmentstrue
(default), using P-O and O-grouping.true
(default), inline bnodes that are used once.true
(default), omit the type if allowed by turtle.true
(default false
), do not print the
final informational message.true
(default false
), write [...] and (...)
on a single line.true
(default), use prefixes from rdf_current_prefix/2.
The option expand
allows for serializing alternative
graph representations. It is called through call/5,
where the first argument is the expand-option, followed by S,P,O,G. G is
the graph-option (which is by default a variable). This notably allows
for writing RDF graphs represented as rdf(S,P,O)
using the
following code fragment:
triple_in(RDF, S,P,O,_G) :- member(rdf(S,P,O), RDF). ..., rdf_save_turtle(Out, [ expand(triple_in(RDF)) ]),
Out | is one of stream(Stream) , a
stream handle, a file-URL or an atom that denotes a filename. |
graph(+Graph)
option and instead processes one additional
option:
encoding(utf8)
,indent(0)
,tab_distance(0)
,subject_white_lines(1)
,align_prefixes(false)
,user_prefixes(false)
comment(false)
,group(false)
,single_line_bnodes(true)