← All compilation units

Flyology_RDF.Turtle_Writers

Description

Turtle and TriG serialization.

Where the N-Quads writer optimises for being trivially comparable, this one optimises for being read: statements are grouped by graph and then by subject, repeated predicates collapse into an object list, and bound prefixes shorten IRIs.

It deliberately does not abbreviate blank nodes into bracket form or collections into parentheses. Both are pleasant to read and neither is free: they require knowing that a blank node is referenced exactly once, in the right position, and that a chain really is well formed. Writing them out costs some elegance and no correctness, and the round trip is what matters here.

Bind

procedure Bind
  (Into      : in out Prefix_Map;
   Prefix    : String;
   Namespace : String)

Bind a prefix to a namespace, replacing any existing binding.

A binding is used only where it produces a legal prefixed name, so binding a namespace that would require escaping in the local part simply leaves those IRIs written in full rather than producing something that does not parse back.

Parameters
Into

Map to extend

Prefix

Prefix without its colon, possibly empty

Namespace

IRI the prefix stands for

No_Prefixes

function No_Prefixes return Prefix_Map

No bindings; every IRI is written in full.

Return value

An empty prefix map

Prefix_Map

type Prefix_Map is private;

A set of prefix bindings to abbreviate with.

To_TriG

function To_TriG
  (Value    : Datasets.Dataset;
   Prefixes : Prefix_Map := No_Prefixes) return String

Serialize a dataset as TriG.

Statements in the default graph are written at the top level, and each named graph in its own block.

Parameters
Value

Dataset to serialize

Prefixes

Bindings to abbreviate with

Return value

The dataset in TriG syntax

To_Turtle

function To_Turtle
  (Value    : Datasets.Dataset;
   Prefixes : Prefix_Map := No_Prefixes) return String

Serialize a dataset as Turtle.

Parameters
Value

Dataset to serialize, holding only the default graph

Prefixes

Bindings to abbreviate with

Return value

The dataset in Turtle syntax

Raised exceptions
Constraint_Error

Value holds a named graph, which Turtle cannot express