コード例 #1
0
 private function initialize_replysets($replysets, AfsQuery $query, AfsHelperConfiguration $config)
 {
     foreach ($replysets as $replyset) {
         if (property_exists($replyset, 'meta') && property_exists($replyset->meta, 'producer')) {
             $producer = $replyset->meta->producer;
             if ($producer == AfsProducer::SEARCH) {
                 if ('Promote' == $replyset->meta->uri) {
                     $this->promote = new AfsPromoteReplysetHelper($replyset, $this->config);
                 } else {
                     $replyset_helper = new AfsReplysetHelper($replyset, $query, $config);
                     $feed = $replyset_helper->get_meta()->get_feed();
                     if ($config->is_array_format()) {
                         $this->replysets[$feed] = $replyset_helper->format();
                     } else {
                         $this->replysets[$feed] = $replyset_helper;
                     }
                 }
             } elseif ($producer == AfsProducer::SPELLCHECK) {
                 $this->spellcheck_mgr->add_spellcheck($replyset);
             } elseif ($producer == AfsProducer::CONCEPT) {
                 $this->concepts->add_concept($replyset);
             }
         }
     }
     if ($config->is_array_format()) {
         if (!is_null($this->promote)) {
             $this->promote = $this->promote->format();
         }
     }
 }
コード例 #2
0
 public function testClustering()
 {
     $input = $this->get_cluster_input_data();
     $config = new AfsHelperConfiguration();
     $query = new AfsQuery();
     $helper = new AfsReplysetHelper($input->replySet[0], $query, $config);
     $this->assertEquals('marketing', $helper->get_meta()->get_cluster_id());
     $this->assertEquals('Marketing', $helper->get_meta()->get_cluster_label());
     $this->assertTrue($helper->has_cluster());
     # First cluster from list of clusters
     $clusters = $helper->get_clusters();
     $this->assertEquals(2, count($clusters));
     $cluster = reset($clusters);
     $this->assertEquals('"OPERATION_8"', $cluster->get_id());
     $this->assertEquals('OPERATION_8', $cluster->get_label());
     $this->assertTrue($cluster->has_reply());
     $replies = $cluster->get_replies();
     $this->assertEquals(1, count($replies));
     $this->assertEquals('166_en', $replies[0]->get_uri());
     # Second cluster from list of clusters
     $cluster = next($clusters);
     $this->assertEquals('"OPERATION_9"', $cluster->get_id());
     $this->assertEquals('5% sur les produtis textiles de plus de 100 euros', $cluster->get_label());
     $this->assertTrue($cluster->has_reply());
     $replies = $cluster->get_replies();
     $this->assertEquals(1, count($replies));
     $this->assertEquals('112_fr', $replies[0]->get_uri());
     # Overspill
     $this->assertTrue($helper->has_reply());
     $replies = $helper->get_replies();
     $this->assertEquals(1, count($replies));
     $reply = reset($replies);
     $this->assertEquals('165_en', $reply->get_uri());
     # Merge replies from all cluster replies
     $replies = $helper->get_cluster_replies();
     $this->assertEquals(2, count($replies));
     $this->assertEquals('166_en', $replies[0]->get_uri());
     $this->assertEquals('112_fr', $replies[1]->get_uri());
     # Merge all replies: cluster replies and overspill
     $replies = $helper->get_all_replies();
     $this->assertEquals(3, count($replies));
     $this->assertEquals('166_en', $replies[0]->get_uri());
     $this->assertEquals('112_fr', $replies[1]->get_uri());
     $this->assertEquals('165_en', $replies[2]->get_uri());
 }