IF Commons GitHub

rdf-write

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0001-rdf FR-006

The RDF writers (commons 0012-ontology FR-006, FR-007): N-Triples and N-Quads, Turtle in one canonical form, and JSON-LD in its expanded form. Each writes the same bytes for the same statements whatever the order they were stated in, so a generated file changes only where a fact does. There is no reader: what these write is read by RDF tools, and commons' own facts are TypeScript.

import { en, named, parseIri } from "./rdf-term.ts";
import { nTriples } from "./rdf-write.ts";
const s = parseIri("https://example.org/a");
const p = parseIri("http://www.w3.org/2000/01/rdf-schema#label");
if (s.kind === "ok" && p.kind === "ok") {
  nTriples([{ subject: named(s.value), predicate: named(p.value), object: en("a") }]);
  // '<https://example.org/a> <http://www.w3.org/2000/01/rdf-schema#label> "a"@en .\n'
}

Source: commons/rdf/src/rdf-write.ts

4 of 6 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

compareCodePointsfunctionno test imports it
function compareCodePoints(a: string, b: string): number

Two strings in the order of their code points (JavaScript's < orders UTF-16 units, which differs above U+FFFF).

nTriplesfunction
function nTriples(triples: readonly Triple[]): string

Triples as N-Triples: each once, one a line, the lines in the order of their code points.

Imported by 10 tests of the run (10 passed, 0 failed): the library's results

nQuadsfunction
function nQuads(quads: readonly Quad[]): string

Quads as N-Quads: each once, one a line (a triple of the default graph has no fourth term), in the order of their code points.

Imported by 10 tests of the run (10 passed, 0 failed): the library's results

TurtleDocumenttypeno test imports it
type TurtleDocument = {
  readonly comments?: readonly string[];
  readonly prefixes: readonly Namespace[];
  readonly triples: readonly Triple[];
};

What a Turtle document is made of: comment lines for its head, the prefixes it may use, and its triples.

turtlefunction
function turtle(doc: TurtleDocument): string

Triples as Turtle in its canonical form: the comment lines, then the prefixes sorted by name, then the subjects in the order of their N-Triples terms, each with its rdf:type first as a and its other predicates by IRI, each predicate's objects in the order of their N-Triples terms, one blank line between subjects. An IRI is a prefixed name where a prefix's IRI starts it and the rest is a plain local name (the longest such prefix), and a whole IRI otherwise; an integer or a boolean of canonical form is written bare.

Imported by 10 tests of the run (10 passed, 0 failed): the library's results

jsonLdfunction
function jsonLd(triples: readonly Triple[]): string

Triples as JSON-LD in its expanded form: one node object for each subject, in the order of their N-Triples terms, with its @id, its @type (the IRIs of its rdf:types, sorted) and then each other predicate by IRI, its values in the order of their N-Triples terms.

Imported by 10 tests of the run (10 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.