Skip to content

Commit

Permalink
add new mode to improve name extraction
Browse files Browse the repository at this point in the history
This commit improves the name extraction by adding `db2` as an alternative mode.
- if there is more than one valid name bit, the last bit will always be the last name
- name bits following the first bit recognised as a last name will not become first names again
  • Loading branch information
MarcMichalsky committed Apr 11, 2024
1 parent 65f9748 commit 8b9f420
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions CRM/Banking/PluginImpl/Matcher/GetOrCreateContactAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,33 @@ 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 = [];
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 8b9f420

Please sign in to comment.