From aff146aec3a0f76b0309f5ac41e07b1370949a84 Mon Sep 17 00:00:00 2001 From: Diana Shkolnikov Date: Thu, 10 Mar 2016 15:59:35 -0500 Subject: [PATCH] Fix local naming convention and confidence score middlewares --- middleware/confidenceScore.js | 10 +- middleware/localNamingConventions.js | 2 +- test/unit/controller/search.js | 12 +- .../dedupe_elasticsearch_nonascii_results.js | 30 ++-- .../fixture/dedupe_elasticsearch_results.js | 168 +++++++++--------- test/unit/middleware/confidenceScore.js | 12 +- .../unit/middleware/localNamingConventions.js | 18 +- test/unit/mock/backend.js | 8 +- test/unit/service/mget.js | 4 +- test/unit/service/search.js | 4 +- 10 files changed, 134 insertions(+), 134 deletions(-) diff --git a/middleware/confidenceScore.js b/middleware/confidenceScore.js index 3cd9d1f3..a0382b25 100644 --- a/middleware/confidenceScore.js +++ b/middleware/confidenceScore.js @@ -95,7 +95,7 @@ function checkForDealBreakers(req, hit) { return false; } - if (check.assigned(req.clean.parsed_text.state) && req.clean.parsed_text.state !== hit.parent.region_a) { + if (check.assigned(req.clean.parsed_text.state) && req.clean.parsed_text.state !== hit.parent.region_a[0]) { logger.debug('[confidence][deal-breaker]: state !== region_a'); return true; } @@ -210,8 +210,8 @@ function propMatch(textProp, hitProp, expectEnriched) { * @param {string|number} [hit.address.number] * @param {string} [hit.address.street] * @param {string|number} [hit.address.zip] - * @param {string} [hit.parent.region_a] - * @param {string} [hit.parent.country_a] + * @param {Array} [hit.parent.region_a] + * @param {Array} [hit.parent.country_a] * @returns {number} */ function checkAddress(text, hit) { @@ -222,8 +222,8 @@ function checkAddress(text, hit) { res += propMatch(text.number, (hit.address ? hit.address.number : null), false); res += propMatch(text.street, (hit.address ? hit.address.street : null), false); res += propMatch(text.postalcode, (hit.address ? hit.address.zip: null), true); - res += propMatch(text.state, hit.parent.region_a, true); - res += propMatch(text.country, hit.parent.country_a, true); + res += propMatch(text.state, hit.parent.region_a[0], true); + res += propMatch(text.country, hit.parent.country_a[0], true); res /= checkCount; } diff --git a/middleware/localNamingConventions.js b/middleware/localNamingConventions.js index 084cfc26..6170cda2 100644 --- a/middleware/localNamingConventions.js +++ b/middleware/localNamingConventions.js @@ -13,7 +13,7 @@ function applyLocalNamingConventions(req, res, next) { // loop through data items and flip relevant number/street res.data.filter(function(place){ // only relevant for German addresses - if( 'DEU' !== place.parent.country_a ){ return false; } + if( place.parent.country_a.indexOf('DEU') === -1 ){ return false; } if( !place.hasOwnProperty('address') ){ return false; } if( !place.address.hasOwnProperty('number') ){ return false; } if( !place.address.hasOwnProperty('street') ){ return false; } diff --git a/test/unit/controller/search.js b/test/unit/controller/search.js index 3d46dde0..cfb715fa 100644 --- a/test/unit/controller/search.js +++ b/test/unit/controller/search.js @@ -51,9 +51,9 @@ module.exports.tests.functional_success = function(test, common) { _score: 10, _type: 'mytype1', parent: { - country: 'country1', - region: 'state1', - county: 'city1' + country: ['country1'], + region: ['state1'], + county: ['city1'] }, center_point: { lat: 100.1, lon: -50.5 }, name: { default: 'test name1' }, @@ -64,9 +64,9 @@ module.exports.tests.functional_success = function(test, common) { _score: 20, _type: 'mytype2', parent: { - country: 'country2', - region: 'state2', - county: 'city2' + country: ['country2'], + region: ['state2'], + county: ['city2'] }, center_point: { lat: 100.2, lon: -51.5 }, name: { default: 'test name2' }, diff --git a/test/unit/fixture/dedupe_elasticsearch_nonascii_results.js b/test/unit/fixture/dedupe_elasticsearch_nonascii_results.js index ce929152..b2a6c383 100644 --- a/test/unit/fixture/dedupe_elasticsearch_nonascii_results.js +++ b/test/unit/fixture/dedupe_elasticsearch_nonascii_results.js @@ -8,9 +8,9 @@ module.exports = [ 'default': '万里长城万里长城' }, 'parent': { - 'country_a': 'CHN', - 'country': 'China', - 'region': 'Beijing' + 'country_a': ['CHN'], + 'country': ['China'], + 'region': ['Beijing'] }, 'confidence': 0.733 }, @@ -23,9 +23,9 @@ module.exports = [ 'default': '万里长城' }, 'parent': { - 'country_a': 'CHN', - 'country': 'China', - 'region': 'Beijing' + 'country_a': ['CHN'], + 'country': ['China'], + 'region': ['Beijing'] }, 'confidence': 0.733 }, @@ -38,12 +38,12 @@ module.exports = [ 'default': '万里花' }, 'parent': { - 'country_a': 'JPN', - 'country': 'Japan', - 'region': 'Tokyo', - 'county': '豊島区', - 'locality': 'Tokyo', - 'neighbourhood': '2丁目' + 'country_a': ['JPN'], + 'country': ['Japan'], + 'region': ['Tokyo'], + 'county': ['豊島区'], + 'locality': ['Tokyo'], + 'neighbourhood': ['2丁目'] }, 'confidence': 0.646 }, @@ -60,9 +60,9 @@ module.exports = [ 'postalcode': '312044' }, 'parent': { - 'country_a': 'CHN', - 'country': 'China', - 'region': 'Zhejiang' + 'country_a': ['CHN'], + 'country': ['China'], + 'region': ['Zhejiang'] }, 'confidence': 0.646 } diff --git a/test/unit/fixture/dedupe_elasticsearch_results.js b/test/unit/fixture/dedupe_elasticsearch_results.js index 84b279d3..a57a3a7f 100644 --- a/test/unit/fixture/dedupe_elasticsearch_results.js +++ b/test/unit/fixture/dedupe_elasticsearch_results.js @@ -6,14 +6,14 @@ module.exports = [ }, 'address': {}, 'parent': { - 'localadmin': 'East Lampeter', - 'region_a': 'PA', - 'region': 'Pennsylvania', - 'locality': 'Smoketown', - 'country_a': 'USA', - 'county': 'Lancaster County', - 'country': 'United States', - 'neighbourhood': 'Greenland' + 'localadmin': ['East Lampeter'], + 'region_a': ['PA'], + 'region': ['Pennsylvania'], + 'locality': ['Smoketown'], + 'country_a': ['USA'], + 'county': ['Lancaster County'], + 'country': ['United States'], + 'neighbourhood': ['Greenland'] }, 'name': { 'default': 'East Lampeter High School' @@ -33,14 +33,14 @@ module.exports = [ }, 'address': {}, 'parent': { - 'localadmin': 'East Lampeter', - 'region_a': 'PA', - 'region': 'Pennsylvania', - 'locality': 'Smoketown', - 'country_a': 'USA', - 'county': 'Lancaster County', - 'country': 'United States', - 'neighbourhood': 'Greenland' + 'localadmin': ['East Lampeter'], + 'region_a': ['PA'], + 'region': ['Pennsylvania'], + 'locality': ['Smoketown'], + 'country_a': ['USA'], + 'county': ['Lancaster County'], + 'country': ['United States'], + 'neighbourhood': ['Greenland'] }, 'name': { 'default': 'East Lampeter, High-School' @@ -60,14 +60,14 @@ module.exports = [ }, 'address': {}, 'parent': { - 'localadmin': 'West Lampeter', - 'region_a': 'PA', - 'region': 'Pennsylvania', - 'locality': 'Lampeter', - 'country_a': 'USA', - 'county': 'Lancaster County', - 'country': 'United States', - 'neighbourhood': 'Wheatland Mills' + 'localadmin': ['West Lampeter'], + 'region_a': ['PA'], + 'region': ['Pennsylvania'], + 'locality': ['Lampeter'], + 'country_a': ['USA'], + 'county': ['Lancaster County'], + 'country': ['United States'], + 'neighbourhood': ['Wheatland Mills'] }, 'name': { 'default': 'Lampeter-Strasburg High School' @@ -87,14 +87,14 @@ module.exports = [ }, 'address': {}, 'parent': { - 'localadmin': 'East Lampeter', - 'region_a': 'PA', - 'region': 'Pennsylvania', - 'locality': 'Smoketown', - 'country_a': 'USA', - 'county': 'Lancaster County', - 'country': 'United States', - 'neighbourhood': 'Greenland' + 'localadmin': ['East Lampeter'], + 'region_a': ['PA'], + 'region': ['Pennsylvania'], + 'locality': ['Smoketown'], + 'country_a': ['USA'], + 'county': ['Lancaster County'], + 'country': ['United States'], + 'neighbourhood': ['Greenland'] }, 'name': { 'default': 'East Lampeter High School' @@ -114,14 +114,14 @@ module.exports = [ }, 'address': {}, 'parent': { - 'region': 'Pennsylvania', - 'locality': 'Lampeter', - 'country_a': 'USA', - 'county': 'Lancaster County', - 'country': 'United States', - 'neighbourhood': 'Wheatland Mills', - 'localadmin': 'West Lampeter', - 'region_a': 'PA' + 'region': ['Pennsylvania'], + 'locality': ['Lampeter'], + 'country_a': ['USA'], + 'county': ['Lancaster County'], + 'country': ['United States'], + 'neighbourhood': ['Wheatland Mills'], + 'localadmin': ['West Lampeter'], + 'region_a': ['PA'] }, 'name': { 'default': 'Lampeter-Strasburg High School' @@ -141,14 +141,14 @@ module.exports = [ }, 'address': {}, 'parent': { - 'region': 'Pennsylvania', - 'locality': 'Smoketown', - 'country_a': 'USA', - 'county': 'Lancaster County', - 'country': 'United States', - 'neighbourhood': 'Greenland', - 'localadmin': 'East Lampeter', - 'region_a': 'PA' + 'region': ['Pennsylvania'], + 'locality': ['Smoketown'], + 'country_a': ['USA'], + 'county': ['Lancaster County'], + 'country': ['United States'], + 'neighbourhood': ['Greenland'], + 'localadmin': ['East Lampeter'], + 'region_a': ['PA'] }, 'name': { 'default': 'East Lampeter School' @@ -168,14 +168,14 @@ module.exports = [ }, 'address': {}, 'parent': { - 'region': 'Pennsylvania', - 'locality': 'Smoketown', - 'country_a': 'USA', - 'county': 'Lancaster County', - 'country': 'United States', - 'neighbourhood': 'Greenland', - 'localadmin': 'East Lampeter', - 'region_a': 'PA' + 'region': ['Pennsylvania'], + 'locality': ['Smoketown'], + 'country_a': ['USA'], + 'county': ['Lancaster County'], + 'country': ['United States'], + 'neighbourhood': ['Greenland'], + 'localadmin': ['East Lampeter'], + 'region_a': ['PA'] }, 'name': { 'default': 'East Lampeter School' @@ -195,13 +195,13 @@ module.exports = [ }, 'address': {}, 'parent': { - 'region': 'Missouri', - 'locality': 'Strasburg', - 'country_a': 'USA', - 'county': 'Cass County', - 'country': 'United States', - 'localadmin': 'Polk', - 'region_a': 'MO' + 'region': ['Missouri'], + 'locality': ['Strasburg'], + 'country_a': ['USA'], + 'county': ['Cass County'], + 'country': ['United States'], + 'localadmin': ['Polk'], + 'region_a': ['MO'] }, 'name': { 'default': 'Strasburg School' @@ -224,13 +224,13 @@ module.exports = [ 'default': 'Strasburg High School' }, 'parent': { - 'region_a': 'VA', - 'region': 'Virginia', - 'locality': 'Strasburg', - 'country_a': 'USA', - 'county': 'Shenandoah County', - 'country': 'United States', - 'neighbourhood': 'Strasburg Junction' + 'region_a': ['VA'], + 'region': ['Virginia'], + 'locality': ['Strasburg'], + 'country_a': ['USA'], + 'county': ['Shenandoah County'], + 'country': ['United States'], + 'neighbourhood': ['Strasburg Junction'] }, 'category': [ 'education' @@ -250,13 +250,13 @@ module.exports = [ 'default': 'Strasburg High School' }, 'parent': { - 'localadmin': 'Strasburg', - 'region_a': 'ND', - 'region': 'North Dakota', - 'locality': 'Strasburg', - 'country_a': 'USA', - 'county': 'Emmons County', - 'country': 'United States' + 'localadmin': ['Strasburg'], + 'region_a': ['ND'], + 'region': ['North Dakota'], + 'locality': ['Strasburg'], + 'country_a': ['USA'], + 'county': ['Emmons County'], + 'country': ['United States'] }, 'category': [ 'education' @@ -276,13 +276,13 @@ module.exports = [ 'default': 'Strasburg High School' }, 'parent': { - 'localadmin': 'Franklin', - 'region_a': 'OH', - 'region': 'Ohio', - 'locality': 'Strasburg', - 'country_a': 'USA', - 'county': 'Tuscarawas County', - 'country': 'United States' + 'localadmin': ['Franklin'], + 'region_a': ['OH'], + 'region': ['Ohio'], + 'locality': ['Strasburg'], + 'country_a': ['USA'], + 'county': ['Tuscarawas County'], + 'country': ['United States'] }, 'category': [ 'education' diff --git a/test/unit/middleware/confidenceScore.js b/test/unit/middleware/confidenceScore.js index 7d516f16..f629874b 100644 --- a/test/unit/middleware/confidenceScore.js +++ b/test/unit/middleware/confidenceScore.js @@ -71,9 +71,9 @@ module.exports.tests.confidenceScore = function(test, common) { center_point: { lat: 100.1, lon: -50.5 }, name: { default: 'test name1' }, parent: { - country: 'country1', - region: 'state1', - county: 'city1' + country: ['country1'], + region: ['state1'], + county: ['city1'] } }, { _score: 20, @@ -81,9 +81,9 @@ module.exports.tests.confidenceScore = function(test, common) { center_point: { lat: 100.2, lon: -51.5 }, name: { default: 'test name2' }, parent: { - country: 'country2', - region: 'state2', - county: 'city2' + country: ['country2'], + region: ['state2'], + county: ['city2'] } }], meta: {scores: [10]} diff --git a/test/unit/middleware/localNamingConventions.js b/test/unit/middleware/localNamingConventions.js index da904e63..d8714af5 100644 --- a/test/unit/middleware/localNamingConventions.js +++ b/test/unit/middleware/localNamingConventions.js @@ -16,9 +16,9 @@ module.exports.tests.flipNumberAndStreet = function(test, common) { 'street': 'Main St' }, 'parent': { - 'region': 'Dungannon', - 'country_a': 'GBR', - 'country': 'United Kingdom' + 'region': ['Dungannon'], + 'country_a': ['GBR'], + 'country': ['United Kingdom'] } }; @@ -33,12 +33,12 @@ module.exports.tests.flipNumberAndStreet = function(test, common) { 'street': 'Grolmanstraße' }, 'parent': { - 'region': 'Berlin', - 'locality': 'Berlin', - 'country_a': 'DEU', - 'county': 'Berlin', - 'country': 'Germany', - 'neighbourhood': 'Hansaviertel' + 'region': ['Berlin'], + 'locality': ['Berlin'], + 'country_a': ['DEU'], + 'county': ['Berlin'], + 'country': ['Germany'], + 'neighbourhood': ['Hansaviertel'] } }; diff --git a/test/unit/mock/backend.js b/test/unit/mock/backend.js index ea20c4d0..84147783 100644 --- a/test/unit/mock/backend.js +++ b/test/unit/mock/backend.js @@ -15,7 +15,7 @@ responses['client/search/ok/1'] = function( cmd, cb ){ value: 1, center_point: { lat: 100.1, lon: -50.5 }, name: { default: 'test name1' }, - parent: { country: 'country1', region: 'state1', county: 'city1' } + parent: { country: ['country1'], region: ['state1'], county: ['city1'] } } }, { _id: 'myid2', @@ -25,7 +25,7 @@ responses['client/search/ok/1'] = function( cmd, cb ){ value: 2, center_point: { lat: 100.2, lon: -51.5 }, name: { default: 'test name2' }, - parent: { country: 'country2', region: 'state2', county: 'city2' } + parent: { country: ['country2'], region: ['state2'], county: ['city2'] } } }])); }; @@ -43,7 +43,7 @@ responses['client/mget/ok/1'] = function( cmd, cb ){ value: 1, center_point: { lat: 100.1, lon: -50.5 }, name: { default: 'test name1' }, - parent: { country: 'country1', region: 'state1', county: 'city1' } + parent: { country: ['country1'], region: ['state1'], county: ['city1'] } } }, { _id: 'myid2', @@ -54,7 +54,7 @@ responses['client/mget/ok/1'] = function( cmd, cb ){ value: 2, center_point: { lat: 100.2, lon: -51.5 }, name: { default: 'test name2' }, - parent: { country: 'country2', region: 'state2', county: 'city2' } + parent: { country: ['country2'], region: ['state2'], county: ['city2'] } } }])); }; diff --git a/test/unit/service/mget.js b/test/unit/service/mget.js index dd093c9f..e2723e6e 100644 --- a/test/unit/service/mget.js +++ b/test/unit/service/mget.js @@ -20,14 +20,14 @@ module.exports.tests.functional_success = function(test, common) { value: 1, center_point: { lat: 100.1, lon: -50.5 }, name: { default: 'test name1' }, - parent: { country: 'country1', region: 'state1', county: 'city1' } + parent: { country: ['country1'], region: ['state1'], county: ['city1'] } }, { _id: 'myid2', _type: 'mytype2', value: 2, center_point: { lat: 100.2, lon: -51.5 }, name: { default: 'test name2' }, - parent: { country: 'country2', region: 'state2', county: 'city2' } + parent: { country: ['country2'], region: ['state2'], county: ['city2'] } } ]; diff --git a/test/unit/service/search.js b/test/unit/service/search.js index 37eb93af..0de8e0fa 100644 --- a/test/unit/service/search.js +++ b/test/unit/service/search.js @@ -23,7 +23,7 @@ module.exports.tests.functional_success = function(test, common) { value: 1, center_point: { lat: 100.1, lon: -50.5 }, name: { default: 'test name1' }, - parent: { country: 'country1', region: 'state1', county: 'city1' } + parent: { country: ['country1'], region: ['state1'], county: ['city1'] } }, { _id: 'myid2', _type: 'mytype2', @@ -31,7 +31,7 @@ module.exports.tests.functional_success = function(test, common) { value: 2, center_point: { lat: 100.2, lon: -51.5 }, name: { default: 'test name2' }, - parent: { country: 'country2', region: 'state2', county: 'city2' } + parent: { country: ['country2'], region: ['state2'], county: ['city2'] } } ];