Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails
WCEmailTemplateChangeSummary::similarity_score
Jaccard word-set similarity in [0.0, 1.0]. Used purely as an LCS tiebreaker, so robustness is more important than linguistic accuracy: lowercase + split on whitespace + intersect-over-union of the resulting word sets. Two empty strings score 1.0 (treated as identical).
Lowercasing goes through wc_strtolower() with an ASCII fallback), not strtolower() — the latter is ASCII-only and would leave accented / Cyrillic / Greek characters uppercase, killing word-overlap matches on translated email templates.
Метод класса: WCEmailTemplateChangeSummary{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$result = WCEmailTemplateChangeSummary::similarity_score( $a, $b ): float;
- $a(строка) (обязательный)
- First text.
- $b(строка) (обязательный)
- Second text.
Код WCEmailTemplateChangeSummary::similarity_score() WCEmailTemplateChangeSummary::similarity score WC 11.2.2
private static function similarity_score( string $a, string $b ): float {
$a = trim( $a );
$b = trim( $b );
if ( '' === $a && '' === $b ) {
return 1.0;
}
if ( '' === $a || '' === $b ) {
return 0.0;
}
$split_a = preg_split( '/\s+/', wc_strtolower( $a ), -1, PREG_SPLIT_NO_EMPTY );
$split_b = preg_split( '/\s+/', wc_strtolower( $b ), -1, PREG_SPLIT_NO_EMPTY );
$words_a = array_unique( false === $split_a ? array() : $split_a );
$words_b = array_unique( false === $split_b ? array() : $split_b );
if ( empty( $words_a ) && empty( $words_b ) ) {
return 1.0;
}
$intersect = count( array_intersect( $words_a, $words_b ) );
$union = count( array_unique( array_merge( $words_a, $words_b ) ) );
return $union > 0 ? $intersect / $union : 0.0;
}