purrdf_core/lib.rs
1// SPDX-FileCopyrightText: 2026 Blackcat Informatics® Inc. <paudley@blackcatinformatics.ca>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! `purrdf-core` -- oxigraph-free, PyO3-free RDF 1.2 kernel for the PurRDF Rust workspace.
5//!
6//! This crate is the ring-fenced core (purrdf P2b) extracted out of
7//! `purrdf`: the immutable value-interned IR, the owned value model, structured
8//! diagnostics, dataset capability flags, the loss ledger, and provenance. It
9//! models RDF 1.2 terms directly, preserves
10//! source/location context where adapters can provide it, and keeps reporting
11//! structured but SARIF-free. The oxigraph adapters and the PyO3 extension surface
12//! live in the sibling `purrdf` crate; **nothing here may pull oxigraph** — that
13//! is the acceptance gate.
14//!
15//! # `no_std` readiness
16//!
17//! The immutable IR ([`ir`]) is the kernel's purest layer and is **file-IO-free**
18//! (no `std::fs`/`std::io`), the first prerequisite for an eventual `alloc`-only
19//! `no_std` core for embedded / C-ABI consumers. The remaining blocker is the
20//! interner's `std::collections::{HashMap, HashSet}` (not in `alloc`); migrating it
21//! to `hashbrown` is tracked as **P3c**. New IR code therefore prefers
22//! `core::`/`alloc::` over `std::` where the item exists in both (e.g. `core::fmt`,
23//! `alloc::sync::Arc`) so the eventual `#![no_std]` flip stays mechanical. Per the
24//! purrdf plan, `no_std` is for embedded/C-ABI targets and is **not** a WASM
25//! prerequisite. Common types are re-exported from [`prelude`].
26#![doc(
27 html_logo_url = "https://raw.githubusercontent.com/Blackcat-Informatics/purrdf/main/docs/purrdf-logo.svg"
28)]
29#![doc(
30 html_favicon_url = "https://raw.githubusercontent.com/Blackcat-Informatics/purrdf/main/docs/purrdf-logo.svg"
31)]
32
33pub mod bundle;
34// Narrow purrdf backend traits (P2d): term interning, parser ingress,
35// SPARQL execution, and serializer egress. PyO3-free, oxigraph-free — pure
36// contract only; concrete adapters live in `purrdf`.
37pub mod backend;
38// RDF Collection (rdf:first/rest/nil) and Container (rdf:Seq/Bag/Alt) traversal:
39// the malformed-list taxonomy and standard-`rdf:` const set backing the
40// `DatasetView` walker methods.
41pub mod collections;
42pub mod content_id;
43pub mod content_store;
44// The static, allocation-free read view over an RDF dataset (purrdf P2):
45// `DatasetView` + `GraphMatch`. PyO3-free, oxigraph-free — pure kernel.
46pub mod dataset_view;
47pub mod describe;
48/// Structured diagnostics: severity, source/GTS locations, conversion losses,
49/// and the [`RdfDiagnostic`] record callers translate to their reporting layer.
50pub mod diagnostic;
51// Native FnO (W3C Function Ontology) typed catalog model + serializer.
52// PyO3-free; the `purrdf-slice` FnO emitter builds a `FnoCatalog` from the slice
53// framework and serializes it here, replacing rdflib `emit_fno`/`_emit_fnom`.
54pub mod fno;
55// The workspace's single fixed-key ahash determinism policy: FastHasher and the
56// FastMap/FastSet/IdSet lookup-table aliases (determinism comes from id-sorting,
57// never hash order).
58pub mod hash;
59// The immutable, value-interned RDF 1.2 dataset IR (C1).
60pub mod ir;
61// Generic provenance sidecar for the immutable RDF 1.2 dataset (S2):
62// UnitId/ArtifactId/OriginSetId newtypes, interners, AssertionOccurrence,
63// DatasetProvenance, and the provenance gate. No PurRDF-specific concepts here.
64/// Structured non-triple material ([`RdfLookaside`]) that travels with an RDF
65/// store: typed sidecar resources, metadata entries, segment/blob records,
66/// suppressions, opaque nodes, and signature records.
67pub mod lookaside;
68pub mod provenance;
69// The machine-readable RDF↔GTS loss ledger and its drift-gated matrix (C0).
70pub mod loss;
71/// The owned RDF 1.2 value model: terms, literals (including base-direction
72/// literals), triples, quads, reifiers, and statement annotations.
73pub mod model;
74// Native SSSOM (Simple Standard for Sharing Ontology Mappings) TSV codec +
75// validator + RDF serializer. PyO3-free; replaces the `sssom` PyPI
76// package's parse+validate behaviour for the PurRDF mapping artifacts.
77// Shared small-vector primitives (SmallVec / IdVec) for hot, short-lived id rows.
78pub mod small;
79pub mod sssom;
80/// Dataset/import capability flags ([`RdfStoreCapabilities`]).
81pub mod store;
82pub mod turtle;
83// The canonical, review-friendly Turtle RENDERER over the IR — the oxigraph-free half
84// of the on-disk normalizer (the oxigraph-coupled text parser stays in `purrdf`).
85// The wasm-clean canonical-Turtle authority for the correspondence EDOAL lowering.
86pub mod turtle_render;
87
88pub use backend::{
89 RdfParseRequest, RdfParserBackend, RdfSerializeRequest, RdfSerializer, SerializeGraph,
90 SparqlEngine, SparqlRequest, SparqlResult, TermFactory,
91};
92pub use bundle::{
93 ArtifactIndex, ArtifactRecord, BundleError, RdfBundle, SegmentUnitMap, UnitCatalog,
94 UnitMetadata,
95};
96pub use collections::RdfListError;
97pub use content_id::{Blake3ContentId, ContentIdScheme};
98pub use content_store::{Bytes, ContentDigest, ContentStore, ContentStoreError};
99pub use dataset_view::{DatasetMut, DatasetView, GraphMatch, GraphMatchValue, ViewTermId};
100pub use describe::{Describer, describe};
101pub use diagnostic::{RdfDiagnostic, RdfLocation, RdfLoss, RdfSeverity};
102pub use fno::{
103 FnFunction, FnImpl, FnMapping, FnOutput, FnParam, FnParamMapping, FnReturnMapping, FnoCatalog,
104 to_ntriples as fno_to_ntriples, to_quads as fno_to_quads,
105};
106pub use hash::{FastHasher, FastMap, FastSet, IdSet};
107pub use ir::{
108 BlankScope, BudgetExceeded, CanonHash, Canonicalized, CountingDemandProvider, DatasetDiff,
109 DatasetSink, FrozenDatasetSource, GlobalDictionary, GlobalTermId, GtsBundle, HandleEntry,
110 HandleKey, InMemoryPageProvider, MutableDataset, PageFault, PageId, PagePart, PageProvider,
111 PageTranslation, PagedDataset, PagedFreezeError, PagedQuadOverlap, PagedQuadTable,
112 PipelineBundle, PipelineBundleError, QuadHandle, QuadIds, QuadPatternCursor, QuadProbePlan,
113 QuadRef, QuadValues, RdfDataset, RdfDatasetBuilder, RdfDatasetVisitor, RdfEnvelope,
114 SubsetPageProvider, TermId, TermRef, TermValue, ValidatedRdfDatasetBuilder, canonicalize,
115 canonicalize_with, dataset_diff, datasets_isomorphic, try_canonicalize, try_canonicalize_with,
116};
117#[doc(hidden)]
118pub use ir::{PackBuilder, PackDigest, PackError, PackId, PackView, pack_digest, verify_pack};
119pub use lookaside::{
120 RdfBlobOrigin, RdfBlobRecord, RdfLookaside, RdfLookasideKind, RdfLookasideResource,
121 RdfMetadataEntry, RdfMetadataValue, RdfOpaqueNodeRecord, RdfSegmentRecord, RdfSignatureRecord,
122 RdfSuppressionRecord,
123};
124pub use loss::{
125 LossEntry, LossLedger, PROJECTION_CODECS, gts_to_rdf_loss_ledger, loss_matrix_json,
126 pair_loss_ledger, rdf_to_gts_loss_ledger, transcode_loss_matrix_json,
127};
128pub use model::{
129 RdfAnnotation, RdfLiteral, RdfQuad, RdfReifier, RdfTerm, RdfTermKind, RdfTextDirection,
130 RdfTriple,
131};
132pub use provenance::{
133 ArtifactId, ArtifactInterner, AssertionOccurrence, Attribution, AttributionRole,
134 DatasetProvenance, OriginKind, OriginSetId, OriginSetInterner, ProvenanceError, UnitId,
135 UnitInterner, check_provenance,
136};
137pub use small::{IdVec, SmallVec, smallvec};
138pub use sssom::{
139 SSSOM_DEFAULT_VALIDATION_TYPES, SssomDiagnostic, SssomMapping, SssomMappingSet, SssomMeta,
140};
141pub use store::RdfStoreCapabilities;
142pub use turtle::{
143 emit_annotation, emit_quad, emit_reifier, emit_resource, emit_term, rule_iri,
144 write_dataset_annotation, write_dataset_quad, write_dataset_reifier, write_dataset_term,
145};
146pub use turtle_render::render as render_canonical_turtle;
147
148/// The common purrdf-core surface, for `use purrdf_core::prelude::*;`.
149///
150/// Pulls in the owned value model, the immutable IR + builder, term identity,
151/// capability flags, and the diagnostic type — the set a typical consumer reaches
152/// for first.
153pub mod prelude {
154 pub use crate::backend::{
155 RdfParseRequest, RdfParserBackend, RdfSerializeRequest, RdfSerializer, SerializeGraph,
156 SparqlEngine, SparqlRequest, SparqlResult, TermFactory,
157 };
158 pub use crate::dataset_view::{DatasetView, GraphMatch};
159 pub use crate::diagnostic::{RdfDiagnostic, RdfLocation, RdfSeverity};
160 pub use crate::ir::{
161 QuadIds, QuadPatternCursor, QuadRef, RdfDataset, RdfDatasetBuilder, TermId, TermRef,
162 TermValue,
163 };
164 pub use crate::model::{
165 RdfAnnotation, RdfLiteral, RdfQuad, RdfReifier, RdfTerm, RdfTermKind, RdfTextDirection,
166 RdfTriple,
167 };
168 pub use crate::store::RdfStoreCapabilities;
169}