14.3 Turtle/TriG Formatting
The Turtle/TriG writer provided in the core emits a sub-set of the Turtle syntax, as described below.
turtle-graph ::= turtle-header turtle-content
turtle-header ::= base-decl? namespace-decl*
turtle-content ::= ( triple | statements )*
base-decl ::= "@base" resource "."
namespace-decl ::= "@prefix" prefix resource "."
prefix ::= LOCAL_NAME? ":"
statements ::= subject predicates "."
predicates ::= predicate objects ( ";" predicate objects )*
objects ::= object ( "," object )*
Turtle also allows for the use of prefixed names instead of direct IRIs for resources, the following re-definitions for subject, predicate, and object show this.
subject ::= resource | prefixed-name | blank-node
predicate ::= resource | prefixed-name
object ::= resource | prefixed-name | blank-node | literal
prefixed-name ::= prefix LOCAL_NAME?
The extension of Turtle into TriG is to add a graph identifier to wrap a set of Turtle statements so that multiple graphs can be serialized into the same resource.
trig-dataset ::= turtle-header trig-graph*
trig-graph ::= graph-name? "{" turtle-content "}"
procedure
(write-turtle-nsmap val [out]) → void?
val : nsmap? out : output-port? = (current-output-port)
procedure
(nsmap->turtle-string val) → void?
val : nsmap?
> (require rdf/core/io rdf/core/nsmap) > (write-turtle-nsmap (make-common-nsmap))
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
> (displayln (nsmap->turtle-string (make-common-nsmap)))
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
procedure
(write-trig-graph val [out]) → void?
val : graph? out : output-port? = (current-output-port)
procedure
(graph->trig-string val) → string?
val : graph?
procedure
(write-trig-dataset val [out]) → void?
val : dataset? out : output-port? = (current-output-port)
procedure
(dataset->trig-string val) → string?
val : dataset?