diff --git a/lib/ofac/index.js b/lib/ofac/index.js index 8db51586..5392ec55 100644 --- a/lib/ofac/index.js +++ b/lib/ofac/index.js @@ -55,7 +55,10 @@ function match (nameParts, birthDateString, threshold) { const words = nameUtils.makeWords(fullName) const wordValues = _.map(_.get('value'), words) - const wordPhonetics = _.flatMap(_.get('phonetics'), words) + const wordPhonetics = _.flatMap(word => { + const {phonetics} = word + return _.map(phonetic => ({word: word.value, phonetic}), phonetics) + }, words) // birthDateString is in YYYYMMDD format const birthDate = _.cond([ diff --git a/lib/ofac/matching.js b/lib/ofac/matching.js index 1f600759..aaf78acf 100644 --- a/lib/ofac/matching.js +++ b/lib/ofac/matching.js @@ -46,8 +46,13 @@ function match (structs, candidate, threshold) { // Gather aliases who's name-parts match phonetically. const getPhoneticMatches = phonetic => structs.phoneticMap.get(phonetic) const phoneticMatches = _.flow( - _.map(getPhoneticMatches), + _.map(wordPhonetic => { + const {word, phonetic} = wordPhonetic + const matches = getPhoneticMatches(phonetic) + return _.map(match => ({...match, word}), matches) + }), _.compact, + // _.map(_.uniqWith((a, b) => a.aliasId === b.aliasId)), _.flatten )(wordPhonetics) @@ -71,7 +76,10 @@ function match (structs, candidate, threshold) { return count >= Math.min(2, alias.words.length) } const aliasIdsFromNamePart = _.flow( - _.uniqWith((a, b) => a.value === b.value && a.aliasId === b.aliasId), + _.uniqWith((a, b) => ( + (a.value === b.value && a.aliasId === b.aliasId) || + (a.word === b.word && a.aliasId === b.aliasId) + )), _.map(_.get('aliasId')), _.countBy(_.identity), _.toPairs, @@ -79,6 +87,11 @@ function match (structs, candidate, threshold) { _.map(_.first) )([...phoneticMatches, ...stringMatches]) + // debug_log(aliasIdsFromFullName) + // debug_log(phoneticMatches) + // debug_log(stringMatches) + // debug_log(aliasIdsFromNamePart) + // Get the full record for each matched id const getIndividual = aliasId => { const individualId = structs.aliasToIndividual.get(aliasId)