pub struct SemanticSynonymExpander {
pub graph: HashMap<String, Vec<SynonymEdge>>,
pub config: ExpanderConfig,
pub stats: SynonymExpanderStats,
}Expand description
Synonym graph for vocabulary expansion in semantic search.
Maintains a weighted directed adjacency list; add_synonym automatically
inserts bidirectional edges with correctly mirrored relationship types.
Fields§
§graph: HashMap<String, Vec<SynonymEdge>>Adjacency list: term → list of outgoing synonym edges.
config: ExpanderConfigExpander configuration.
stats: SynonymExpanderStatsRuntime statistics.
Implementations§
Source§impl SemanticSynonymExpander
impl SemanticSynonymExpander
Sourcepub fn new(config: ExpanderConfig) -> Self
pub fn new(config: ExpanderConfig) -> Self
Create a new expander with the given configuration.
Sourcepub fn add_synonym(
&mut self,
from: &str,
to: &str,
relation: SynonymRelation,
weight: f32,
)
pub fn add_synonym( &mut self, from: &str, to: &str, relation: SynonymRelation, weight: f32, )
Add a bidirectional synonym edge between from and to.
The reverse edge uses the mirrored relation:
Broader↔NarrowerExact↔ExactNear↔Near
Duplicate edges (same target + same relation) are silently skipped;
stats.total_edges is incremented only for edges actually inserted.
Sourcepub fn expand(
&mut self,
term: &str,
allowed_relations: Option<&[SynonymRelation]>,
) -> Vec<ExpandedTerm>
pub fn expand( &mut self, term: &str, allowed_relations: Option<&[SynonymRelation]>, ) -> Vec<ExpandedTerm>
BFS expansion from term up to config.max_hops hops.
Only follows edges whose weight >= config.min_weight and whose relation
is in allowed_relations (if Some). Results are sorted by
cumulative_weight descending, then alphabetically by term, and
truncated to config.max_expansions.
Sourcepub fn remove_term(&mut self, term: &str)
pub fn remove_term(&mut self, term: &str)
Remove term from the graph and all incoming edges from other nodes.
Sourcepub fn stats(&self) -> &SynonymExpanderStats
pub fn stats(&self) -> &SynonymExpanderStats
Return a reference to the current statistics.
Sourcepub fn term_count(&self) -> usize
pub fn term_count(&self) -> usize
Return the number of unique terms currently in the graph.
Auto Trait Implementations§
impl Freeze for SemanticSynonymExpander
impl RefUnwindSafe for SemanticSynonymExpander
impl Send for SemanticSynonymExpander
impl Sync for SemanticSynonymExpander
impl Unpin for SemanticSynonymExpander
impl UnsafeUnpin for SemanticSynonymExpander
impl UnwindSafe for SemanticSynonymExpander
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.