Skip to content

Commit

Permalink
Replace tooManySnippetPartsMatched (has false positives)
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardspec committed Jan 9, 2025
1 parent a907959 commit 222c9c6
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions modules/ext.askai.findpar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
* If part of the snippet is found in more paragraphs than this, discard these matches,
* assuming it to be an overly common word/expression.
*/
const tooManyParagraphsLimit = 5;
const partInTooManyParagraphsLimit = 5;

/**
* If snippet had to be cut into more parts than this to find matches, discard all matches,
* assuming that the snippet was generated from a list or table, not a continuous paragraph.
* If findText() found more paragraphs than this, discard all matches as uncertain,
* assuming that the snippet was generated from a list or table,
* not a continuous paragraph.
*/
const tooManySnippetPartsMatched = 4;
const entireSnippetInTooManyParagraphsLimit = 12;

mw.askai = mw.askai || {};

Expand Down Expand Up @@ -119,7 +120,7 @@
words = result.leftoverWords;
result.parNumbers = getParNumbers( result.paragraphs );

if ( result.parNumbers.length <= tooManyParagraphsLimit ) {
if ( result.parNumbers.length <= partInTooManyParagraphsLimit ) {
// New usable result.
results.push( result );
} else {
Expand Down Expand Up @@ -159,9 +160,9 @@
'], leftoverWords=' + result.leftoverWords );
}

if ( results.length > tooManySnippetPartsMatched ) {
console.log( 'findpar.js: discarding all matches (they are likely incorrect, ' +
'because snippet was split into too many parts)' );
if ( results.length > entireSnippetInTooManyParagraphsLimit ) {
console.log( 'findpar.js: found too many paragraphs (' + results.length +
'), discarding all matches (they are likely incorrect).' );
return [];
}

Expand Down

0 comments on commit 222c9c6

Please sign in to comment.