Skip to main content

CompilerImport

Struct CompilerImport 

Source
pub struct CompilerImport;
Expand description

Import utilities for reverse synchronization.

Implementations§

Source§

impl CompilerImport

Source

pub fn import_domains( table: &mut SymbolTable, domains: &HashMap<String, usize>, ) -> Result<()>

Import domain information from a compiler context back into a symbol table.

This is useful for synchronizing state after compilation.

§Example
use tensorlogic_adapters::{SymbolTable, CompilerImport};
use std::collections::HashMap;

let mut domains = HashMap::new();
domains.insert("Person".to_string(), 100);
domains.insert("Location".to_string(), 50);

let mut table = SymbolTable::new();
CompilerImport::import_domains(&mut table, &domains).unwrap();

assert!(table.get_domain("Person").is_some());
assert!(table.get_domain("Location").is_some());
Source

pub fn import_predicates( table: &mut SymbolTable, signatures: &HashMap<String, Vec<String>>, ) -> Result<()>

Import predicate signatures from a compiler context.

§Example
use tensorlogic_adapters::{SymbolTable, DomainInfo, CompilerImport};
use std::collections::HashMap;

let mut table = SymbolTable::new();
table.add_domain(DomainInfo::new("Person", 100)).unwrap();

let mut signatures = HashMap::new();
signatures.insert("knows".to_string(), vec!["Person".to_string(), "Person".to_string()]);

CompilerImport::import_predicates(&mut table, &signatures).unwrap();

assert!(table.get_predicate("knows").is_some());
Source

pub fn import_variables( table: &mut SymbolTable, bindings: &HashMap<String, String>, ) -> Result<()>

Import variable bindings from a compiler context.

§Example
use tensorlogic_adapters::{SymbolTable, DomainInfo, CompilerImport};
use std::collections::HashMap;

let mut table = SymbolTable::new();
table.add_domain(DomainInfo::new("Person", 100)).unwrap();

let mut bindings = HashMap::new();
bindings.insert("x".to_string(), "Person".to_string());
bindings.insert("y".to_string(), "Person".to_string());

CompilerImport::import_variables(&mut table, &bindings).unwrap();

assert_eq!(table.get_variable_domain("x"), Some("Person"));
assert_eq!(table.get_variable_domain("y"), Some("Person"));
Source

pub fn import_all( table: &mut SymbolTable, bundle: &CompilerExportBundle, ) -> Result<()>

Import a complete bundle into a symbol table.

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