inference-engine 0.1.0-alpha.6

Native Rust inference foundation with checked RDF rule-profile compilation
Documentation
//! Checked complete RDFS decisions for schema-free, literal-free, ground targets.
mod admission;
mod types;
use super::{IriTermAccess, SimpleEntailment};
use crate::reasoning::{LiteralRole, TripleSource};
use admission::Admission;
pub use types::{
    SchemaFreeGroundError, SchemaFreeGroundLimits, SchemaFreeGroundOutcome, SchemaFreeGroundReport,
    SchemaFreeGroundRestriction,
};

/// Decide the explicitly checked ordinary-vocabulary ground fragment of RDFS 1.2.
///
/// Both graphs must be literal-free normative RDF and use IRIs outside the
/// RDF/RDFS/XSD namespaces. Source blanks are allowed; target blanks are not.
/// A free injective constructor model with separate names/source blank atoms and
/// exact asserted ordinary-property extensions supplies every negative witness.
/// Standard vocabulary and datatype conditions are completed independently.
/// This does not enable the full `rdfs` execution selector.
pub struct SchemaFreeGroundEntailment {
    limits: SchemaFreeGroundLimits,
}
impl SchemaFreeGroundEntailment {
    /// Set every admission/matching budget explicitly.
    pub const fn new(limits: SchemaFreeGroundLimits) -> Self {
        Self { limits }
    }

    /// Admit the entire selected source, then target, before shared ground matching.
    ///
    /// Reuse one immutable graph/dictionary domain through all scans. No facts,
    /// dictionary entries, closures or countermodel graphs are constructed here.
    /// Keep input snapshot/graph identity with the returned scoped result.
    ///
    /// # Errors
    /// Storage, cancellation and exhausted work/metadata budgets abort the check;
    /// even late failures invalidate any incomplete positive/negative result.
    pub async fn check<S, E, A>(
        &self,
        source: &S,
        target: &E,
        access: &A,
    ) -> Result<SchemaFreeGroundOutcome<S::Term>, SchemaFreeGroundError<S::Term, S::Error>>
    where
        S: TripleSource,
        E: TripleSource<Term = S::Term, Error = S::Error>,
        A: IriTermAccess<Term = S::Term, Error = S::Error>,
    {
        let source_occurrences = match self.admit(source, access, LiteralRole::Source).await? {
            Admission::Accepted(count) => count,
            Admission::Unsupported {
                restriction,
                occurrence,
            } => {
                return Ok(SchemaFreeGroundOutcome::Unsupported {
                    restriction,
                    occurrence,
                });
            }
        };
        let target_occurrences = match self
            .admit(target, access, LiteralRole::TargetContext)
            .await?
        {
            Admission::Accepted(count) => count,
            Admission::Unsupported {
                restriction,
                occurrence,
            } => {
                return Ok(SchemaFreeGroundOutcome::Unsupported {
                    restriction,
                    occurrence,
                });
            }
        };
        let matching = SimpleEntailment::new(self.limits.matching)
            .check(source, target, access)
            .await
            .map_err(SchemaFreeGroundError::Matching)?;
        Self::cancelled(access)?;
        let report = SchemaFreeGroundReport {
            source_occurrences,
            target_occurrences,
            target_triples: matching.target_triples,
            matching_steps: matching.steps,
        };
        Ok(if matching.entailed {
            SchemaFreeGroundOutcome::Entailed(report)
        } else {
            SchemaFreeGroundOutcome::NotEntailed(report)
        })
    }
    fn cancelled<A: IriTermAccess>(
        access: &A,
    ) -> Result<(), SchemaFreeGroundError<A::Term, A::Error>> {
        if access.is_cancelled() {
            Err(SchemaFreeGroundError::Cancelled)
        } else {
            Ok(())
        }
    }
}