|
35 | 35 | * "1,000+ integrations" or a figure left from an older catalog spreads to third-party sites. |
36 | 36 | * A count belongs to Sim when "Sim" comes before it in the same clause and no other product's |
37 | 37 | * possessive directly precedes it, or when it sits in a table row whose label cell is Sim. |
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. |
| 38 | + * A comparison that opens a sentence or names a new subject ("while Zapier", "Zapier, like |
| 39 | + * Sim,") is its own clause up to the next comma, and the main clause resumes after it; ", and" |
| 40 | + * before a capitalized word also starts a new clause. |
40 | 41 | * A count whose owner is ambiguous within its clause is treated as Sim's; when it belongs to |
41 | 42 | * another product, name that product as its owner ("Zapier's 9,000+") or give it a sentence. |
42 | 43 | * Blog and changelog posts are dated, so their counts are true as of publication. |
@@ -149,24 +150,32 @@ const LINE_PREFIX = /^\s*(?:(?:[-*+>]|\d+[.)]|#{1,6})\s+)*(?:\w+:\s*["'])?/ |
149 | 150 | const SIM_NAME = /\bSim\b/ |
150 | 151 | /** Words that turn a sentence toward another product: "while Zapier lists ...", "unlike Zapier". */ |
151 | 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\.?)` |
152 | 155 | /** Sentence punctuation, with any closing quote or bracket, before whitespace. */ |
153 | 156 | const SENTENCE_END = /(?<=[.!?;]['"”’)\]]*)\s+/ |
| 157 | +/** ", and" before a capitalized word, which starts a clause with its own subject. */ |
| 158 | +const NEW_SUBJECT = /,\s+and\s+(?=[A-Z])/ |
154 | 159 | /** |
155 | | - * Where a comparison clause starts: a contrast word, or "like" when it opens the sentence or |
156 | | - * follows a comma ("Like Sim, ...", "Zapier, like Sim, ..."), but not "tools like Slack". |
| 160 | + * Where a comparison clause starts: a sentence-opening contrast ("Unlike Sim, ..."), or a contrast |
| 161 | + * followed by a capitalized word, the new subject ("..., while Zapier", "Zapier, like Sim, ..."). |
| 162 | + * A contrast that keeps the subject ("open source but has ...") does not start one. |
157 | 163 | */ |
158 | 164 | const COMPARISON_START = new RegExp( |
159 | | - String.raw`(?:^|,\s*|\s+)(?=${CONTRAST}\b)|(?:^|,\s*)(?=like\b)`, |
160 | | - 'i' |
| 165 | + String.raw`^(?=${OPENING_CONTRAST}\b)|,\s*(?=(?:like|${CONTRAST})\s+[A-Z])|\s+(?=${CONTRAST}\s+[A-Z])` |
161 | 166 | ) |
| 167 | +/** A count continuing a list ("..., 9,000+ actions, and 530+ triggers, ..."), not a new clause. */ |
| 168 | +const COUNT_LIST_ITEM = String.raw`(?:and\s+)?\d[\d,]*\+?\s+(?:integrations|actions|triggers)\b\s*(?:,|and\b|$)` |
162 | 169 | /** |
163 | 170 | * Where a comparison clause ends: the first comma that is not a thousands separator, not the |
164 | 171 | * 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"). |
| 172 | + * not the next item in a list of counts. |
166 | 173 | */ |
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') |
| 174 | +const COMPARISON_END = new RegExp( |
| 175 | + String.raw`,(?!\d)(?!\s*(?:which|that|who)\b)(?!\s*${COUNT_LIST_ITEM})` |
| 176 | +) |
| 177 | +/** A contrast with a new subject inside a comparison clause ("..., but Zapier has ..."). */ |
| 178 | +const INNER_CONTRAST = new RegExp(String.raw`,?\s+(?=${CONTRAST}\s+[A-Z])`) |
170 | 179 | /** The product whose possessive directly precedes a count, as in "Zapier's 9,000+". */ |
171 | 180 | const POSSESSIVE_OWNER = /([\w.-]+)['’]s\s*$/ |
172 | 181 | /** A Sim count below this share of the catalog total is left from an older catalog. */ |
@@ -200,7 +209,11 @@ function sentenceClauses(sentence: string): string[] { |
200 | 209 |
|
201 | 210 | /** Each count whose clause names Sim before it, unless another product's possessive owns it. */ |
202 | 211 | function simProseCounts(text: string): RegExpMatchArray[] { |
203 | | - const clauses = text.replace(LINE_PREFIX, '').split(SENTENCE_END).flatMap(sentenceClauses) |
| 212 | + const clauses = text |
| 213 | + .replace(LINE_PREFIX, '') |
| 214 | + .split(SENTENCE_END) |
| 215 | + .flatMap((sentence) => sentence.split(NEW_SUBJECT)) |
| 216 | + .flatMap(sentenceClauses) |
204 | 217 | return clauses.flatMap((clause) => |
205 | 218 | [...clause.matchAll(COUNT_CLAIM)].filter((match) => { |
206 | 219 | const before = clause.slice(0, match.index) |
|
0 commit comments