Browse Source

made `locality` and `localadmin` equivalent in fallback scoring

pull/705/head
Stephen Hess 8 years ago
parent
commit
916e7d6736
  1. 4
      middleware/confidenceScoreFallback.js
  2. 57
      test/unit/middleware/confidenceScoreFallback.js

4
middleware/confidenceScoreFallback.js

@ -72,13 +72,13 @@ function checkFallbackLevel(req, hit) {
return 0.8;
case 'street':
return 0.8;
case 'localadmin':
case 'locality':
case 'borough':
case 'neighbourhood':
return 0.6;
case 'macrocounty':
case 'county':
case 'localadmin':
return 0.4;
case 'region':
return 0.3;
@ -99,7 +99,7 @@ function checkFallbackLevel(req, hit) {
function checkFallbackOccurred(req, hit) {
return (requestedAddress(req) && hit.layer !== 'address') ||
(requestedStreet(req) && hit.layer !== 'street') ||
(requestedCity(req) && hit.layer !== 'locality');
(requestedCity(req) && hit.layer !== 'locality' && hit.layer !== 'localadmin');
}
function requestedAddress(req) {

57
test/unit/middleware/confidenceScoreFallback.js

@ -203,6 +203,40 @@ module.exports.tests.confidenceScore = function(test, common) {
t.end();
});
test('fallback to localadmin should have score deduction', function(t) {
var req = {
clean: {
text: '123 Main St, City, NM',
parsed_text: {
number: 123,
street: 'Main St',
state: 'NM'
}
}
};
var res = {
data: [{
_score: 10,
found: true,
value: 1,
layer: 'localadmin',
center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' },
parent: {
country: ['country1']
}
}],
meta: {
scores: [10],
query_type: 'fallback'
}
};
confidenceScore(req, res, function() {});
t.equal(res.data[0].confidence, 0.6, 'score was set');
t.end();
});
test('fallback to country should have score deduction', function(t) {
var req = {
clean: {
@ -261,6 +295,29 @@ module.exports.tests.confidenceScore = function(test, common) {
t.end();
});
test('city input granularity with localadmin result should set score to 1.0', function(t) {
var req = {
clean: {
parsed_text: {
city: 'city name',
state: 'state name'
}
}
};
var res = {
data: [{
layer: 'localadmin'
}],
meta: {
query_type: 'fallback'
}
};
confidenceScore(req, res, function() {});
t.equal(res.data[0].confidence, 1.0, 'score was set');
t.end();
});
test('city input granularity with region fallback should set score to 0.3', function(t) {
var req = {
clean: {

Loading…
Cancel
Save