Skip to content

Commit 6f89fa6

Browse files
committed
fix(library): split sim-count contrasts nested in comparisons, keep count lists together, and end sentences before closing quotes
1 parent dee23a4 commit 6f89fa6

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

‎scripts/check-library-content.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,11 @@ describe('check-library-content', () => {
356356
],
357357
['Sim, unlike Make.com, has 1,000+ integrations.', '1,000+ integrations', 'overstates'],
358358
['Sim connects tools like Slack to 1,000+ integrations.', '1,000+ integrations', 'overstates'],
359+
[
360+
'While Sim has 280+ integrations, 9,000+ actions, and 530+ triggers, Zapier focuses on simple automations.',
361+
'9,000+ actions',
362+
'overstates',
363+
],
359364
[
360365
'While Sim has 1,000+ integrations, Zapier focuses on simple automations.',
361366
'1,000+ integrations',
@@ -420,6 +425,8 @@ describe('check-library-content', () => {
420425
'Sim has 280+ integrations, unlike Zapier, which has 9,000+ integrations.',
421426
'Zapier, unlike Sim, has 9,000+ integrations.',
422427
'Sim is open source but Zapier has 9,000+ integrations.',
428+
'While Sim has 280+ integrations but Zapier has 9,000+ integrations, both support webhooks.',
429+
'"Sim is open source." Zapier has 9,000+ integrations.',
423430
'While Sim has 280+ integrations, Zapier lists 9,000+ integrations.',
424431
'Zapier, like Sim, has 9,000+ integrations.',
425432
'Sim, unlike Zapier, which has 9,000+ integrations, is open source.',

‎scripts/check-library-content.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ const LINE_PREFIX = /^\s*(?:(?:[-*+>]|\d+[.)]|#{1,6})\s+)*(?:\w+:\s*["'])?/
149149
const SIM_NAME = /\bSim\b/
150150
/** Words that turn a sentence toward another product: "while Zapier lists ...", "unlike Zapier". */
151151
const CONTRAST = String.raw`(?:while|whereas|but|unlike|compared (?:with|to)|versus|vs\.?)`
152-
const SENTENCE_END = /(?<=[.!?;])\s+/
152+
/** Sentence punctuation, with any closing quote or bracket, before whitespace. */
153+
const SENTENCE_END = /(?<=[.!?;]['"”’)\]]*)\s+/
153154
/**
154155
* Where a comparison clause starts: a contrast word, or "like" when it opens the sentence or
155156
* follows a comma ("Like Sim, ...", "Zapier, like Sim, ..."), but not "tools like Slack".
@@ -159,10 +160,13 @@ const COMPARISON_START = new RegExp(
159160
'i'
160161
)
161162
/**
162-
* Where a comparison clause ends: the first comma that is neither a thousands separator nor the
163-
* start of a relative clause continuing it ("unlike Zapier, which has 9,000+ integrations").
163+
* Where a comparison clause ends: the first comma that is not a thousands separator, not the
164+
* start of a relative clause continuing it ("unlike Zapier, which has 9,000+ integrations"), and
165+
* not the next item in a list of counts ("280+ integrations, 9,000+ actions, and 530+ triggers").
164166
*/
165-
const COMPARISON_END = /,(?!\d)(?!\s*(?:which|that|who)\b)/
167+
const COMPARISON_END = /,(?!\d)(?!\s*(?:which|that|who)\b)(?!\s*(?:and\s+)?\d)/
168+
/** A contrast inside a comparison clause, which starts a clause of its own ("..., but Zapier"). */
169+
const INNER_CONTRAST = new RegExp(String.raw`,?\s+(?=${CONTRAST}\b)`, 'i')
166170
/** The product whose possessive directly precedes a count, as in "Zapier's 9,000+". */
167171
const POSSESSIVE_OWNER = /([\w.-]+)['’]s\s*$/
168172
/** A Sim count below this share of the catalog total is left from an older catalog. */
@@ -188,7 +192,7 @@ function sentenceClauses(sentence: string): string[] {
188192
main.push(rest.slice(0, start.index))
189193
const comparison = rest.slice(start.index + start[0].length)
190194
const end = COMPARISON_END.exec(comparison)
191-
comparisons.push(end ? comparison.slice(0, end.index) : comparison)
195+
comparisons.push(...(end ? comparison.slice(0, end.index) : comparison).split(INNER_CONTRAST))
192196
rest = end ? comparison.slice(end.index + 1) : ''
193197
}
194198
return [[...main, rest].join(' '), ...comparisons]

0 commit comments

Comments
 (0)