Browse Source

Fix local naming convention and confidence score middlewares

pull/447/head
Diana Shkolnikov 9 years ago
parent
commit
aff146aec3
  1. 10
      middleware/confidenceScore.js
  2. 2
      middleware/localNamingConventions.js
  3. 12
      test/unit/controller/search.js
  4. 30
      test/unit/fixture/dedupe_elasticsearch_nonascii_results.js
  5. 168
      test/unit/fixture/dedupe_elasticsearch_results.js
  6. 12
      test/unit/middleware/confidenceScore.js
  7. 18
      test/unit/middleware/localNamingConventions.js
  8. 8
      test/unit/mock/backend.js
  9. 4
      test/unit/service/mget.js
  10. 4
      test/unit/service/search.js

10
middleware/confidenceScore.js

@ -95,7 +95,7 @@ function checkForDealBreakers(req, hit) {
return false; 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'); logger.debug('[confidence][deal-breaker]: state !== region_a');
return true; return true;
} }
@ -210,8 +210,8 @@ function propMatch(textProp, hitProp, expectEnriched) {
* @param {string|number} [hit.address.number] * @param {string|number} [hit.address.number]
* @param {string} [hit.address.street] * @param {string} [hit.address.street]
* @param {string|number} [hit.address.zip] * @param {string|number} [hit.address.zip]
* @param {string} [hit.parent.region_a] * @param {Array} [hit.parent.region_a]
* @param {string} [hit.parent.country_a] * @param {Array} [hit.parent.country_a]
* @returns {number} * @returns {number}
*/ */
function checkAddress(text, hit) { 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.number, (hit.address ? hit.address.number : null), false);
res += propMatch(text.street, (hit.address ? hit.address.street : 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.postalcode, (hit.address ? hit.address.zip: null), true);
res += propMatch(text.state, hit.parent.region_a, true); res += propMatch(text.state, hit.parent.region_a[0], true);
res += propMatch(text.country, hit.parent.country_a, true); res += propMatch(text.country, hit.parent.country_a[0], true);
res /= checkCount; res /= checkCount;
} }

2
middleware/localNamingConventions.js

@ -13,7 +13,7 @@ function applyLocalNamingConventions(req, res, next) {
// loop through data items and flip relevant number/street // loop through data items and flip relevant number/street
res.data.filter(function(place){ res.data.filter(function(place){
// only relevant for German addresses // 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.hasOwnProperty('address') ){ return false; }
if( !place.address.hasOwnProperty('number') ){ return false; } if( !place.address.hasOwnProperty('number') ){ return false; }
if( !place.address.hasOwnProperty('street') ){ return false; } if( !place.address.hasOwnProperty('street') ){ return false; }

12
test/unit/controller/search.js

@ -51,9 +51,9 @@ module.exports.tests.functional_success = function(test, common) {
_score: 10, _score: 10,
_type: 'mytype1', _type: 'mytype1',
parent: { parent: {
country: 'country1', country: ['country1'],
region: 'state1', region: ['state1'],
county: 'city1' county: ['city1']
}, },
center_point: { lat: 100.1, lon: -50.5 }, center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' }, name: { default: 'test name1' },
@ -64,9 +64,9 @@ module.exports.tests.functional_success = function(test, common) {
_score: 20, _score: 20,
_type: 'mytype2', _type: 'mytype2',
parent: { parent: {
country: 'country2', country: ['country2'],
region: 'state2', region: ['state2'],
county: 'city2' county: ['city2']
}, },
center_point: { lat: 100.2, lon: -51.5 }, center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' }, name: { default: 'test name2' },

30
test/unit/fixture/dedupe_elasticsearch_nonascii_results.js

@ -8,9 +8,9 @@ module.exports = [
'default': '万里长城万里长城' 'default': '万里长城万里长城'
}, },
'parent': { 'parent': {
'country_a': 'CHN', 'country_a': ['CHN'],
'country': 'China', 'country': ['China'],
'region': 'Beijing' 'region': ['Beijing']
}, },
'confidence': 0.733 'confidence': 0.733
}, },
@ -23,9 +23,9 @@ module.exports = [
'default': '万里长城' 'default': '万里长城'
}, },
'parent': { 'parent': {
'country_a': 'CHN', 'country_a': ['CHN'],
'country': 'China', 'country': ['China'],
'region': 'Beijing' 'region': ['Beijing']
}, },
'confidence': 0.733 'confidence': 0.733
}, },
@ -38,12 +38,12 @@ module.exports = [
'default': '万里花' 'default': '万里花'
}, },
'parent': { 'parent': {
'country_a': 'JPN', 'country_a': ['JPN'],
'country': 'Japan', 'country': ['Japan'],
'region': 'Tokyo', 'region': ['Tokyo'],
'county': '豊島区', 'county': ['豊島区'],
'locality': 'Tokyo', 'locality': ['Tokyo'],
'neighbourhood': '2丁目' 'neighbourhood': ['2丁目']
}, },
'confidence': 0.646 'confidence': 0.646
}, },
@ -60,9 +60,9 @@ module.exports = [
'postalcode': '312044' 'postalcode': '312044'
}, },
'parent': { 'parent': {
'country_a': 'CHN', 'country_a': ['CHN'],
'country': 'China', 'country': ['China'],
'region': 'Zhejiang' 'region': ['Zhejiang']
}, },
'confidence': 0.646 'confidence': 0.646
} }

168
test/unit/fixture/dedupe_elasticsearch_results.js

@ -6,14 +6,14 @@ module.exports = [
}, },
'address': {}, 'address': {},
'parent': { 'parent': {
'localadmin': 'East Lampeter', 'localadmin': ['East Lampeter'],
'region_a': 'PA', 'region_a': ['PA'],
'region': 'Pennsylvania', 'region': ['Pennsylvania'],
'locality': 'Smoketown', 'locality': ['Smoketown'],
'country_a': 'USA', 'country_a': ['USA'],
'county': 'Lancaster County', 'county': ['Lancaster County'],
'country': 'United States', 'country': ['United States'],
'neighbourhood': 'Greenland' 'neighbourhood': ['Greenland']
}, },
'name': { 'name': {
'default': 'East Lampeter High School' 'default': 'East Lampeter High School'
@ -33,14 +33,14 @@ module.exports = [
}, },
'address': {}, 'address': {},
'parent': { 'parent': {
'localadmin': 'East Lampeter', 'localadmin': ['East Lampeter'],
'region_a': 'PA', 'region_a': ['PA'],
'region': 'Pennsylvania', 'region': ['Pennsylvania'],
'locality': 'Smoketown', 'locality': ['Smoketown'],
'country_a': 'USA', 'country_a': ['USA'],
'county': 'Lancaster County', 'county': ['Lancaster County'],
'country': 'United States', 'country': ['United States'],
'neighbourhood': 'Greenland' 'neighbourhood': ['Greenland']
}, },
'name': { 'name': {
'default': 'East Lampeter, High-School' 'default': 'East Lampeter, High-School'
@ -60,14 +60,14 @@ module.exports = [
}, },
'address': {}, 'address': {},
'parent': { 'parent': {
'localadmin': 'West Lampeter', 'localadmin': ['West Lampeter'],
'region_a': 'PA', 'region_a': ['PA'],
'region': 'Pennsylvania', 'region': ['Pennsylvania'],
'locality': 'Lampeter', 'locality': ['Lampeter'],
'country_a': 'USA', 'country_a': ['USA'],
'county': 'Lancaster County', 'county': ['Lancaster County'],
'country': 'United States', 'country': ['United States'],
'neighbourhood': 'Wheatland Mills' 'neighbourhood': ['Wheatland Mills']
}, },
'name': { 'name': {
'default': 'Lampeter-Strasburg High School' 'default': 'Lampeter-Strasburg High School'
@ -87,14 +87,14 @@ module.exports = [
}, },
'address': {}, 'address': {},
'parent': { 'parent': {
'localadmin': 'East Lampeter', 'localadmin': ['East Lampeter'],
'region_a': 'PA', 'region_a': ['PA'],
'region': 'Pennsylvania', 'region': ['Pennsylvania'],
'locality': 'Smoketown', 'locality': ['Smoketown'],
'country_a': 'USA', 'country_a': ['USA'],
'county': 'Lancaster County', 'county': ['Lancaster County'],
'country': 'United States', 'country': ['United States'],
'neighbourhood': 'Greenland' 'neighbourhood': ['Greenland']
}, },
'name': { 'name': {
'default': 'East Lampeter High School' 'default': 'East Lampeter High School'
@ -114,14 +114,14 @@ module.exports = [
}, },
'address': {}, 'address': {},
'parent': { 'parent': {
'region': 'Pennsylvania', 'region': ['Pennsylvania'],
'locality': 'Lampeter', 'locality': ['Lampeter'],
'country_a': 'USA', 'country_a': ['USA'],
'county': 'Lancaster County', 'county': ['Lancaster County'],
'country': 'United States', 'country': ['United States'],
'neighbourhood': 'Wheatland Mills', 'neighbourhood': ['Wheatland Mills'],
'localadmin': 'West Lampeter', 'localadmin': ['West Lampeter'],
'region_a': 'PA' 'region_a': ['PA']
}, },
'name': { 'name': {
'default': 'Lampeter-Strasburg High School' 'default': 'Lampeter-Strasburg High School'
@ -141,14 +141,14 @@ module.exports = [
}, },
'address': {}, 'address': {},
'parent': { 'parent': {
'region': 'Pennsylvania', 'region': ['Pennsylvania'],
'locality': 'Smoketown', 'locality': ['Smoketown'],
'country_a': 'USA', 'country_a': ['USA'],
'county': 'Lancaster County', 'county': ['Lancaster County'],
'country': 'United States', 'country': ['United States'],
'neighbourhood': 'Greenland', 'neighbourhood': ['Greenland'],
'localadmin': 'East Lampeter', 'localadmin': ['East Lampeter'],
'region_a': 'PA' 'region_a': ['PA']
}, },
'name': { 'name': {
'default': 'East Lampeter School' 'default': 'East Lampeter School'
@ -168,14 +168,14 @@ module.exports = [
}, },
'address': {}, 'address': {},
'parent': { 'parent': {
'region': 'Pennsylvania', 'region': ['Pennsylvania'],
'locality': 'Smoketown', 'locality': ['Smoketown'],
'country_a': 'USA', 'country_a': ['USA'],
'county': 'Lancaster County', 'county': ['Lancaster County'],
'country': 'United States', 'country': ['United States'],
'neighbourhood': 'Greenland', 'neighbourhood': ['Greenland'],
'localadmin': 'East Lampeter', 'localadmin': ['East Lampeter'],
'region_a': 'PA' 'region_a': ['PA']
}, },
'name': { 'name': {
'default': 'East Lampeter School' 'default': 'East Lampeter School'
@ -195,13 +195,13 @@ module.exports = [
}, },
'address': {}, 'address': {},
'parent': { 'parent': {
'region': 'Missouri', 'region': ['Missouri'],
'locality': 'Strasburg', 'locality': ['Strasburg'],
'country_a': 'USA', 'country_a': ['USA'],
'county': 'Cass County', 'county': ['Cass County'],
'country': 'United States', 'country': ['United States'],
'localadmin': 'Polk', 'localadmin': ['Polk'],
'region_a': 'MO' 'region_a': ['MO']
}, },
'name': { 'name': {
'default': 'Strasburg School' 'default': 'Strasburg School'
@ -224,13 +224,13 @@ module.exports = [
'default': 'Strasburg High School' 'default': 'Strasburg High School'
}, },
'parent': { 'parent': {
'region_a': 'VA', 'region_a': ['VA'],
'region': 'Virginia', 'region': ['Virginia'],
'locality': 'Strasburg', 'locality': ['Strasburg'],
'country_a': 'USA', 'country_a': ['USA'],
'county': 'Shenandoah County', 'county': ['Shenandoah County'],
'country': 'United States', 'country': ['United States'],
'neighbourhood': 'Strasburg Junction' 'neighbourhood': ['Strasburg Junction']
}, },
'category': [ 'category': [
'education' 'education'
@ -250,13 +250,13 @@ module.exports = [
'default': 'Strasburg High School' 'default': 'Strasburg High School'
}, },
'parent': { 'parent': {
'localadmin': 'Strasburg', 'localadmin': ['Strasburg'],
'region_a': 'ND', 'region_a': ['ND'],
'region': 'North Dakota', 'region': ['North Dakota'],
'locality': 'Strasburg', 'locality': ['Strasburg'],
'country_a': 'USA', 'country_a': ['USA'],
'county': 'Emmons County', 'county': ['Emmons County'],
'country': 'United States' 'country': ['United States']
}, },
'category': [ 'category': [
'education' 'education'
@ -276,13 +276,13 @@ module.exports = [
'default': 'Strasburg High School' 'default': 'Strasburg High School'
}, },
'parent': { 'parent': {
'localadmin': 'Franklin', 'localadmin': ['Franklin'],
'region_a': 'OH', 'region_a': ['OH'],
'region': 'Ohio', 'region': ['Ohio'],
'locality': 'Strasburg', 'locality': ['Strasburg'],
'country_a': 'USA', 'country_a': ['USA'],
'county': 'Tuscarawas County', 'county': ['Tuscarawas County'],
'country': 'United States' 'country': ['United States']
}, },
'category': [ 'category': [
'education' 'education'

12
test/unit/middleware/confidenceScore.js

@ -71,9 +71,9 @@ module.exports.tests.confidenceScore = function(test, common) {
center_point: { lat: 100.1, lon: -50.5 }, center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' }, name: { default: 'test name1' },
parent: { parent: {
country: 'country1', country: ['country1'],
region: 'state1', region: ['state1'],
county: 'city1' county: ['city1']
} }
}, { }, {
_score: 20, _score: 20,
@ -81,9 +81,9 @@ module.exports.tests.confidenceScore = function(test, common) {
center_point: { lat: 100.2, lon: -51.5 }, center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' }, name: { default: 'test name2' },
parent: { parent: {
country: 'country2', country: ['country2'],
region: 'state2', region: ['state2'],
county: 'city2' county: ['city2']
} }
}], }],
meta: {scores: [10]} meta: {scores: [10]}

18
test/unit/middleware/localNamingConventions.js

@ -16,9 +16,9 @@ module.exports.tests.flipNumberAndStreet = function(test, common) {
'street': 'Main St' 'street': 'Main St'
}, },
'parent': { 'parent': {
'region': 'Dungannon', 'region': ['Dungannon'],
'country_a': 'GBR', 'country_a': ['GBR'],
'country': 'United Kingdom' 'country': ['United Kingdom']
} }
}; };
@ -33,12 +33,12 @@ module.exports.tests.flipNumberAndStreet = function(test, common) {
'street': 'Grolmanstraße' 'street': 'Grolmanstraße'
}, },
'parent': { 'parent': {
'region': 'Berlin', 'region': ['Berlin'],
'locality': 'Berlin', 'locality': ['Berlin'],
'country_a': 'DEU', 'country_a': ['DEU'],
'county': 'Berlin', 'county': ['Berlin'],
'country': 'Germany', 'country': ['Germany'],
'neighbourhood': 'Hansaviertel' 'neighbourhood': ['Hansaviertel']
} }
}; };

8
test/unit/mock/backend.js

@ -15,7 +15,7 @@ responses['client/search/ok/1'] = function( cmd, cb ){
value: 1, value: 1,
center_point: { lat: 100.1, lon: -50.5 }, center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' }, name: { default: 'test name1' },
parent: { country: 'country1', region: 'state1', county: 'city1' } parent: { country: ['country1'], region: ['state1'], county: ['city1'] }
} }
}, { }, {
_id: 'myid2', _id: 'myid2',
@ -25,7 +25,7 @@ responses['client/search/ok/1'] = function( cmd, cb ){
value: 2, value: 2,
center_point: { lat: 100.2, lon: -51.5 }, center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' }, 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, value: 1,
center_point: { lat: 100.1, lon: -50.5 }, center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' }, name: { default: 'test name1' },
parent: { country: 'country1', region: 'state1', county: 'city1' } parent: { country: ['country1'], region: ['state1'], county: ['city1'] }
} }
}, { }, {
_id: 'myid2', _id: 'myid2',
@ -54,7 +54,7 @@ responses['client/mget/ok/1'] = function( cmd, cb ){
value: 2, value: 2,
center_point: { lat: 100.2, lon: -51.5 }, center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' }, name: { default: 'test name2' },
parent: { country: 'country2', region: 'state2', county: 'city2' } parent: { country: ['country2'], region: ['state2'], county: ['city2'] }
} }
}])); }]));
}; };

4
test/unit/service/mget.js

@ -20,14 +20,14 @@ module.exports.tests.functional_success = function(test, common) {
value: 1, value: 1,
center_point: { lat: 100.1, lon: -50.5 }, center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' }, name: { default: 'test name1' },
parent: { country: 'country1', region: 'state1', county: 'city1' } parent: { country: ['country1'], region: ['state1'], county: ['city1'] }
}, },
{ {
_id: 'myid2', _type: 'mytype2', _id: 'myid2', _type: 'mytype2',
value: 2, value: 2,
center_point: { lat: 100.2, lon: -51.5 }, center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' }, name: { default: 'test name2' },
parent: { country: 'country2', region: 'state2', county: 'city2' } parent: { country: ['country2'], region: ['state2'], county: ['city2'] }
} }
]; ];

4
test/unit/service/search.js

@ -23,7 +23,7 @@ module.exports.tests.functional_success = function(test, common) {
value: 1, value: 1,
center_point: { lat: 100.1, lon: -50.5 }, center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' }, name: { default: 'test name1' },
parent: { country: 'country1', region: 'state1', county: 'city1' } parent: { country: ['country1'], region: ['state1'], county: ['city1'] }
}, },
{ {
_id: 'myid2', _type: 'mytype2', _id: 'myid2', _type: 'mytype2',
@ -31,7 +31,7 @@ module.exports.tests.functional_success = function(test, common) {
value: 2, value: 2,
center_point: { lat: 100.2, lon: -51.5 }, center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' }, name: { default: 'test name2' },
parent: { country: 'country2', region: 'state2', county: 'city2' } parent: { country: ['country2'], region: ['state2'], county: ['city2'] }
} }
]; ];

Loading…
Cancel
Save