Skip to main content

CoreSession

Struct CoreSession 

Source
pub struct CoreSession { /* private fields */ }
Expand description

The shared session: a nibli_reason::KnowledgeBase + the compute-predicate registry, with the compile/assert/query verbs every surface previously hand-mirrored. No env reads, no linting, no persistence — those are per-surface boundary policy (see the module doc).

Implementations§

Source§

impl CoreSession

Source

pub fn new() -> Self

A fresh in-memory session seeded with the built-in arithmetic compute predicates (nibli_reason::default_compute_predicates).

Source

pub fn with_kb(kb: KnowledgeBase) -> Self

Wrap an already-constructed KB (e.g. one built with a persistent write-through fact store via KnowledgeBase::with_store).

Source

pub fn kb(&self) -> &KnowledgeBase

The underlying KB, for surface-specific extras (cancel flags, predicate tracing, contradiction scans, store replay via assert_fact_with_id).

Source

pub fn compute_predicates(&self) -> &HashSet<String>

The current compute-predicate set (the marking input).

Source

pub fn register_compute_predicate(&mut self, name: String)

Register a predicate name for external compute dispatch.

Source

pub fn set_compute_dispatch( &self, eval: fn(&str, &[LogicalTerm]) -> Result<bool, String>, batch_eval: fn(&[ComputeRequest]) -> Vec<Result<bool, String>>, )

Register this session’s external compute dispatch (per-instance; see nibli_reason::KnowledgeBase::set_compute_dispatch for the trust boundary). Without it, external predicates error; built-in arithmetic still resolves in-engine.

Source

pub fn set_verbose(&self, verbose: bool)

Engine stdout diagnostics ([Rule]/[Skolem]/[Constraint]). Default OFF — a silent library; surfaces opt in.

Source

pub fn set_strict(&self, strict: bool)

STRICT MODE (default off — permissive warn-and-insert).

Source

pub fn set_existential_import(&self, on: bool)

EXISTENTIAL-IMPORT MODE (default ON — the v0.1 xorlo behavior). OFF gives the clean-core some = plain ∃ profile (no presupposition witnesses).

Source

pub fn set_materialization(&self, on: bool)

STRATUM-ORDERED MATERIALISATION (default ON). OFF sends every negation-as-failure check back through backward chaining.

Source

pub fn materialization_report(&self) -> (Vec<String>, Vec<(String, String)>)

What the last query’s saturation covered: (complete, [(relation, why not)]). Empty until a query has run and after any KB mutation.

Source

pub fn compile_text(&self, text: &str) -> Result<LogicBuffer, NibliError>

THE compile chain against this session’s compute-predicate set.

Source

pub fn assert_text( &self, text: &str, ) -> Result<Vec<(u64, LogicBuffer)>, NibliError>

Compile KR text and assert it, splitting a multi-statement input into one INDEPENDENT fact per root (split_roots — connectives compile to a single root and stay one compound fact). The full input text is each root’s label. Returns one (id, compiled-sub-buffer) pair per root so a persisting caller can store the FACT itself and replay it recompile-free; callers that only need ids map the pairs down.

Source

pub fn assert_fact_direct( &self, relation: &str, args: &[LogicalTerm], id: Option<u64>, ) -> Result<u64, NibliError>

Assert a fact directly by relation name and arguments, bypassing text parsing, under an optional caller-chosen id (store replay). The label is ":assert {relation}". Event-decomposes to the SAME shape a surface assertion produces, so the injected fact is matched by surface text queries (not just raw-FOL / same-shape direct queries). Identity stays flat; arity follows the injected-arity policy (fail-closed) — see nibli_semantics::compile_injected_fact.

Source

pub fn query_text(&self, text: &str) -> Result<QueryResult, NibliError>

Compile a KR query and run the entailment check.

Source

pub fn query_text_with_proof( &self, text: &str, ) -> Result<(QueryResult, ProofTrace), NibliError>

Compile a KR query, run the entailment check, and return the typed result with the canonical wire ProofTrace.

Source

pub fn query_find_text( &self, text: &str, ) -> Result<Vec<Vec<WitnessBinding>>, NibliError>

Compile a KR query and extract all satisfying witness binding sets.

Source

pub fn count_witnesses_text(&self, text: &str) -> Result<usize, NibliError>

Count the distinct witness binding sets satisfying a KR query.

Source

pub fn aggregate_text( &self, text: &str, variable: &str, op: AggregateOp, ) -> Result<Option<f64>, NibliError>

Aggregate the numeric values bound to variable across all witness binding sets of a KR query. Ok(None) when no numeric witnesses exist.

Source

pub fn retract_fact(&self, id: u64) -> Result<(), NibliError>

Retract a fact by id and rebuild derived state (KB only — durable tombstones are the persisting surface’s concern).

Source

pub fn reset(&self) -> Result<(), NibliError>

Reset the KB, clearing all facts and rules.

Source

pub fn list_facts(&self) -> Result<Vec<FactSummary>, NibliError>

List all active (non-retracted) facts with their ids and labels.

Trait Implementations§

Source§

impl Default for CoreSession

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.