EquivalenceMapper

Struct EquivalenceMapper 

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

Equivalence mapper for semantic synonym mapping

Maps field values to their canonical forms based on field-specific equivalence rules. This enables recognition of synonyms like “admin” → “administrator” or “yes” → “1”.

Implementations§

Source§

impl EquivalenceMapper

Source

pub fn new() -> Self

Creates a new empty equivalence mapper

Source

pub fn with_defaults() -> Self

Creates a mapper with default boolean equivalences

Provides common boolean synonym mappings that can be applied to any field by calling apply_default_bool_mappings(fid).

Source

pub fn add_mapping(&mut self, fid: FieldId, from: String, to: String)

Adds a custom mapping for a specific field

§Arguments
  • fid - The field ID to add the mapping for
  • from - The source value to map from
  • to - The canonical value to map to
§Examples
use lnmp_codec::EquivalenceMapper;

let mut mapper = EquivalenceMapper::new();
mapper.add_mapping(12, "admin".to_string(), "administrator".to_string());
mapper.add_mapping(12, "dev".to_string(), "developer".to_string());

assert_eq!(mapper.map(12, "admin"), Some("administrator".to_string()));
assert_eq!(mapper.map(12, "dev"), Some("developer".to_string()));
Source

pub fn add_mappings<I>(&mut self, fid: FieldId, mappings: I)
where I: IntoIterator<Item = (String, String)>,

Adds multiple mappings for a specific field

§Arguments
  • fid - The field ID to add mappings for
  • mappings - Iterator of (from, to) value pairs
Source

pub fn apply_default_bool_mappings(&mut self, fid: FieldId)

Applies default boolean equivalence mappings to a field

Maps common boolean representations to “1” (true) or “0” (false):

  • “yes”, “true” → “1”
  • “no”, “false” → “0”
§Examples
use lnmp_codec::EquivalenceMapper;

let mut mapper = EquivalenceMapper::new();
mapper.apply_default_bool_mappings(7);

assert_eq!(mapper.map(7, "yes"), Some("1".to_string()));
assert_eq!(mapper.map(7, "true"), Some("1".to_string()));
assert_eq!(mapper.map(7, "no"), Some("0".to_string()));
assert_eq!(mapper.map(7, "false"), Some("0".to_string()));
Source

pub fn map(&self, fid: FieldId, value: &str) -> Option<String>

Maps a value to its canonical form for a specific field

Returns Some(canonical_value) if a mapping exists, or None if the value has no mapping for this field.

§Arguments
  • fid - The field ID to look up mappings for
  • value - The value to map
§Examples
use lnmp_codec::EquivalenceMapper;

let mut mapper = EquivalenceMapper::new();
mapper.add_mapping(12, "admin".to_string(), "administrator".to_string());

assert_eq!(mapper.map(12, "admin"), Some("administrator".to_string()));
assert_eq!(mapper.map(12, "user"), None);
assert_eq!(mapper.map(99, "admin"), None); // Different field
Source

pub fn has_mapping(&self, fid: FieldId, value: &str) -> bool

Checks if a mapping exists for a specific field and value

§Arguments
  • fid - The field ID to check
  • value - The value to check for a mapping
Source

pub fn field_count(&self) -> usize

Returns the number of fields with mappings

Source

pub fn mapping_count(&self, fid: FieldId) -> usize

Returns the number of mappings for a specific field

§Arguments
  • fid - The field ID to count mappings for
Source

pub fn clear_field(&mut self, fid: FieldId)

Clears all mappings for a specific field

§Arguments
  • fid - The field ID to clear mappings for
Source

pub fn clear(&mut self)

Clears all mappings

Trait Implementations§

Source§

impl Clone for EquivalenceMapper

Source§

fn clone(&self) -> EquivalenceMapper

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for EquivalenceMapper

Source§

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

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

impl Default for EquivalenceMapper

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.