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
impl ProductDomain
Sourcepub fn binary(a: impl Into<String>, b: impl Into<String>) -> Self
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");Sourcepub fn ternary(
a: impl Into<String>,
b: impl Into<String>,
c: impl Into<String>,
) -> Self
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");Sourcepub fn components(&self) -> &[String]
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"]);Sourcepub fn arity(&self) -> usize
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);Sourcepub fn cardinality(&self, table: &SymbolTable) -> Result<usize, AdapterError>
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);Sourcepub fn validate(&self, table: &SymbolTable) -> Result<(), AdapterError>
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());Sourcepub fn project(&self, index: usize) -> Option<&str>
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);Sourcepub fn slice(
&self,
start: usize,
end: usize,
) -> Result<ProductDomain, AdapterError>
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"]);Trait Implementations§
Source§impl Clone for ProductDomain
impl Clone for ProductDomain
Source§fn clone(&self) -> ProductDomain
fn clone(&self) -> ProductDomain
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ProductDomain
impl Debug for ProductDomain
Source§impl<'de> Deserialize<'de> for ProductDomain
impl<'de> Deserialize<'de> for ProductDomain
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>,
Source§impl Display for ProductDomain
impl Display for ProductDomain
Source§impl Hash for ProductDomain
impl Hash for ProductDomain
Source§impl PartialEq for ProductDomain
impl PartialEq for ProductDomain
Source§impl Serialize for ProductDomain
impl Serialize for ProductDomain
impl Eq for ProductDomain
impl StructuralPartialEq for ProductDomain
Auto Trait Implementations§
impl Freeze for ProductDomain
impl RefUnwindSafe for ProductDomain
impl Send for ProductDomain
impl Sync for ProductDomain
impl Unpin for ProductDomain
impl UnwindSafe for ProductDomain
Blanket Implementations§
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,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.