IF Commons GitHub

integrations/pure/read-rdf-xml

A reader of RDF/XML (commons 0019-mizan-integrations FR-024, FR-025): the text of an outside ontology published as RDF/XML (the W3C's SKOS, OWL, PROV-O, SHACL, DCAT) as triples, with what the typed form cannot hold named as findings and never dropped silently. It is hand-written TypeScript, and needs no Exception (0017-two-languages FR-003): it read every W3C RDF/XML file it was tried on to the graph rdflib reads (the decision and the evidence are in 0019 FR-024).

Two layers in one file. The first is a minimal XML reader: elements, attributes, text, CDATA, comments, processing instructions, character references, the five predefined entities, the entities a <!DOCTYPE> internal subset declares (<!ENTITY rdf "http://...#">, which RDF/XML files use to shorten IRIs), namespaces and xml:lang and xml:base; it refuses what is not well formed with the line. The second is the RDF/XML grammar: node elements (rdf:Description and typed nodes, rdf:about, rdf:ID, rdf:nodeID, anonymous nodes), property elements (literals, rdf:resource, rdf:datatype, nested nodes, rdf:parseType="Resource" and "Collection"), property attributes, rdf:li counting, rdf:ID reification, and relative IRIs resolved against xml:base (RFC 3986). Blank nodes keep their structure as blank terms (labels genid-N in document order, and rdf:nodeID as written). A parseType="Literal" (an XML literal, whose canonical form this reader does not compute) and an external entity are unsupported findings, the property or entity is not read and the rest is.

import { readRdfXml } from "./read-rdf-xml.ts";
const r = readRdfXml('<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ex="https://example.org/"><ex:B rdf:about="https://example.org/a"/></rdf:RDF>');
r.kind === "ok" && r.value.triples.length; // 1

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

2 of 4 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.readRdfXmlfunctionno test imports it
function readRdfXml(text: string, base?: string): Result<Read, readonly IntegrationFinding[]>

RDF/XML text as triples, with the findings of what the typed form cannot hold; a document that is not well-formed XML or not RDF/XML ends the read with one syntax finding. base is the IRI the document was read from, which a relative rdf:about resolves against where the document has no xml:base.

integrations.resolveIrifunctionno test imports it
function resolveIri(base: string, ref: string): string

An IRI resolved against a base (RFC 3986 section 5), as text: removes dot segments and keeps the rest as given.

readRdfXmlfunction
function readRdfXml(text: string, base?: string): Result<Read, readonly IntegrationFinding[]>

RDF/XML text as triples, with the findings of what the typed form cannot hold; a document that is not well-formed XML or not RDF/XML ends the read with one syntax finding. base is the IRI the document was read from, which a relative rdf:about resolves against where the document has no xml:base.

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

resolveIrifunction
function resolveIri(base: string, ref: string): string

An IRI resolved against a base (RFC 3986 section 5), as text: removes dot segments and keeps the rest as given.

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

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