Name matching logic
This commit is contained in:
parent
910d7e200f
commit
620863d703
3 changed files with 83 additions and 66 deletions
|
|
@ -1,46 +1,33 @@
|
|||
const metaphone = require('talisman/phonetics/metaphone')
|
||||
const doubleMetaphone = require('talisman/phonetics/double-metaphone')
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
// KOSTIS TODO: Decide on a method. Remove the others
|
||||
|
||||
const phoneticMethod1 = metaphone
|
||||
|
||||
const phoneticMethod2 = _.flow(doubleMetaphone, _.uniq)
|
||||
|
||||
const phoneticMethod3 = _.flow(_.split(' '), _.map(phoneticMethod2))
|
||||
const makePhonetic = _.flow(doubleMetaphone, _.uniq)
|
||||
|
||||
// Combine name-parts in a standard order.
|
||||
|
||||
const commonOrderings = [
|
||||
['firstName', 'lastName'],
|
||||
['firstName', 'middleName', 'lastName'],
|
||||
['firstName', 'maidenName', 'lastName'],
|
||||
['firstName', 'patronymic', 'lastName'],
|
||||
['firstName', 'matronymic', 'lastName']
|
||||
]
|
||||
const partOrdering = ['firstName', 'middleName', 'maidenName', 'patronymic', 'matronymic', 'lastName']
|
||||
|
||||
// const getFrom = _.flip()
|
||||
|
||||
const getFrom = _.curry((obj, key) => obj[key])
|
||||
|
||||
const getOrderedParts = (parts, ordering) => _.map(getFrom(parts), ordering)
|
||||
|
||||
const combineParts = _.curryN(2, _.flow(
|
||||
getOrderedParts,
|
||||
_.compact,
|
||||
_.join(' ')
|
||||
))
|
||||
|
||||
const makeAllOrderings = parts => _.map(combineParts(parts), commonOrderings)
|
||||
|
||||
const makeFullNames = _.flow(
|
||||
makeAllOrderings,
|
||||
_.uniq
|
||||
const usingPartOrder = _.flow(
|
||||
_.get('partName'),
|
||||
_.partialRight(_.indexOf, [partOrdering])
|
||||
)
|
||||
|
||||
const makeFullName = _.flow(
|
||||
_.sortBy(usingPartOrder),
|
||||
_.map(_.get('value')),
|
||||
_.join(' ')
|
||||
)
|
||||
|
||||
const makeWords = value => {
|
||||
const words = _.split(' ', value)
|
||||
const phonetic = _.map(makePhonetic, words)
|
||||
const props = _.zipAll([words, phonetic])
|
||||
return _.map(_.zipObject(['value', 'phonetic']), props)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
makeFullNames,
|
||||
phonetic: phoneticMethod3
|
||||
makeFullName,
|
||||
makeWords
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue