Skip to content

Commit

Permalink
requote: check end of spans too
Browse files Browse the repository at this point in the history
  • Loading branch information
Mehrad0711 committed Oct 13, 2021
1 parent e5f39ed commit 64909ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions test/unit/test_requote.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ const CONTEXTUAL_TEST_CASES_NEW = [
'what is the price of QUOTED_STRING_2 train ?',
'... departure =~ QUOTED_STRING_0 && destination =~ QUOTED_STRING_1 && id =~ QUOTED_STRING_2 ) => notify ;'
],

[
'$dialogue ... station ( ) filter show =~ QUOTED_STRING_1 && show =~ QUOTED_STRING_2 => @com.tunein ...',
'i can see radio javan playing see radio',
'... station ( ) filter id =~ " radio javan " && show =~ " see radio " ) ;',
'i can see QUOTED_STRING_3 playing QUOTED_STRING_4',
'... station ( ) filter id =~ QUOTED_STRING_3 && show =~ QUOTED_STRING_4 ) ;'
],
];

const CONTEXTUAL_TEST_CASES_LEGACY = [
Expand Down
6 changes: 3 additions & 3 deletions tool/requote.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ function doReplaceNumbers(token) {
return NUMBER_MATCH_REGEX.test(token) && token !== '0' && token !== '1';
}

function findSpanContaining(index, spansBySentencePos) {
function findSpanContaining(index, spansBySentencePos, end = null) {
for (let i = 0; i < spansBySentencePos.length; i++) {
const span = spansBySentencePos[i];
if (index >= span.begin && index < span.end)
if ((index >= span.begin && index < span.end) || (end && end > span.begin && end <= span.end))
return span;
}
return false;
Expand Down Expand Up @@ -80,7 +80,7 @@ function findSubstring(sequence, substring, spansBySentencePos, allowOverlapping
parsedWithArticle = true;
}
}
if (found && (allowOverlapping || !findSpanContaining(i, spansBySentencePos))) {
if (found && (allowOverlapping || !findSpanContaining(i, spansBySentencePos, i + substring.length))) {
if (allowOverlapping)
allFoundIndices.push([i, parsedWithArticle]);
else
Expand Down

0 comments on commit 64909ee

Please sign in to comment.