value_checks
value_checks
¶
Checks the executor applies to generated replacement values.
This module lives outside replacement.generators so the executor can check
candidates without importing generator implementations.
Functions:
| Name | Description |
|---|---|
generated_value_is_valid |
Return whether a generated value meets the request's local constraints. |
is_ipv4 |
Return whether |
is_ipv6 |
Return whether |
is_luhn_valid |
Return whether the ASCII digits in |
keeps_original_name_part |
Return whether a full-name replacement keeps the original's first, middle, or last name. |
generated_value_is_valid(request, value)
¶
Return whether a generated value meets the request's local constraints.
A replacement must differ from its original ignoring letter case, because a reused replacement may be
written in the case of each occurrence it replaces: Ada accepted for ADA would be written back
as ADA. Surrounding whitespace is ignored too: Kenneth for Kenneth keeps the real name,
and free text, which never has the padding, would reuse it for every Kenneth.
Source code in src/nemo_safe_synthesizer/pii_replacer/replacement/value_checks.py
is_ipv4(value)
¶
Return whether value is an IPv4 address.
is_ipv6(value)
¶
Return whether value, with any enclosing URL brackets removed, is an IPv6 address.
Source code in src/nemo_safe_synthesizer/pii_replacer/replacement/value_checks.py
is_luhn_valid(value)
¶
Return whether the ASCII digits in value, ignoring separators such as spaces and dashes, pass the Luhn check.
Example
is_luhn_valid("4111 1111 1111 1111") is True.
Source code in src/nemo_safe_synthesizer/pii_replacer/replacement/value_checks.py
keeps_original_name_part(original, candidate, pattern, *, locale='en_US')
¶
Return whether a full-name replacement keeps the original's first, middle, or last name.
A whole-name comparison accepts John Brown for John Smith, which keeps the real first name. Both names are
read by nameparser in the order of pattern or locale, so titles such as Mr., suffixes such as
Jr., and a Last, First layout do not hide a kept part, and each part is compared with the same part.
Words that are fixed text in pattern, such as Dr. in Dr. {First} {Last}, are skipped. Trailing
commas and periods are ignored, and single letters are not compared, so a shared initial does not count.
Example
keeps_original_name_part("Mr. John Smith", "John Brown", None) # True: same first name keeps_original_name_part("Dr. Ana Ruiz", "Dr. Maria Lopez", "Dr. {First} {Last}") # False