Class: Kiba::Extend::Transforms::Helpers::PersonNameChecker
- Inherits:
-
Object
- Object
- Kiba::Extend::Transforms::Helpers::PersonNameChecker
- Defined in:
- lib/kiba/extend/transforms/helpers/person_name_checker.rb
Overview
Returns true/false indicating whether given value matches any given or added patterns. Used on a list of names and name-like values, where standard inverted name entry patterns are followed, this works ok. It will not work at all on directly- entered names. Used on a list of subject like terms or on freetext, be wary of false positives (though the patterns and the duplicative anchoring matching tries to avoid matching subject-like terms
The default name list provided is all unique first names from the data set at https://www.ssa.gov/OACT/babynames/limits.html which have been on more than 100 Social Security card applications from 1880-2022. So there is a definite U.S. bias.
Constant Summary collapse
- DEFAULT_PATTERNS =
rubocop:disable Layout/LineLength
[]
- ANTIPATTERNS =
[ /^\d/, /^\w+\.?$/ ]
- FAMILY_PATTERNS =
[ / famil(ies|y)/i ]
Class Method Summary collapse
Instance Method Summary collapse
-
#call(value) ⇒ true, false
-
#initialize(added_patterns: [], family_is_person: false, name_lists: [File.join(Kiba::Extend.ke_dir, "data", "us_names_1880-2022_gt100.txt")], mode: :strict, order: :inverted) ⇒ PersonNameChecker
constructor
A new instance of PersonNameChecker.
Constructor Details
#initialize(added_patterns: [], family_is_person: false, name_lists: [File.join(Kiba::Extend.ke_dir, "data", "us_names_1880-2022_gt100.txt")], mode: :strict, order: :inverted) ⇒ PersonNameChecker
Returns a new instance of PersonNameChecker.
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/kiba/extend/transforms/helpers/person_name_checker.rb', line 66 def initialize(added_patterns: [], family_is_person: false, name_lists: [File.join(Kiba::Extend.ke_dir, "data", "us_names_1880-2022_gt100.txt")], mode: :strict, order: :inverted) base = DEFAULT_PATTERNS + added_patterns @patterns = family_is_person ? base + FAMILY_PATTERNS : base anti = ANTIPATTERNS @antipatterns = family_is_person ? anti : anti + FAMILY_PATTERNS @names = set_up_names(name_lists) @mode = mode @order = order end |
Class Method Details
.call(value:, added_patterns: [], family_is_person: false) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/kiba/extend/transforms/helpers/person_name_checker.rb', line 26 def call( value:, added_patterns: [], family_is_person: false ) new( added_patterns: added_patterns, family_is_person: family_is_person ).call(value) end |
Instance Method Details
#call(value) ⇒ true, false
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/kiba/extend/transforms/helpers/person_name_checker.rb', line 82 def call(value) return false if value.blank? return false if antipatterns.any? do |pattern| value.match?(pattern) end return true if patterns.any? do |pattern| value.match?(pattern) end (mode == :lenient) ? lenient_check(value) : strict_check(value) end |