Skip to content

Commit c2076b1

Browse files
committed
fix(library): handle colon lists, parenthetical comparisons, relative clauses, prefixes, and linked names in sim-count
1 parent a270435 commit c2076b1

2 files changed

Lines changed: 35 additions & 12 deletions

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ describe('check-library-content', () => {
330330
['Sim listens for events with 300+ triggers.', '300+ triggers', 'stale'],
331331
['Sim has **1,000+** integrations.', '1,000+ integrations', 'overstates'],
332332
['Sim has 1,000+ Integrations.', '1,000+ Integrations', 'overstates'],
333+
['Sim offers: 1,000+ integrations.', '1,000+ integrations', 'overstates'],
334+
['Sim, unlike Zapier, has 1,000+ integrations.', '1,000+ integrations', 'overstates'],
335+
['Sim, which ships 1,000+ integrations, runs agents.', '1,000+ integrations', 'overstates'],
333336
[
334337
'[Sim](https://www.sim.ai) combines [Chat](https://docs.sim.ai/execution/chat) with 1,000+ integrations.',
335338
'1,000+ integrations',
@@ -383,13 +386,17 @@ describe('check-library-content', () => {
383386
'Sim is open source. Workato cites 14,000+ integrations.',
384387
'Unlike Sim, Zapier lists 9,000+ integrations.',
385388
'Like Sim, n8n ships 2,000+ integrations.',
389+
'- Unlike Sim, Zapier lists 9,000+ integrations.',
390+
"Sim has fewer than [Zapier](https://zapier.com)'s 9,000+ integrations.",
391+
'Sim is an alternative to Zapier, which has 9,000+ integrations.',
386392
'Sim has 280+ integrations, while Zapier lists 9,000+ integrations.',
387393
"Sim has 280+ integrations, fewer than Zapier's 9,000+ integrations.",
388394
'| n8n | Self-hosted, unlike Sim | 2,000+ integrations |',
389395
'Teams that need 20 integrations and five builders often pick Sim.',
390396
'```text\nSim has 1,000+ integrations\n```',
391397
'````md\n```text\nSim has 1,000+ integrations\n````',
392-
].join('\n\n')
398+
].join('\n\n'),
399+
{ faq: '\n - q: "Is Sim like n8n?"\n a: "Like Sim, n8n ships 2,000+ integrations."' }
393400
)
394401
expect(await findingsFor('library', 'post')).toEqual([])
395402
})

‎scripts/check-library-content.ts‎

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,29 +139,45 @@ const ROUTE_FILES = ['page.tsx', 'page.ts', 'route.tsx', 'route.ts']
139139
const COUNT_CLAIM = /\b(\d{1,3}(?:,\d{3})+|\d+)\+?\s+(integrations|actions|triggers)\b/gi
140140
/** Inline emphasis and code markers, which would otherwise split "**1,000+** integrations". */
141141
const INLINE_MARKERS = /\*\*|__|[*`]/g
142+
/** A Markdown link, read as its visible text so "[Zapier](https://zapier.com)'s" names Zapier. */
143+
const LINK_TEXT = /\[([^\]\n]*)\]\([^)\n]*\)/g
144+
/** List, heading, and quote markers, or a quoted YAML key such as `a: "`, ahead of the sentence. */
145+
const LINE_PREFIX = /^\s*(?:(?:[-*+>]|\d+[.)]|#{1,6})\s+)*(?:\w+:\s*["'])?/
142146
const SIM_NAME = /\bSim\b/
143-
/** A table row's label cell naming Sim, plain or linked: "Sim" or "[Sim](https://www.sim.ai)". */
144-
const SIM_LABEL = /^\[?Sim\b/
145-
/** Words that turn a sentence toward another product: "while Zapier lists...", "Unlike Sim, ...". */
147+
/** Words that turn a sentence toward another product: "while Zapier lists ...", "unlike Zapier". */
146148
const CONTRAST = String.raw`(?:while|whereas|but|unlike|compared (?:with|to)|versus|vs\.?)`
147-
/** A sentence end, or a contrast that hands the rest of the sentence to another subject. */
148-
const CLAUSE_BREAK = new RegExp(String.raw`(?<=[.!?;:])\s+|,?\s+${CONTRAST}\s+`, 'i')
149-
/** An opening comparison ("Unlike Sim, ...", "Like Sim, ...") whose main clause is about another product. */
150-
const LEADING_CONTRAST = new RegExp(String.raw`^(?:like|${CONTRAST})\b[^,]*,\s*`, 'i')
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')
151+
/**
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 ...").
154+
*/
155+
const CLAUSE_BREAK = new RegExp(
156+
String.raw`(?<=[.!?;])\s+|,?\s+${CONTRAST}\s+|(?<!\bSim),\s+(?:which|who)\s+`,
157+
'i'
158+
)
159+
/** An opening comparison ("Unlike Sim, ...") whose main clause is about another product. */
160+
const LEADING_COMPARISON = new RegExp(String.raw`^(?:like|${CONTRAST})\b[^,]*,\s*`, 'i')
151161
/** The product whose possessive directly precedes a count, as in "Zapier's 9,000+". */
152162
const POSSESSIVE_OWNER = /([\w.-]+)['’]s\s*$/
153163
/** A Sim count below this share of the catalog total is left from an older catalog. */
154164
const SIM_COUNT_FLOOR = 0.9
155165

156166
/** Every count in a table row whose first cell names Sim. */
157167
function simTableRowCounts(row: string): RegExpMatchArray[] {
158-
return SIM_LABEL.test(row.split('|')[1]?.trim() ?? '') ? [...row.matchAll(COUNT_CLAIM)] : []
168+
return SIM_NAME.test(row.split('|')[1]?.trim().split(/\s/)[0] ?? '')
169+
? [...row.matchAll(COUNT_CLAIM)]
170+
: []
159171
}
160172

161173
/** Each count whose clause names Sim before it, unless another product's possessive owns it. */
162174
function simProseCounts(text: string): RegExpMatchArray[] {
163-
return text.split(CLAUSE_BREAK).flatMap((sentence) => {
164-
const clause = sentence.replace(LEADING_CONTRAST, '')
175+
const sentences = text
176+
.replace(LINE_PREFIX, '')
177+
.replace(PARENTHETICAL_COMPARISON, '')
178+
.split(CLAUSE_BREAK)
179+
return sentences.flatMap((sentence) => {
180+
const clause = sentence.replace(LEADING_COMPARISON, '')
165181
return [...clause.matchAll(COUNT_CLAIM)].filter((match) => {
166182
const before = clause.slice(0, match.index)
167183
const owner = POSSESSIVE_OWNER.exec(before)?.[1]
@@ -172,7 +188,7 @@ function simProseCounts(text: string): RegExpMatchArray[] {
172188

173189
/** The counts on one line of text that belong to Sim, with the claim as written. */
174190
function simCountClaims(line: string): { claim: string; count: number; unit: SimCountUnit }[] {
175-
const text = line.replace(INLINE_MARKERS, '')
191+
const text = line.replace(INLINE_MARKERS, '').replace(LINK_TEXT, '$1')
176192
const matches = text.trimStart().startsWith('|') ? simTableRowCounts(text) : simProseCounts(text)
177193
return matches.map((match) => ({
178194
claim: match[0],

0 commit comments

Comments
 (0)