Browse Source

Handle empty country_a values as well

pull/599/head
Julian Simioni 8 years ago
parent
commit
8cae743c80
No known key found for this signature in database
GPG Key ID: 6DAD08919FDBF563
  1. 4
      middleware/confidenceScore.js
  2. 8
      test/unit/middleware/confidenceScore.js

4
middleware/confidenceScore.js

@ -219,8 +219,8 @@ function checkAddress(text, hit) {
res += propMatch(text.number, (hit.address_parts ? hit.address_parts.number : null), false);
res += propMatch(text.street, (hit.address_parts ? hit.address_parts.street : null), false);
res += propMatch(text.postalcode, (hit.address_parts ? hit.address_parts.zip: null), true);
res += propMatch(text.state, hit.parent.region_a[0], true);
res += propMatch(text.country, hit.parent.country_a[0], true);
res += propMatch(text.state, (hit.parent.region_a ? hit.parent.region_a[0] : null), true);
res += propMatch(text.country, (hit.parent.country_a ? hit.parent.country_a[0] :null), true);
res /= checkCount;
}

8
test/unit/middleware/confidenceScore.js

@ -97,9 +97,11 @@ module.exports.tests.confidenceScore = function(test, common) {
test('undefined region fields should be handled gracefully', function(t) {
var req = {
clean: {
text: 'test name1, TX',
text: '123 Main St, City, NM',
parsed_text: {
state: 'TX'
number: 123,
street: 'Main St',
state: 'NM'
}
}
};
@ -121,7 +123,7 @@ module.exports.tests.confidenceScore = function(test, common) {
};
confidenceScore(req, res, function() {});
t.equal(res.data[0].confidence, 0.54, 'score was set');
t.equal(res.data[0].confidence, 0.28, 'score was set');
t.end();
});
};

Loading…
Cancel
Save