Skip to main content

SchemaBuilder

Struct SchemaBuilder 

Source
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

Source

pub fn new() -> Self

Create a new schema builder.

Source

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);
Source

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");
Source

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);
Source

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"]);
Source

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");
Source

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");
Source

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");
Source

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());
Source

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

Source§

fn clone(&self) -> SchemaBuilder

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 SchemaBuilder

Source§

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

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

impl Default for SchemaBuilder

Source§

fn default() -> SchemaBuilder

Returns the “default value” for a type. Read more

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<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, 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.