Skip to main content

tpt_eve_core/
pattern.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2use crate::fact::Value;
3use serde::{Deserialize, Serialize};
4
5/// One slot of a [`Pattern`]: either bound to a concrete value or an
6/// unbound variable to be solved for during unification.
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8pub enum PatternTerm {
9    Bound(Value),
10    Variable(String),
11}
12
13/// A triple pattern used for querying working memory. Any combination of
14/// slots may be bound or variable.
15#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
16pub struct Pattern {
17    pub subject: PatternTerm,
18    pub predicate: PatternTerm,
19    pub object: PatternTerm,
20}
21
22impl Pattern {
23    pub fn new(subject: PatternTerm, predicate: PatternTerm, object: PatternTerm) -> Self {
24        Pattern {
25            subject,
26            predicate,
27            object,
28        }
29    }
30}