Skip to main content

EntityResolver

Struct EntityResolver 

Source
pub struct EntityResolver { /* private fields */ }
Expand description

Resolves entity references to canonical names using a three-tier strategy:

  1. Learned cache — instant lookup from alias table (no LLM call)
  2. Rule-based — case normalization, substring matching
  3. LLM-powered — CognitiveLlmService.resolve_entities() for ambiguous cases

The alias table persists across sessions so the LLM is only consulted for genuinely new entity references.

Implementations§

Source§

impl EntityResolver

Source

pub fn new() -> Self

Source

pub fn resolve(&self, name: &str) -> ResolvedEntity

Resolve an entity reference using the learned cache and rule-based matching. Does not call the LLM — use resolve_with_llm for the full pipeline.

Source

pub async fn resolve_batch_with_llm<J: LlmJudge>( &mut self, names: &[String], contexts: &[Option<String>], llm: &CognitiveLlmService<J>, ) -> Vec<ResolvedEntity>

Full three-tier resolution: cache → rules → LLM.

Resolves a batch of entity references. Any LLM-confirmed merges are automatically added to the alias table for future cache hits.

Source

pub fn learn_group(&mut self, group: &EntityMergeGroup)

Learn a merge group from the LLM, adding all aliases to the cache.

Source

pub fn add_alias(&mut self, alias: &str, canonical: &str, confidence: f32)

Manually register an alias mapping.

Source

pub fn get_canonical(&self, name: &str) -> Option<&String>

Get the canonical name for an alias, if known.

Source

pub fn known_entities(&self) -> Vec<String>

Returns all known canonical entity names.

Source

pub fn alias_count(&self) -> usize

Source

pub fn is_known_different(&self, a: &str, b: &str) -> bool

Check if two entity names are known to be different (negative cache).

Source

pub fn mark_different(&mut self, a: &str, b: &str)

Mark two entity names as confirmed different (negative cache).

Source

pub fn unresolved_names(&self, names: &[String]) -> Vec<String>

Returns the set of entity names that are NOT yet resolved (no cache hit, no rule-based match). These need LLM resolution.

Source

pub fn negative_count(&self) -> usize

Number of negative-cached pairs.

Source

pub fn save(&self, path: &Path) -> Result<()>

Save the alias table to a JSON file.

Source

pub fn load(&mut self, path: &Path) -> Result<()>

Load the alias table from a JSON file, merging with existing entries.

Trait Implementations§

Source§

impl Clone for EntityResolver

Source§

fn clone(&self) -> EntityResolver

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EntityResolver

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EntityResolver

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.