-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(deduplication): add deduplication post processing script
- Loading branch information
1 parent
e61690c
commit 1d9c00d
Showing
5 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Deduplication post-processing script ensures that array | ||
* values only contain unique entries. | ||
*/ | ||
|
||
const _ = require('lodash'); | ||
const prefixes = [ 'name', 'address_parts' ]; | ||
|
||
function deduplication( doc ){ | ||
prefixes.forEach(prefix => { | ||
let index = doc[prefix]; | ||
if ( _.isPlainObject( index ) ){ | ||
for( let field in index ){ | ||
let values = index[field]; | ||
if( _.isArray( values ) && values.length > 1 ){ | ||
index[field] = _.uniq(values); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
module.exports = deduplication; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
var Document = require('../../Document'); | ||
var deduplication = require('../../post/deduplication'); | ||
|
||
module.exports.tests = {}; | ||
|
||
module.exports.tests.dedupe = function (test) { | ||
test('dedupe - name', function (t) { | ||
var doc = new Document('mysource', 'mylayer', 'myid'); | ||
|
||
doc.setNameAlias('default', 'test'); | ||
doc.setName('default', 'test'); | ||
doc.setNameAlias('default', 'test'); | ||
doc.setNameAlias('default', 'test 2'); | ||
doc.setNameAlias('default', 'test'); | ||
|
||
deduplication(doc); | ||
t.deepEquals(doc.name.default, ['test', 'test 2']); | ||
|
||
t.end(); | ||
}); | ||
test('dedupe - address_parts', function (t) { | ||
var doc = new Document('mysource', 'mylayer', 'myid'); | ||
|
||
doc.setAddressAlias('street', 'test'); | ||
doc.setAddress('street', 'test'); | ||
doc.setAddressAlias('street', 'test'); | ||
doc.setAddressAlias('street', 'test 2'); | ||
doc.setAddressAlias('street', 'test'); | ||
|
||
deduplication(doc); | ||
t.deepEquals(doc.address_parts.street, ['test', 'test 2']); | ||
|
||
t.end(); | ||
}); | ||
}; | ||
|
||
module.exports.all = function (tape, common) { | ||
|
||
function test(name, testFunction) { | ||
return tape('post/deduplication: ' + name, testFunction); | ||
} | ||
|
||
for (var testCase in module.exports.tests) { | ||
module.exports.tests[testCase](test, common); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters