pub struct Expression(/* private fields */);Expand description
Typed, serializable condition evaluated against a knowledge snapshot.
Empty all and any groups are rejected, avoiding vacuous truth and
configuration mistakes. Negated branches never contribute evidence to a
Bayesian conclusion because absence is not an immutable observation.
Claim wire objects require value to be present: exact claims carry a typed
value and existence claims carry explicit null. Unknown fields reject, so
a misspelled exact value cannot broaden into existence.
§Example
use termivar_core::{EvidenceValue, KnowledgePredicate};
use termivar_scanner::{Expression, KnowledgeLayer};
let condition = Expression::all(vec![
Expression::equals(
KnowledgeLayer::Evidence,
KnowledgePredicate::new("technology", "framework")?,
EvidenceValue::Text("Laravel".into()),
),
Expression::equals(
KnowledgeLayer::Evidence,
KnowledgePredicate::new("authentication", "mechanism")?,
EvidenceValue::Text("Sanctum".into()),
),
])?;
assert!(serde_json::to_string(&condition)?.contains("all"));Implementations§
Source§impl Expression
impl Expression
Sourcepub fn all(expressions: Vec<Self>) -> Result<Self, RuleEngineError>
pub fn all(expressions: Vec<Self>) -> Result<Self, RuleEngineError>
Requires every child expression to match.
Sourcepub fn any(expressions: Vec<Self>) -> Result<Self, RuleEngineError>
pub fn any(expressions: Vec<Self>) -> Result<Self, RuleEngineError>
Requires at least one child expression to match.
Sourcepub fn negate(expression: Self) -> Self
pub fn negate(expression: Self) -> Self
Inverts a child condition without treating absence as evidence.
Sourcepub fn equals(
layer: KnowledgeLayer,
predicate: KnowledgePredicate,
value: EvidenceValue,
) -> Self
pub fn equals( layer: KnowledgeLayer, predicate: KnowledgePredicate, value: EvidenceValue, ) -> Self
Matches a predicate and exact typed value in one knowledge layer.
Sourcepub fn exists(layer: KnowledgeLayer, predicate: KnowledgePredicate) -> Self
pub fn exists(layer: KnowledgeLayer, predicate: KnowledgePredicate) -> Self
Matches the existence of a predicate in one knowledge layer.
Sourcepub fn text_contains(
layer: KnowledgeLayer,
predicate: KnowledgePredicate,
needle: impl Into<String>,
) -> Result<Self, RuleEngineError>
pub fn text_contains( layer: KnowledgeLayer, predicate: KnowledgePredicate, needle: impl Into<String>, ) -> Result<Self, RuleEngineError>
Matches a substring in a text or text-list claim value.
Sourcepub fn text_contains_ascii_case_insensitive(
layer: KnowledgeLayer,
predicate: KnowledgePredicate,
needle: impl Into<String>,
) -> Result<Self, RuleEngineError>
pub fn text_contains_ascii_case_insensitive( layer: KnowledgeLayer, predicate: KnowledgePredicate, needle: impl Into<String>, ) -> Result<Self, RuleEngineError>
Matches an ASCII case-insensitive substring in a text claim value.
This comparison is deterministic and locale-independent, making it suitable for protocol tokens and product fingerprints.
Sourcepub fn text_list_contains_exact(
layer: KnowledgeLayer,
predicate: KnowledgePredicate,
value: impl Into<String>,
) -> Result<Self, RuleEngineError>
pub fn text_list_contains_exact( layer: KnowledgeLayer, predicate: KnowledgePredicate, value: impl Into<String>, ) -> Result<Self, RuleEngineError>
Matches exact membership of a value in an EvidenceValue::TextList.
Unlike Self::text_contains, this compares complete list elements with
exact, case-sensitive string equality. It never performs substring
matching and never falls back to a scalar EvidenceValue::Text: a
record whose value is Text("_token") does not match, and a list element
"_token_old" does not match the value "_token". This keeps typed
inventory reasoning fail-closed — only a record carrying the exact element
contributes.
Sourcepub fn ontology_relation(
subject: ConceptId,
relation: RelationTypeId,
object: ConceptId,
) -> Self
pub fn ontology_relation( subject: ConceptId, relation: RelationTypeId, object: ConceptId, ) -> Self
Matches one semantic relationship in the captured ontology.
Sourcepub fn evaluate(
&self,
snapshot: &KnowledgeSnapshot,
) -> Result<ExpressionEvaluation, RuleEngineError>
pub fn evaluate( &self, snapshot: &KnowledgeSnapshot, ) -> Result<ExpressionEvaluation, RuleEngineError>
Evaluates the expression and returns an explainable trace.
Trait Implementations§
Source§impl Clone for Expression
impl Clone for Expression
Source§fn clone(&self) -> Expression
fn clone(&self) -> Expression
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Expression
impl Debug for Expression
Source§impl<'de> Deserialize<'de> for Expression
impl<'de> Deserialize<'de> for Expression
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl Eq for Expression
Source§impl PartialEq for Expression
impl PartialEq for Expression
Source§impl Serialize for Expression
impl Serialize for Expression
impl StructuralPartialEq for Expression
Auto Trait Implementations§
impl Freeze for Expression
impl RefUnwindSafe for Expression
impl Send for Expression
impl Sync for Expression
impl Unpin for Expression
impl UnsafeUnpin for Expression
impl UnwindSafe for Expression
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.