Skip to content

Commit ac63c10

Browse files
committed
fix(library): keep sim relative clauses attached, anchor parenthetical comparisons to sim, and detect pipe-less table rows
1 parent c2076b1 commit ac63c10

2 files changed

Lines changed: 27 additions & 15 deletions

File tree

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,13 @@ describe('check-library-content', () => {
333333
['Sim offers: 1,000+ integrations.', '1,000+ integrations', 'overstates'],
334334
['Sim, unlike Zapier, has 1,000+ integrations.', '1,000+ integrations', 'overstates'],
335335
['Sim, which ships 1,000+ integrations, runs agents.', '1,000+ integrations', 'overstates'],
336+
[
337+
'Sim is an AI workspace, which connects to 1,000+ integrations.',
338+
'1,000+ integrations',
339+
'overstates',
340+
],
341+
['Sim, unlike n8n, has 1,000+ integrations.', '1,000+ integrations', 'overstates'],
342+
['Sim | Governed agents | 1,000+ integrations |', '1,000+ integrations', 'overstates'],
336343
[
337344
'[Sim](https://www.sim.ai) combines [Chat](https://docs.sim.ai/execution/chat) with 1,000+ integrations.',
338345
'1,000+ integrations',
@@ -388,7 +395,8 @@ describe('check-library-content', () => {
388395
'Like Sim, n8n ships 2,000+ integrations.',
389396
'- Unlike Sim, Zapier lists 9,000+ integrations.',
390397
"Sim has fewer than [Zapier](https://zapier.com)'s 9,000+ integrations.",
391-
'Sim is an alternative to Zapier, which has 9,000+ integrations.',
398+
'Sim has 280+ integrations, unlike Zapier, which has 9,000+ integrations.',
399+
'n8n | Alternative to Sim | 2,000+ integrations |',
392400
'Sim has 280+ integrations, while Zapier lists 9,000+ integrations.',
393401
"Sim has 280+ integrations, fewer than Zapier's 9,000+ integrations.",
394402
'| n8n | Self-hosted, unlike Sim | 2,000+ integrations |',

‎scripts/check-library-content.ts‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
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.
3838
* Sentence ends and contrasts ("while", "unlike", "compared with") start a new clause.
39+
* A count whose owner is ambiguous within its clause is treated as Sim's; when it belongs to
40+
* another product, name that product as its owner ("Zapier's 9,000+") or give it a sentence.
3941
* Blog and changelog posts are dated, so their counts are true as of publication.
4042
*
4143
* Run one post with `--slug <section>/<slug>` or `--slug <slug>`.
@@ -146,35 +148,36 @@ const LINE_PREFIX = /^\s*(?:(?:[-*+>]|\d+[.)]|#{1,6})\s+)*(?:\w+:\s*["'])?/
146148
const SIM_NAME = /\bSim\b/
147149
/** Words that turn a sentence toward another product: "while Zapier lists ...", "unlike Zapier". */
148150
const CONTRAST = String.raw`(?:while|whereas|but|unlike|compared (?:with|to)|versus|vs\.?)`
149-
/** A comparison set off by commas inside a sentence, as in "Sim, unlike Zapier, has ...". */
150-
const PARENTHETICAL_COMPARISON = new RegExp(String.raw`,\s+(?:like|${CONTRAST})\s+[^,\d]*,`, 'gi')
151151
/**
152-
* A sentence end, a contrast that hands the rest of the sentence to another subject, or a
153-
* relative clause about a product other than Sim ("Zapier, which has ...").
152+
* A comparison set off by commas right after Sim, as in "Sim, unlike Zapier, has ...". The span
153+
* ends at the first comma that is not a thousands separator, so "Sim, unlike n8n, ..." matches.
154154
*/
155-
const CLAUSE_BREAK = new RegExp(
156-
String.raw`(?<=[.!?;])\s+|,?\s+${CONTRAST}\s+|(?<!\bSim),\s+(?:which|who)\s+`,
157-
'i'
155+
const SIM_PARENTHETICAL = new RegExp(
156+
String.raw`\bSim,\s+(?:like|${CONTRAST})\s+(?:[^,]|,(?=\d))*?,(?!\d)`,
157+
'gi'
158158
)
159+
/** A sentence end, or a contrast that hands the rest of the sentence to another subject. */
160+
const CLAUSE_BREAK = new RegExp(String.raw`(?<=[.!?;])\s+|,?\s+${CONTRAST}\s+`, 'i')
159161
/** An opening comparison ("Unlike Sim, ...") whose main clause is about another product. */
160162
const LEADING_COMPARISON = new RegExp(String.raw`^(?:like|${CONTRAST})\b[^,]*,\s*`, 'i')
161163
/** The product whose possessive directly precedes a count, as in "Zapier's 9,000+". */
162164
const POSSESSIVE_OWNER = /([\w.-]+)['’]s\s*$/
163165
/** A Sim count below this share of the catalog total is left from an older catalog. */
164166
const SIM_COUNT_FLOOR = 0.9
165167

166-
/** Every count in a table row whose first cell names Sim. */
167-
function simTableRowCounts(row: string): RegExpMatchArray[] {
168-
return SIM_NAME.test(row.split('|')[1]?.trim().split(/\s/)[0] ?? '')
169-
? [...row.matchAll(COUNT_CLAIM)]
168+
/** Every count in a table row whose label (first non-empty cell) names Sim. */
169+
function simTableRowCounts(cells: string[]): RegExpMatchArray[] {
170+
const label = cells.map((cell) => cell.trim()).find((cell) => cell !== '') ?? ''
171+
return SIM_NAME.test(label.split(/\s/)[0])
172+
? cells.flatMap((cell) => [...cell.matchAll(COUNT_CLAIM)])
170173
: []
171174
}
172175

173176
/** Each count whose clause names Sim before it, unless another product's possessive owns it. */
174177
function simProseCounts(text: string): RegExpMatchArray[] {
175178
const sentences = text
176179
.replace(LINE_PREFIX, '')
177-
.replace(PARENTHETICAL_COMPARISON, '')
180+
.replace(SIM_PARENTHETICAL, 'Sim')
178181
.split(CLAUSE_BREAK)
179182
return sentences.flatMap((sentence) => {
180183
const clause = sentence.replace(LEADING_COMPARISON, '')
@@ -189,7 +192,8 @@ function simProseCounts(text: string): RegExpMatchArray[] {
189192
/** The counts on one line of text that belong to Sim, with the claim as written. */
190193
function simCountClaims(line: string): { claim: string; count: number; unit: SimCountUnit }[] {
191194
const text = line.replace(INLINE_MARKERS, '').replace(LINK_TEXT, '$1')
192-
const matches = text.trimStart().startsWith('|') ? simTableRowCounts(text) : simProseCounts(text)
195+
const cells = text.split('|')
196+
const matches = cells.length > 2 ? simTableRowCounts(cells) : simProseCounts(text)
193197
return matches.map((match) => ({
194198
claim: match[0],
195199
count: Number.parseInt(match[1].replaceAll(',', ''), 10),
@@ -486,7 +490,7 @@ export async function checkPost(
486490
count > total
487491
? `"${claim}" overstates Sim's catalog, which has ${total} ${unit}.`
488492
: `"${claim}" is stale: Sim's catalog has ${total} ${unit}.`,
489-
`Write ${formatLowerBound(total)} ${unit}, the catalog-derived figure (INTEGRATION_TOTALS in packages/deployment-config/src/integration-totals.ts).`
493+
`Write ${formatLowerBound(total)} ${unit}, the catalog-derived figure (INTEGRATION_TOTALS in packages/deployment-config/src/integration-totals.ts). If the count is another product's, name it as the owner ("Zapier's 9,000+") or give it its own sentence.`
490494
)
491495
}
492496
}

0 commit comments

Comments
 (0)