Skip to main content

ProductDomain

Struct ProductDomain 

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

A product domain representing a tuple of component domains.

Product domains enable cross-domain reasoning by creating composite types from multiple base domains. The cardinality of a product domain is the product of its component cardinalities.

§Examples

use tensorlogic_adapters::ProductDomain;

let product = ProductDomain::new(vec![
    "Person".to_string(),
    "Location".to_string()
]);

assert_eq!(product.arity(), 2);
assert_eq!(product.to_string(), "Person × Location");

Implementations§

Source§

impl ProductDomain

Source

pub fn new(components: Vec<String>) -> Self

Create a new product domain from component domains.

§Panics

Panics if components has fewer than 2 elements.

§Examples
use tensorlogic_adapters::ProductDomain;

let product = ProductDomain::new(vec!["A".to_string(), "B".to_string()]);
assert_eq!(product.arity(), 2);
Source

pub fn binary(a: impl Into<String>, b: impl Into<String>) -> Self

Create a binary product domain (A × B).

§Examples
use tensorlogic_adapters::ProductDomain;

let product = ProductDomain::binary("Person", "Location");
assert_eq!(product.to_string(), "Person × Location");
Source

pub fn ternary( a: impl Into<String>, b: impl Into<String>, c: impl Into<String>, ) -> Self

Create a ternary product domain (A × B × C).

§Examples
use tensorlogic_adapters::ProductDomain;

let product = ProductDomain::ternary("Person", "Location", "Time");
assert_eq!(product.to_string(), "Person × Location × Time");
Source

pub fn components(&self) -> &[String]

Get the component domains.

§Examples
use tensorlogic_adapters::ProductDomain;

let product = ProductDomain::binary("A", "B");
assert_eq!(product.components(), &["A", "B"]);
Source

pub fn arity(&self) -> usize

Get the arity (number of components) of this product.

§Examples
use tensorlogic_adapters::ProductDomain;

let product = ProductDomain::ternary("A", "B", "C");
assert_eq!(product.arity(), 3);
Source

pub fn cardinality(&self, table: &SymbolTable) -> Result<usize, AdapterError>

Compute the cardinality of this product domain.

Returns the product of component cardinalities, or an error if any component domain is not found in the symbol table.

§Examples
use tensorlogic_adapters::{SymbolTable, DomainInfo, ProductDomain};

let mut table = SymbolTable::new();
table.add_domain(DomainInfo::new("A", 10)).unwrap();
table.add_domain(DomainInfo::new("B", 20)).unwrap();

let product = ProductDomain::binary("A", "B");
assert_eq!(product.cardinality(&table).unwrap(), 200);
Source

pub fn validate(&self, table: &SymbolTable) -> Result<(), AdapterError>

Check if all component domains exist in the symbol table.

§Examples
use tensorlogic_adapters::{SymbolTable, DomainInfo, ProductDomain};

let mut table = SymbolTable::new();
table.add_domain(DomainInfo::new("A", 10)).unwrap();
table.add_domain(DomainInfo::new("B", 20)).unwrap();

let product = ProductDomain::binary("A", "B");
assert!(product.validate(&table).is_ok());

let invalid = ProductDomain::binary("A", "Unknown");
assert!(invalid.validate(&table).is_err());
Source

pub fn project(&self, index: usize) -> Option<&str>

Project to a specific component by index.

Returns the domain name of the component at the given index.

§Examples
use tensorlogic_adapters::ProductDomain;

let product = ProductDomain::ternary("A", "B", "C");
assert_eq!(product.project(0), Some("A"));
assert_eq!(product.project(1), Some("B"));
assert_eq!(product.project(2), Some("C"));
assert_eq!(product.project(3), None);
Source

pub fn slice( &self, start: usize, end: usize, ) -> Result<ProductDomain, AdapterError>

Get a subproduct by slicing component indices.

§Examples
use tensorlogic_adapters::ProductDomain;

let product = ProductDomain::new(vec![
    "A".to_string(),
    "B".to_string(),
    "C".to_string(),
    "D".to_string()
]);

// Get middle two components (B × C)
let sub = product.slice(1, 3).unwrap();
assert_eq!(sub.components(), &["B", "C"]);
Source

pub fn extend(&mut self, additional: Vec<String>)

Extend this product with additional components.

§Examples
use tensorlogic_adapters::ProductDomain;

let mut product = ProductDomain::binary("A", "B");
product.extend(vec!["C".to_string(), "D".to_string()]);
assert_eq!(product.arity(), 4);

Trait Implementations§

Source§

impl Clone for ProductDomain

Source§

fn clone(&self) -> ProductDomain

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProductDomain

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ProductDomain

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for ProductDomain

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Vec<String>> for ProductDomain

Source§

fn from(components: Vec<String>) -> Self

Converts to this type from the input type.
Source§

impl Hash for ProductDomain

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ProductDomain

Source§

fn eq(&self, other: &ProductDomain) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ProductDomain

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for ProductDomain

Source§

impl StructuralPartialEq for ProductDomain

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,