pub struct TermIndexBuilder {
pub index: HashMap<TermType, Vec<TermRef>>,
}Expand description
Builds and queries an inverted index over TensorLogic terms.
The index maps each TermType to the list of TermRefs (posting list)
that identify every rule/fact position where that term occurs.
§Example
use ipfrs_tensorlogic::term_index::{TermIndexBuilder, TermPosition, TermType};
let mut builder = TermIndexBuilder::new();
builder.index_term(
TermType::Predicate("parent".to_string()),
1,
TermPosition::Head,
);
let refs = builder.lookup_predicate("parent");
assert_eq!(refs.len(), 1);
assert_eq!(refs[0].rule_id, 1);Fields§
§index: HashMap<TermType, Vec<TermRef>>The underlying inverted index.
Implementations§
Source§impl TermIndexBuilder
impl TermIndexBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new, empty TermIndexBuilder.
Sourcepub fn index_term(
&mut self,
term: TermType,
rule_id: u64,
position: TermPosition,
)
pub fn index_term( &mut self, term: TermType, rule_id: u64, position: TermPosition, )
Add a term occurrence to the index.
Appends a TermRef to the posting list for term.
Sourcepub fn lookup(&self, term: &TermType) -> &[TermRef]
pub fn lookup(&self, term: &TermType) -> &[TermRef]
Return the posting list for term, or an empty slice if absent.
Sourcepub fn lookup_predicate(&self, name: &str) -> &[TermRef]
pub fn lookup_predicate(&self, name: &str) -> &[TermRef]
Return the posting list for Predicate(name), or an empty slice.
Sourcepub fn lookup_constant(&self, name: &str) -> &[TermRef]
pub fn lookup_constant(&self, name: &str) -> &[TermRef]
Return the posting list for Constant(name), or an empty slice.
Sourcepub fn rules_for_predicate(&self, name: &str) -> Vec<u64>
pub fn rules_for_predicate(&self, name: &str) -> Vec<u64>
Return a deduplicated, sorted list of rule IDs that mention
Predicate(name).
Sourcepub fn remove_rule(&mut self, rule_id: u64)
pub fn remove_rule(&mut self, rule_id: u64)
Remove all TermRefs belonging to rule_id from every posting list.
Posting lists that become empty after removal are dropped from the index.
Sourcepub fn stats(&self) -> IndexStats
pub fn stats(&self) -> IndexStats
Return statistics about the current state of the index.
Trait Implementations§
Source§impl Debug for TermIndexBuilder
impl Debug for TermIndexBuilder
Source§impl Default for TermIndexBuilder
impl Default for TermIndexBuilder
Source§fn default() -> TermIndexBuilder
fn default() -> TermIndexBuilder
Auto Trait Implementations§
impl Freeze for TermIndexBuilder
impl RefUnwindSafe for TermIndexBuilder
impl Send for TermIndexBuilder
impl Sync for TermIndexBuilder
impl Unpin for TermIndexBuilder
impl UnsafeUnpin for TermIndexBuilder
impl UnwindSafe for TermIndexBuilder
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more