@@ -149,17 +149,24 @@ const SIM_NAME = /\bSim\b/
149149/** Words that turn a sentence toward another product: "while Zapier lists ...", "unlike Zapier". */
150150const CONTRAST = String . raw `(?:while|whereas|but|unlike|compared (?:with|to)|versus|vs\.?)`
151151/**
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.
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 ends at the first comma that is not a
154+ * thousands separator, and it is kept when a relative clause follows ("unlike Zapier, which has").
154155 */
155- const SIM_PARENTHETICAL = new RegExp (
156- String . raw `\bSim ,\s+(?:like|${ CONTRAST } )\s+(?:[^,]|,(?=\d))*?,(?!\d)` ,
156+ const PARENTHETICAL_COMPARISON = new RegExp (
157+ String . raw `,\s+(?:like|${ CONTRAST } )\s+(?:[^,]|,(?=\d))*?,(?!\d)(?!\s*(?:which|that|who)\b )` ,
157158 'gi'
158159)
159160/** A sentence end, or a contrast that hands the rest of the sentence to another subject. */
160161const CLAUSE_BREAK = new RegExp ( String . raw `(?<=[.!?;])\s+|,?\s+${ CONTRAST } \s+` , 'i' )
161- /** An opening comparison ("Unlike Sim, ...") whose main clause is about another product. */
162- const LEADING_COMPARISON = new RegExp ( String . raw `^(?:like|${ CONTRAST } )\b[^,]*,\s*` , 'i' )
162+ /**
163+ * An opening comparison ("Unlike Sim, ...") whose main clause is about another product. An opener
164+ * that states a count of its own ("While Sim has 280+ integrations, ...") is kept.
165+ */
166+ const LEADING_COMPARISON = new RegExp (
167+ String . raw `^(?:like|${ CONTRAST } )\b(?:[^,]|,(?=\d))*?,(?!\d)\s*` ,
168+ 'i'
169+ )
163170/** The product whose possessive directly precedes a count, as in "Zapier's 9,000+". */
164171const POSSESSIVE_OWNER = / ( [ \w . - ] + ) [ ' ’ ] s \s * $ /
165172/** A Sim count below this share of the catalog total is left from an older catalog. */
@@ -177,10 +184,14 @@ function simTableRowCounts(cells: string[]): RegExpMatchArray[] {
177184function simProseCounts ( text : string ) : RegExpMatchArray [ ] {
178185 const sentences = text
179186 . replace ( LINE_PREFIX , '' )
180- . replace ( SIM_PARENTHETICAL , 'Sim ' )
187+ . replace ( PARENTHETICAL_COMPARISON , '' )
181188 . split ( CLAUSE_BREAK )
182189 return sentences . flatMap ( ( sentence ) => {
183- const clause = sentence . replace ( LEADING_COMPARISON , '' )
190+ const opener = LEADING_COMPARISON . exec ( sentence ) ?. [ 0 ]
191+ const clause =
192+ opener !== undefined && opener . match ( COUNT_CLAIM ) === null
193+ ? sentence . slice ( opener . length )
194+ : sentence
184195 return [ ...clause . matchAll ( COUNT_CLAIM ) ] . filter ( ( match ) => {
185196 const before = clause . slice ( 0 , match . index )
186197 const owner = POSSESSIVE_OWNER . exec ( before ) ?. [ 1 ]
0 commit comments