get_id() ); } /** * {@inheritDoc} */ public function run( WC_Product $product ) { $result = $this->result(); $raw = (string) $product->get_description(); $text = trim( wp_strip_all_tags( $raw ) ); if ( '' === $text ) { $result->set_score( 0.0 ); $result->add_issue( 'empty_description', __( 'No long description — agents have no factual text to read.', 'agentictrack-agent-readiness-for-woocommerce' ), ARWC_Check_Result::SEVERITY_CRITICAL ); return $result; } $word_count = $this->count_words( $text ); // 1) Length sub-score: ramps to full marks around 50 words. $length_score = min( 1.0, $word_count / 50 ); // 2) Factual sub-score: presence of spec-like signals (numbers + units). $has_specs = $this->has_factual_signals( $text ); $factual_score = $has_specs ? 1.0 : 0.0; // 3) Fluff penalty: ratio of marketing words to total words. $fluff_ratio = $this->fluff_ratio( $text, $word_count ); $fluff_score = max( 0.0, 1.0 - ( $fluff_ratio * 8 ) ); // ~12.5% fluff zeroes it. // Weighted blend of the three sub-scores. $score = ( $length_score * 0.4 ) + ( $factual_score * 0.4 ) + ( $fluff_score * 0.2 ); $result->set_score( $score ); if ( $word_count < 30 ) { $result->add_issue( 'thin_description', sprintf( /* translators: %d: word count of the description. */ __( 'Thin description (%d words) — add specifications and factual detail.', 'agentictrack-agent-readiness-for-woocommerce' ), (int) $word_count ), ARWC_Check_Result::SEVERITY_WARNING ); } if ( ! $has_specs ) { $result->add_issue( 'no_specs_in_description', __( 'Description has no measurable specs (numbers with units) — agents prefer concrete facts.', 'agentictrack-agent-readiness-for-woocommerce' ), ARWC_Check_Result::SEVERITY_WARNING ); } if ( $fluff_ratio >= 0.06 ) { $result->add_issue( 'marketing_heavy_description', __( 'Description is marketing-heavy — replace superlatives with factual attributes.', 'agentictrack-agent-readiness-for-woocommerce' ), ARWC_Check_Result::SEVERITY_INFO ); } return $result; } /** * Count words in a plain-text string (multibyte-safe-ish). * * @param string $text Plain text. * @return int */ protected function count_words( $text ) { $parts = preg_split( '/\s+/', trim( $text ), -1, PREG_SPLIT_NO_EMPTY ); return is_array( $parts ) ? count( $parts ) : 0; } /** * Detect factual/spec signals: a number adjacent to a unit, or generally a * reasonable density of numeric tokens. * * @param string $text Plain text. * @return bool */ protected function has_factual_signals( $text ) { $units = 'mm|cm|m|km|in|inch|inches|ft|"|kg|g|mg|lb|lbs|oz|ml|l|liter|litre|gal|w|kw|v|hz|mah|gb|tb|mb|mp|px|ppi|dpi|%|°|°c|°f'; if ( preg_match( '/\b\d+(?:[.,]\d+)?\s?(?:' . $units . ')\b/i', $text ) ) { return true; } // Fallback: at least two distinct numeric tokens suggests some specs. return preg_match_all( '/\b\d+(?:[.,]\d+)?\b/', $text ) >= 2; } /** * Ratio of marketing/fluff words to total words. * * @param string $text Plain text. * @param int $word_count Pre-computed word count. * @return float */ protected function fluff_ratio( $text, $word_count ) { if ( $word_count <= 0 ) { return 0.0; } $lower = function_exists( 'mb_strtolower' ) ? mb_strtolower( $text ) : strtolower( $text ); $hits = 0; foreach ( $this->fluff_words as $word ) { $hits += substr_count( $lower, $word ); } return $hits / $word_count; } }