pub struct SignatureMatcher { /* private fields */ }Expand description
Indexed structure for fast predicate signature matching.
This provides O(1) lookup of predicates by:
- Arity (number of arguments)
- Exact signature (ordered domain types)
- Domain patterns (unordered domain types)
§Example
use tensorlogic_adapters::{PredicateInfo, SignatureMatcher};
let mut matcher = SignatureMatcher::new();
let knows = PredicateInfo::new(
"knows",
vec!["Person".to_string(), "Person".to_string()]
);
matcher.add_predicate(&knows);
// Find by arity
let arity_2 = matcher.find_by_arity(2);
assert_eq!(arity_2.len(), 1);
// Find by exact signature
let signature = vec!["Person".to_string(), "Person".to_string()];
let matches = matcher.find_by_signature(&signature);
assert_eq!(matches.len(), 1);
assert_eq!(matches[0], "knows");Implementations§
Source§impl SignatureMatcher
impl SignatureMatcher
Sourcepub fn add_predicate(&mut self, pred: &PredicateInfo)
pub fn add_predicate(&mut self, pred: &PredicateInfo)
Add a predicate to the matcher indices.
Sourcepub fn remove_predicate(&mut self, name: &str)
pub fn remove_predicate(&mut self, name: &str)
Remove a predicate from all indices.
Sourcepub fn find_by_arity(&self, arity: usize) -> Vec<String>
pub fn find_by_arity(&self, arity: usize) -> Vec<String>
Find all predicates with the given arity.
§Example
use tensorlogic_adapters::{PredicateInfo, SignatureMatcher};
let mut matcher = SignatureMatcher::new();
matcher.add_predicate(&PredicateInfo::new("knows", vec!["Person".into(), "Person".into()]));
matcher.add_predicate(&PredicateInfo::new("age", vec!["Person".into()]));
let unary = matcher.find_by_arity(1);
assert_eq!(unary.len(), 1);
assert!(unary.contains(&"age".to_string()));Sourcepub fn find_by_signature(&self, signature: &[String]) -> Vec<String>
pub fn find_by_signature(&self, signature: &[String]) -> Vec<String>
Find all predicates with the exact signature (ordered domain types).
§Example
use tensorlogic_adapters::{PredicateInfo, SignatureMatcher};
let mut matcher = SignatureMatcher::new();
matcher.add_predicate(&PredicateInfo::new("at", vec!["Person".into(), "Location".into()]));
let sig = vec!["Person".to_string(), "Location".to_string()];
let matches = matcher.find_by_signature(&sig);
assert_eq!(matches, vec!["at"]);Sourcepub fn find_by_domain_set(&self, domains: &[String]) -> Vec<String>
pub fn find_by_domain_set(&self, domains: &[String]) -> Vec<String>
Find all predicates with the given domain types (unordered).
This is useful for finding predicates that operate on a set of domains regardless of argument order.
§Example
use tensorlogic_adapters::{PredicateInfo, SignatureMatcher};
let mut matcher = SignatureMatcher::new();
matcher.add_predicate(&PredicateInfo::new("knows", vec!["Person".into(), "Person".into()]));
let domains = vec!["Person".to_string()];
let matches = matcher.find_by_domain_set(&domains);
// "knows" has signature [Person, Person], which when deduplicated matches [Person]
// Note: This requires exact match of sorted signatureSourcepub fn get_predicate(&self, name: &str) -> Option<&PredicateInfo>
pub fn get_predicate(&self, name: &str) -> Option<&PredicateInfo>
Get full predicate information by name.
Sourcepub fn predicate_names(&self) -> Vec<String>
pub fn predicate_names(&self) -> Vec<String>
Get all predicate names.
Sourcepub fn stats(&self) -> MatcherStats
pub fn stats(&self) -> MatcherStats
Get statistics about the index sizes.
Sourcepub fn from_predicates<'a>(
predicates: impl IntoIterator<Item = &'a PredicateInfo>,
) -> Self
pub fn from_predicates<'a>( predicates: impl IntoIterator<Item = &'a PredicateInfo>, ) -> Self
Build a matcher from a collection of predicates.
Trait Implementations§
Source§impl Clone for SignatureMatcher
impl Clone for SignatureMatcher
Source§fn clone(&self) -> SignatureMatcher
fn clone(&self) -> SignatureMatcher
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 SignatureMatcher
impl Debug for SignatureMatcher
Source§impl Default for SignatureMatcher
impl Default for SignatureMatcher
Source§fn default() -> SignatureMatcher
fn default() -> SignatureMatcher
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for SignatureMatcher
impl RefUnwindSafe for SignatureMatcher
impl Send for SignatureMatcher
impl Sync for SignatureMatcher
impl Unpin for SignatureMatcher
impl UnwindSafe for SignatureMatcher
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