pub struct SchemaBuilder { /* private fields */ }Expand description
Builder for constructing SymbolTable instances.
Provides a fluent API for building schemas step by step.
§Example
use tensorlogic_adapters::SchemaBuilder;
let table = SchemaBuilder::new()
.domain("Person", 100)
.domain("Location", 50)
.predicate("at", vec!["Person", "Location"])
.build()
.unwrap();
assert_eq!(table.domains.len(), 2);
assert_eq!(table.predicates.len(), 1);Implementations§
Source§impl SchemaBuilder
impl SchemaBuilder
Sourcepub fn domain(self, name: impl Into<String>, cardinality: usize) -> Self
pub fn domain(self, name: impl Into<String>, cardinality: usize) -> Self
Add a domain with the given name and cardinality.
§Example
use tensorlogic_adapters::SchemaBuilder;
let builder = SchemaBuilder::new()
.domain("Person", 100)
.domain("Location", 50);Sourcepub fn domain_with_desc(
self,
name: impl Into<String>,
cardinality: usize,
description: impl Into<String>,
) -> Self
pub fn domain_with_desc( self, name: impl Into<String>, cardinality: usize, description: impl Into<String>, ) -> Self
Add a domain with description.
§Example
use tensorlogic_adapters::SchemaBuilder;
let builder = SchemaBuilder::new()
.domain_with_desc("Person", 100, "Human entities");Sourcepub fn domain_with_metadata(
self,
name: impl Into<String>,
cardinality: usize,
metadata: Metadata,
) -> Self
pub fn domain_with_metadata( self, name: impl Into<String>, cardinality: usize, metadata: Metadata, ) -> Self
Add a domain with metadata.
§Example
use tensorlogic_adapters::{SchemaBuilder, Metadata};
let mut meta = Metadata::new();
meta.add_tag("core");
let builder = SchemaBuilder::new()
.domain_with_metadata("Person", 100, meta);Sourcepub fn predicate<S: Into<String>>(
self,
name: impl Into<String>,
arg_domains: Vec<S>,
) -> Self
pub fn predicate<S: Into<String>>( self, name: impl Into<String>, arg_domains: Vec<S>, ) -> Self
Add a predicate with the given name and argument domains.
§Example
use tensorlogic_adapters::SchemaBuilder;
let builder = SchemaBuilder::new()
.domain("Person", 100)
.predicate("knows", vec!["Person", "Person"]);Sourcepub fn predicate_with_desc<S: Into<String>>(
self,
name: impl Into<String>,
arg_domains: Vec<S>,
description: impl Into<String>,
) -> Self
pub fn predicate_with_desc<S: Into<String>>( self, name: impl Into<String>, arg_domains: Vec<S>, description: impl Into<String>, ) -> Self
Add a predicate with description.
§Example
use tensorlogic_adapters::SchemaBuilder;
let builder = SchemaBuilder::new()
.domain("Person", 100)
.domain("Location", 50)
.predicate_with_desc("at", vec!["Person", "Location"], "Person at location");Sourcepub fn variable(self, var: impl Into<String>, domain: impl Into<String>) -> Self
pub fn variable(self, var: impl Into<String>, domain: impl Into<String>) -> Self
Bind a variable to a domain.
§Example
use tensorlogic_adapters::SchemaBuilder;
let builder = SchemaBuilder::new()
.domain("Person", 100)
.variable("x", "Person")
.variable("y", "Person");Sourcepub fn subtype(
self,
subtype: impl Into<String>,
supertype: impl Into<String>,
) -> Self
pub fn subtype( self, subtype: impl Into<String>, supertype: impl Into<String>, ) -> Self
Add a domain hierarchy relationship.
§Example
use tensorlogic_adapters::SchemaBuilder;
let builder = SchemaBuilder::new()
.domain("Agent", 200)
.domain("Person", 100)
.subtype("Person", "Agent");Sourcepub fn build(self) -> Result<SymbolTable>
pub fn build(self) -> Result<SymbolTable>
Build the final SymbolTable.
§Errors
Returns an error if:
- A predicate references an undefined domain
- A variable is bound to an undefined domain
- The domain hierarchy is cyclic
§Example
use tensorlogic_adapters::SchemaBuilder;
let result = SchemaBuilder::new()
.domain("Person", 100)
.predicate("person", vec!["Person"])
.build();
assert!(result.is_ok());Sourcepub fn build_and_validate(self) -> Result<SymbolTable>
pub fn build_and_validate(self) -> Result<SymbolTable>
Build and validate the schema.
This performs additional validation beyond the basic build.
§Example
use tensorlogic_adapters::SchemaBuilder;
let result = SchemaBuilder::new()
.domain("Person", 100)
.predicate("knows", vec!["Person", "Person"])
.build_and_validate();
assert!(result.is_ok());Trait Implementations§
Source§impl Clone for SchemaBuilder
impl Clone for SchemaBuilder
Source§fn clone(&self) -> SchemaBuilder
fn clone(&self) -> SchemaBuilder
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SchemaBuilder
impl Debug for SchemaBuilder
Source§impl Default for SchemaBuilder
impl Default for SchemaBuilder
Source§fn default() -> SchemaBuilder
fn default() -> SchemaBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for SchemaBuilder
impl RefUnwindSafe for SchemaBuilder
impl Send for SchemaBuilder
impl Sync for SchemaBuilder
impl Unpin for SchemaBuilder
impl UnwindSafe for SchemaBuilder
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
Mutably borrows from an owned value. Read more