14.1 N-Triple Formatting
The following pseudo-BNF describes the structure of the N-Triples representation. Note that some terminals are not described in detail here, the BNF is intended as informational.
ntriple-graph ::= triple*
triple ::= subject predicate object "." NEWLINE
subject ::= resource | blank-node
predicate ::= resource
object ::= resource | blank-node | literal
resource ::= "<" URI ">"
blank-node ::= "_:" BLANK_LABEL
literal ::= DQUOTE_STRING ( literal-type | literal-lang )?
literal-type ::= "^^" resource
literal-lang ::= "@" LANG_TAG
procedure
(write-ntriple-literal val [ #:nsmap namespace-map out]) → void? val : literal? namespace-map : nsmap? = #f out : output-port? = (current-output-port)
procedure
(literal->ntriple-string val [ #:nsmap namespace-map]) → string? val : literal? namespace-map : nsmap? = #f
> (require rdf/core/io rdf/core/literal rdf/core/nsmap rdf/core/v/xsd) > (write-ntriple-literal (make-untyped-literal "hello")) "hello"
> (write-ntriple-literal (make-lang-string-literal "hola" "es")) "hola"@es
> (displayln (literal->ntriple-string (make-typed-literal "42" (nsname->resource xsd:short)))) "42"^^<http://www.w3.org/2001/XMLSchema#short>
> (displayln (literal->ntriple-string (make-typed-literal "42" (nsname->resource xsd:short)) #:nsmap (make-common-nsmap))) "42"^^xsd:short
procedure
(write-ntriple-blank-node val [out]) → void?
val : blank-node? out : output-port? = (current-output-port)
procedure
(blank-node->ntriple-string val) → string?
val : blank-node?
> (require rdf/core/io rdf/core/statement) > (write-ntriple-blank-node (make-blank-node)) _:B20f
> (displayln (blank-node->ntriple-string (make-blank-node "alice"))) _:alice
procedure
(write-ntriple-resource val [ #:nsmap namespace-map out]) → void? val : resource? namespace-map : nsmap? = #f out : output-port? = (current-output-port)
procedure
(resource->ntriple-string val [ #:nsmap namespace-map]) → string? val : resource? namespace-map : nsmap? = #f
> (require rdf/core/io rdf/core/statement)
> (write-ntriple-resource (string->resource "http://example.com/ns/")) <http://example.com/ns/>
> (displayln (resource->ntriple-string (string->resource "http://example.com/ns/"))) <http://example.com/ns/>
procedure
(write-ntriple-subject val [ #:nsmap namespace-map out]) → void? val : subject? namespace-map : nsmap? = #f out : output-port? = (current-output-port)
procedure
(subject->ntriple-string val [ #:nsmap namespace-map]) → string? val : subject? namespace-map : nsmap? = #f
This uses either write-ntriple-resource or write-ntriple-blank-node for generation.
> (require rdf/core/io rdf/core/statement)
> (write-ntriple-subject (string->resource "http://example.com/ns/")) <http://example.com/ns/>
> (displayln (subject->ntriple-string (string->resource "http://example.com/ns/"))) <http://example.com/ns/>
> (write-ntriple-subject (make-blank-node)) _:B210
> (displayln (subject->ntriple-string (make-blank-node "bob"))) _:bob
procedure
(write-ntriple-predicate val [ #:nsmap namespace-map out]) → void? val : predicate? namespace-map : nsmap? = #f out : output-port? = (current-output-port)
procedure
(predicate->ntriple-string val [ #:nsmap namespace-map]) → string? val : predicate? namespace-map : nsmap? = #f
This uses the write-ntriple-resource for generation.
> (require rdf/core/io rdf/core/statement)
> (write-ntriple-predicate (string->resource "http://example.com/ns/hasExample")) <http://example.com/ns/hasExample>
> (displayln (predicate->ntriple-string (string->resource "http://example.com/ns/hasExample"))) <http://example.com/ns/hasExample>
procedure
(write-ntriple-object val [ #:nsmap namespace-map out]) → void? val : object? namespace-map : nsmap? = #f out : output-port? = (current-output-port)
procedure
(object->ntriple-string val [ #:nsmap namespace-map]) → string? val : object? namespace-map : nsmap? = #f
This uses either write-ntriple-resource, write-ntriple-blank-node, or write-ntriple-literal for generation.
> (require rdf/core/io rdf/core/literal rdf/core/statement)
> (write-ntriple-object (string->resource "http://example.com/ns/hasExample")) <http://example.com/ns/hasExample>
> (displayln (object->ntriple-string (string->resource "http://example.com/ns/hasExample"))) <http://example.com/ns/hasExample>
> (write-ntriple-object (make-blank-node)) _:B211
> (displayln (object->ntriple-string (make-blank-node "carlos"))) _:carlos
> (write-ntriple-object (make-untyped-literal "hello")) "hello"
> (write-ntriple-object (make-lang-string-literal "hola" "es")) "hola"@es
> (displayln (object->ntriple-string (make-typed-literal "42" (nsname->resource xsd:short)))) "42"^^<http://www.w3.org/2001/XMLSchema#short>
procedure
(write-ntriple-statement val [ #:nsmap namespace-map out]) → void? val : statement? namespace-map : nsmap? = #f out : output-port? = (current-output-port)
procedure
(statement->ntriple-string val [ #:nsmap namespace-map]) → string? val : statement? namespace-map : nsmap? = #f
This uses write-ntriple-subject, write-ntriple-predicate, and write-ntriple-object for generation.
procedure
(write-ntriple-graph val [out]) → void?
val : graph? out : output-port? = (current-output-port)
procedure
(graph->ntriple-string val) → string?
val : graph?