IF Commons GitHub

integrations/pure/read-rdf

A reader of Turtle and N-Triples, the first importer's input (commons 0019-mizan-integrations FR-004, FR-007): the text of an outside ontology as triples, with what the typed form cannot hold named as findings and never dropped silently. It lives here and not in the kernel, which reads no RDF syntax (0012-ontology FR-007).

It reads @prefix and @base (and the SPARQL forms PREFIX and BASE), IRIs, prefixed names, a, ; and , lists, plain, language and datatyped literals (short and long strings, with the usual escapes), numbers and booleans, blank node labels and comments. A bracketed blank node ([ ... ]) or a collection (( ... )) is skipped with a loss finding that names the line, and everything else is still read. A syntax it does not understand ends the read with a syntax finding and its line.

import { readTurtle } from "./read-rdf.ts";
const r = readTurtle('@prefix ex: <https://example.org/> .\nex:a a ex:B ; ex:n 3 .\n');
r.kind === "ok" && r.value.triples.length; // 2

Source: commons/mizan/src/integrations/pure/read-rdf.ts

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

integrations.readNTriplesfunctionno test imports it
function readNTriples(text: string): Result<Read, readonly IntegrationFinding[]>

N-Triples' text as triples: the same reader, which takes N-Triples as the Turtle it is a subset of.

integrations.readTurtlefunctionno test imports it
function readTurtle(text: string): Result<Read, readonly IntegrationFinding[]>

Turtle's text as triples, with the findings of what the typed form cannot hold; a syntax it does not understand ends the read with one syntax finding.

integrations.Readtypeno test imports it
type Read = { readonly triples: readonly RdfTriple[]; readonly findings: readonly IntegrationFinding[] };

What a read gives: the triples, and what the typed form cannot hold.

integrations.RdfTermtypeno test imports it
type RdfTerm =
  | { readonly kind: "iri"; readonly value: string }
  | { readonly kind: "blank"; readonly label: string }
  | { readonly kind: "literal"; readonly value: string; readonly datatype: string; readonly lang?: string };

A term of a triple as the reader gives it: an IRI, a blank node label, or a literal with its datatype and language.

integrations.RdfTripletypeno test imports it
type RdfTriple = { readonly subject: RdfTerm; readonly predicate: string; readonly object: RdfTerm; readonly line: number };

A triple and the line it starts on.

integrations.tripleKeyfunctionno test imports it
function tripleKey(t: RdfTriple): string

A triple as one N-Triples line, in one form whatever the syntax it was read from: a set of these is a graph, comparable with another.

integrations.TYPEconstno test imports it
const TYPE: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"

rdf:type, which a stands for.

readNTriplesfunction
function readNTriples(text: string): Result<Read, readonly IntegrationFinding[]>

N-Triples' text as triples: the same reader, which takes N-Triples as the Turtle it is a subset of.

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

readTurtlefunction
function readTurtle(text: string): Result<Read, readonly IntegrationFinding[]>

Turtle's text as triples, with the findings of what the typed form cannot hold; a syntax it does not understand ends the read with one syntax finding.

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

Readtypeno test imports it
type Read = { readonly triples: readonly RdfTriple[]; readonly findings: readonly IntegrationFinding[] };

What a read gives: the triples, and what the typed form cannot hold.

RdfTermtypeno test imports it
type RdfTerm =
  | { readonly kind: "iri"; readonly value: string }
  | { readonly kind: "blank"; readonly label: string }
  | { readonly kind: "literal"; readonly value: string; readonly datatype: string; readonly lang?: string };

A term of a triple as the reader gives it: an IRI, a blank node label, or a literal with its datatype and language.

RdfTripletype
type RdfTriple = { readonly subject: RdfTerm; readonly predicate: string; readonly object: RdfTerm; readonly line: number };

A triple and the line it starts on.

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

tripleKeyfunction
function tripleKey(t: RdfTriple): string

A triple as one N-Triples line, in one form whatever the syntax it was read from: a set of these is a graph, comparable with another.

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

TYPEconstno test imports it
const TYPE: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"

rdf:type, which a stands for.

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