Skip to content
Closed
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
45 changes: 43 additions & 2 deletions sanitizer/_text_pelias_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,31 @@ function _sanitize (raw, clean) {
return messages;
}

function parse (clean) {

function isAmbiguousStreetOrPlaceParse(solutions){
if (!solutions) {
return false;
}

const topTwoSolutions = _.take(solutions, 2);
const streetOnlySolution = topTwoSolutions.find(solution => {
return solution.pair &&
solution.pair.length === 1 &&
solution.pair[0].classification.label === 'street';
});
const placeOnlySolution = topTwoSolutions.find(solution => {
return solution.pair &&
solution.pair.length === 1 &&
solution.pair[0].classification.label === 'place';
});

return (
streetOnlySolution &&
placeOnlySolution &&
streetOnlySolution.pair[0].span.body === placeOnlySolution.pair[0].span.body
);
}

function parse (clean) {
// parse text
let start = new Date();
const t = new Tokenizer(clean.text);
Expand Down Expand Up @@ -108,6 +131,24 @@ function parse (clean) {
}
}

// (Theory) If the parser's two top solutions were labeling the entire query as a venue/place,
// and labeling the entire query as a street, then the parse is telling us it's pretty
// ambiguous, so we shouldn't bother boosting street or place matches in our search.
//
// This helps with queries like "wrigley field" that have a word (field) that could be
// a street suffix but is also a likely venue word.
//
// (Reality) There's no way to tell if the parser labeled the "whole query" because
// punctuation in the incoming query is unlabeled, so in reality this checks if
// the top two solutions were venue-only and place-only and labeled identical parts of the query
if (isAmbiguousStreetOrPlaceParse(t.solution) &&
(parsed_text.street || parsed_text.place)) {
delete parsed_text.street;
delete parsed_text.place;
mask = mask.replace(/S/g, ' ');
mask = mask.replace(/V/g, ' ');
}

// the entire input text as seen by the parser with any postcode classification(s) removed
let body = t.span.body.split('')
.map((c, i) => (mask[i] !== 'P') ? c : ' ')
Expand Down
5 changes: 5 additions & 0 deletions test/unit/sanitizer/_text_pelias_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ module.exports.tests.text_parser = function (test, common) {
cases.push(['Air & Space Museum D', { subject: 'Air & Space Museum' }, true]);
cases.push(['Air & Space Museum DC', { subject: 'Air & Space Museum' }, true]);

// ambiguous venue
cases.push(['mccarren park', {
subject: 'mccarren park',
}]);

// admin areas
cases.push(['N', { subject: 'N' }, true]);
cases.push(['Ne', { subject: 'Ne' }, true]);
Expand Down