Skip to content

Commit

Permalink
fix: do not break subsequent exclamation points or question marks in …
Browse files Browse the repository at this point in the history
…`nlp/sentencize`

PR-URL: #5380
Closes: #3013
Closes: stdlib-js/metr-issue-tracker#1
Reviewed-by: Athan Reines <[email protected]>
  • Loading branch information
Planeshifter authored Feb 22, 2025
1 parent ecfa20e commit 0830450
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/node_modules/@stdlib/nlp/sentencize/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ function isEndOfSentence( tokens, i ) {
if (
( token === '!' || token === '?' ) &&
!RE_PREFIXES.test( tokens[ im1 ] ) &&
!RE_SUFFIXES.test( tokens[ ip1 ] )
!RE_SUFFIXES.test( tokens[ ip1 ] ) &&
( tokens[ ip1 ] !== '!' && tokens[ ip1 ] !== '?' )
) {
return true;
}
Expand Down
22 changes: 22 additions & 0 deletions lib/node_modules/@stdlib/nlp/sentencize/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,28 @@ tape( 'the function splits a string into an array of sentences (unfinished last
t.end();
});

tape( 'the function splits a string into an array of sentences (multiple punctuation marks)', function test( t ) {
var expected;
var actual;
var str;

str = 'HAPPY BIRTHDAY!!! Have an awesome day!';
expected = [ 'HAPPY BIRTHDAY!!!', 'Have an awesome day!' ];
actual = sentencize( str );
t.deepEqual( actual, expected, 'returns an array of sentences' );

str = 'What?? How can that be??';
expected = [ 'What??', 'How can that be??' ];
actual = sentencize( str );
t.deepEqual( actual, expected, 'returns an array of sentences' );

str = 'How dare you!?!';
expected = [ 'How dare you!?!' ];
actual = sentencize( str );
t.deepEqual( actual, expected, 'returns an array of sentences' );
t.end();
});

tape( 'the function returns an empty array if provided an empty string', function test( t ) {
var out = sentencize( '' );
t.equal( isArray( out ), true, 'returns an array' );
Expand Down

1 comment on commit 0830450

@stdlib-bot
Copy link
Contributor

Choose a reason for hiding this comment

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

Coverage Report

Package Statements Branches Functions Lines
nlp/sentencize $\color{green}178/178$
$\color{green}+100.00\%$
$\color{green}30/30$
$\color{green}+100.00\%$
$\color{green}2/2$
$\color{green}+100.00\%$
$\color{green}178/178$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this push.

Please sign in to comment.