Fixed issue with one word matching multiple

This commit is contained in:
Konstantin Mamalakis 2018-03-12 02:05:36 +02:00 committed by Josh Harvey
parent 3e80cb745b
commit 3722ab2af3
2 changed files with 19 additions and 3 deletions

View file

@ -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)