Skip to content

Commit dee23a4

Browse files
committed
refactor(library): read sim-count comparisons as their own clauses instead of deleting them
1 parent 70596cc commit dee23a4

2 files changed

Lines changed: 47 additions & 28 deletions

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,18 @@ describe('check-library-content', () => {
344344
'1,000+ integrations',
345345
'overstates',
346346
],
347+
[
348+
'Zapier, while Sim has 1,000+ integrations, focuses on simple automations.',
349+
'1,000+ integrations',
350+
'overstates',
351+
],
352+
[
353+
'Zapier is popular, while Sim has 1,000+ integrations, and both support webhooks.',
354+
'1,000+ integrations',
355+
'overstates',
356+
],
357+
['Sim, unlike Make.com, has 1,000+ integrations.', '1,000+ integrations', 'overstates'],
358+
['Sim connects tools like Slack to 1,000+ integrations.', '1,000+ integrations', 'overstates'],
347359
[
348360
'While Sim has 1,000+ integrations, Zapier focuses on simple automations.',
349361
'1,000+ integrations',
@@ -407,6 +419,8 @@ describe('check-library-content', () => {
407419
"Sim has fewer than [Zapier](https://zapier.com)'s 9,000+ integrations.",
408420
'Sim has 280+ integrations, unlike Zapier, which has 9,000+ integrations.',
409421
'Zapier, unlike Sim, has 9,000+ integrations.',
422+
'Sim is open source but Zapier has 9,000+ integrations.',
423+
'While Sim has 280+ integrations, Zapier lists 9,000+ integrations.',
410424
'Zapier, like Sim, has 9,000+ integrations.',
411425
'Sim, unlike Zapier, which has 9,000+ integrations, is open source.',
412426
'n8n | Alternative to Sim | 2,000+ integrations |',

‎scripts/check-library-content.ts‎

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
* "1,000+ integrations" or a figure left from an older catalog spreads to third-party sites.
3636
* A count belongs to Sim when "Sim" comes before it in the same clause and no other product's
3737
* possessive directly precedes it, or when it sits in a table row whose label cell is Sim.
38-
* Sentence ends and contrasts ("while", "unlike", "compared with") start a new clause.
38+
* A comparison ("while", "unlike", "compared with", or "like" after a comma) is its own clause
39+
* up to the next comma, and the sentence's main clause resumes after it.
3940
* A count whose owner is ambiguous within its clause is treated as Sim's; when it belongs to
4041
* another product, name that product as its owner ("Zapier's 9,000+") or give it a sentence.
4142
* Blog and changelog posts are dated, so their counts are true as of publication.
@@ -148,26 +149,20 @@ const LINE_PREFIX = /^\s*(?:(?:[-*+>]|\d+[.)]|#{1,6})\s+)*(?:\w+:\s*["'])?/
148149
const SIM_NAME = /\bSim\b/
149150
/** Words that turn a sentence toward another product: "while Zapier lists ...", "unlike Zapier". */
150151
const CONTRAST = String.raw`(?:while|whereas|but|unlike|compared (?:with|to)|versus|vs\.?)`
152+
const SENTENCE_END = /(?<=[.!?;])\s+/
151153
/**
152-
* A comparison set off by commas, as in "Sim, unlike Zapier, has ..." or "Zapier, like Sim, has
153-
* ...", removed so the sentence keeps its subject. The span stays inside its sentence, ends at the
154-
* first comma that is not a thousands separator, and is kept when a relative clause follows
155-
* ("unlike Zapier, which has").
154+
* Where a comparison clause starts: a contrast word, or "like" when it opens the sentence or
155+
* follows a comma ("Like Sim, ...", "Zapier, like Sim, ..."), but not "tools like Slack".
156156
*/
157-
const PARENTHETICAL_COMPARISON = new RegExp(
158-
String.raw`,\s+(?:like|${CONTRAST})\s+(?:[^,.!?;]|[,.](?=\d))*?,(?!\d)(?!\s*(?:which|that|who)\b)`,
159-
'gi'
157+
const COMPARISON_START = new RegExp(
158+
String.raw`(?:^|,\s*|\s+)(?=${CONTRAST}\b)|(?:^|,\s*)(?=like\b)`,
159+
'i'
160160
)
161-
/** A sentence end, or a contrast that hands the rest of the sentence to another subject. */
162-
const CLAUSE_BREAK = new RegExp(String.raw`(?<=[.!?;])\s+|,?\s+${CONTRAST}\s+`, 'i')
163161
/**
164-
* An opening comparison ("Unlike Sim, ...") whose main clause is about another product. An opener
165-
* that states a count of its own ("While Sim has 280+ integrations, ...") is kept.
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").
166164
*/
167-
const LEADING_COMPARISON = new RegExp(
168-
String.raw`^(?:like|${CONTRAST})\b(?:[^,.!?;]|[,.](?=\d))*?,(?!\d)\s*`,
169-
'i'
170-
)
165+
const COMPARISON_END = /,(?!\d)(?!\s*(?:which|that|who)\b)/
171166
/** The product whose possessive directly precedes a count, as in "Zapier's 9,000+". */
172167
const POSSESSIVE_OWNER = /([\w.-]+)['’]s\s*$/
173168
/** A Sim count below this share of the catalog total is left from an older catalog. */
@@ -181,24 +176,34 @@ function simTableRowCounts(cells: string[]): RegExpMatchArray[] {
181176
: []
182177
}
183178

179+
/**
180+
* A sentence's clauses: its main clause, with each comparison taken out and read as a clause of
181+
* its own, so "Sim, unlike Zapier, has ..." reads as "Sim has ..." plus "unlike Zapier".
182+
*/
183+
function sentenceClauses(sentence: string): string[] {
184+
const main: string[] = []
185+
const comparisons: string[] = []
186+
let rest = sentence
187+
for (let start = COMPARISON_START.exec(rest); start; start = COMPARISON_START.exec(rest)) {
188+
main.push(rest.slice(0, start.index))
189+
const comparison = rest.slice(start.index + start[0].length)
190+
const end = COMPARISON_END.exec(comparison)
191+
comparisons.push(end ? comparison.slice(0, end.index) : comparison)
192+
rest = end ? comparison.slice(end.index + 1) : ''
193+
}
194+
return [[...main, rest].join(' '), ...comparisons]
195+
}
196+
184197
/** Each count whose clause names Sim before it, unless another product's possessive owns it. */
185198
function simProseCounts(text: string): RegExpMatchArray[] {
186-
const sentences = text
187-
.replace(LINE_PREFIX, '')
188-
.replace(PARENTHETICAL_COMPARISON, '')
189-
.split(CLAUSE_BREAK)
190-
return sentences.flatMap((sentence) => {
191-
const opener = LEADING_COMPARISON.exec(sentence)?.[0]
192-
const clause =
193-
opener !== undefined && opener.match(COUNT_CLAIM) === null
194-
? sentence.slice(opener.length)
195-
: sentence
196-
return [...clause.matchAll(COUNT_CLAIM)].filter((match) => {
199+
const clauses = text.replace(LINE_PREFIX, '').split(SENTENCE_END).flatMap(sentenceClauses)
200+
return clauses.flatMap((clause) =>
201+
[...clause.matchAll(COUNT_CLAIM)].filter((match) => {
197202
const before = clause.slice(0, match.index)
198203
const owner = POSSESSIVE_OWNER.exec(before)?.[1]
199204
return SIM_NAME.test(before) && (owner === undefined || owner === 'Sim')
200205
})
201-
})
206+
)
202207
}
203208

204209
/** The counts on one line of text that belong to Sim, with the claim as written. */

0 commit comments

Comments
 (0)