-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AI Assistant: Add long sentences feature to proofread (#38314)
* add long sentences feature * changelog * fix ts test * rename word to text * fix popover on second-level highlight
- Loading branch information
Showing
13 changed files
with
195 additions
and
54 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/add-proofread-long-sentences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: other | ||
|
||
AI Assistant: Add long sentences feature to proofread |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
.../extensions/plugins/ai-assistant-plugin/components/breve/features/long-sentences/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { escapeRegExp } from '../../utils/escapeRegExp'; | ||
/** | ||
* Types | ||
*/ | ||
import type { BreveFeatureConfig, HighlightedText } from '../../types'; | ||
|
||
export const LONG_SENTENCES: BreveFeatureConfig = { | ||
name: 'long-sentences', | ||
title: 'Long sentences', | ||
tagName: 'span', | ||
className: 'has-proofread-highlight--long-sentences', | ||
}; | ||
|
||
const sentenceRegex = /[^\s][^.!?]+[.!?]+/g; | ||
|
||
export default function longSentences( text: string ): Array< HighlightedText > { | ||
const highlightedTexts: Array< HighlightedText > = []; | ||
|
||
const sentenceMatches = text.match( sentenceRegex ); | ||
|
||
if ( ! sentenceMatches ) { | ||
return highlightedTexts; | ||
} | ||
|
||
const sentences = [ | ||
// Unique sentences with more than 20 words | ||
...new Set( sentenceMatches.filter( sentence => sentence.split( /\s+/ ).length > 20 ) ), | ||
]; | ||
|
||
sentences.forEach( sentence => { | ||
const regex = new RegExp( escapeRegExp( sentence ), 'gi' ); | ||
const matches = text.matchAll( regex ); | ||
|
||
for ( const match of matches ) { | ||
highlightedTexts.push( { | ||
text: sentence, | ||
startIndex: match.index, | ||
endIndex: match.index + sentence.length, | ||
} ); | ||
} | ||
} ); | ||
|
||
return highlightedTexts; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.