Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for missing parent object in confidence score computation #1006

Merged
merged 1 commit into from
Sep 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions middleware/confidenceScore.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ function checkForDealBreakers(req, hit) {
return false;
}

if (check.assigned(req.clean.parsed_text.state) && hit.parent.region_a && req.clean.parsed_text.state !== hit.parent.region_a[0]) {
if (check.assigned(req.clean.parsed_text.state) && check.assigned(hit.parent) &&
hit.parent.region_a && req.clean.parsed_text.state !== hit.parent.region_a[0]) {
logger.debug('[confidence][deal-breaker]: state !== region_a');
return true;
}
Expand Down Expand Up @@ -220,8 +221,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 ? hit.parent.region_a[0] : null), true);
res += propMatch(text.country, (hit.parent.country_a ? hit.parent.country_a[0] :null), true);
res += propMatch(text.state, ((hit.parent && hit.parent.region_a) ? hit.parent.region_a[0] : null), true);
res += propMatch(text.country, ((hit.parent && hit.parent.country_a) ? hit.parent.country_a[0] :null), true);
Copy link
Member

@orangejulius orangejulius Sep 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subtle hint to @trescube that refactoring all this code to use lodash _.get would be amazing :P

Copy link
Contributor Author

@dianashk dianashk Sep 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, not only a hint to @trescube but rather to the whole team

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I singled out @trescube because i know he has no greater joy in life than refactoring code to use lodash :P


res /= checkCount;
}
Expand Down
32 changes: 32 additions & 0 deletions test/unit/middleware/confidenceScore.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,38 @@ module.exports.tests.confidenceScore = function(test, common) {
t.false(res.data[0].hasOwnProperty('confidence'), 'score was not set');
t.end();
});

test('missing parent object should not throw an exception', 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,
center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' },
}],
meta: {
scores: [10],
query_type: 'original'
}
};

t.doesNotThrow(() => {
confidenceScore(req, res, () => {});
});
t.equal(res.data[0].confidence, 0.28, 'score was set');
t.end();
});
};

module.exports.all = function (tape, common) {
Expand Down