コード例 #1
0
ファイル: item.php プロジェクト: antoniomachine/bigml-php
 public function matches()
 {
     /*
     Checks whether the value is in a range for numeric fields or
     matches a category for categorical fields.
     */
     $field_type = $this->field_info->optype;
     if (is_null($value)) {
         return is_null($this->name);
     }
     if ($field_type == "numeric" and (!is_null($this->bin_end) or is_null($this->bin_start))) {
         $result = ($this->bin_start <= $value) <= $this->bin_end;
         if (!is_null($this->bin_start) && !is_null($this->bin_end)) {
             $result = ($this->bin_start <= $value) <= $this->bin_end;
         } else {
             if (!is_null($this->bin_end)) {
                 $result = $value <= $this->bin_end;
             } else {
                 $result = $value >= $this->bin_start;
             }
         }
     } else {
         if ($field_type == "categorical") {
             $result = $this->name == $value;
         } else {
             if ($field_type = "text") {
                 $all_forms = array_key_exists("term_forms", $this->field_info->summary) ? $this->field_info->summary : array();
                 $term_forms = array_key_exists($this->name, $all_forms) ? $all_forms->{$this->name} : array();
                 $terms = array_merge(array($this->name), $term_forms);
                 $options = $this->field_info->term_analysis;
                 $result = term_matches($value, $terms, $options) > 0;
             } else {
                 if ($field_type = "items") {
                     $options = $this->field_info->term_analysis;
                 }
             }
         }
     }
     if ($this->complement) {
         $result = !$result;
     }
     return $result;
 }
コード例 #2
0
 function apply($input_data, $fields)
 {
     /*
        Applies the operators defined in the predicate as strings toi the provided input data
     */
     // for missing operators
     if (!array_key_exists($this->field, $input_data)) {
         // text and item fields will treat missing values by following the
         // doesn't contain branch
         if (is_null($this->term)) {
             return $this->missing || $this->operator == '=' && is_null($this->value);
         }
     } else {
         if ($this->operator == "!=" && is_null($this->value)) {
             return true;
         }
     }
     $op = operatorFunction($this->operator);
     if ($this->term != null) {
         if ($fields->{$this->field}->optype == 'text') {
             $term_forms = property_exists($fields->{$this->field}->summary, 'term_forms') && !empty($fields->{$this->field}->summary->term_forms) ? property_exists($fields->{$this->field}->summary->term_forms, $this->term) ? $fields->{$this->field}->summary->term_forms->{$this->term} : array() : array();
             $terms = array($this->term);
             $terms = array_merge($terms, $term_forms);
             $options = $fields->{$this->field}->term_analysis;
             return $op(term_matches(array_key_exists($this->field, $input_data) ? $input_data[$this->field] : "", $terms, $options), $this->value);
         } else {
             $options = $fields->{$this->field}->item_analysis;
             return $op(item_matches(array_key_exists($this->field, $input_data) ? $input_data[$this->field] : "", $this->term, $options), $this->value);
         }
     }
     if ($this->operator == "in") {
         return $op($this->value, $input_data[$this->field]);
     } else {
         return $op($input_data[$this->field], $this->value);
     }
 }