inference-engine 0.1.0-alpha.16

Native Rust RDF inference engine with a shared command-line interface
Documentation
//! Actual on-disk Oxigraph graph selection, durable reopen and deletion invalidation.
#![cfg(feature = "oxigraph-disk-tests")]
mod disk_ground_support;
use disk_ground_support::DiskFixture;
use inference_engine::{
    entailment::{
        EntailmentLimits, Rdfs12FragmentEntailment, Rdfs12FragmentLimits, Rdfs12FragmentOutcome,
    },
    reasoning::OccurrenceLimits,
};
use std::{
    num::{NonZeroU32, NonZeroU64},
    time::{SystemTime, UNIX_EPOCH},
};
fn checker() -> Rdfs12FragmentEntailment {
    Rdfs12FragmentEntailment::new(Rdfs12FragmentLimits::new(
        OccurrenceLimits::new(
            NonZeroU32::new(8).unwrap(),
            NonZeroU64::new(1000).unwrap(),
            NonZeroU64::new(10000).unwrap(),
        ),
        EntailmentLimits::new(
            NonZeroU32::new(16).unwrap(),
            NonZeroU32::new(16).unwrap(),
            NonZeroU32::new(64).unwrap(),
            NonZeroU64::new(10000).unwrap(),
        ),
        NonZeroU32::new(4096).unwrap(),
    ))
}
#[tokio::test]
async fn persisted_named_graphs_reopen_with_the_same_ground_decisions_after_insert_and_delete() {
    let path = std::env::temp_dir().join(format!(
        "inference-ground-{}-{}",
        std::process::id(),
        SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_nanos()
    ));
    let fixture = DiskFixture::try_new(path).await.unwrap();
    let (content, quote, count) = fixture.check(&checker()).await.unwrap();
    assert!(matches!(content, Rdfs12FragmentOutcome::NotEntailed { .. }));
    assert!(matches!(quote, Rdfs12FragmentOutcome::Entailed(_)));
    assert_eq!(count, 5); // Includes the unselected assertion and unselected RDFS schema.
    fixture.assert_content(true).await.unwrap();
    let (content, quote, count) = fixture.check(&checker()).await.unwrap();
    assert!(matches!(content, Rdfs12FragmentOutcome::Entailed(_)));
    assert!(matches!(quote, Rdfs12FragmentOutcome::Entailed(_)));
    assert_eq!(count, 6);
    fixture.assert_content(false).await.unwrap();
    let (content, quote, count) = fixture.check(&checker()).await.unwrap();
    assert!(matches!(content, Rdfs12FragmentOutcome::NotEntailed { .. }));
    assert!(matches!(quote, Rdfs12FragmentOutcome::Entailed(_)));
    assert_eq!(count, 5);
    fixture.remove().await.unwrap();
}

#[tokio::test]
async fn persisted_projection_keeps_shared_blank_conflicts_and_standard_tail_uncertainty() {
    let path = std::env::temp_dir().join(format!(
        "inference-projection-{}-{}",
        std::process::id(),
        SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_nanos()
    ));
    let fixture = DiskFixture::try_new_projection(path).await.unwrap();
    let (full, ordinary, count) = fixture.check_projection(&checker()).await.unwrap();
    assert!(matches!(full, Rdfs12FragmentOutcome::NotEntailed { .. }));
    assert!(matches!(
        ordinary,
        Rdfs12FragmentOutcome::NotEntailed { .. }
    ));
    assert_eq!(count, 9);
    fixture.align_quotes(true).await.unwrap();
    let (full, ordinary, count) = fixture.check_projection(&checker()).await.unwrap();
    assert!(matches!(full, Rdfs12FragmentOutcome::Unsupported { .. }));
    assert!(matches!(ordinary, Rdfs12FragmentOutcome::Entailed(_)));
    assert_eq!(count, 9);
    fixture.align_quotes(false).await.unwrap();
    let (full, ordinary, count) = fixture.check_projection(&checker()).await.unwrap();
    assert!(matches!(full, Rdfs12FragmentOutcome::NotEntailed { .. }));
    assert!(matches!(
        ordinary,
        Rdfs12FragmentOutcome::NotEntailed { .. }
    ));
    assert_eq!(count, 9);
    fixture.remove().await.unwrap();
}

#[tokio::test]
async fn persisted_default_datatype_certificates_invalidate_when_source_admission_changes() {
    use inference_engine::entailment::{Rdfs12FragmentRefutation, Rdfs12FragmentRestriction};
    let path = std::env::temp_dir().join(format!(
        "inference-datatype-{}-{}",
        std::process::id(),
        SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_nanos()
    ));
    let fixture = DiskFixture::try_new_datatype(path).await.unwrap();
    let (results, count) = fixture.check_datatypes(&checker()).await.unwrap();
    assert_eq!(count, 5);
    for result in results {
        assert!(matches!(
            result,
            Rdfs12FragmentOutcome::NotEntailed {
                refutation: Rdfs12FragmentRefutation::DefaultDatatypeMembership { .. },
                ..
            }
        ));
    }
    fixture.assert_datatype_membership(true).await.unwrap();
    let (results, count) = fixture.check_datatypes(&checker()).await.unwrap();
    assert_eq!(count, 6);
    for result in results {
        assert!(matches!(
            result,
            Rdfs12FragmentOutcome::Unsupported {
                restriction: Rdfs12FragmentRestriction::UnsupportedSourceSchema,
                ..
            }
        ));
    }
    fixture.assert_datatype_membership(false).await.unwrap();
    let (results, count) = fixture.check_datatypes(&checker()).await.unwrap();
    assert_eq!(count, 5);
    for result in results {
        assert!(matches!(
            result,
            Rdfs12FragmentOutcome::NotEntailed {
                refutation: Rdfs12FragmentRefutation::DefaultDatatypeMembership { .. },
                ..
            }
        ));
    }
    fixture.remove().await.unwrap();
}

#[tokio::test]
async fn persisted_property_search_uses_selected_root_and_nested_occurrence_scope() {
    use inference_engine::entailment::Rdfs12FragmentRefutation;
    let path = std::env::temp_dir().join(format!(
        "inference-property-{}-{}",
        std::process::id(),
        SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_nanos()
    ));
    let fixture = DiskFixture::try_new_property(path).await.unwrap();
    let ([result], count) = fixture.check_property(&checker()).await.unwrap();
    assert_eq!(count, 4);
    assert!(matches!(
        result,
        Rdfs12FragmentOutcome::NotEntailed {
            refutation: Rdfs12FragmentRefutation::NamedPropertyMembership { .. },
            ..
        }
    ));
    fixture.assert_property_predicate(true).await.unwrap();
    let ([result], count) = fixture.check_property(&checker()).await.unwrap();
    assert_eq!(count, 5);
    assert!(matches!(result, Rdfs12FragmentOutcome::Unsupported { .. }));
    fixture.assert_property_predicate(false).await.unwrap();
    let ([result], count) = fixture.check_property(&checker()).await.unwrap();
    assert_eq!(count, 4);
    assert!(matches!(
        result,
        Rdfs12FragmentOutcome::NotEntailed {
            refutation: Rdfs12FragmentRefutation::NamedPropertyMembership { .. },
            ..
        }
    ));
    fixture.remove().await.unwrap();
}

#[tokio::test]
async fn persisted_target_denotation_changes_only_with_a_selected_property_declaration() {
    use inference_engine::entailment::Rdfs12FragmentRefutation;
    let path = std::env::temp_dir().join(format!(
        "inference-denotation-{}-{}",
        std::process::id(),
        SystemTime::now()
            .duration_since(UNIX_EPOCH)
            .unwrap()
            .as_nanos()
    ));
    let fixture = DiskFixture::try_new_triple_term(path).await.unwrap();
    let ([result], count) = fixture.check_triple_term(&checker()).await.unwrap();
    assert_eq!(count, 3);
    assert!(matches!(
        result,
        Rdfs12FragmentOutcome::NotEntailed {
            refutation: Rdfs12FragmentRefutation::TripleTermPredicate { .. },
            ..
        }
    ));
    fixture.assert_property_declaration(true).await.unwrap();
    let ([result], count) = fixture.check_triple_term(&checker()).await.unwrap();
    assert_eq!(count, 4);
    assert!(matches!(result, Rdfs12FragmentOutcome::Unsupported { .. }));
    fixture.assert_property_declaration(false).await.unwrap();
    let ([result], count) = fixture.check_triple_term(&checker()).await.unwrap();
    assert_eq!(count, 3);
    assert!(matches!(
        result,
        Rdfs12FragmentOutcome::NotEntailed {
            refutation: Rdfs12FragmentRefutation::TripleTermPredicate { .. },
            ..
        }
    ));
    fixture.remove().await.unwrap();
}