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
impl EquivalenceMapper
Sourcepub fn with_defaults() -> Self
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).
Sourcepub fn add_mapping(&mut self, fid: FieldId, from: String, to: String)
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 forfrom- The source value to map fromto- 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()));Sourcepub fn add_mappings<I>(&mut self, fid: FieldId, mappings: I)
pub fn add_mappings<I>(&mut self, fid: FieldId, mappings: I)
Adds multiple mappings for a specific field
§Arguments
fid- The field ID to add mappings formappings- Iterator of (from, to) value pairs
Sourcepub fn apply_default_bool_mappings(&mut self, fid: FieldId)
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()));Sourcepub fn map(&self, fid: FieldId, value: &str) -> Option<String>
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 forvalue- 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 fieldSourcepub fn has_mapping(&self, fid: FieldId, value: &str) -> bool
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 checkvalue- The value to check for a mapping
Sourcepub fn field_count(&self) -> usize
pub fn field_count(&self) -> usize
Returns the number of fields with mappings
Sourcepub fn mapping_count(&self, fid: FieldId) -> usize
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
Sourcepub fn clear_field(&mut self, fid: FieldId)
pub fn clear_field(&mut self, fid: FieldId)
Trait Implementations§
Source§impl Clone for EquivalenceMapper
impl Clone for EquivalenceMapper
Source§fn clone(&self) -> EquivalenceMapper
fn clone(&self) -> EquivalenceMapper
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more