Example #1
0
 protected function renew_function_variables()
 {
     //這邊請用k-means來做
     $this->_CI_load('library', 'kals_resource/Webpage', 'webpage');
     $function_variables = NULL;
     $webpage_id = intval($this->get_field('webpage_id'));
     $webpage = new Webpage($webpage_id);
     $annotation_coll = $webpage->get_appended_annotation();
     //標註數量太少的話就沒有分群的價值,取消分群
     if ($annotation_coll->length() < 20) {
         return $this;
     }
     $data = array();
     foreach ($annotation_coll as $annotation) {
         $data[] = $this->get_feature($annotation);
     }
     $this->_CI_load('library', 'fuzzy/Output_language_variable_collection', 'output_language_variable_collection');
     $membership = new Output_language_variable_collection();
     $number = $membership->get_number();
     $this->_CI_load('library', 'fuzzy/Clustering', 'clustering');
     $clustering = Clustering::get_clustering();
     $clustering->set_data($data);
     $clustering->set_clusters_number($number);
     $positions = $clustering->get_result_positions();
     $function_variables = '';
     foreach ($positions as $p) {
         if ($function_variables != '') {
             $function_variables .= ',';
         }
         $function_variables .= $p;
     }
     $this->set_field('function_variables', $function_variables);
     return $this;
 }