pub struct QueryUtils;Expand description
Query utilities for advanced filtering and searching.
Implementations§
Source§impl QueryUtils
impl QueryUtils
Sourcepub fn find_predicates_using_domain(
table: &SymbolTable,
domain_name: &str,
) -> Vec<PredicateInfo>
pub fn find_predicates_using_domain( table: &SymbolTable, domain_name: &str, ) -> Vec<PredicateInfo>
Find all predicates that use a specific domain.
§Examples
use tensorlogic_adapters::{SymbolTable, DomainInfo, PredicateInfo, QueryUtils};
let mut table = SymbolTable::new();
table.add_domain(DomainInfo::new("Person", 100)).unwrap();
table.add_predicate(PredicateInfo::new("knows", vec!["Person".to_string(), "Person".to_string()])).unwrap();
let predicates = QueryUtils::find_predicates_using_domain(&table, "Person");
assert_eq!(predicates.len(), 1);
assert_eq!(predicates[0].name, "knows");Sourcepub fn find_unused_domains(table: &SymbolTable) -> Vec<String>
pub fn find_unused_domains(table: &SymbolTable) -> Vec<String>
Find all domains that are never used by any predicate.
§Examples
use tensorlogic_adapters::{SymbolTable, DomainInfo, QueryUtils};
let mut table = SymbolTable::new();
table.add_domain(DomainInfo::new("Person", 100)).unwrap();
table.add_domain(DomainInfo::new("Unused", 10)).unwrap();
let unused = QueryUtils::find_unused_domains(&table);
assert_eq!(unused.len(), 2); // Both are unused as no predicates definedSourcepub fn find_predicates_by_arity(
table: &SymbolTable,
arity: usize,
) -> Vec<PredicateInfo>
pub fn find_predicates_by_arity( table: &SymbolTable, arity: usize, ) -> Vec<PredicateInfo>
Find predicates with a specific arity.
§Examples
use tensorlogic_adapters::{SymbolTable, DomainInfo, PredicateInfo, QueryUtils};
let mut table = SymbolTable::new();
table.add_domain(DomainInfo::new("Person", 100)).unwrap();
table.add_predicate(PredicateInfo::new("knows", vec!["Person".to_string(), "Person".to_string()])).unwrap();
table.add_predicate(PredicateInfo::new("age", vec!["Person".to_string()])).unwrap();
let binary = QueryUtils::find_predicates_by_arity(&table, 2);
assert_eq!(binary.len(), 1);
assert_eq!(binary[0].name, "knows");Sourcepub fn group_predicates_by_arity(
table: &SymbolTable,
) -> HashMap<usize, Vec<PredicateInfo>>
pub fn group_predicates_by_arity( table: &SymbolTable, ) -> HashMap<usize, Vec<PredicateInfo>>
Group predicates by their arity.
§Examples
use tensorlogic_adapters::{SymbolTable, DomainInfo, PredicateInfo, QueryUtils};
let mut table = SymbolTable::new();
table.add_domain(DomainInfo::new("Person", 100)).unwrap();
table.add_predicate(PredicateInfo::new("knows", vec!["Person".to_string(), "Person".to_string()])).unwrap();
table.add_predicate(PredicateInfo::new("age", vec!["Person".to_string()])).unwrap();
let grouped = QueryUtils::group_predicates_by_arity(&table);
assert_eq!(grouped.get(&1).unwrap().len(), 1);
assert_eq!(grouped.get(&2).unwrap().len(), 1);Auto Trait Implementations§
impl Freeze for QueryUtils
impl RefUnwindSafe for QueryUtils
impl Send for QueryUtils
impl Sync for QueryUtils
impl Unpin for QueryUtils
impl UnsafeUnpin for QueryUtils
impl UnwindSafe for QueryUtils
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