Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails

WCEmailTemplateChangeSummary::similarity_scoreprivate staticWC 1.0

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.

Method of the class: WCEmailTemplateChangeSummary{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = WCEmailTemplateChangeSummary::similarity_score( $a, $b ): float;
$a(string) (required)
First text.
$b(string) (required)
Second text.

WCEmailTemplateChangeSummary::similarity_score() code WC 10.9.1

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;
}