Skip to content

Commit

Permalink
Merge remote-tracking branch 'MarcMichalsky/improve_name_extraction'
Browse files Browse the repository at this point in the history
[#112] Improve Name Extraction in Banking Matcher Plugin
  • Loading branch information
jensschuppe committed Jun 27, 2024
2 parents ea979a7 + 31a478d commit 08fb8f2
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions CRM/Banking/PluginImpl/Matcher/GetOrCreateContactAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,44 @@ protected function applyNameExtraction($btx, &$xcm_values, $name_mode)
$xcm_values['last_name'] = implode(' ', $last_names);
break;

// See PR #112
case 'db2':

$first_names = [];
$last_names = [];

// If the name contains a comma, we assume that the name is in the format "Lastname, Firstname"
if (in_array(',', $name_bits)) {
$last_names += array_slice($name_bits, 0, array_search(',', $name_bits));
$first_names += array_slice($name_bits, array_search(',', $name_bits) + 1);
}
// Otherwise, we assume that the name is in the format "Firstname Lastname"
else {
foreach ($name_bits as $name_bit) {
if (!$this->isNameBlacklisted($name_bit, $config->name_blacklist)) {
if ((!$this->isNameBlacklisted($name_bit, $config->first_name_blacklist))
&& $this->isDBFirstName($name_bit)
&& empty($last_names)) {
$first_names[] = $name_bit;
}
else {
$last_names[] = $name_bit;
}
}
}

// If we didn't find any last names, but we found more than one first name,
// then we assume that the last one is the last name of the contact
if (empty($last_names) && count($first_names) > 1) {
$last_names[] = array_pop($first_names);
}
}

$this->logMessage("Identified (by DB) first names of '{$btx_name}' are: " . implode(',', $first_names), 'debug');
$xcm_values['first_name'] = implode(' ', $first_names);
$xcm_values['last_name'] = implode(' ', $last_names);
break;

default:
case 'off':
break;
Expand Down

0 comments on commit 08fb8f2

Please sign in to comment.