Skip to main content

inference_engine/reasoning/source/
mod.rs

1//! Source-only default-map preparation before target-relative entailment context.
2mod diagnostic;
3mod engine;
4mod error;
5mod literals;
6use super::{
7    DatatypeConflictLimits, LiteralTypingLimits, OccurrenceLimits, PropositionLimits, RunLimits,
8};
9use crate::entailment::EntailmentTerms;
10pub use diagnostic::{Rdf12SourceDiagnostic, Rdf12SourceDiagnosticSink, SourceLiteralLimits};
11pub use engine::Rdfs12Source;
12pub use error::Rdfs12SourceError;
13use rdf_reasoning::Rdf12ContainerProperty;
14use serde::{Deserialize, Serialize};
15use std::{
16    future::Future,
17    num::{NonZeroU32, NonZeroU64},
18};
19
20/// Authoritative, bounded classification of canonical container-property IRIs.
21pub trait Rdf12ContainerAccess: EntailmentTerms {
22    /// Borrowed or shared bounded IRI metadata, without requiring a string clone.
23    type ContainerIri<'a>: AsRef<str> + Send + Sync
24    where
25        Self: 'a;
26    /// Return a shared checked descriptor only for this exact appearing IRI key.
27    /// Return `None` for a supported noncontainer term; cache misses reload or fail.
28    /// Bound owned IRI metadata before allocation with `maximum_iri_bytes`, and
29    /// report unsupported access/resource failures explicitly through the backend.
30    fn container_property<'a>(
31        &'a self,
32        term: &Self::Term,
33        maximum_iri_bytes: NonZeroU32,
34    ) -> impl Future<
35        Output = Result<Option<Rdf12ContainerProperty<Self::ContainerIri<'a>>>, Self::Error>,
36    > + Send;
37}
38
39/// Explicit serialized resource configuration; no implicit budget defaults.
40///
41/// Phase budgets apply per source round, except preflight and cumulative axiom seeding.
42/// The round cap therefore also bounds total phase work. Backends separately
43/// enforce attempt-wide scratch, dictionary, I/O and metadata budgets.
44#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
45#[serde(deny_unknown_fields)]
46pub struct Rdfs12SourceConfig {
47    /// Cumulative novel ground, container and nonempty-witness axioms.
48    pub axioms: NonZeroU64,
49    /// Source rounds, including the final round proving no additional facts.
50    pub rounds: NonZeroU32,
51    /// Shared core fixpoint work/output caps for each round.
52    pub structural: RunLimits,
53    /// Depth, appearances and work caps for each immutable traversal.
54    pub traversal: OccurrenceLimits,
55    /// Source-only literal preflight caps, before seeding or inference.
56    pub inspection: SourceLiteralLimits,
57    /// Literal occurrence/output/lexical-byte caps per round.
58    pub literals: LiteralTypingLimits,
59    /// Work/output caps for each existing-term candidate check.
60    pub propositions: PropositionLimits,
61    /// Complete source-only diagnostic phase budgets.
62    pub conflicts: DatatypeConflictLimits,
63    /// Maximum owned metadata bytes for one classified container IRI.
64    pub iri_bytes: NonZeroU32,
65}
66
67/// Completed source preparation counters; not a source-to-target decision.
68#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
69#[serde(deny_unknown_fields)]
70pub struct Rdfs12SourceReport {
71    /// Completed source rounds, including the final round with no new facts.
72    pub rounds: u32,
73    /// Novel ground/container/nonempty-witness axioms across the whole operation.
74    pub seeded: u64,
75    /// Total novel facts across seeding and all executed phases.
76    pub inferred: u64,
77    /// Literal appearances inspected, including preflight and repeated derived occurrences.
78    pub literals: u64,
79    /// Aggregate streamed lexical bytes, including repeated inspections.
80    pub lexical_bytes: u64,
81    /// Supported source lexical and default-map conflicts retained outside RDF output.
82    pub diagnostics: u64,
83}
84impl Rdfs12SourceReport {
85    fn add<T, E>(target: &mut u64, count: u64) -> Result<(), Rdfs12SourceError<T, E>> {
86        *target = target
87            .checked_add(count)
88            .ok_or(Rdfs12SourceError::CounterOverflow)?;
89        Ok(())
90    }
91}
92
93/// Outcome of the selected source phases; neither variant is an entailment verdict.
94#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)]
95#[serde(deny_unknown_fields)]
96pub enum Rdfs12SourceOutcome {
97    /// Source phases completed without these supported datatype conflicts.
98    /// Full target-relative construction/matching and unsupported semantics remain separate.
99    Prepared(Rdfs12SourceReport),
100    /// Supported source conflicts were retained; do not promote the scratch graph.
101    Conflicting(Rdfs12SourceReport),
102}