|
33 | 33 | * against the generated catalog (`INTEGRATION_TOTALS`): no higher than the total, and no |
34 | 34 | * lower than 90% of it. Answer engines quote these figures, so an overclaim such as |
35 | 35 | * "1,000+ integrations" or a figure left from an older catalog spreads to third-party sites. |
36 | | - * A count belongs to Sim when the nearest "Sim" before it on the line is at most 12 words back |
37 | | - * with no capitalized word between, which leaves competitor counts alone. |
| 36 | + * A count belongs to Sim when "Sim" comes before it in the same clause and no other product's |
| 37 | + * possessive directly precedes it, or when it sits in a table row whose label cell is Sim |
| 38 | + * (other rows are read cell by cell). A comparison that opens a sentence or names a new subject |
| 39 | + * ("while Zapier", "Zapier, like Sim,") is its own clause up to the next comma, and the main |
| 40 | + * clause resumes after it; ", and" before a new subject also starts a clause. |
| 41 | + * A count whose owner is ambiguous within its clause is treated as Sim's; when it belongs to |
| 42 | + * another product, name that product as its owner ("Zapier's 9,000+") or give it a sentence. |
38 | 43 | * Blog and changelog posts are dated, so their counts are true as of publication. |
39 | 44 | * |
40 | 45 | * Run one post with `--slug <section>/<slug>` or `--slug <slug>`. |
@@ -138,35 +143,101 @@ const ROUTE_FILES = ['page.tsx', 'page.ts', 'route.tsx', 'route.ts'] |
138 | 143 | const COUNT_CLAIM = /\b(\d{1,3}(?:,\d{3})+|\d+)\+?\s+(integrations|actions|triggers)\b/gi |
139 | 144 | /** Inline emphasis and code markers, which would otherwise split "**1,000+** integrations". */ |
140 | 145 | const INLINE_MARKERS = /\*\*|__|[*`]/g |
141 | | -const SIM_NAME = /\bSim\b/g |
142 | | -const SIM_CLAIM_MAX_WORDS = 12 |
| 146 | +/** A Markdown link, read as its visible text so "[Zapier](https://zapier.com)'s" names Zapier. */ |
| 147 | +const LINK_TEXT = /\[([^\]\n]*)\]\([^)\n]*\)/g |
| 148 | +/** List, heading, and quote markers, or a quoted YAML key such as `a: "`, ahead of the sentence. */ |
| 149 | +const LINE_PREFIX = /^\s*(?:(?:[-*+>]|\d+[.)]|#{1,6})\s+)*(?:\w+:\s*["'])?/ |
| 150 | +const SIM_NAME = /\bSim\b/ |
| 151 | +/** Words that turn a sentence toward another product: "while Zapier lists ...", "unlike Zapier". */ |
| 152 | +const CONTRAST = String.raw`(?:while|whereas|but|unlike|compared (?:with|to)|versus|vs\.?)` |
| 153 | +/** The same words opening a sentence, plus "Like" ("Like Sim, n8n ..."). */ |
| 154 | +const OPENING_CONTRAST = String.raw`(?:While|Whereas|But|Unlike|Like|Compared (?:with|to)|Versus|Vs\.?)` |
| 155 | +/** Sentence punctuation, with any closing quote or bracket, before whitespace. */ |
| 156 | +const SENTENCE_END = /(?<=[.!?;]['"”’)\]]*)\s+/ |
| 157 | +/** The start of a new subject: a capitalized word, or a lowercase product name with a digit (n8n). */ |
| 158 | +const SUBJECT = String.raw`(?:[A-Z]|[a-z]+\d)` |
| 159 | +/** ", and" before a new subject, which starts a clause of its own ("..., and Zapier has ..."). */ |
| 160 | +const NEW_SUBJECT = new RegExp(String.raw`,\s+and\s+(?=${SUBJECT})`) |
| 161 | +/** |
| 162 | + * Where a comparison clause starts: a sentence-opening contrast ("Unlike Sim, ..."), or a contrast |
| 163 | + * followed by a new subject ("..., while Zapier", "Zapier, like Sim, ..."). A contrast that keeps |
| 164 | + * the subject ("open source but has ...", "while working") does not start one. |
| 165 | + */ |
| 166 | +const COMPARISON_START = new RegExp( |
| 167 | + String.raw`^(?=${OPENING_CONTRAST}\b)|,\s*(?=(?:like|${CONTRAST})\s+${SUBJECT})|\s+(?=${CONTRAST}\s+${SUBJECT})` |
| 168 | +) |
| 169 | +/** A count continuing a list ("..., 9,000+ actions, and 530+ triggers, ..."), not a new clause. */ |
| 170 | +const COUNT_LIST_ITEM = String.raw`(?:and\s+)?\d[\d,]*\+?\s+(?:integrations|actions|triggers)\b\s*(?:,|and\b|$)` |
| 171 | +/** |
| 172 | + * Where a comparison clause ends: the first comma that is not a thousands separator, not the |
| 173 | + * start of a relative clause continuing it ("unlike Zapier, which has 9,000+ integrations"), and |
| 174 | + * not the next item in a list of counts. |
| 175 | + */ |
| 176 | +const COMPARISON_END = new RegExp( |
| 177 | + String.raw`,(?!\d)(?!\s*(?:which|that|who)\b)(?!\s*${COUNT_LIST_ITEM})` |
| 178 | +) |
| 179 | +/** A contrast with a new subject inside a comparison clause ("..., but Zapier has ..."). */ |
| 180 | +const INNER_CONTRAST = new RegExp(String.raw`,?\s+(?=${CONTRAST}\s+${SUBJECT})`) |
| 181 | +/** The product whose possessive directly precedes a count, as in "Zapier's 9,000+". */ |
| 182 | +const POSSESSIVE_OWNER = /([\w.-]+)['’]s\s*$/ |
143 | 183 | /** A Sim count below this share of the catalog total is left from an older catalog. */ |
144 | 184 | const SIM_COUNT_FLOOR = 0.9 |
145 | 185 |
|
146 | 186 | /** |
147 | | - * The counts on one line of text that belong to Sim, with the claim as written. A sentence or |
148 | | - * clause that moves on to another product starts with a capitalized word, which ends Sim's claim. |
| 187 | + * The Sim counts in a table row: every count when its label (first non-empty cell) names Sim, and |
| 188 | + * otherwise each cell's own Sim claims, read like prose ("| Catalog | Sim has 280+ integrations |"). |
149 | 189 | */ |
150 | | -function simCountClaims(line: string): { claim: string; count: number; unit: SimCountUnit }[] { |
151 | | - const claims: { claim: string; count: number; unit: SimCountUnit }[] = [] |
152 | | - const text = line.replace(INLINE_MARKERS, '') |
153 | | - for (const match of text.matchAll(COUNT_CLAIM)) { |
154 | | - const before = text.slice(0, match.index) |
155 | | - const lastSim = [...before.matchAll(SIM_NAME)].at(-1) |
156 | | - if (lastSim?.index === undefined) continue |
157 | | - const words = before |
158 | | - .slice(lastSim.index + lastSim[0].length) |
159 | | - .split(/\s+/) |
160 | | - .map((word) => word.replace(/^[^A-Za-z0-9]+/, '')) |
161 | | - .filter(Boolean) |
162 | | - if (words.length > SIM_CLAIM_MAX_WORDS || words.some((word) => /^[A-Z]/.test(word))) continue |
163 | | - claims.push({ |
164 | | - claim: match[0], |
165 | | - count: Number.parseInt(match[1].replaceAll(',', ''), 10), |
166 | | - unit: match[2].toLowerCase() as SimCountUnit, |
167 | | - }) |
| 190 | +function simTableRowCounts(cells: string[]): RegExpMatchArray[] { |
| 191 | + const label = cells.map((cell) => cell.trim()).find((cell) => cell !== '') ?? '' |
| 192 | + return SIM_NAME.test(label.split(/\s/)[0]) |
| 193 | + ? cells.flatMap((cell) => [...cell.matchAll(COUNT_CLAIM)]) |
| 194 | + : cells.flatMap(simProseCounts) |
| 195 | +} |
| 196 | + |
| 197 | +/** |
| 198 | + * A sentence's clauses: its main clause, with each comparison taken out and read as a clause of |
| 199 | + * its own, so "Sim, unlike Zapier, has ..." reads as "Sim has ..." plus "unlike Zapier". |
| 200 | + */ |
| 201 | +function sentenceClauses(sentence: string): string[] { |
| 202 | + const main: string[] = [] |
| 203 | + const comparisons: string[] = [] |
| 204 | + let rest = sentence |
| 205 | + for (let start = COMPARISON_START.exec(rest); start; start = COMPARISON_START.exec(rest)) { |
| 206 | + main.push(rest.slice(0, start.index)) |
| 207 | + const comparison = rest.slice(start.index + start[0].length) |
| 208 | + const end = COMPARISON_END.exec(comparison) |
| 209 | + comparisons.push(...(end ? comparison.slice(0, end.index) : comparison).split(INNER_CONTRAST)) |
| 210 | + rest = end ? comparison.slice(end.index + 1) : '' |
168 | 211 | } |
169 | | - return claims |
| 212 | + return [[...main, rest].join(' '), ...comparisons] |
| 213 | +} |
| 214 | + |
| 215 | +/** Each count whose clause names Sim before it, unless another product's possessive owns it. */ |
| 216 | +function simProseCounts(text: string): RegExpMatchArray[] { |
| 217 | + const clauses = text |
| 218 | + .replace(LINE_PREFIX, '') |
| 219 | + .split(SENTENCE_END) |
| 220 | + .flatMap((sentence) => sentence.split(NEW_SUBJECT)) |
| 221 | + .flatMap(sentenceClauses) |
| 222 | + return clauses.flatMap((clause) => |
| 223 | + [...clause.matchAll(COUNT_CLAIM)].filter((match) => { |
| 224 | + const before = clause.slice(0, match.index) |
| 225 | + const owner = POSSESSIVE_OWNER.exec(before)?.[1] |
| 226 | + return SIM_NAME.test(before) && (owner === undefined || owner === 'Sim') |
| 227 | + }) |
| 228 | + ) |
| 229 | +} |
| 230 | + |
| 231 | +/** The counts on one line of text that belong to Sim, with the claim as written. */ |
| 232 | +function simCountClaims(line: string): { claim: string; count: number; unit: SimCountUnit }[] { |
| 233 | + const text = line.replace(INLINE_MARKERS, '').replace(LINK_TEXT, '$1') |
| 234 | + const cells = text.split('|') |
| 235 | + const matches = cells.length > 2 ? simTableRowCounts(cells) : simProseCounts(text) |
| 236 | + return matches.map((match) => ({ |
| 237 | + claim: match[0], |
| 238 | + count: Number.parseInt(match[1].replaceAll(',', ''), 10), |
| 239 | + unit: match[2].toLowerCase() as SimCountUnit, |
| 240 | + })) |
170 | 241 | } |
171 | 242 |
|
172 | 243 | function isSection(value: string): value is Section { |
@@ -458,7 +529,7 @@ export async function checkPost( |
458 | 529 | count > total |
459 | 530 | ? `"${claim}" overstates Sim's catalog, which has ${total} ${unit}.` |
460 | 531 | : `"${claim}" is stale: Sim's catalog has ${total} ${unit}.`, |
461 | | - `Write ${formatLowerBound(total)} ${unit}, the catalog-derived figure (INTEGRATION_TOTALS in packages/deployment-config/src/integration-totals.ts).` |
| 532 | + `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.` |
462 | 533 | ) |
463 | 534 | } |
464 | 535 | } |
|
0 commit comments