Skip to main content

NicknameTable

Struct NicknameTable 

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

Equivalence-class lookup table for given-name nicknames.

Each class is a Vec<String> of normalised forms that the table considers interchangeable. Two inputs are equivalent under the table iff their normalised forms appear in the same class — or are byte-identical after normalisation.

The type is Clone + Debug + PartialEq + Eq so it composes into crate::MatchConfig without surprises. Construction is cheap and allocates once per class; lookup is O(classes × entries) and is dominated by the table’s size, not the input string length.

§Example

use worker_matcher::NicknameTable;

let t = NicknameTable::empty()
    .with_class(["Michael", "Mike", "Mickey"])
    .with_class(["Elizabeth", "Liz", "Beth"]);

assert!(t.are_equivalent("Mike", "Michael"));
assert!(t.are_equivalent("liz", "BETH"));
assert!(!t.are_equivalent("Michael", "Liz"));

Implementations§

Source§

impl NicknameTable

Source

pub fn empty() -> Self

Construct an empty table that considers every pair of distinct strings non-equivalent (identical strings remain trivially equal).

use worker_matcher::NicknameTable;
let t = NicknameTable::empty();
assert!(!t.are_equivalent("Mike", "Michael"));
assert!(t.are_equivalent("Mike", "Mike"));
Source

pub fn with_class<I, S>(self, names: I) -> Self
where I: IntoIterator<Item = S>, S: AsRef<str>,

Append an equivalence class to the table.

Each input string is normalised via crate::Normalizer::normalize_name before insertion so the table is closed under the same normalisation pipeline the matcher uses at lookup time. Duplicate or empty entries are silently dropped, and a class with fewer than two distinct normalised entries is dropped entirely (it would never make a pair equivalent).

use worker_matcher::NicknameTable;
let t = NicknameTable::empty().with_class(["Robert", "Bob", "Rob"]);
assert!(t.are_equivalent("BOB", "robert"));
Source

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

Return true iff a and b, after name normalisation, are considered the same worker by this table.

Identical normalised strings are trivially equivalent. Otherwise both inputs must appear in the same equivalence class.

use worker_matcher::NicknameTable;
let t = NicknameTable::english();
assert!(t.are_equivalent("Mike",  "Michael"));
assert!(t.are_equivalent("mike",  "MICHAEL"));   // case-insensitive
assert!(!t.are_equivalent("Mike", "Robert"));
assert!(t.are_equivalent("",       ""));         // trivially equal
Source

pub fn is_empty(&self) -> bool

true iff the table contains no equivalence classes — equivalent to comparing with NicknameTable::empty but cheaper to test.

use worker_matcher::NicknameTable;
assert!(NicknameTable::empty().is_empty());
assert!(!NicknameTable::english().is_empty());
Source

pub fn len(&self) -> usize

Number of equivalence classes registered with this table.

use worker_matcher::NicknameTable;
assert_eq!(NicknameTable::empty().len(), 0);
let t = NicknameTable::empty().with_class(["A", "B"]);
assert_eq!(t.len(), 1);
Source

pub fn english() -> Self

A built-in table covering the most common English-language nicknames encountered in healthcare data: Michael/Mike, Robert/Bob, Elizabeth/Liz, and similar.

The exact contents are not part of the public contract — entries may be added in minor releases. Callers that need a stable dictionary SHOULD construct their own via NicknameTable::with_class.

use worker_matcher::NicknameTable;
let t = NicknameTable::english();
assert!(t.are_equivalent("Bill",      "William"));
assert!(t.are_equivalent("Liz",       "Elizabeth"));
assert!(t.are_equivalent("Steve",     "Steven"));
assert!(t.are_equivalent("Steve",     "Stephen"));

Trait Implementations§

Source§

impl Clone for NicknameTable

Source§

fn clone(&self) -> NicknameTable

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 NicknameTable

Source§

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

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

impl Default for NicknameTable

Source§

fn default() -> NicknameTable

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

impl<'de> Deserialize<'de> for NicknameTable

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for NicknameTable

Source§

fn eq(&self, other: &NicknameTable) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for NicknameTable

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for NicknameTable

Source§

impl StructuralPartialEq for NicknameTable

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,