wp_aisl_queue class AISL_Clustering { const THRESHOLD = 0.75; public static function assign_clusters() { global $wpdb; $rows = $wpdb->get_results("SELECT post_id, embedding FROM {$wpdb->prefix}aisl_embeddings"); foreach ($rows as $rowA) { $vecA = json_decode($rowA->embedding, true); $cluster = []; foreach ($rows as $rowB) { if ($rowA->post_id == $rowB->post_id) continue; $vecB = json_decode($rowB->embedding, true); $score = AISL_Similarity::cosine($vecA, $vecB); if ($score >= self::THRESHOLD) { $cluster[] = $rowB->post_id; } } update_post_meta($rowA->post_id, '_aisl_cluster', json_encode($cluster)); } } } class AISL_Equity { public static function calculate() { $posts = get_posts(['numberposts' => -1]); foreach ($posts as $post) { $inbound = self::count_inbound($post->ID); $outbound = self::count_outbound($post->post_content); $score = ($inbound * 2) - ($outbound * 0.5); update_post_meta($post->ID, '_aisl_equity_score', $score); } } private static function count_inbound($post_id) { global $wpdb; $url = get_permalink($post_id); return $wpdb->get_var($wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_content LIKE %s", '%' . $wpdb->esc_like($url) . '%' )); } private static function count_outbound($content) { preg_match_all('/ 'POST', 'callback' => ['AISL_Embedding_Processor', 'run_batch'], 'permission_callback' => function () { return current_user_can('manage_options'); } ]); }); Richard – Page 100 – Geek Rewind
Concrete CMS featured image

Author: Richard

Exit mobile version