|
|
@ -1,5 +1,4 @@ |
|
|
|
var util = require('util'); |
|
|
|
var logger = require('pelias-logger').get('api'); |
|
|
|
var logger = require('pelias-logger').get('api:middle:dedupe'); |
|
|
|
|
|
|
|
var _ = require('lodash'); |
|
|
|
var _ = require('lodash'); |
|
|
|
|
|
|
|
|
|
|
|
function setup() { |
|
|
|
function setup() { |
|
|
@ -45,8 +44,8 @@ function isDifferent(item1, item2) { |
|
|
|
if (item1.hasOwnProperty('name') && item2.hasOwnProperty('name')) { |
|
|
|
if (item1.hasOwnProperty('name') && item2.hasOwnProperty('name')) { |
|
|
|
propMatch(item1.name, item2.name, 'default'); |
|
|
|
propMatch(item1.name, item2.name, 'default'); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (item1.name !== item2.name) { |
|
|
|
else { |
|
|
|
throw 'different'; |
|
|
|
propMatch(item1, item2, 'name'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (item1.hasOwnProperty('address') && item2.hasOwnProperty('address')) { |
|
|
|
if (item1.hasOwnProperty('address') && item2.hasOwnProperty('address')) { |
|
|
@ -68,15 +67,29 @@ function isDifferent(item1, item2) { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Throw exception if properties are different |
|
|
|
* Throw exception if properties are different |
|
|
|
* |
|
|
|
* |
|
|
|
* @param item1 |
|
|
|
* @param {object} item1 |
|
|
|
* @param item2 |
|
|
|
* @param {object} item2 |
|
|
|
* @param prop |
|
|
|
* @param {string} prop |
|
|
|
|
|
|
|
* @throws {string} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function propMatch(item1, item2, prop) { |
|
|
|
function propMatch(item1, item2, prop) { |
|
|
|
if (item1[prop] !== item2[prop]) { |
|
|
|
if (normalizeString(item1[prop]) !== normalizeString(item2[prop])) { |
|
|
|
throw 'different'; |
|
|
|
throw 'different'; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Remove punctuation and lowercase |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param {string} str |
|
|
|
|
|
|
|
* @returns {string} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
function normalizeString(str) { |
|
|
|
|
|
|
|
if (!str) { |
|
|
|
|
|
|
|
return ''; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return _.words(str.toLowerCase()).join(' '); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = setup; |
|
|
|
module.exports = setup; |