tensorlogic_adapters/
lib.rs

1//! Adapter utilities for the Tensorlogic ecosystem.
2//!
3//! This crate provides the bridge between logical expressions and tensor execution
4//! by managing symbol tables, domain hierarchies, and schema validation.
5//!
6//! # Overview
7//!
8//! `tensorlogic-adapters` offers a comprehensive system for managing the metadata
9//! and structure of logical systems compiled to tensor operations. It provides:
10//!
11//! - **Symbol tables** - Central registry for predicates, domains, and variables
12//! - **Domain hierarchies** - Type relationships with subtyping and inheritance
13//! - **Parametric types** - Generic domains like `List<T>`, `Option<T>`, `Map<K,V>`
14//! - **Predicate composition** - Define predicates in terms of other predicates
15//! - **Rich metadata** - Provenance tracking, documentation, version history
16//! - **Schema validation** - Completeness, consistency, and semantic checks
17//!
18//! # Quick Start
19//!
20//! ```rust
21//! use tensorlogic_adapters::{SymbolTable, DomainInfo, PredicateInfo};
22//!
23//! // Create a symbol table
24//! let mut table = SymbolTable::new();
25//!
26//! // Add a domain
27//! table.add_domain(DomainInfo::new("Person", 100)).unwrap();
28//!
29//! // Add a predicate
30//! let knows = PredicateInfo::new(
31//!     "knows",
32//!     vec!["Person".to_string(), "Person".to_string()]
33//! );
34//! table.add_predicate(knows).unwrap();
35//!
36//! // Bind a variable
37//! table.bind_variable("x", "Person").unwrap();
38//! ```
39//!
40//! # Features
41//!
42//! ## Domain Hierarchies
43//!
44//! Define type hierarchies with subtype relationships:
45//!
46//! ```rust
47//! use tensorlogic_adapters::DomainHierarchy;
48//!
49//! let mut hierarchy = DomainHierarchy::new();
50//! hierarchy.add_subtype("Student", "Person");
51//! hierarchy.add_subtype("Person", "Agent");
52//!
53//! assert!(hierarchy.is_subtype("Student", "Agent")); // Transitive
54//! ```
55//!
56//! ## Parametric Types
57//!
58//! Create generic domain types:
59//!
60//! ```rust
61//! use tensorlogic_adapters::{ParametricType, TypeParameter};
62//!
63//! let list_person = ParametricType::list(
64//!     TypeParameter::concrete("Person")
65//! );
66//! assert_eq!(list_person.to_string(), "List<Person>");
67//! ```
68//!
69//! ## Schema Validation
70//!
71//! Validate schemas for correctness:
72//!
73//! ```rust
74//! use tensorlogic_adapters::{SymbolTable, SchemaValidator, DomainInfo};
75//!
76//! let mut table = SymbolTable::new();
77//! table.add_domain(DomainInfo::new("Person", 100)).unwrap();
78//!
79//! let validator = SchemaValidator::new(&table);
80//! let report = validator.validate().unwrap();
81//!
82//! assert!(report.errors.is_empty());
83//! ```
84
85mod axis;
86mod builder;
87mod compact;
88mod compiler_integration;
89mod composition;
90mod computed;
91mod constraint;
92mod diff;
93mod domain;
94mod error;
95mod hierarchy;
96mod lazy;
97mod mask;
98mod metadata;
99mod parametric;
100mod performance;
101mod predicate;
102mod product;
103mod schema_analysis;
104mod signature_matcher;
105mod symbol_table;
106mod validation;
107
108#[cfg(test)]
109mod tests;
110
111pub use axis::AxisMetadata;
112pub use builder::SchemaBuilder;
113pub use compact::{CompactSchema, CompressionStats};
114pub use compiler_integration::{
115    CompilerExport, CompilerExportBundle, CompilerImport, SymbolTableSync, ValidationResult,
116};
117pub use composition::{CompositePredicate, CompositeRegistry, PredicateBody, PredicateTemplate};
118pub use computed::{ComputedDomain, ComputedDomainRegistry, DomainComputation};
119pub use constraint::{FunctionalDependency, PredicateConstraints, PredicateProperty, ValueRange};
120pub use diff::{
121    check_compatibility, compute_diff, merge_tables, CompatibilityLevel, DiffSummary,
122    DomainModification, PredicateModification, SchemaDiff, VariableModification,
123};
124pub use domain::DomainInfo;
125pub use error::AdapterError;
126pub use hierarchy::DomainHierarchy;
127pub use lazy::{FileSchemaLoader, LazyLoadStats, LazySymbolTable, LoadStrategy, SchemaLoader};
128pub use mask::DomainMask;
129pub use metadata::{
130    Documentation, Example, Metadata, Provenance, TagCategory, TagRegistry, VersionEntry,
131};
132pub use parametric::{BoundConstraint, ParametricType, TypeBound, TypeParameter};
133pub use performance::{CacheStats, LookupCache, MemoryStats, StringInterner};
134pub use predicate::PredicateInfo;
135pub use product::{ProductDomain, ProductDomainExt};
136pub use schema_analysis::{SchemaAnalyzer, SchemaIssue, SchemaRecommendations, SchemaStatistics};
137pub use signature_matcher::{MatcherStats, SignatureMatcher};
138pub use symbol_table::SymbolTable;
139pub use validation::{SchemaValidator, ValidationReport};