/**
  * 預設計算關係度的方法
  * @param Annotation $annotation
  * @return Output_language_variable_collection
  */
 protected function _get_membership_default(Annotation $annotation)
 {
     //請由子類別來覆寫此方法
     $speech_array = $this->get_feature($annotation);
     $this->_CI_load('library', 'fuzzy/Output_language_variable_collection', 'output_language_variable_collection');
     $membership = new Output_language_variable_collection();
     $this->CI->config->load('kals');
     $membership_function_variables = $this->CI->config->item($this->name . '.membership_function_variables');
     $membership->set_memberships(array(1, 0, 0));
     foreach ($membership_function_variables as $speech => $ms_var) {
         if (in_array($speech, $speech_array)) {
             $var = $membership_function_variables[$speech];
             $membership->set_memberships($var);
             break;
         }
     }
     return $membership;
 }
 /**
  * 預設計算關係度的方法
  * @param Annotation $annotation
  * @return Output_language_variable_collection
  */
 protected function _get_membership_default(Annotation $annotation)
 {
     $location_array = $this->get_feature($annotation);
     $this->_CI_load('library', 'fuzzy/Output_language_variable_collection', 'output_language_variable_collection');
     $membership = new Output_language_variable_collection();
     $this->CI->config->load('kals');
     $membership_function_variables = $this->CI->config->item($this->name . '.membership_function_variables');
     $membership->set_memberships(array(1, 0, 0));
     if (is_null($location_array)) {
         return $menbership;
     }
     //test_msg('lang location ', array(count($location_array), $location_array[0], is_array($location_array)));
     foreach ($membership_function_variables as $location_id => $ms_var) {
         if (in_array($location_id, $location_array) === TRUE) {
             $membership->set_memberships($ms_var);
             break;
         }
     }
     return $membership;
 }
Example #3
0
 /**
  * 產生提示文字
  * @return String
  */
 public function _produce_tip_text()
 {
     //langvar.speech.tip.recommend_by_threshold
     $threshold = $this->CI->config->item('langvar.' . $this->langvar_name . '.tip.recommend_by_threshold');
     $membership_function = $this->_get_membership_function();
     $anchor_speech = $this->annotation->get_anchor_speech();
     $this->_CI_load('library', 'fuzzy/Output_language_variable_collection');
     $tip_text_header = $this->name . '.';
     $recommend_langs = array();
     foreach ($membership_function as $speech => $ms) {
         if (FALSE === in_array($speech, $anchor_speech)) {
             //先計算是否高過recommend_by_threshold
             $ms_langcoll = new Output_language_variable_collection();
             $ms_langcoll->set_memberships($ms);
             $score = $ms_langcoll->get_defuzzy_code();
             $lang = $this->lang->line($tip_text_header . $speech);
             //test_msg($score, array($this->langvar_name.'.tip.recommend_by_threshold', $lang, $threshold, ($score < $threshold)));
             if ($score < $threshold) {
                 break;
             }
             if (FALSE === $lang) {
                 continue;
             }
             $recommend_langs[] = $lang;
             if (count($recommend_langs) > 4) {
                 break;
             }
         }
     }
     $recommend = '';
     foreach ($recommend_langs as $lang) {
         if ($recommend != '') {
             $recommend .= $this->lang->line('tip.comma');
         }
         $recommend .= $lang;
     }
     $text = $this->lang->line($this->name . '.text', $recommend);
     return $text;
 }
Example #4
0
 /**
  * 預設計算關係度的方法
  * @param Annotation $annotation
  * @return Output_language_variable_collection
  */
 protected function _get_membership_default(Annotation $annotation)
 {
     //請由子類別來覆寫此方法
     $feature = $this->get_feature($annotation);
     $this->_CI_load('library', 'fuzzy/Output_language_variable_collection', 'output_language_variable_collection');
     $membership = new Output_language_variable_collection();
     $this->CI->config->load('kals');
     $membership_function_variables = $this->CI->config->item($this->name . '.membership_function_variables');
     if ($this->nominal_feature) {
         $var = $membership_function_variables['default'];
         if (isset($membership_function_variables[$feature])) {
             $var = $membership_function_variables[$feature];
         }
         //if ($annotation->get_id() == 2363)
         //    test_msg(array(json_encode ($var), $feature, $this->name, 'default'));
         //if ($this->type_id == 6)
         //    test_msg('有找到membership function嗎?', array($annotation->get_id(), isset($membership_function_variables[$feature]), $feature));
         $membership->set_memberships($var);
     } else {
         //if ($annotation->get_id() == 2348 && $this->name == 'langvar.like')
         //    test_msg(json_encode($membership_function_variables));
         foreach ($membership_function_variables as $key => $ms_var) {
             //if ($annotation->get_id() == 2348 && $this->name == 'langvar.like')
             //    test_msg(array($feature, $key, ($feature <= $key), ($key === 'default')));
             if ($feature <= $key) {
                 $var = $membership_function_variables[$key];
                 //if ($annotation->get_id() == 2348 && $this->name == 'langvar.like')
                 //    test_msg(array($feature, json_encode ($var), $key, $this->name));
                 $membership->set_memberships($var);
                 break;
             }
             if ($key === 'default') {
                 $var = $membership_function_variables[$key];
                 //if ($annotation->get_id() == 2348 && $this->name == 'langvar.like')
                 //    test_msg(array($feature, json_encode ($var), $key, $this->name, 'default'));
                 $membership->set_memberships($var);
                 break;
             }
         }
     }
     return $membership;
 }